Commits

ZyX_I committed aab598a

Added some options support to AuGlog and aurum://glog, fixed some bugs introduced in previous commit

  • Participants
  • Parent commits c2dad5c

Comments (0)

Files changed (3)

File ftplugin/aurumgraphlog.vim

     return a:text
 endfunction
 "▶2 glog.summary
-function s:F.glog.summary(cs)
-    "▶3 Add date and changeset
+function s:F.glog.summary(cs, opts)
     let special={}
-    let date=strftime("%d %b %Y %H:%M", a:cs.time)
-    let text =  ['Changeset '.a:cs.rev.':'.a:cs.hex,
-                \'Commited '.date.' by '.a:cs.user,]
-    "▶4 Specials: changeset_l, commit_l, date_r, user_r
+    let text=[]
+    let r={'text': text, 'special': special}
+    "▶3 Add changeset (and, possibly, branch)
+    let text+=['Changeset '.a:cs.rev.':'.a:cs.hex]
     let special.changeset_l=[0, 0]
-    let special.commit_l=[1, 0]
-    let commitedlen=len('Commited ')
-    let special.date_r=[[1, commitedlen], [1, commitedlen+len(date)]]
-    let special.user_r=[[1, len(text[1])-len(a:cs.user)], [1, len(text[1])-1]]
-    "▲4
     if a:cs.branch isnot# 'default'
         let changesetend=len(text[0])
         let special.changeset_r=[[0, 0], [0, changesetend]]
         let text[0].=' (branch '.a:cs.branch.')'
         let special.branch_r=[[0, changesetend+1], [0, len(text[0])-1]]
     endif
+    "▶3 Minimize changesets that do not match opts
+    if (has_key(a:opts, 'branch') && a:cs.branch isnot# a:opts.branch) ||
+                \(has_key(a:opts, 'merges') &&
+                \   ((a:opts.merges)?(len(a:cs.parents)<=1):
+                \                    (len(a:cs.parents)>1))) ||
+                \(has_key(a:opts, 'search') &&
+                \   a:cs.description!~#a:opts.search) ||
+                \(has_key(a:opts, 'user') && a:cs.user!~#a:opts.user)
+        return r
+    endif
+    if has_key(a:opts, 'date')
+        let nums=map(split(a:opts.date, '\v[^0-9*]+'), 'v:val is# "*"? "\\d*":'.
+                    \                                                 'v:val')
+        if len(nums)>2 && len(nums[2])==2
+            let nums[2]='\d\+'.nums[2]
+        endif
+        call map(nums, 'len(v:val)==1 ? "0".v:val : v:val')
+        if strftime('%d %m %Y %H %M')!~'\m^'.join(nums)
+            return r
+        endif
+    endif
+    "▶3 Add date and user
+    let date=strftime("%d %b %Y %H:%M", a:cs.time)
+    let text+=['Commited '.date.' by '.a:cs.user]
+    "▶4 Specials: commit_l, date_r, user_r
+    let special.commit_l=[1, 0]
+    let commitedlen=stridx(text[-1], ' ')+1
+    let special.date_r=[[1, commitedlen], [1, commitedlen+len(date)]]
+    let special.user_r=[[1, len(text[1])-len(a:cs.user)], [1, len(text[1])-1]]
     "▶3 Add bookmarks and tags
     for key in filter(['bookmarks', 'tags'], '!empty(a:cs[v:val])')
         let upkey=toupper(key[0]).key[1:-2]
                     \           [len(text)+len(newtext)-1, 0]]
         let text+=newtext
     endfor
+    "▶3 Add files
+    if get(a:opts, 'showfiles', 0)
+        let curline=len(text)
+        let special.files_l=[curline, 0]
+        let text+=['Files: '.join(a:cs.files, ', ')]
+        let flens=map(copy(a:cs.files), 'len(v:val)')
+        let start=stridx(text[-1], ' ')+1
+        let i=0
+        for flen in flens
+            let special['file'.i.'_r']=[[curline, start], [curline, start+flen]]
+            let start+=flen+2
+            let i+=1
+        endfor
+    endif
     "▶3 Add description
     let description=map(split(a:cs.description, "\n", 1), '"  ".v:val')
     let special.description_R=[[len(text),                    0],
     let text+=description
     "▲3
     let text+=['']
-    return {'text': text, 'special': special}
+    return r
 endfunction
 "▶2 glog.generate
-function s:F.glog.generate(css, showparents, Dumper)
+function s:F.glog.generate(css, showparents, Dumper, opts)
     let seen=[]
     let state=[0, 0]
     let r=      {'text': [],
                 \'specials': {},
                 \'rectangles': [],}
-    for cs in a:css
-        let char=((has_key(a:showparents, cs.hex))?('@'):('o'))
-        let text=call(a:Dumper, [cs], {})
+    let revs=get(a:opts, 'rev', [0, get(a:opts, 'limit', 0)-1])
+    for cs in a:css[revs[0]:revs[1]]
+        let char=((index(a:showparents, cs.hex)==-1)?('o'):('@'))
+        let text=call(a:Dumper, [cs, a:opts], {})
         call s:F.glog.utf(state, 'C', char, text,
                     \     s:F.glog.utfedges(seen, cs.hex, cs.parents))
+        let text.block_r[0][0]+=len(r.text)
+        let text.block_r[1][0]+=len(r.text)
         let r.text+=text.text
         let r.specials[cs.hex]=text.special
         let r.rectangles+=[text.block_r+[cs.hex]]
     return r
 endfunction
 "▶2 glog.graphlog
-function s:F.glog.graphlog(repo)
+function s:F.glog.graphlog(repo, opts)
     let css=reverse(a:repo.cslist[:-2])
-    return s:F.glog.generate(css, {a:repo.work_hex: '1'}, s:F.glog.summary)
+    return s:F.glog.generate(css, [a:repo.work_hex], s:F.glog.summary, a:opts)
 endfunction
 "▶1 setup
 function s:F.setup()
     let buf=bufnr('%')
     let bvar=s:_r.aurum.bufvars[buf]
-    let text=s:F.glog.graphlog(bvar.repo)
+    let text=s:F.glog.graphlog(bvar.repo, bvar.opts)
     let bvar.specials=text.specials
     let bvar.rectangles=text.rectangles
     call setline(1, text.text)
     setlocal readonly
     call s:_f.augroup.add('AuGlog', [['InsertEnter', '<buffer='.buf.'>', 0,
                 \                     'call feedkeys("\e", "n")']])
+    " FIXME
     let b:bvar=bvar
 endfunction
 let s:filetype=expand('<sfile>:t:r')
 let s:_functions+=['s:spSort']
 "▲2
 function s:F.findCurSpecial(bvar, hex, blockstartline)
-    let specials=a:bvar.specials[a:hex]
+    let special=a:bvar.specials[a:hex]
     let line=line('.')-1-a:blockstartline
     let col=col('.')-1
-    for [spname, splist] in sort(items(specials), function('s:spSort'))
+    for [spname, splist] in sort(items(special), function('s:spSort'))
         let suffix=((spname[-2:-2] is# '_')?(spname[-1:]):('-'))
-        echom spname string(splist)
-        let r=matchstr(spname, '\v^\l+')
+        let r=matchstr(spname, '\v^\l+\d*')
         if suffix is# '-'
             if [line, col]==splist[:1]
                 return r
 function s:F.cr()
     let bvar=s:_r.aurum.bufvars[bufnr('%')]
     let [blockstart, blockend, hex]=s:F.getblock(bvar)
-    let special=s:F.findCurSpecial(bvar, hex, blockstart[0])
-    echom string(hex) string(special)
+    let spname=s:F.findCurSpecial(bvar, hex, blockstart[0])
+    echom string(hex) string(spname)
     return ''
 endfunction
 call s:_f.mapgroup.add('AuGlog', {'Enter': {'lhs': '<CR>',

File plugin/aurum.vim

                 \                      '@/os': '0.1',
                 \                  '@/python': '0.0',
                 \            '@/autocommands': '0.0',
-                \               '@/resources': '0.0',}, 0)
+                \               '@/resources': '0.0',
+                \                     '@/fwc': '0.0',}, 0)
     call map(['hg', 'comm', 'graph', 'glog'], 'extend(s:F, {v:val : {}})')
     lockvar 1 s:F
     "▶2 Команды
     call FraworLoad('@/commands')
     call FraworLoad('@/functions')
     let s:glogfunc={}
-    call s:_f.command.add('AuGlog', s:glogfunc, {'nargs': '?'})
+    let s:glogcomp=[]
+    call s:_f.command.add('AuGlog', s:glogfunc, {'nargs': '*',
+                \                                'complete': s:glogcomp})
     let s:annfunc={}
     call s:_f.command.add('AuAnnotate', s:annfunc, {'nargs': '*'})
     "▶2 Autocommands
     let d={}
     execute s:_r.py.cmd 'aurum.get_updates(vim.eval("a:repo.path"), '.
                 \                         'vim.eval("a:repo.tip_hex"))'
-    if !empty(d)
+    if empty(d)
         return a:repo
     endif
     call a:repo.functions.removechangesets(a:repo, d.startrev)
         return repo.functions.update(repo)
     endif
     let repo={'functions': s:F.hg}
-    execute s:_r.py.cmd 'aurum.new_repo(vim.eval("a:path"))'
+    try
+        execute s:_r.py.cmd 'aurum.new_repo(vim.eval("a:path"))'
+    catch
+        return 0
+    endtry
     call repo.functions.addchangesets(repo, repo.cslist)
     let repo.work=repo.changesets[repo.work_hex]
     let repo.tip=repo.changesets[repo.tip_hex]
     endif
     return s:F.hg.repo(path)
 endfunction
+"▶3 comm.globtopattern :: glob → pattern
+function s:F.comm.globtopattern(glob)
+    return '\V\^'.substitute(substitute(substitute(substitute(substitute(
+                \substitute(substitute(a:glob,
+                \'\v\\(.)', '\="\\{".char2nr(submatch(1))."}"', 'g'),
+                \'\V**',    '\\.\\\\{42}',    'g'),
+                \'\V*',     '\\\\{91}^/]\\*', 'g'),
+                \'\V?',     '\\.',            'g'),
+                \'\V[',     '\\[',            'g'),
+                \'\V\\{'.char2nr('\').'}', '\\\\', 'g'),
+                \'\V\\{\(\d\+\)}', '\=nr2char(submatch(1))', 'g').'\$'
+endfunction
 "▶3 glogfunc
-function s:glogfunc.function(...)
-    execute 'new' fnameescape('aurum://glog:'.get(a:000, 0, ''))
+function s:glogfunc.function(repo, opts)
+    new aurum://glog:no-op
+    if has_key(a:opts, 'rev')
+        call map(a:opts.rev,
+                    \'a:repo.changesets['.
+                    \   'a:repo.functions.getrevhex(a:repo, v:val)].rev')
+    endif
+    let s:bufvars[bufnr('%')]={'repo': a:repo, 'opts': a:opts}
+    setlocal buftype=nofile filetype=aurumgraphlog bufhidden=wipe
+    runtime ftplugin/aurumgraphlog.vim
 endfunction
+let s:glogfunc['@FWC']=['[:=(".")(either(path d, match @\v^\w+%(\+\w+)*\V://@)'.
+            \                    '|*F.comm.getrepo)'.
+            \           ' { *?files   (type "" |*F.comm.globtopattern)'.
+            \           '    ?date    match /\v%(\d\d?|\*)'.
+            \                                 '%(\.%(\d\d?|\*)'.
+            \                                 '%(\.%(\d\d%(\d\d)?|\*)'.
+            \                                 '%(\ %(\d\d?|\*)'.
+            \                                 '%(\:%(\d\d?|\*))?)?)?)?/'.
+            \           '    ?search  isreg'.
+            \           '  +2?rev     type "" type ""'.
+            \           '   !?merges'.
+            \           '    ?user    isreg'.
+            \           '    ?branch  type ""'.
+            \           '   !?patch'.
+            \           '    ?limit   range 1 inf'.
+            \           '   !?stat'.
+            \           '   !?showfiles}]',
+            \'filter']
+call add(s:glogcomp,
+            \substitute(substitute(s:glogfunc['@FWC'][0],
+            \'\V|*F.comm.getrepo',  '',           ''),
+            \'\vfiles\s+\([^)]*\)', 'files path', ''))
 "▶3 auefunc
 let s:bufvars={}
 "▶4 comm.repotuplesplit :: str, UInt → (repo, String, ...)
     endfor
     return [repo]+strings+[opts]
 endfunction
-"▶4 comm.globtopattern :: glob → pattern
-function s:F.comm.globtopattern(glob)
-    return '\V\^'.substitute(substitute(substitute(substitute(substitute(
-                \substitute(substitute(a:glob,
-                \'\v\\(.)', '\="\\{".char2nr(submatch(1))."}"', 'g'),
-                \'\V**',    '\\.\\\\{42}',    'g'),
-                \'\V*',     '\\\\{91}^/]\\*', 'g'),
-                \'\V?',     '\\.',            'g'),
-                \'\V[',     '\\[',            'g'),
-                \'\V\\{'.char2nr('\').'}', '\\\\', 'g'),
-                \'\V\\{\(\d\+\)}', '\=nr2char(submatch(1))', 'g').'\$'
-endfunction
 "▲4
 function s:auefunc.function()
     "▶4 Split <amatch> into command and arguments
     let tail=substitute(expand('<amatch>'), '\V\^aurum://', '', '')
     let command=matchstr(tail, '\v^\w+')
     let tail=tail[len(command)+1:]
+    if tail is# 'no-op'
+        return
+    endif
     "▶4 glog command
     if command is# 'glog'
         let [repo, opts]=s:F.comm.repotupleoptssplit(tail, 0)
         endfor
         "▶5 Filter out requested files
         call map(csfiles, 'join(s:_r.os.path.split(v:val)[1:], "/")')
-        call map(files, 'join(s:_r.os.path.split(v:val)[1:], "/")')
         let filelist=[]
         for pattern in map(split(files, '\v%(\\@<!\\%(\\\\)*)@<!,'),
                     \      's:F.comm.globtopattern(v:val)')

File syntax/aurumgraphlog.vim

     finish
 endif
 
-syn match auGlogLineStart /\v^[@o|+\-\/\\ ]+/ nextgroup=auGlogChangeset,auGlogCommit,auGlogTag,auGlogBookmark,auGlogMessage
+syn match auGlogLineStart /\v^[@o|+\-\/\\ ]+/ nextgroup=auGlogChangeset,auGlogCommit,auGlogTag,auGlogBookmark,auGlogMessage,auGlogFiles
 syn match auGlogChangeset         /Changeset / contained nextgroup=auGlogChangesetNum
 syn match auGlogChangesetNum      /\v\d+/      contained nextgroup=auGlogChangesetSep
 syn match auGlogChangesetSep      /:/          contained nextgroup=auGlogChangesetHexStart
 syn match auGlogTagSep        /, /                contained nextgroup=auGlogTagNames
 syn match auGlogTagName       /\v.*/              contained
 
+syn match auGlogFiles         /Files: /           contained nextgroup=auGlogFile
+syn match auGlogFile          /\v%(%(, )@!.)+/    contained nextgroup=auGlogFileSep
+syn match auGlogFileSep       /, /                contained nextgroup=auGlogFile
+
 hi def link auGlogChangeset         Special
 hi def link auGlogChangesetNum      Statement
 hi def link auGlogChangesetSep      Comment