Commits

ZyX_I committed 89e7fe5

@%aurum/commit: Added Diff and Fdiff mappings
Moved vimdiffrecordcb to @%aurum/record
Ref #72, ref #52, ref #70

Comments (0)

Files changed (8)

aurum-addon-info.txt

         "test/hgtestrepo.tar.xz",
         "test/maps-annotate.in",
         "test/maps-annotate.ok",
+        "test/maps-commit-diff.in",
+        "test/maps-commit-diff.ok",
         "test/maps-diff.in",
         "test/maps-diff.ok",
         "test/maps-file.in",

autoload/aurum/commit.vim

 "▶1 
 scriptencoding utf-8
-execute frawor#Setup('1.1', {'@/resources': '0.0',
+execute frawor#Setup('1.2', {'@/resources': '0.0',
             \                  '@/options': '0.0',
+            \                       '@/os': '0.0',
             \                     '@aurum': '1.0',
             \             '@%aurum/status': '1.2',
             \           '@%aurum/cmdutils': '4.0',
             \            '@%aurum/bufvars': '0.0',
+            \            '@%aurum/vimdiff': '1.1',
             \               '@%aurum/edit': '1.0',
             \               '@aurum/cache': '2.1',})
 let s:_messages={
 let s:_options={
             \'remembermsg':         {'default': 1, 'filter': 'bool'},
             \'bufleaveremembermsg': {'default': 1, 'filter': 'bool'},
+            \'commitinfowincmd':    {
+            \   'default': 'largest_adjacent',
+            \   'checker': 'match /\v^%([jkhlwWtbpcvs]|'.
+            \                          'largest%(_%(vertical|'.
+            \                                      'horizontal|'.
+            \                                      'adjacent))?)$/'},
         \}
 "▶1 parsedate string → [year, month, day, hour, minute, second]
 " Date must have one of the following formats (XXX it is not validated):
     endif
     return r
 endfunction
+"▶1 vimdiffcb
+function s:F.vimdiffcb(file, bvar, hex)
+    execute 'silent tabnew'
+                \ fnameescape(s:_r.os.path.join(a:bvar.repo.path, a:file))
+    return s:_r.vimdiff.split([['file', a:bvar.repo, a:hex, a:file]], 0)
+endfunction
+"▶1 findwindow
+function s:F.winsize(wnr)
+    let width=winwidth(a:wnr)
+    return (width>80 ? 80 : width)*winheight(a:wnr)
+endfunction
+function s:F.winsplit()
+    if winwidth(0)>=&textwidth*2
+        execute 'silent' (winwidth(0)-&textwidth)                'vsplit'
+    else
+        execute 'silent' (max([winheight(0)-5, winheight(0)/2]))  'split'
+    endif
+endfunction
+function s:F.findwindow()
+    let wcommand=s:_f.getoption('commitinfowincmd')
+    if len(wcommand)==1
+        let commit_mark=reltime()
+        let wscope=w:
+        let w:aurum_commit_mark=commit_mark
+        try
+            execute 'wincmd' wcommand
+            if              exists('w:aurum_commit_mark')
+                        \&& w:aurum_commit_mark is# commit_mark
+                call s:F.winsplit()
+            endif
+        finally
+            call remove(wscope, 'aurum_commit_mark')
+        endtry
+    elseif wcommand is# 'largest'
+        let maxsize=0
+        let mwnr=0
+        for wnr in filter(range(1, winnr('$')), 'v:val!='.winnr())
+            let size=s:F.winsize(a:wnr)
+            if size>maxsize
+                let maxsize=size
+                let mwnr=a:wnr
+            endif
+        endfor
+        if mwnr
+            execute mwnr.'wincmd w'
+        else
+            call s:F.winsplit()
+        endif
+    else
+        let maxsize=0
+        let mwcmd=0
+        let wcmds={
+                    \'vertical':   ['j', 'k'],
+                    \'horizontal': ['h', 'l'],
+                    \'adjacent':   ['h', 'l', 'j', 'k'],
+                \}[wcommand[8:]]
+        let curwin=winnr()
+        for wcmd in wcmds
+            execute 'wincmd' wcmd
+            if winnr()!=curwin
+                let size=s:F.winsize(0)
+                wincmd p
+                if size>maxsize
+                    let maxsize=size
+                    let mwcmd=wcmd
+                endif
+            endif
+        endfor
+        if mwcmd is 0
+            call s:F.winsplit()
+        else
+            execute 'wincmd' mwcmd
+        endif
+    endif
+endfunction
 "▶1 commit :: repo, opts, files, status, types → + repo
 let s:defdate=['strftime("%Y")',
             \  'strftime("%m")',
     augroup END
     return {'user': a:user, 'date': a:date, 'files': a:files,
                 \'closebranch': !!a:cb, 'write': s:F.finish,
-                \'did_message': 0}
+                \'did_message': 0, 'vimdiffcb': s:F.vimdiffcb,
+                \'findwindow': s:F.findwindow,}
 endfunction
 let s:_augroups+=['AuCommit']
 function s:commit.write(lines, repo, user, date, cb, files)

autoload/aurum/record.vim

             \               '@/mappings': '0.0',
             \                   '@aurum': '1.0',
             \             '@aurum/cache': '2.1',
-            \           '@%aurum/commit': '1.1',
+            \           '@%aurum/commit': '1.2',
             \         '@%aurum/cmdutils': '4.0',
             \        '@%aurum/lineutils': '0.0',
             \             '@%aurum/edit': '1.5',
             \           "  2. You edited a file which discards undo ".
             \                "information unless g:aurum_fullundo is set",
         \}
+"▶1 commitvimdiffcb
+function s:F.commitvimdiffcb(file, bvar, hex)
+    let [lwnr, rwnr, swnr]=s:F.getwnrs()
+
+    execute lwnr.'wincmd w'
+    let file=s:_r.os.path.join(a:bvar.repo.path, a:file)
+    let existed=bufexists(file)
+    execute 'silent edit' fnameescape(file)
+    if !existed
+        setlocal bufhidden=wipe
+    endif
+    diffthis
+
+    execute rwnr.'wincmd w'
+    let existed=s:_r.run('silent edit', 'file', a:bvar.repo, a:hex, a:file)
+    if !existed
+        setlocal bufhidden=wipe
+    endif
+    diffthis
+
+    execute lwnr.'wincmd w'
+endfunction
+"▶1 commitfindwindow
+function s:F.commitfindwindow()
+    let [lwnr, rwnr, swnr]=s:F.getwnrs()
+    execute lwnr.'wincmd w'
+endfunction
 "▶1 write
 function s:F.write(bvar)
     call feedkeys("\<C-\>\<C-n>:call ".
         let cbvar.sbvar=a:bvar
         let cbvar.sbuf=a:buf
         let cbvar.bwfunc=s:F.srestore
+        let cbvar.vimdiffcb=s:F.commitvimdiffcb
+        let cbvar.findwindow=s:F.commitfindwindow
         let cbvar.winview=winview
     endif
     return 0
                                                  *g:frawormap_AuCommitMessage*
        *g:frawormap_AuCommitMessage_Commit* *g:frawormap_AuCommitMessage_Prev*
        *g:frawormap_AuCommitMessage_Vdiff*  *g:frawormap_AuCommitMessage_Next*
+       *g:frawormap_AuCommitMessage_Fdiff*  *g:frawormap_AuCommitMessage_Diff*
        *g:frawormap_AuCommitMessage_FVdiff*
            *aurum-m-AuCommitMessage_Commit*     *aurum-m-AuCommitMessage_Prev*
            *aurum-m-AuCommitMessage_Vdiff*      *aurum-m-AuCommitMessage_Next*
+           *aurum-m-AuCommitMessage_Fdiff*      *aurum-m-AuCommitMessage_Diff*
            *aurum-m-AuCommitMessage_FVdiff*
     Mapname  LHS  Description ~
     Commit    i   Finish writing commit message and commit changes
                         message will be inserted before the first line of the 
                         buffer.
     Next      K   Like above, but works for descendants.
+    Diff      d   Open a diff with the selected file (uses file under cursor 
+                  or prompts user).
+    Fdiff    gd   Open a diff with all changes to be committed.
     Vdiff     D   Open a vimdiff split with the selected file (uses file under 
                   cursor or prompts user).
     FVdiff   gD   Open a number of vimdiff splits with all files to be 
     Open differencies between revisions {rev1} and {rev2} of files {files} 
     (semicolon-delimited list, semicolons in filenames can be escaped). For 
     {diffopts} see |aurum-diffoptions|. If one of {rev1} or {rev2} is empty 
-    then it will open the same diff as |:AuDiff| would if “rev1”, “rev2” and 
-    “changes” options were not given. If {files} is empty, then it will show 
-    all changes.
+    then it will open the same diff as |:AuDiff| would if “rev1” and/or “rev2” 
+    and “changes” options were not given. If {files} is empty, then it will 
+    show all changes.
     Local mappings (mgid=AuDiff, without leader by default):
                                                           *g:frawormap_AuDiff*
                          *g:frawormap_AuDiff_Next* *g:frawormap_AuDiff_FVdiff*
 Vdiff       D   acDf S  g  Shows vimdiff between cur. rev. and WD for file
                            (status and diff: between two current revisions)
 RVdiff      C   a  f s     Shows changes to file in cur. rev. as a vimdiff
-Fdiff      gd   a   lS  g  Shows diff between current revision and working dir
+Fdiff      gd   ac  lS  g  Shows diff between current revision and working dir
                            (status: between two current revisions)
 RFdiff     gc   a   ls     Shows changes introduced by current revision
-Diff        d   a  flS  g  Shows diff between rev and WD for current file
+Diff        d   ac flS  g  Shows diff between rev and WD for current file
                            (status: between two current revisions)
 Rdiff       c   a  fls     Shows changes done in current rev to current file
 Prev/Next  J/K  acdfl      Go to previous/next revision
     Ignored if there is only one window left.
     Default: “c”.
 
+commitinfowincmd                                    *g:aurum_commitinfowincmd*
+    String, one of “j”, “k”, “h”, “l”, “w”, “W”, “t”, “b”, “p”, “s”, “v”, 
+    “largest_vertical”, “largest_horizontal”, “largest_adjacent”, “largest”. 
+    Determines what window should be switched to when running 
+    |aurum-m-AuCommit_Diff| and |aurum-m-AuCommit_Fdiff| mappings. See 
+    |window-move-cursor| and |open-window| for the description of the keys. 
+    Values, beginning with “largest_” are special: they select the largest 
+    window out of vertical, horizontal or all four directions respectively. 
+    The largest is determined by comparing |winwidth()|*|winheight()|, window 
+    width in this formula is capped with 80 columns.
+
 remembermsg                                              *g:aurum_remembermsg*
     Bool. Determines whether message typed in commit buffer should be saved 
     when commit is performed in case of rollback. This message will appear in 
 @%aurum/commit:
     1.0: Added fifth argument to _r.commit.commit().
     1.1: Added sixth optional argument to _r.commit.commit()
+    1.2: Added vimdiffcb and findwindow functions to aurum://commit bvar, 
+         added |g:aurum_commitinfowincmd| option
 @%aurum/annotate:
     1.0: Removed one argument to _r.annotate.setannbuf().
 @%aurum/cmdutils:

ftplugin/aurumcommit.vim

             \           '@%aurum/bufvars': '0.0',
             \          '@%aurum/maputils': '0.0',
             \           '@%aurum/vimdiff': '1.1',
-            \            '@%aurum/commit': '1.0',
+            \            '@%aurum/commit': '1.2',
             \              '@%aurum/edit': '1.0',})
 "▶1 listfiles
 function s:F.listfiles(bvar)
         let status=a:bvar.repo.functions.status(a:bvar.repo, 0, 0, a:bvar.files)
         let status=filter(copy(status), 'index(s:defstats, v:key)!=-1')
         let revstatus={}
-        call map(copy(a:status), 'map(copy(v:val),'.
-                    \              '"extend(revstatus,{v:val:''".v:key."''})")')
+        call map(copy(status),'map(copy(v:val),'.
+                    \             '"extend(revstatus,{v:val :''".v:key."''})")')
         let a:bvar.revstatus=revstatus
         return keys(a:bvar.revstatus)
     endif
     endif
     return 0
 endfunction
-"▶1 vimdiffcb
-function s:F.vimdiffcb(file, bvar, hex)
-    execute 'silent tabnew'
-                \ fnameescape(s:_r.os.path.join(a:bvar.repo.path, a:file))
-    return s:_r.vimdiff.split([['file', a:bvar.repo, a:hex, a:file]], 0)
-endfunction
-"▶1 vimdiffrecordcb
-function s:F.vimdiffrecordcb(file, bvar, hex)
-    let [lwnr, rwnr, swnr]=a:bvar.sbvar.getwnrs()
-
-    execute lwnr.'wincmd w'
-    let file=s:_r.os.path.join(a:bvar.repo.path, a:file)
-    let existed=bufexists(file)
-    execute 'silent edit' fnameescape(file)
-    if !existed
-        setlocal bufhidden=wipe
-    endif
-    diffthis
-
-    execute rwnr.'wincmd w'
-    let existed=s:_r.run('silent edit', 'file', a:bvar.repo, a:hex, a:file)
-    if !existed
-        setlocal bufhidden=wipe
-    endif
-    diffthis
-
-    execute lwnr.'wincmd w'
+"▶1 diffcb
+function s:F.diffcb(file, bvar, hex)
+    call a:bvar.findwindow()
+    call s:_r.mrun('silent edit', 'diff', a:bvar.repo, 0, 0, [a:file], {})
 endfunction
 "▶1 runcommap
 function s:F.runcommap(count, action)
                     \                                      bvar.recallcs.hex,
                     \                                      cnt)
         call append(0, split(bvar.recallcs.description, "\n", 1))
-    elseif a:action is# 'vimdiff'
+    elseif a:action is# 'fulldiff'
+        call bvar.findwindow()
+        call s:_r.mrun('silent edit', 'diff', bvar.repo, 0, 0,
+                    \                         s:F.listfiles(bvar), {})
+    elseif a:action is# 'diff' || a:action is# 'vimdiff'
         let file=s:F.getfile(bvar)
         let hex=bvar.repo.functions.getworkhex(bvar.repo)
-        let cbargs=[((has_key(bvar, 'sbvar'))?
-                    \   (s:F.vimdiffrecordcb):
-                    \   (s:F.vimdiffcb)), bvar, hex]
+        let cbargs=[(a:action is# 'diff' ? s:F.diffcb : bvar.vimdiffcb),
+                    \bvar, hex]
         if file is 0
             let pvargs=[s:_r.maputils.readfilewrapper, bvar.repo, hex]
             return s:_r.maputils.promptuser(s:F.listfiles(bvar), cbargs, pvargs)
             \ 'Commit': {'lhs':  'i', 'rhs': ['commit'     ]},
             \   'Prev': {'lhs':  'J', 'rhs': ['recallprev' ]},
             \   'Next': {'lhs':  'K', 'rhs': ['recallnext' ]},
+            \   'Diff': {'lhs':  'd', 'rhs': ['diff'       ]},
+            \  'Fdiff': {'lhs': 'gd', 'rhs': ['fulldiff'   ]},
             \  'Vdiff': {'lhs':  'D', 'rhs': ['vimdiff'    ]},
             \ 'FVdiff': {'lhs': 'gD', 'rhs': ['fullvimdiff']},
             \   'Exit': {'lhs':  'X', 'rhs': ['discard'    ]},

test/gentests-setuptestrepos.zsh

 
 for test in cmd-annotate-buffers cmd+maps-commit cmd-record cmd-status \
             maps-status cmd+maps-vimdiff cmd-diff cmd-update opts-remembermsg \
-            opts-vimdiffusewin cmd-vimdiff-full cmdaus maps-record-undo
+            opts-vimdiffusewin cmd-vimdiff-full cmdaus maps-record-undo \
+            maps-commit-diff
 do
     ln -s util-add-modified-repo.zsh $test.pre
 done

test/maps-commit-diff.in

+:W{{{1 Diff mapping
+:R AuCommit all
+G$,d:WW
+:bwipeout!
+:W{{{1 FDiff mapping
+,gd:WW
+:bwipeout!
+:bwipeout!
+:W{{{1 commitinfocmd
+vvsslsslss=4>jjh4+k
+:R silent edit aurum://commit
+:command -nargs=1 -bar Tcic :W{{{2 commitinfowincmd=<args> | let g:aurum_commitinfowincmd=<q-args> | execute 'normal ,gd' | WW | enew | wincmd p
+:Tcic largest_horizontal
+:Tcic largest_vertical
+:Tcic largest_adjacent
+:Tcic h
+:Tcic j
+:Tcic k
+:Tcic l

test/maps-commit-diff.ok

+{{{1 Diff mapping
+#1: aurum://commit:%ETMPDIR%%-test%-maps-commit-diffrepo:::0:
+*2: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:hglines2.lst:
+{{{1 FDiff mapping
+*1: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:addeddef;hglines2.lst;nohglinesrev.lst:
+#2: aurum://commit:%ETMPDIR%%-test%-maps-commit-diffrepo:::0:
+{{{1 commitinfocmd
+{{{2 commitinfowincmd=largest_horizontal
+ 1: 
+ 2: 
+ 3: 
+ 4: 
+#5: aurum://commit
+ 6: 
+ 7: 
+*8: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:addeddef;hglines2.lst;nohglinesrev.lst:
+ 9: 
+{{{2 commitinfowincmd=largest_vertical
+ 1: 
+ 2: 
+ 3: 
+ 4: 
+#5: aurum://commit
+*6: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:addeddef;hglines2.lst;nohglinesrev.lst:
+ 7: 
+ 8: 
+ 9: 
+{{{2 commitinfowincmd=largest_adjacent
+ 1: 
+ 2: 
+ 3: 
+ 4: 
+#5: aurum://commit
+*6: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:addeddef;hglines2.lst;nohglinesrev.lst:
+ 7: 
+ 8: 
+ 9: 
+{{{2 commitinfowincmd=h
+ 1: 
+*2: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:addeddef;hglines2.lst;nohglinesrev.lst:
+ 3: 
+ 4: 
+#5: aurum://commit
+ 6: 
+ 7: 
+ 8: 
+ 9: 
+{{{2 commitinfowincmd=j
+ 1: 
+ 2: 
+ 3: 
+ 4: 
+#5: aurum://commit
+*6: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:addeddef;hglines2.lst;nohglinesrev.lst:
+ 7: 
+ 8: 
+ 9: 
+{{{2 commitinfowincmd=k
+ 1: 
+ 2: 
+ 3: 
+*4: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:addeddef;hglines2.lst;nohglinesrev.lst:
+#5: aurum://commit
+ 6: 
+ 7: 
+ 8: 
+ 9: 
+{{{2 commitinfowincmd=l
+ 1: 
+ 2: 
+ 3: 
+ 4: 
+#5: aurum://commit
+ 6: 
+ 7: 
+*8: aurum://diff:%ETMPDIR%%-test%-maps-commit-diffrepo:0:0:addeddef;hglines2.lst;nohglinesrev.lst:
+ 9: 
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.