1. ZyX_I
  2. aurum

Commits

ZyX_I  committed e4a96ba

Added :AuDiff command
Fixed `files' option support in glog mappings
Fixed accident modification of diffoptslst
Removed additional empty line at the end of aurum://diff buffer

  • Participants
  • Parent commits 865583b
  • Branches default

Comments (0)

Files changed (8)

File ftplugin/aurumgraphlog.vim

View file
  • Ignore whitespace
     elseif spname is# 'curdiff'
         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),
+            let cmd.=fnameescape(':'.join(map(copy(bvar.opts.csfiles[hex]),
                         \                 'escape(v:val, "\\:;")'), ';'))
         endif
     "▶3 other: view commit diff
     else
-        let cmd='edit '.fnameescape('aurum://diff:'.epath.':'.hex)
+        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.csfiles[hex]),
+                        \                 'escape(v:val, "\\:;")'), ';'))
+        endif
     endif
     "▲3
     return s:F.cwin().":".cmd."\n"
         if len(cs.files)==1
             let file=cs.files[0]
         else
+            if has_key(bvar.opts, 'files') &&
+                        \!has_key(bvar.opts.ignorefiles, 'diff')
+                let files=copy(bvar.opts.csfiles[hex])
+                call filter(files, 'index(cs.files, v:val)!=-1')
+            else
+                let files=copy(cs.files)
+            endif
             let choice=inputlist(['Select file (0 to cancel):']+
-                        \               map(copy(cs.files),
-                        \                   '(v:key+1).". ".v:val'))
+                        \        map(files, '(v:key+1).". ".v:val'))
             if choice
                 let file=cs.files[choice-1]
             endif

File plugin/aurum.vim

View file
  • Ignore whitespace
     let s:vimdcomp=[]
     call s:_f.command.add('AuVimDiff', s:vimdfunc, {'nargs': '*',
                 \                                'complete': s:vimdcomp})
+    let s:difffunc={}
+    let s:diffcomp=[]
+    call s:_f.command.add('AuDiff', s:difffunc, {'nargs': '*',
+                \                             'complete': s:diffcomp})
     let s:filefunc={}
     let s:filecomp=[]
     call s:_f.command.add('AuFile', s:filefunc, {'nargs': '*',
                 \                             'complete': s:filecomp})
-    " TODO Add :AuDiff
     let s:statfunc={}
     let s:statcomp=[]
     call s:_f.command.add('AuStatus', s:statfunc, {'nargs': '*',
 " XXX Some code relies on the fact that all options from s:diffoptslst are
 "     numeric
 let s:diffoptslst=keys(s:hgdiffopts)
-let s:diffoptsstr=join(map(s:diffoptslst,
+let s:diffoptsstr=join(map(copy(s:diffoptslst),
             \          'v:val is# "numlines" ? '.
             \               '" ?".v:val." range 0 inf" : '.
             \               '"!?".v:val'))
     if oldbuf!=a:buf
         execute 'buffer' a:buf
     endif
+    if len(diff)>1 && empty(diff[-1])
+        call remove(diff, -1)
+    else
+        setlocal binary noendofline
+    endif
     call setline('.', diff)
     if oldbuf!=a:buf
         execute 'buffer' oldbuf
     elseif command is# 'file'
         let [repo, rev, file]=s:F.comm.repotuplesplit(tail, 2)
         let fcontents=repo.functions.readfile(repo, rev, file)
-        if empty(fcontents[-1])
+        if len(fcontents)>1 && empty(fcontents[-1])
             call remove(fcontents, -1)
         else
             setlocal binary noendofline
     "▶3 copy command (file)
     elseif command is# 'copy'
         let fcontents=readfile(tail)
-        if empty(fcontents[-1])
+        if len(fcontents)>1 && empty(fcontents[-1])
             call remove(fcontents, -1)
         else
             setlocal binary noendofline
 call add(s:vimdcomp,
             \substitute(s:vimdfunc['@FWC'][0],
             \'\vfile\s+type\s*\V""', 'file path', ''))
+"▶2 difffunc
+function s:difffunc.function(opts, ...)
+    let repo=a:opts.repo
+    if type(repo)!=type({})
+        call s:_f.throw('nrepo')
+    endif
+    let files=map(copy(a:000), 'repo.functions.reltorepo(repo, v:val)')
+    let rev1=get(a:opts, 'rev1', '')
+    let rev2=get(a:opts, 'rev2', '')
+    "▶3 Get revisions and file list
+    if empty(rev1) && empty(rev2)
+        let rev2=repo.work_hex
+    endif
+    if !empty(rev1)
+        let rev1=repo.functions.getrevhex(repo, rev1)
+        let cs1=repo.functions.getcs(repo, rev1)
+        let csfiles=repo.functions.getcsprop(repo, cs1, 'files')
+    endif
+    if !empty(rev2)
+        let rev2=repo.functions.getrevhex(repo, rev2)
+        let cs2=repo.functions.getcs(repo, rev2)
+        let csfiles=repo.functions.getcsprop(repo, cs2, 'files')
+    endif
+    if !empty(rev1) && !empty(rev2)
+        let cs1files=cs1.files
+        let cs2files=cs2.files
+        let csfiles=filter(cs1files, 'index(cs2files, v:val)!=-1')+cs2files
+    endif
+    "▶3 Add directories to the list of files
+    for file in csfiles
+        while file isnot# '.'
+            let file=fnamemodify(file, ':h')
+            if file is# '.' || index(csfiles, file)!=-1
+                break
+            endif
+            call add(csfiles, file)
+        endwhile
+    endfor
+    "▶3 Filter out requested files
+    call map(csfiles, 'join(s:_r.os.path.split(v:val)[1:], "/")')
+    let filelist=[]
+    for pattern in map(copy(files), 's:F.comm.globtopattern(v:val)')
+        let filelist+=filter(csfiles, 'v:val=~#pattern && '.
+                    \                 'index(filelist, v:val)==-1')
+    endfor
+    "▲3
+    let opts=s:F.comm.encodeopts(filter(copy(a:opts),
+                \                       'index(s:diffoptslst, v:key)!=-1'))
+    let epath=escape(repo.path, ':\')
+    let efiles=join(map(filelist, 'escape(v:val, "\\;:")'), ';')
+    execute 'silent edit'
+                \fnameescape('aurum://diff:'.epath.':'.rev1.':'.rev2.
+                \                        ':'.efiles.':'.opts)
+endfunction
+let s:difffunc['@FWC']=['-onlystrings '.
+            \           '{  repo  '.substitute(s:repoarg, '\V"."', '":"', '').
+            \           '  ?rev1  type ""'.
+            \           '  ?rev2  type ""'.
+            \           s:diffoptsstr.
+            \           '}'.
+            \           '+ type ""', 'filter']
+call add(s:diffcomp,
+            \substitute(substitute(s:difffunc['@FWC'][0],
+            \'\V|*F.comm.getrepo',  '',           ''),
+            \'\V+ type ""', '+ (path)', ''))
 "▶2 filefunc
 function s:filefunc.function(rev, file, repopath)
     let opts={'rev': a:rev, 'repo': a:repopath}

File python/aurum.py

View file
  • Ignore whitespace
     try:
         ui=CaptureToBuf(vim.current.buffer)
         dodiff(ui, *args, **kwargs)
+        if len(vim.current.buffer)>1 and vim.current.buffer[-1] == '':
+            vim.current.buffer[-1:]=[]
+        else:
+            vim.command('setlocal binary noendofline')
     except FindError:
         pass
 

File test/diff.in

View file
  • Ignore whitespace
+:let g:postcmd='g/\V\^\(+++\|---\)/s/\t.*//'
+:W{{{1
+:Run AuDiff
+:bwipeout!
+:W{{{1 rev1
+:Run AuDiff rev1 -2
+:bwipeout!
+:W{{{1 rev2
+:Run AuDiff rev2 -1
+:bwipeout!
+:W{{{1 rev1 + rev2
+:Run AuDiff rev1 -2 rev2 -1
+:bwipeout!
+:W{{{1 rev1 + rev2 + reverse
+:Run AuDiff rev1 -2 rev2 -1 reverse
+:bwipeout!
+:W{{{1 numlines
+:Run AuDiff rev1 2 numlines 0
+:bwipeout!
+:W{{{1 git
+:Run AuDiff rev1 2 git
+:bwipeout!
+:W{{{1 file
+:Run AuDiff nohglinesrev.lst
+:bwipeout!
+:source addmessages.vim

File test/diff.ok

View file
  • Ignore whitespace
+{{{1
+diff -r bd8865085771 addeddef
+--- /dev/null
++++ b/addeddef
+@@ -0,0 +1,1 @@
++Def
+diff -r bd8865085771 hglines2.lst
+--- a/hglines2.lst
++++ /dev/null
+@@ -1,41 +0,0 @@
+-    hg init testrepo
+-    hg commit -A -m 'Added «createrepo.zsh»' \
+-    hg mv createrepo.zsh crepo.zsh
+-    hg commit -A -m 'Renamed «createrepo.zsh» to «crepo.zsh»' \
+-    hg commit -m $'Replaced\n    {\n        ...\n    }\nwith\n    {\n        ...\n    }' \
+-    hg mv crepo.zsh chgrepo.zsh
+-    hg commit -A -m 'Renamed «crepo.zsh» to «chgrepo.zsh»' \
+-    hg commit -A -m 'Added «hglines.lst» and «datelines.lst»' \
+-    hg branch A
+-    hg commit -A -m 'Added dlines.lst' \
+-    hg branch B
+-    hg commit -A -m 'Added alines.lst' \
+-    hg branch C
+-    hg commit -A -m 'Added ablines.lst' \
+-    hg tag ablines \
+-    hg update default
+-    hg merge -r ablines
+-    hg commit -m 'Merge from C' \
+-    hg update C
+-    hg commit -A -m 'Added blines.lst' \
+-    hg tag blines \
+-    hg update -r -2
+-    hg commit -A -m 'Added clines.lst' \
+-    hg tag clines \
+-    hg update A
+-    hg merge -r B
+-    hg commit -m 'Merge from B' \
+-    hg merge -r clines
+-    hg commit -m 'Merge from C:2' \
+-    hg update default
+-    hg merge -r blines
+-    hg commit -m 'Merge from C:1' \
+-    hg merge -r A
+-    hg commit -m 'Merge from A' \
+-    hg cp hglines.lst hglines2.lst
+-    hg commit -A -m 'Copied “hglines.lst” to “hglines2.lst”' \
+-    hg commit -A -m 'Added nohglines.lst' \
+-    hg commit -A -m 'Added nohglinesrev.lst' \
+-    hg commit -A -m 'Added ignored10.lst' \
+-    hg commit -A -m 'Added .hgignore' \
+-    hg rm hglines2.lst
+diff -r bd8865085771 nohglinesrev.lst
+--- a/nohglinesrev.lst
++++ b/nohglinesrev.lst
+@@ -51,3 +51,4 @@
+ cbaderongi > 'cbA' ohce    
+ }
+ opertset zx.rat.opertset fJc rat
++abc
+{{{1 rev1
+diff -r 94915b6e8a20 -r 9b5258a5153f ignored10.lst
+--- /dev/null
++++ b/ignored10.lst
+@@ -0,0 +1,10 @@
++1
++2
++3
++4
++5
++6
++7
++8
++9
++10
+{{{1 rev2
+diff -r bd8865085771 addeddef
+--- /dev/null
++++ b/addeddef
+@@ -0,0 +1,1 @@
++Def
+diff -r bd8865085771 hglines2.lst
+--- a/hglines2.lst
++++ /dev/null
+@@ -1,41 +0,0 @@
+-    hg init testrepo
+-    hg commit -A -m 'Added «createrepo.zsh»' \
+-    hg mv createrepo.zsh crepo.zsh
+-    hg commit -A -m 'Renamed «createrepo.zsh» to «crepo.zsh»' \
+-    hg commit -m $'Replaced\n    {\n        ...\n    }\nwith\n    {\n        ...\n    }' \
+-    hg mv crepo.zsh chgrepo.zsh
+-    hg commit -A -m 'Renamed «crepo.zsh» to «chgrepo.zsh»' \
+-    hg commit -A -m 'Added «hglines.lst» and «datelines.lst»' \
+-    hg branch A
+-    hg commit -A -m 'Added dlines.lst' \
+-    hg branch B
+-    hg commit -A -m 'Added alines.lst' \
+-    hg branch C
+-    hg commit -A -m 'Added ablines.lst' \
+-    hg tag ablines \
+-    hg update default
+-    hg merge -r ablines
+-    hg commit -m 'Merge from C' \
+-    hg update C
+-    hg commit -A -m 'Added blines.lst' \
+-    hg tag blines \
+-    hg update -r -2
+-    hg commit -A -m 'Added clines.lst' \
+-    hg tag clines \
+-    hg update A
+-    hg merge -r B
+-    hg commit -m 'Merge from B' \
+-    hg merge -r clines
+-    hg commit -m 'Merge from C:2' \
+-    hg update default
+-    hg merge -r blines
+-    hg commit -m 'Merge from C:1' \
+-    hg merge -r A
+-    hg commit -m 'Merge from A' \
+-    hg cp hglines.lst hglines2.lst
+-    hg commit -A -m 'Copied “hglines.lst” to “hglines2.lst”' \
+-    hg commit -A -m 'Added nohglines.lst' \
+-    hg commit -A -m 'Added nohglinesrev.lst' \
+-    hg commit -A -m 'Added ignored10.lst' \
+-    hg commit -A -m 'Added .hgignore' \
+-    hg rm hglines2.lst
+diff -r bd8865085771 nohglinesrev.lst
+--- a/nohglinesrev.lst
++++ b/nohglinesrev.lst
+@@ -51,3 +51,4 @@
+ cbaderongi > 'cbA' ohce    
+ }
+ opertset zx.rat.opertset fJc rat
++abc
+{{{1 rev1 + rev2
+diff -r 94915b6e8a20 -r 9b5258a5153f ignored10.lst
+--- /dev/null
++++ b/ignored10.lst
+@@ -0,0 +1,10 @@
++1
++2
++3
++4
++5
++6
++7
++8
++9
++10
+{{{1 rev1 + rev2 + reverse
+diff -r 9b5258a5153f -r 94915b6e8a20 ignored10.lst
+--- a/ignored10.lst
++++ /dev/null
+@@ -1,10 +0,0 @@
+-1
+-2
+-3
+-4
+-5
+-6
+-7
+-8
+-9
+-10
+{{{1 numlines
+diff -r 6a040abfa945 -r 1ddeac9b650f crepo.zsh
+--- a/crepo.zsh
++++ b/crepo.zsh
+@@ -7,1 +7,1 @@
+-(
++{
+@@ -18,2 +18,2 @@
+-    perl -p -i -e 'tr/()/{}/' crepo.zsh
+-    hg commit -m $'Replaced\n    (\n        ...\n    )\nwith\n    {\n        ...\n    }' \
++    perl -p -i -e 'tr/{}/{}/' crepo.zsh
++    hg commit -m $'Replaced\n    {\n        ...\n    }\nwith\n    {\n        ...\n    }' \
+@@ -93,1 +93,1 @@
+-)
++}
+{{{1 git
+diff --git a/crepo.zsh b/crepo.zsh
+--- a/crepo.zsh
++++ b/crepo.zsh
+@@ -4,7 +4,7 @@
+ local A='A <a@example.com>'
+ local B='B <b@example.org>'
+ local C='C <c@example.gov>'
+-(
++{
+     set -e
+     hg init testrepo
+     cd testrepo
+@@ -15,8 +15,8 @@
+     hg mv createrepo.zsh crepo.zsh
+     hg commit -A -m 'Renamed «createrepo.zsh» to «crepo.zsh»' \
+         --date '2000-01-05 7:30' --user $A
+-    perl -p -i -e 'tr/()/{}/' crepo.zsh
+-    hg commit -m $'Replaced\n    (\n        ...\n    )\nwith\n    {\n        ...\n    }' \
++    perl -p -i -e 'tr/{}/{}/' crepo.zsh
++    hg commit -m $'Replaced\n    {\n        ...\n    }\nwith\n    {\n        ...\n    }' \
+         --date '2000-01-15 15:00' --user $B
+     hg mv crepo.zsh chgrepo.zsh
+     hg commit -A -m 'Renamed «crepo.zsh» to «chgrepo.zsh»' \
+@@ -90,5 +90,5 @@
+     rm nohglines.lst
+     cat hglines.lst | rev > hglinesrev.lst
+     echo 'Abc' > ignoredabc
+-)
++}
+ tar cJf testrepo.tar.xz testrepo
+{{{1 file
+diff -r bd8865085771 addeddef
+--- /dev/null
++++ b/addeddef
+@@ -0,0 +1,1 @@
++Def
+diff -r bd8865085771 hglines2.lst
+--- a/hglines2.lst
++++ /dev/null
+@@ -1,41 +0,0 @@
+-    hg init testrepo
+-    hg commit -A -m 'Added «createrepo.zsh»' \
+-    hg mv createrepo.zsh crepo.zsh
+-    hg commit -A -m 'Renamed «createrepo.zsh» to «crepo.zsh»' \
+-    hg commit -m $'Replaced\n    {\n        ...\n    }\nwith\n    {\n        ...\n    }' \
+-    hg mv crepo.zsh chgrepo.zsh
+-    hg commit -A -m 'Renamed «crepo.zsh» to «chgrepo.zsh»' \
+-    hg commit -A -m 'Added «hglines.lst» and «datelines.lst»' \
+-    hg branch A
+-    hg commit -A -m 'Added dlines.lst' \
+-    hg branch B
+-    hg commit -A -m 'Added alines.lst' \
+-    hg branch C
+-    hg commit -A -m 'Added ablines.lst' \
+-    hg tag ablines \
+-    hg update default
+-    hg merge -r ablines
+-    hg commit -m 'Merge from C' \
+-    hg update C
+-    hg commit -A -m 'Added blines.lst' \
+-    hg tag blines \
+-    hg update -r -2
+-    hg commit -A -m 'Added clines.lst' \
+-    hg tag clines \
+-    hg update A
+-    hg merge -r B
+-    hg commit -m 'Merge from B' \
+-    hg merge -r clines
+-    hg commit -m 'Merge from C:2' \
+-    hg update default
+-    hg merge -r blines
+-    hg commit -m 'Merge from C:1' \
+-    hg merge -r A
+-    hg commit -m 'Merge from A' \
+-    hg cp hglines.lst hglines2.lst
+-    hg commit -A -m 'Copied “hglines.lst” to “hglines2.lst”' \
+-    hg commit -A -m 'Added nohglines.lst' \
+-    hg commit -A -m 'Added nohglinesrev.lst' \
+-    hg commit -A -m 'Added ignored10.lst' \
+-    hg commit -A -m 'Added .hgignore' \
+-    hg rm hglines2.lst
+diff -r bd8865085771 nohglinesrev.lst
+--- a/nohglinesrev.lst
++++ b/nohglinesrev.lst
+@@ -51,3 +51,4 @@
+ cbaderongi > 'cbA' ohce    
+ }
+ opertset zx.rat.opertset fJc rat
++abc

File test/gentests-setuptestrepos.zsh

View file
  • Ignore whitespace
 emulate -L zsh
 tar xJf testrepo.tar.xz
 
-for test in annotate-buffers commit record stat statmaps vimdiff ; do
+for test in annotate-buffers commit record stat statmaps vimdiff diff ; do
     mkdir ${test}repo
     tar c -C testrepo . | (cd ${test}repo && tar x)
 done

File test/glogmaps.ok

View file
  • Ignore whitespace
 {{{1 <CR>
-aurum://diff:%TMPDIR%/test/glogmapsrepo:bd8865085771912fc9ab56425f385a1751696ec1
+aurum://diff:%TMPDIR%/test/glogmapsrepo:bd8865085771912fc9ab56425f385a1751696ec1:
 {{{1 branch <CR>
 aurum://glog:%TMPDIR%/test/glogmapsrepo:branch:A,crrestrict:branch
 {{{1 user <CR>
 {{{1 gd
 aurum://diff:%TMPDIR%/test/glogmapsrepo::6a040abfa9457d6066c8469fab4f9e3ae1f3e494
 {{{1 gc
-aurum://diff:%TMPDIR%/test/glogmapsrepo:1ddeac9b650f689aec0a77b68463ba9de40d9e01
+aurum://diff:%TMPDIR%/test/glogmapsrepo:1ddeac9b650f689aec0a77b68463ba9de40d9e01:
 {{{1 d
 aurum://diff:%TMPDIR%/test/glogmapsrepo:6a040abfa9457d6066c8469fab4f9e3ae1f3e494::crepo.zsh
 w$: 1

File test/vimrc

View file
  • Ignore whitespace
         execute 'cd' fnameescape(reporoot)
     endif
     execute a:cmd
+    if exists('g:postcmd')
+        execute 'silent' g:postcmd
+    endif
     if !a:bang
         cd ..
     endif