Commits

Ludovic Chabant committed 671f5e1

Added "diff summary" commands to use `hg diff` instead of Vim's diff.
Added documenation for the new commands.
Got rid of the useless hard-coded revision numbers.

  • Participants
  • Parent commits b484fe8

Comments (0)

Files changed (2)

doc/lawrencium.txt

 
                                                 *:Hgdiff*
 :Hgdiff                 Diffs the current file against its parent revision.
+                        This splits the current window to show both the
+                        current file and the parent revision file, using Vim's
+                        |diff| abilities.
 
                                                 *:Hgdiff_f*
-:Hgdiff {revspec}       Diffs the current file against the specified revision.
+:Hgdiff {revspec}       Same as |:Hgdiff| but shows a diff of the current file
+                        with the specified revision. Any revision number, hash
+                        or spec that can be passed to `hg cat` is valid.
 
                                                 *:Hgvdiff*
-:Hgvdiff                Same as |:Hgdiff| but uses a vertical split.
+:Hgvdiff                Same as |:Hgdiff| but uses a vertical split instead of
+                        a horizontal split.
 
                                                 *:Hgvdiff_f*
 :Hgvdiff {revspec}      Same as |:Hgdiff_f| but uses a vertical split.
 
+                                                *:Hgdiffsum*
+:Hgdiffsum              Shows the "diff summary" (the output of `hg diff`)
+                        of the current file against its parent revision.
+
+                                                *:Hgdiffsum_f*
+:Hgdiffsum {revspec}    Same as |:Hgdiffsum| but shows a "diff summary" of the
+                        current file with the specified revision. Any revision
+                        number, hash or spec that can be passed to `hg diff`
+                        is valid.
+
+                                                *:Hgdiffsumsplit*
+                                                *:Hgdiffsumsplit_f*
+:Hgdiffsumsplit
+:Hgdiffsumsplit {revspec}
+                        Same as |:Hgdiffsum| and |:Hgdiffsum_f| respectively, 
+                        but opens the diff summary in a split window instead
+                        of the current window.
+
+                                                *:Hgvdiffsumsplit*
+                                                *:Hgvdiffsumsplit_f*
+:Hgvdiffsumsplit
+:Hgvdiffsumsplit {revspec}
+                        Same as |:Hgdiffsumsplit| and |:Hgdiffsumsplit_f|
+                        respectively, but uses a vertical split window instead
+                        of a horizontal split window.
+
                                                 *:Hgcommit*
 :Hgcommit               Opens a new window to edit a commit message into a
                         temporary file and, upon quitting the buffer, if that

plugin/lawrencium.vim

 " Hgdiff {{{
 
 function! s:HgDiff(filename, vertical, ...) abort
-    " Default revisions to diff: the working directory (special Lawrencium 
-    " hard-coded syntax) and the parent of the working directory (using 
-    " Mercurial's revsets syntax).
-    let l:rev1 = 'lawrencium#_wdir_'
+    " Default revisions to diff: the working directory (null string) 
+    " and the parent of the working directory (using Mercurial's revsets syntax).
+    let l:rev1 = ''
     let l:rev2 = 'p1()'
     if a:0 == 1
         let l:rev2 = a:1
     let l:diff_buffers = []
 
     " Get the first file and open it.
-    if l:rev1 == 'lawrencium#_wdir_'
+    if l:rev1 == ''
         if bufexists(l:path)
             execute 'buffer ' . fnameescape(l:path)
         else
     if a:vertical
         let l:diffsplit = 'vertical diffsplit'
     endif
-    if l:rev2 == 'lawrencium#_wdir_'
+    if l:rev2 == ''
         execute l:diffsplit . ' ' . fnameescape(l:path)
     else
         let l:temp_file = tempname()
 
 " }}}
 
+" HgdiffSummary {{{
+
+function! s:HgDiffSummary(split, filename, ...) abort
+    " Default revisions to diff: the working directory (null string) 
+    " and the parent of the working directory (using Mercurial's revsets syntax).
+    let l:revs = ''
+    if a:0 == 1
+        let l:revs = a:1
+    elseif a:0 >= 2
+        let l:revs = a:1 . ',' . a:2
+    endif
+
+    " Get the current repo, and expand the given filename in case it contains
+    " fancy filename modifiers.
+    let l:repo = s:hg_repo()
+    let l:path = expand(a:filename)
+    call s:trace("Diff'ing revisions: '".l:revs."' on file: ".l:path)
+    let l:special = l:repo.GetLawrenciumPath(l:path, 'diff', l:revs)
+    if a:split == 1
+        split
+    elseif a:split == 2
+        vsplit
+    endif
+    execute 'edit ' . l:special
+    " Open all folds by default.
+    " TODO: maybe set `nofoldenable` instead?
+    %foldopen!
+endfunction
+
+call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiffsum       :call s:HgDiffSummary(0, '%:p', <f-args>)")
+call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgdiffsumsplit  :call s:HgDiffSummary(1, '%:p', <f-args>)")
+call s:AddMainCommand("-nargs=* -complete=customlist,s:ListRepoFiles Hgvdiffsumsplit :call s:HgDiffSummary(2, '%:p', <f-args>)")
+
+" }}}
+
 " Hgcommit {{{
 
 function! s:HgCommit(bang, vertical, ...) abort
             else
                 call l:repo.ReadCommandOutput('diff', '-r', l:rev1, '-r', l:rev2, l:comps['path'])
             endif
+        elseif l:comps['value'] != ''
+            call l:repo.ReadCommandOutput('diff', '-c', l:comps['value'], l:comps['path'])
         else
-            call l:repo.ReadCommandOutput('diff', '-c', l:comps['value'], l:comps['path'])
+            call l:repo.ReadCommandOutput('diff', l:comps['path'])
         endif
         setlocal filetype=diff
     endif