# HG changeset patch # User Ludovic Chabant # Date 1353902434 28800 # Node ID 75e9d909758accee9147116ec53c3d6e5e17ae3a # Parent e8f252a7ed9e05396eb0251d029de89cc16cd608 `Hglog` changes: - `Hglog` now list the history for the whole repository. - `Hglogthis` lists the history for the current file. Fixed a bug with displaying diff summaries. Updated documentation. diff -r e8f252a7ed9e -r 75e9d909758a doc/lawrencium.txt --- a/doc/lawrencium.txt Sat Nov 24 08:50:30 2012 -0800 +++ b/doc/lawrencium.txt Sun Nov 25 20:00:34 2012 -0800 @@ -154,20 +154,18 @@ *:Hglog* :Hglog - Opens the history (log) for the currently edited file - in a split window. Some extra-commands, along with + Opens the history (log) for the current repository + in the |preview-window|. Some extra-commands, along with some default mappings, are available in this window. See |lawrencium-log-window|. *:Hglog_f* :Hglog {file} Same as |:Hglog|, but opens the log for the specified - file instead of the currently edited file. + file or direcotry instead of the whole repository. - *:Hgrepolog* -:Hgrepolog Opens the history (log) for the whole repository in a - split window. Some extra-commands, along with some - default mappings, are available in this window. - See |lawrencium-log-window|. + *:Hglogthis* +:Hglogthis Same as |:Hglog| but opens the history (log) for the + currently edited file instead of the whole repository. *:Hgannotate* :Hgannotate Splits the current window to show annotations in the @@ -275,7 +273,10 @@ :Hglogrevedit Looks at the revision specified on the current line, and opens that revision for edit in the previous window (although as a read-only buffer). - Mapped to ||. + 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 ||. *:Hglogdiff* :Hglogdiff Looks at the revision specified on the current line, @@ -284,7 +285,7 @@ opens that diff in the previous window. It doesn't do anything if the cursor is on the last line. - Mapped to ||. + Mapped to ||. *:Hglogdiff_r* :Hglogdiff {rev} Same as |:Hglogdiff|, but opens a diff between the diff -r e8f252a7ed9e -r 75e9d909758a plugin/lawrencium.vim --- a/plugin/lawrencium.vim Sat Nov 24 08:50:30 2012 -0800 +++ b/plugin/lawrencium.vim Sun Nov 25 20:00:34 2012 -0800 @@ -425,6 +425,10 @@ return l:newBuffer endfunction +function! s:Buffer.GetName() dict abort + return bufname(self.nr) +endfunction + function! s:Buffer.GetVar(var) dict abort return getbufvar(self.nr, a:var) endfunction @@ -1041,15 +1045,13 @@ 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) + let l:cmd = 'edit ' if a:split == 1 - split + let l:cmd = 'rightbelow split ' elseif a:split == 2 - vsplit + let l:cmd = 'rightbelow vsplit ' endif - execute 'edit ' . l:special - " Open all folds by default. - " TODO: maybe set `nofoldenable` instead? - %foldopen! + execute l:cmd . l:special endfunction call s:AddMainCommand("-nargs=* Hgdiffsum :call s:HgDiffSummary('%:p', 0, )") @@ -1193,39 +1195,35 @@ " }}} -" Hglog, Hgrepolog {{{ +" Hglog, Hglogthis {{{ -function! s:HgLog(is_file, ...) abort - " Get the file or directory to get the log from, or figure out - " some nice defaults (the current file, or the whole repository). - if a:is_file - let l:path = expand('%:p') +function! s:HgLog(...) abort + " Get the file or directory to get the log from. + " (empty string is for the whole repository) + let l:repo = s:hg_repo() + if a:0 > 0 + let l:path = l:repo.GetRelativePath(expand(a:1)) else let l:path = '' endif - " Remember the file that opened this log. - let l:original_path = expand('%:p') - - " Get the Lawrencium path for this `hg log`. - let l:repo = s:hg_repo() + " Get the Lawrencium path for this `hg log`, + " open it in a preview window and jump to it. let l:log_path = l:repo.GetLawrenciumPath(l:path, 'log', '') - - " Open it in a preview window and jump to it. execute 'pedit ' . l:log_path wincmd P " 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() - if a:is_file - let b:lawrencium_logged_path = l:repo.GetRelativePath(l:path) - command! -buffer -nargs=? Hglogrevedit :call s:HgLog_FileRevEdit() + if l:is_file + command! -buffer Hglogrevedit :call s:HgLog_FileRevEdit() endif if g:lawrencium_define_mappings nnoremap :Hglogdiff - nnoremap q :bdelete! - if a:is_file + nnoremap q :bdelete! + if l:is_file nnoremap :Hglogrevedit endif endif @@ -1242,17 +1240,12 @@ endif endfunction -function! s:HgLog_FileRevEdit(...) - if a:0 > 0 - " Revision was given manually. - let l:rev = a:1 - else - " Revision should be parsed from the current line in the log. - let l:rev = s:HgLog_GetSelectedRev() - endif +function! s:HgLog_FileRevEdit() let l:repo = s:hg_repo() let l:bufobj = s:buffer_obj() - let l:path = l:repo.GetLawrenciumPath(b:lawrencium_logged_path, 'rev', l:rev) + let l:rev = s:HgLog_GetSelectedRev() + let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName()) + let l:path = l:repo.GetLawrenciumPath(l:log_path['path'], 'rev', l:rev) " Go to the window we were in before going in the log window, " and open the revision there. @@ -1270,7 +1263,8 @@ endif let l:repo = s:hg_repo() let l:bufobj = s:buffer_obj() - let l:path = l:repo.GetLawrenciumPath(b:lawrencium_logged_path, 'diff', l:revs) + let l:log_path = s:parse_lawrencium_path(l:bufobj.GetName()) + let l:path = l:repo.GetLawrenciumPath(l:log_path['path'], 'diff', l:revs) " Go to the window we were in before going in the log window, " and open the diff there. @@ -1292,8 +1286,8 @@ return l:rev endfunction -call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoDirs Hgrepolog :call s:HgLog(0, )") -call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog(1, )") +call s:AddMainCommand("Hglogthis :call s:HgLog('%:p')") +call s:AddMainCommand("-nargs=? -complete=customlist,s:ListRepoFiles Hglog :call s:HgLog()") " }}}