Commits

ZyX_I committed daf70bf

glog: Added support for `files' option to patch and renames commit message sections, added ignfiles :AuGlog option

  • Participants
  • Parent commits 588e356

Comments (0)

Files changed (2)

ftplugin/aurumgraphlog.vim

             \            '@/mappings': '0.0',
             \        '@/autocommands': '0.0',
             \               '@/table': '0.0',
-            \                  '@/os': '0.0',})
+            \                  '@/os': '0.0',
+            \             '@/options': '0.0',})
 let s:F.glog={}
+let s:_options={
+            \'ignorefiles': {'default': [],
+            \                'checker': 'list in [patch renames diff]'},
+        \}
 "▶1 bisect :: [a], function + self → a
 function s:F.bisect(list, function)
     let llist=len(a:list)
         for [cur, old] in items(a:opts.repo.functions.getcsprop(a:opts.repo,
                     \                                           a:cs,
                     \                                           'renames'))
-            if type(old)!=type('') || (exists('files') && index(files, cur)==-1)
+            if type(old)!=type('') ||
+                        \(exists('files') &&
+                        \ !has_key(a:opts.ignorefiles, 'renames') &&
+                        \ index(files, cur)==-1)
                 continue
             endif
             let cl=len(text)
     let text+=description
     "▶3 Add patch
     if get(a:opts, 'patch', 0) && !empty(a:cs.parents)
+        let patchfiles=((exists('files') &&
+                    \    !has_key(a:opts.ignorefiles, 'patch'))?
+                    \       (files):
+                    \       ([]))
         let diff=a:opts.repo.functions.diff(a:opts.repo, a:cs.hex,
-                    \                       a:cs.parents[0], [], {})
+                    \                       a:cs.parents[0], patchfiles, a:opts)
         call map(diff, '":".v:val')
         let special.diff_R=[[len(text), 0], [len(text)+len(diff)-1, 0]]
         let text+=diff
                 \'rectangles': [],
                 \'csstarts': {},}
     for cs in a:css
-        echom cs.rev
         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,
 endfunction
 "▶2 glog.graphlog
 function s:F.glog.graphlog(repo, opts)
-    let css=reverse(a:repo.cslist[a:opts.revrange[0]:a:opts.revrange[1]-1])
+    let css=reverse(a:repo.cslist[a:opts.revs[0]:a:opts.revs[1]-1])
     let a:opts.repo=a:repo
     return s:F.glog.generate(css, [a:repo.work_hex], s:F.glog.summary, a:opts)
 endfunction
     let crrestrict=get(a:opts, 'crrestrict', 0)
     for [key, value] in filter(items(a:opts), 'crrestrict isnot# v:val[0]')
         if type(value)==type({}) || key is# 'crrestrict' || key is# 'filepats'
+                    \            || key is# 'revs'
             unlet value
             continue
         endif
     endif
     let bvar.createdlog=1
     call bvar.repo.functions.getchangesets(bvar.repo)
+    "▶2 Add `ignorefiles'
+    let ignorefiles=(has_key(bvar.opts, 'ignfiles')?
+                \               (bvar.opts.ignfiles):
+                \               (s:_f.getoption('ignorefiles')))
+    let bvar.opts.ignorefiles={}
+    call map(copy(ignorefiles), 'extend(bvar.opts.ignorefiles, {v:val : 1})')
+    unlet ignorefiles
     "▶2 Create buffer name
     if empty(bufname('%'))
         let epath=escape(bvar.repo.path, ':\')
     endif
     "▶2 Get revision range
     if has_key(bvar.opts, 'revrange')
-        call map(bvar.opts.revrange,
+        let bvar.opts.revs=map(copy(bvar.opts.revrange),
                     \'bvar.repo.changesets['.
                     \   'bvar.repo.functions.getrevhex(bvar.repo, v:val)].rev')
     elseif get(bvar.opts, 'limit', 0)>0
-        let bvar.opts.revrange=[bvar.repo.csnum-limit, -1]
+        let bvar.opts.revs=[bvar.repo.csnum-limit, -1]
     else
-        let bvar.opts.revrange=[0, bvar.repo.csnum-1]
+        let bvar.opts.revs=[0, bvar.repo.csnum-1]
     endif
     "▶2 Process `revision' option
     if has_key(bvar.opts, 'revision')
         let hex=bvar.repo.functions.getrevhex(bvar.repo, bvar.opts.revision)
         let cs=bvar.repo.changesets[hex]
-        if cs.rev<bvar.opts.revrange[1]
-            let bvar.opts.revrange[1]=cs.rev
+        if cs.rev<bvar.opts.revs[1]
+            let bvar.opts.revs[1]=cs.rev
         endif
         let bvar.opts.revisions={}
         let addrevs=[cs]
         endwhile
     endif
     "▲2
-    let cslist=bvar.repo.cslist[bvar.opts.revrange[0]:bvar.opts.revrange[1]]
+    let cslist=bvar.repo.cslist[bvar.opts.revs[0]:bvar.opts.revs[1]]
     "▶2 Generate cs.renames for `showrenames' option
     if has_key(bvar.opts, 'showrenames')
         for cs in cslist
     "▶3 diff: view diff between changeset and current state
     elseif spname is# 'diff'
         let cmd='edit '.fnameescape('aurum://diff:'.epath.'::'.hex)
+        if has_key(bvar.opts, 'files') && !has_key(bvar.opts.ignorefiles,'diff')
+            let cmd.=fnameescape(':'.join(map(copy(bvar.opts.files),
+                        \                 'escape(v:val, "\\,:;")'), ';'))
+        endif
     "▶3 other: view commit diff
     else
         let cmd='edit '.fnameescape('aurum://diff:'.epath.':'.hex)
 endfunction
 "▶3 hg.getrevhex :: repo, rev → rev(hex)
 function s:F.hg.getrevhex(repo, rev)
-    execute s:_r.py.cmd
-                \ 'vim.command(''return "''+'.
-                \    'aurum.get_repo(vim.eval("a:repo.path"))'.
-                \                             '[vim.eval("a:rev")].hex()+''"'')'
+    try
+        execute s:_r.py.cmd
+                    \ 'vim.command(''return "''+'.
+                    \    'aurum.get_repo(vim.eval("a:repo.path"))'.
+                    \                         '[vim.eval("a:rev")].hex()+''"'')'
+    endtry
 endfunction
 "▶3 hg.readfile :: repo, rev, file → [String]
 function s:F.hg.readfile(repo, rev, file)
     " XXX If more metacharacters will be supported, they must be added to 
     " escape() calls in s:F.filehistory and s:F.runmap in ftplugin/aurumannotate
     return '\V\^'.substitute(substitute(substitute(substitute(substitute(
-                \substitute(substitute(a:glob,
+                \substitute(substitute(substitute(a:glob,
                 \'\v\\(.)', '\="\\{".char2nr(submatch(1))."}"', 'g'),
+                \'\V**/',   '\\(**/\\)\\=',   'g'),
                 \'\V**',    '\\.\\\\{42}',    'g'),
                 \'\V*',     '\\\\{91}^/]\\*', 'g'),
                 \'\V?',     '\\.',            'g'),
     endif
     new
     if has_key(a:opts, 'files')
-        call map(a:opts.files, 's:_r.os.path.join('.
+        call map(a:opts.files, 'join('.
                     \          's:_r.os.path.split('.
                     \          's:_r.os.path.relpath(v:val, a:repo.path))[1:],'.
                     \               '"/")')
             \                        '|*F.comm.getrepo)'
 let s:glogfunc['@FWC']=['['.s:repoarg.']'.
             \           '{ *?files    (type "")'.
+            \           '  *?ignfiles in [patch renames diff] ~start'.
             \           '   ?date     match /\v%(\d\d?|\*)'.
             \                                 '%(\.%(\d\d?|\*)'.
             \                                 '%(\.%(\d\d%(\d\d)?|\*)'.
             call insert(closedfolds, line)
         endif
     endfor
-    echom string(closedfolds)
     execute 'diffsplit' fnameescape(a:difftarget)
     let bvar.diffbuf=bufnr('%')
     augroup AurumDiff