Mercurial > vim-lawrencium
changeset 138:a2d823c82e5f
Merge pull request #11 from GitHub.
author | Ludovic Chabant <ludovic@chabant.com> |
---|---|
date | Tue, 19 Apr 2016 21:33:41 -0700 |
parents | 90f8d4bf4fa7 (diff) 3f1c7af69b43 (current diff) |
children | 065625e1bb31 |
files | plugin/lawrencium.vim |
diffstat | 2 files changed, 54 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- a/doc/lawrencium.txt Sun Feb 21 15:48:51 2016 +0900 +++ b/doc/lawrencium.txt Tue Apr 19 21:33:41 2016 -0700 @@ -474,6 +474,9 @@ :Hgannotatediffsum Show a diff summary (similar to |:Hgdiffsum|) for the revision mentioned under the cursor. Mapped to |<CR>|. +:Hgannotatelog Show the complete commit for the revision mentioned + under the cursor. + Mapped to <Leader><CR>.
--- a/plugin/lawrencium.vim Sun Feb 21 15:48:51 2016 +0900 +++ b/plugin/lawrencium.vim Tue Apr 19 21:33:41 2016 -0700 @@ -2,6 +2,7 @@ " Maintainer: Ludovic Chabant <http://ludovic.chabant.com> " Version: 0.4.0 + " Globals {{{ if !exists('g:lawrencium_debug') @@ -61,11 +62,6 @@ return fnamemodify(a:path, ':s?[/\\]$??') endfunction -" Surrounds the given string with double quotes. -function! s:addquotes(str) - return '"' . a:str . '"' -endfunction - " Returns whether a path is absolute. function! s:isabspath(path) return a:path =~# '\v^(\w\:)?[/\\]' @@ -356,24 +352,38 @@ if a:0 == 1 && type(a:1) == type([]) let l:arg_list = a:1 endif + let l:prev_shellslash = &shellslash + setlocal noshellslash let l:hg_command = g:lawrencium_hg_executable . ' --repository ' . shellescape(s:stripslash(self.root_dir)) let l:hg_command = l:hg_command . ' ' . a:command for l:arg in l:arg_list - if stridx(l:arg, ' ') >= 0 - let l:hg_command = l:hg_command . ' "' . l:arg . '"' - else - let l:hg_command = l:hg_command . ' ' . l:arg - endif + let l:hg_command = l:hg_command . ' ' . shellescape(l:arg) endfor + if l:prev_shellslash + setlocal shellslash + endif return l:hg_command endfunction " Runs a Mercurial command in the repo. function! s:HgRepo.RunCommand(command, ...) abort + let l:all_args = [1, a:command] + a:000 + return call(self['RunCommandEx'], l:all_args, self) +endfunction + +function! s:HgRepo.RunCommandEx(plain_mode, command, ...) abort + let l:prev_hgplain = $HGPLAIN + if a:plain_mode + let $HGPLAIN = 'true' + endif let l:all_args = [a:command] + a:000 let l:hg_command = call(self['GetCommand'], l:all_args, self) call s:trace("Running Mercurial command: " . l:hg_command) - return system(l:hg_command) + let l:cmd_out = system(l:hg_command) + if a:plain_mode + let $HGPLAIN = l:prev_hgplain + endif + return l:cmd_out endfunction " Runs a Mercurial command in the repo and reads its output into the current @@ -672,7 +682,7 @@ if l:rev == '' call a:repo.ReadCommandOutput('cat', a:full_path) else - call a:repo.ReadCommandOutput('cat', '-r', s:addquotes(l:rev), a:full_path) + call a:repo.ReadCommandOutput('cat', '-r', l:rev, a:full_path) endif endfunction @@ -704,6 +714,17 @@ setlocal filetype=hglog endfunction +function! s:read_lawrencium_logpatch(repo, path_parts, full_path) abort + let l:log_cmd = 'log --patch --verbose --rev ' . a:path_parts['value'] + + if a:path_parts['path'] == '' + call a:repo.ReadCommandOutput(l:log_cmd) + else + call a:repo.ReadCommandOutput(l:log_cmd, a:full_path) + endif + setlocal filetype=diff +endfunction + " Diff revisions (`hg diff`) function! s:read_lawrencium_diff(repo, path_parts, full_path) abort let l:diffargs = [] @@ -712,11 +733,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', s:addquotes(l:rev2) ] + let l:diffargs = [ '-r', l:rev2 ] elseif l:rev2 == '-' - let l:diffargs = [ '-r', s:addquotes(l:rev1) ] + let l:diffargs = [ '-r', l:rev1 ] else - let l:diffargs = [ '-r', s:addquotes(l:rev1), '-r', s:addquotes(l:rev2) ] + let l:diffargs = [ '-r', l:rev1, '-r', l:rev2 ] endif elseif a:path_parts['value'] != '' let l:diffargs = [ '-c', a:path_parts['value'] ] @@ -767,6 +788,7 @@ let s:lawrencium_file_readers = { \'rev': function('s:read_lawrencium_rev'), \'log': function('s:read_lawrencium_log'), + \'logpatch': function('s:read_lawrencium_logpatch'), \'diff': function('s:read_lawrencium_diff'), \'status': function('s:read_lawrencium_status'), \'annotate': function('s:read_lawrencium_annotate'), @@ -875,7 +897,7 @@ " to make auto-completed paths work magically. execute 'cd! ' . fnameescape(l:repo.root_dir) endif - let l:output = call(l:repo.RunCommand, a:000, l:repo) + let l:output = call(l:repo.RunCommandEx, [0] + a:000, l:repo) if g:lawrencium_auto_cd execute 'cd! -' endif @@ -1395,6 +1417,7 @@ let w:lawrencium_diffoff['&cursorbind'] = &l:cursorbind let w:lawrencium_diffoff['&foldmethod'] = &l:foldmethod let w:lawrencium_diffoff['&foldcolumn'] = &l:foldcolumn + let w:lawrencium_diffoff['&foldenable'] = &l:foldenable let w:lawrencium_diff_id = a:diff_id diffthis autocmd BufWinLeave <buffer> call s:HgDiff_CleanUp() @@ -2015,8 +2038,10 @@ " Add some other nice commands and mappings. command! -buffer Hgannotatediffsum :call s:HgAnnotate_DiffSummary() + command! -buffer Hgannotatelog :call s:HgAnnotate_DiffSummary(1) if g:lawrencium_define_mappings nnoremap <buffer> <silent> <cr> :Hgannotatediffsum<cr> + nnoremap <buffer> <silent> <leader><cr> :Hgannotatelog<cr> endif " Clean up when the annotate buffer is deleted. @@ -2030,15 +2055,20 @@ endif endfunction -function! s:HgAnnotate_DiffSummary() abort +function! s:HgAnnotate_DiffSummary(...) abort " Get the path for the diff of the revision specified under the cursor. let l:line = getline('.') let l:rev_hash = matchstr(l:line, '\v[a-f0-9]{12}') + let l:log = (a:0 > 0 ? a:1 : 0) " Get the Lawrencium path for the diff, and the buffer object for the " annotation. let l:repo = s:hg_repo() - let l:path = l:repo.GetLawrenciumPath(b:lawrencium_annotated_path, 'diff', l:rev_hash) + if l:log + let l:path = l:repo.GetLawrenciumPath(b:lawrencium_annotated_path, 'logpatch', l:rev_hash) + else + let l:path = l:repo.GetLawrenciumPath(b:lawrencium_annotated_path, 'diff', l:rev_hash) + endif let l:annotate_buffer = s:buffer_obj() " Find a window already displaying diffs for this annotation. @@ -2179,7 +2209,7 @@ call l:orig_buf.DefineCommand('Hgrecordabort', ':call s:HgRecord_Abort()') call l:orig_buf.DefineCommand('Hgrecordcommit', ':call s:HgRecord_Execute()') call s:HgDiff_DiffThis(l:diff_id) - setlocal foldmethod=marker + setlocal foldmethod=diff " Split the window and open the parent revision in the right or bottom " window. Keep the current buffer in the left or top window... we're going @@ -2188,7 +2218,7 @@ if a:split == 1 let l:cmd = 'keepalt rightbelow vsplit ' endif - let l:rev_path = l:repo.GetLawrenciumPath(expand('%'), 'rev', '') + let l:rev_path = l:repo.GetLawrenciumPath(expand('%:p'), 'rev', '') execute l:cmd . fnameescape(l:rev_path) " This new buffer with the parent revision is set as a Lawrencium buffer. @@ -2215,7 +2245,7 @@ " Make it the other part of the diff. call s:HgDiff_DiffThis(l:diff_id) - setlocal foldmethod=marker + setlocal foldmethod=diff call l:rec_buf.SetVar('&filetype', l:orig_buf.GetVar('&filetype')) call l:rec_buf.SetVar('&fileformat', l:orig_buf.GetVar('&fileformat'))