Commits

ZyX_I  committed f4271c2

Added mappings to graphlog buffer, fixed children, fixed options parsing in aurum://glog

  • Participants
  • Parent commits 9cb8ed0

Comments (0)

Files changed (2)

File ftplugin/aurumgraphlog.vim

             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)
+        if strftime('%d %m %Y %H %M', a:cs.time)!~'\m^'.join(nums)
             let r.min=1
             return r
         endif
     let state=[0, 0]
     let r=      {'text': [],
                 \'specials': {},
-                \'rectangles': [],}
+                \'rectangles': [],
+                \'csstarts': {},}
     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.block_r[1][0]+=len(r.text)
             let r.specials[cs.hex]=text.special
             let r.rectangles+=[text.block_r+[cs.hex]]
+            let r.csstarts[cs.hex]=text.block_r[0][0]
         endif
         let r.text+=text.text
     endfor
     let text=s:F.glog.graphlog(bvar.repo, bvar.opts)
     let bvar.specials=text.specials
     let bvar.rectangles=text.rectangles
+    let bvar.csstarts=text.csstarts
     call setline(1, text.text)
     setlocal readonly
-    call s:_f.augroup.add('AuGlog', [['InsertEnter', '<buffer='.buf.'>', 0,
-                \                     'call feedkeys("\e", "n")']])
+    augroup AuGlogNoInsert
+        autocmd InsertEnter <buffer> :call feedkeys("\e", "n")
+    augroup END
 endfunction
+let s:_augroups+=['AuGlogNoInsert']
 let s:filetype=expand('<sfile>:t:r')
 call s:_f.augroup.add('AuGlog', [['FileType', s:filetype, 0, s:F.setup]])
 call s:F.setup()
     let special=a:bvar.specials[a:hex]
     let line=line('.')-1-a:blockstartline
     let col=col('.')-1
+    if col<len(matchstr(getline('.'), '\v^[@o|+\-/\\ ]+'))
+        return 'linestart'
+    endif
     for [spname, splist] in sort(items(special), function('s:spSort'))
         let suffix=((spname[-2:-2] is# '_')?(spname[-1:]):('-'))
         let r=matchstr(spname, '\v^\l+\d*')
     return 0
 endfunction
 "▶1 cr
-function s:F.cr()
+function s:F.cr(...)
+    "▶2 Get changeset and current special
+    let bvar=s:_r.aurum.bufvars[bufnr('%')]
+    let [blockstart, blockend, hex]=s:F.getblock(bvar)
+    if a:0
+        let spname=a:1
+    else
+        let spname=s:F.findCurSpecial(bvar, hex, blockstart[0])
+    endif
+    let epath=escape(bvar.repo.path, ':\')
+    let cs=bvar.repo.changesets[hex]
+    "▶2 Get options
+    let opts=''
+    let crrestrict=get(bvar.opts, 'crrestrict', [])
+    for [key, value] in filter(items(bvar.opts), 'crrestrict isnot# v:val[0]')
+        if key is# 'repo' || key is# 'crrestrict'
+            unlet value
+            continue
+        endif
+        let opts.=key.':'
+        if type(value)==type([])
+            let opts.=join(map(copy(value), 'escape(v:val, "\\:,;")'), ';')
+        else
+            let opts.=escape(value, '\:,')
+        endif
+        let opts.=','
+        unlet value
+    endfor
+    "▶2 Commit actions based on current special
+    "▶3 branch: add `branch' filter
+    if spname is# 'branch'
+        let cmd='edit '.fnameescape('aurum://glog:'.epath.':'.opts.
+                    \               'branch:'.cs.branch.','.
+                    \               'crrestrict:branch')
+    "▶3 user: add `user' filter
+    elseif spname is# 'user'
+        let cmd='edit '.fnameescape('aurum://glog:'.epath.':'.opts.
+                    \               'user:\V'.escape(escape(cs.user, '\:,'),
+                    \                                '\').','.
+                    \               'crrestrict:user')
+    "▶3 date: add `date' filter (only show commits done in the current month)
+    elseif spname is# 'date'
+        let cmd='edit '.fnameescape('aurum://glog:'.epath.':'.opts.
+                    \               'date:'.strftime('*\:%m\:%Y', cs.time).','.
+                    \               'crrestrict:date')
+    "▶3 file: view file
+    elseif spname=~#'\v^file\d+$'
+        let file=cs.files[+spname[4:]]
+        let cmd='edit '.fnameescape('aurum://file:'.epath.':'.hex.':'.file)
+    "▶3 other: view commit diff
+    else
+        let cmd='edit '.fnameescape('aurum://diff:'.epath.':'.hex)
+    endif
+    "▲3
+    return ':'.cmd."\n"
+endfunction
+"▶1 gethexfile
+function s:F.gethexfile()
     let bvar=s:_r.aurum.bufvars[bufnr('%')]
     let [blockstart, blockend, hex]=s:F.getblock(bvar)
     let spname=s:F.findCurSpecial(bvar, hex, blockstart[0])
-    echom string(hex) string(spname)
+    let cs=bvar.repo.changesets[hex]
+    if spname=~#'\v^file\d+$'
+        let file=cs.files[+spname[4:]]
+    elseif !empty(cs.files)
+        if len(cs.files)==1
+            let file=cs.files[0]
+        else
+            let file=cs.files[inputlist(['Select file:']+
+                        \               map(copy(cs.files),
+                        \                   '(v:key+1).". ".v:val'))-1]
+        endif
+    endif
+    return [hex, exists('file') ? file : 0]
+endfunction
+"▶1 open
+function s:F.open()
+    let [hex, file]=s:F.gethexfile()
+    let bvar=s:_r.aurum.bufvars[bufnr('%')]
+    let epath=escape(bvar.repo.path, ':\')
+    if file isnot 0
+        return ':edit '.fnameescape('aurum://file:'.epath.':'.hex.':'.file)."\n"
+    endif
     return ''
 endfunction
-call s:_f.mapgroup.add('AuGlog', {'Enter': {'lhs': '<CR>',
-            \                               'rhs': s:F.cr,}},)
+"▶1 vimdiff
+function s:F.vimdiff()
+    let [hex, file]=s:F.gethexfile()
+    let bvar=s:_r.aurum.bufvars[bufnr('%')]
+    let cs=bvar.repo.changesets[hex]
+    if !empty(cs.parents)
+        let epath=escape(bvar.repo.path, ':\')
+        return ':e '.fnameescape('aurum://file:'.epath.':'.hex.':'.file)."\n".
+                    \':diffsplit '.fnameescape('aurum://file:'.epath.':'.
+                    \                          cs.parents[0].hex.':'.file)."\n"
+    endif
+    return ''
+endfunction
+"▶1 next
+function s:F.next()
+    let bvar=s:_r.aurum.bufvars[bufnr('%')]
+    let [blockstart, blockend, hex]=s:F.getblock(bvar)
+    let child=get(bvar.repo.changesets[hex].children, 0, 0)
+    if child isnot 0
+        return (bvar.csstarts[child.hex]+1).'gg'
+    endif
+    return ''
+endfunction
+"▶1 prev
+function s:F.prev()
+    let bvar=s:_r.aurum.bufvars[bufnr('%')]
+    let [blockstart, blockend, hex]=s:F.getblock(bvar)
+    let parent=get(bvar.repo.changesets[hex].parents, 0, 0)
+    if parent isnot 0
+        return (bvar.csstarts[parent.hex]+1).'gg'
+    endif
+    return ''
+endfunction
+"▶1 AuGlog mapping group
+call s:_f.mapgroup.add('AuGlog', {'Enter': {'lhs': '<CR>', 'rhs': [],},
+            \                     'Diff':  {'lhs': 'd', 'rhs': ['diff']},
+            \                     'Open':  {'lhs': 'o', 'rhs': s:F.open},
+            \                     'VDiff': {'lhs': 'D', 'rhs': s:F.vimdiff},
+            \                     'Next':  {'lhs': 'K', 'rhs': s:F.next},
+            \                     'Prev':  {'lhs': 'J', 'rhs': s:F.prev},},
+            \          {'func': s:F.cr})
 "▶1
 execute frawor#Lockvar(s:, '_r')

File plugin/aurum.vim

     for cs in a:css
         call map(cs.parents, 'a:repo.changesets[v:val]')
         for parent in cs.parents
-            call add(a:repo.changesets[parent.hex].children, parent)
+            call add(a:repo.changesets[parent.hex].children, cs)
         endfor
     endfor
 endfunction
         if colonidx==-1
             continue
         endif
-        let opts[o[:(colonidx-1)]]=o[(colonidx+1):]
+        let opts[o[:(colonidx-1)]]=substitute(o[(colonidx+1):],
+                    \                         '\v\\([:,\\])', '\1', 'g')
     endfor
     return [repo]+strings+[opts]
 endfunction
     if tail is# 'no-op'
         return
     endif
-    "▶4 glog command
+    "▶4 glog command (repo:opts)
     if command is# 'glog'
         let [repo, opts]=s:F.comm.repotupleoptssplit(tail, 0)
+        if has_key(opts, 'files')
+            let opts.files=map(split(opts.files, '\v%(\\@<!\\%(\\\\)*)@<!;'),
+                        \            's:F.comm.globtopattern(v:val)')
+        endif
+        if has_key(opts, 'rev')
+            let opts.rev=split(opts.rev, ';')
+        endif
+        for key in filter(['merges', 'patch', 'limit', 'stat', 'showfiles'],
+                    \     'has_key(opts, v:val)')
+            let opts[key]=+opts[key]
+        endfor
         let s:bufvars[bufnr('%')]={'repo': repo, 'opts': opts}
         setlocal buftype=nofile filetype=aurumgraphlog bufhidden=wipe
         runtime ftplugin/aurumgraphlog.vim
-    "▶4 file command
+    "▶4 file command (repo:rev:file)
     elseif command is# 'file'
         let [repo, rev, file]=s:F.comm.repotuplesplit(tail, 2)
         setlocal buftype=nofile
             setlocal binary noendofline
         endif
         call setline('.', fcontents)
-    "▶4 annotate command
+    "▶4 annotate command (repo:rev:file)
     elseif command is# 'annotate'
         let [repo, rev, file]=s:F.comm.repotuplesplit(tail, 2)
         let s:bufvars[bufnr('%')]={'repo': repo, 'rev': rev, 'file': file}
         setlocal buftype=nofile filetype=aurumannotate bufhidden=wipe
         runtime ftplugin/aurumannotate.vim
-    "▶4 diff command
+    "▶4 diff command (repo:rev1:rev2:files:opts)
     elseif command is# 'diff'
         let [repo, rev1, rev2, files, opts]=s:F.comm.repotupleoptssplit(tail, 3)
         "▶5 Get revisions and file list