Mercurial > vim-lawrencium
changeset 73:785d1a1faa6c
Changes and fixes to the `Hglog` window:
- Fixed a bug with showing diffs.
- Made the diff behaviour and commands more consistent with those of
the `Hgstatus` window.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Sun, 16 Feb 2014 22:33:11 -0800 |
parents | a987094d5ae6 |
children | e023d7764361 |
files | doc/lawrencium.txt plugin/lawrencium.vim |
diffstat | 2 files changed, 119 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/lawrencium.txt Sun Feb 16 17:31:18 2014 -0800 +++ b/doc/lawrencium.txt Sun Feb 16 22:33:11 2014 -0800 @@ -281,6 +281,29 @@ `0`, some commands are mapped to keyboard shortcuts, as detailed in the following descriptions. + *:Hglogdiffsum* +:Hglogdiffsum Splits the previous window to show a diff summary (as + returned by `hg diff`) of the change specified on + the current line. + Mapped to |<C-U>|. + + *:Hglogdiffsum_r* +:Hglogdiffsum {rev1} {rev2} + Same as |:Hglogdiffsum| but shows a diff summary of + the change between the two specified revisions. If + only {rev1} is specified, the change at that revision + will be shown. + + *:Hglogvdiffsum* +:Hglogvdiffsum Same as |:Hglogdiffsum| but opens a vertical split + instead of a horizontal one. + Mapped to |<C-H>| and |<CR>|. + + *:Hglogvdiffsum_r* +:Hglogvdiffsum {rev1} {rev2} + Same as |:Hglogdiffsum_r| but opens a vertical split + instead of a horizontal one. + *:Hglogrevedit* :Hglogrevedit Looks at the revision specified on the current line, and opens that revision for edit in the previous @@ -292,21 +315,28 @@ *:Hglogdiff* :Hglogdiff Looks at the revision specified on the current line, - and runs an `hg diff` between that revision and the - previously listed revision (in the line below). It - opens that diff in the previous window. - It doesn't do anything if the cursor is on the last - line. - Mapped to |<CR>|. + and opens a Vim diff between that revision and its + first parent. + This is only valid if the logged path maps to a file + (i.e. not a directory, and not the whole repository as + with |:Hglog|). + Mapped to |<C-D>|. *:Hglogdiff_r* -:Hglogdiff {rev} Same as |:Hglogdiff|, but opens a diff between the - specified revision and the working directory. - - *:Hglogdiff_r_r* :Hglogdiff {rev1} {rev2} Same as |:Hglogdiff|, but opens a diff between the - two specified revisions. + specified revisions. If only {rev1} is specified, + opens a Vim diff between that revision and its first + parent. + + *:Hglogvdiff* +:Hglogvdiff Same as |:Hglogdiff|, but opens a vertical split + instead of a horizontal one. + + *:Hglogvdiff_r* +:Hglogvdiff {rev1} {rev2} + Same as |:Hglogdiff_r| but opens a vertical split + instead of a horizontal one. *lawrencium-log-mappings* A few other mappings are available in the log window:
--- a/plugin/lawrencium.vim Sun Feb 16 17:31:18 2014 -0800 +++ b/plugin/lawrencium.vim Sun Feb 16 22:33:11 2014 -0800 @@ -49,6 +49,11 @@ return fnamemodify(a:path, ':s?[/\\]$??') endfunction +" Surrounds the given string with double quotes. +function! s:addquotes(str) + return '"' . a:str . '"' +endfunction + " Normalizes the slashes in a path. function! s:normalizepath(path) if exists('+shellslash') && &shellslash @@ -547,10 +552,11 @@ " Read revision (`hg cat`) function! s:read_lawrencium_rev(repo, path_parts, full_path) abort - if a:path_parts['value'] == '' + let l:rev = a:path_parts['value'] + if l:rev == '' call a:repo.ReadCommandOutput('cat', a:full_path) else - call a:repo.ReadCommandOutput('cat', '-r', a:path_parts['value'], a:full_path) + call a:repo.ReadCommandOutput('cat', '-r', s:addquotes(l:rev), a:full_path) endif endfunction @@ -587,11 +593,11 @@ let l:rev1 = strpart(a:path_parts['value'], 0, l:commaidx) let l:rev2 = strpart(a:path_parts['value'], l:commaidx + 1) if l:rev1 == '-' - let l:diffargs = [ '-r', l:rev2 ] + let l:diffargs = [ '-r', s:addquotes(l:rev2) ] elseif l:rev2 == '-' - let l:diffargs = [ '-r', l:rev1 ] + let l:diffargs = [ '-r', s:addquotes(l:rev1) ] else - let l:diffargs = [ '-r', l:rev1, '-r', l:rev2 ] + let l:diffargs = [ '-r', s:addquotes(l:rev1), '-r', s:addquotes(l:rev2) ] endif elseif a:path_parts['value'] != '' let l:diffargs = [ '-c', a:path_parts['value'] ] @@ -1112,7 +1118,16 @@ let l:rev1 = '' let l:rev2 = 'p1()' if a:0 == 1 - let l:rev2 = a:1 + if type(a:1) == type([]) + if len(a:1) >= 2 + let l:rev1 = a:1[0] + let l:rev2 = a:1[1] + elseif len(a:1) == 1 + let l:rev2 = a:1[0] + endif + else + let l:rev2 = a:1 + endif elseif a:0 == 2 let l:rev1 = a:1 let l:rev2 = a:2 @@ -1152,7 +1167,7 @@ if l:rev2 == '' execute l:diffsplit . ' ' . fnameescape(l:path) else - let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev1) + let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev2) execute l:diffsplit . ' ' . fnameescape(l:rev_path) endif endfunction @@ -1242,7 +1257,15 @@ " Otherwise, use the 1 or 2 revisions specified as extra parameters. let l:revs = '' if a:0 == 1 - let l:revs = a:1 + if type(a:1) == type([]) + if len(a:1) >= 2 + let l:revs = a:1[0] . ',' . a:1[1] + elseif len(a:1) == 1 + let l:revs = a:1[0] + endif + else + let l:revs = a:1 + endif elseif a:0 >= 2 let l:revs = a:1 . ',' . a:2 endif @@ -1423,16 +1446,23 @@ " Add some other nice commands and mappings. let l:is_file = (l:path != '' && filereadable(l:repo.GetFullPath(l:path))) - command! -buffer -nargs=* Hglogdiff :call s:HgLog_Diff(<f-args>) + command! -buffer -nargs=* Hglogdiffsum :call s:HgLog_DiffSummary(0, <f-args>) + command! -buffer -nargs=* Hglogvdiffsum :call s:HgLog_DiffSummary(1, <f-args>) if l:is_file - command! -buffer Hglogrevedit :call s:HgLog_FileRevEdit() + command! -buffer Hglogrevedit :call s:HgLog_FileRevEdit() + command! -buffer -nargs=* Hglogdiff :call s:HgLog_Diff(0, <f-args>) + command! -buffer -nargs=* Hglogvdiff :call s:HgLog_Diff(1, <f-args>) endif if g:lawrencium_define_mappings - nnoremap <buffer> <silent> <cr> :Hglogdiff<cr> - nnoremap <buffer> <silent> q :bdelete!<cr> + nnoremap <buffer> <silent> <C-U> :Hglogdiffsum<cr> + nnoremap <buffer> <silent> <C-H> :Hglogvdiffsum<cr> + nnoremap <buffer> <silent> <cr> :Hglogvdiffsum<cr> + nnoremap <buffer> <silent> q :bdelete!<cr> if l:is_file nnoremap <buffer> <silent> <C-E> :Hglogrevedit<cr> + nnoremap <buffer> <silent> <C-D> :Hglogdiff<cr> + nnoremap <buffer> <silent> <C-V> :Hglogvdiff<cr> endif endif @@ -1461,23 +1491,52 @@ call s:edit_deletable_buffer('lawrencium_rev_for', l:bufobj.nr, l:path) endfunction -function! s:HgLog_Diff(...) abort +function! s:HgLog_Diff(vertical, ...) abort + let l:revs = [] if a:0 >= 2 - let l:revs = a:1 . ',' . a:2 + let l:revs = [a:1, a:2] elseif a:0 == 1 - let l:revs = a:1 + let l:revs = [a:1, 'p1('.a:1.')'] else - let l:revs = s:HgLog_GetSelectedRev() + let l:sel = s:HgLog_GetSelectedRev() + let l:revs = [l:sel, 'p1('.l:sel.')'] endif + let l:repo = s:hg_repo() let l:bufobj = s:buffer_obj() let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName()) - let l:path = l:repo.GetLawrenciumPath(l:log_path['path'], 'diff', l:revs) + let l:path = l:repo.GetFullPath(l:log_path['path']) + + " Go to the window we were in before going to the log window, + " and open the split diff there. + wincmd p + call s:HgDiff(l:path, a:vertical, l:revs) +endfunction + +function! s:HgLog_DiffSummary(vertical, ...) abort + let l:revs = [] + if a:0 >= 2 + let l:revs = [a:1, a:2] + elseif a:0 == 1 + let l:revs = [a:1] + else + let l:revs = [s:HgLog_GetSelectedRev()] + endif + + let l:split_type = 1 + if a:vertical + let l:split_type = 2 + endif + + let l:repo = s:hg_repo() + let l:bufobj = s:buffer_obj() + let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName()) + let l:path = l:repo.GetFullPath(l:log_path['path']) " Go to the window we were in before going in the log window, - " and open the diff there. + " and split for the diff summary from there. wincmd p - call s:edit_deletable_buffer('lawrencium_diff_for', l:bufobj.nr, l:path) + call s:HgDiffSummary(l:path, l:split_type, l:revs) endfunction function! s:HgLog_GetSelectedRev(...) abort