# HG changeset patch # User Ludovic Chabant # Date 1712726834 25200 # Tue Apr 09 22:27:14 2024 -0700 # Node ID 528bb9bd9401a2448baed09ae171d8d7f7e38990 # Parent 8ef4da9be292add67b989a30d3656139f4833dfe Add command to quickly get the revision that last touched a line. diff --git a/autoload/lawrencium/log.vim b/autoload/lawrencium/log.vim --- a/autoload/lawrencium/log.vim +++ b/autoload/lawrencium/log.vim @@ -4,6 +4,8 @@ call lawrencium#add_command("-nargs=* -complete=customlist,lawrencium#log#list_logthis_options Hgvlogthis :call lawrencium#log#HgLog(1, '%:p', )") call lawrencium#add_command("-nargs=* -complete=customlist,lawrencium#log#list_log_options Hglog :call lawrencium#log#HgLog(0, )") call lawrencium#add_command("-nargs=* -complete=customlist,lawrencium#log#list_log_options Hgvlog :call lawrencium#log#HgLog(1, )") + call lawrencium#add_command("Hglogline :call lawrencium#log#HgLogLine(0)") + call lawrencium#add_command("Hgvlogline :call lawrencium#log#HgLogLine(1)") call lawrencium#add_reader("log", "lawrencium#log#read") call lawrencium#add_reader("logpatch", "lawrencium#log#read_patch") @@ -108,6 +110,23 @@ call l:bufobj.OnDelete('call lawrencium#log#HgLog_Delete(' . l:bufobj.nr . ')') endfunction +function! lawrencium#log#HgLogLine(vertical, ...) abort + let l:path = expand('%:p') + let l:repo = lawrencium#hg_repo() + let l:annotate_lines = split(l:repo.RunCommand('annotate', l:path, '-T', "{lines % '{node}\\n'}"), "\n") + + let l:cur_line = line('.') + if (l:cur_line - 1) < len(l:annotate_lines) + let l:line_rev = l:annotate_lines[l:cur_line - 1] + let l:rev_range = l:line_rev . '^..' . l:line_rev + call lawrencium#log#HgLog(a:vertical, l:path, '-r', l:rev_range) + else + call lawrencium#error( + \"Can't find line " . (l:cur_line - 1) . " in annotate command output. " . + \"Got " . len(l:annotate_lines) . " lines.") + endif +endfunction + function! lawrencium#log#HgLog_Delete(bufnr) if g:lawrencium_auto_close_buffers call lawrencium#delete_dependency_buffers('lawrencium_diff_for', a:bufnr) diff --git a/doc/lawrencium.txt b/doc/lawrencium.txt --- a/doc/lawrencium.txt +++ b/doc/lawrencium.txt @@ -190,6 +190,11 @@ :Hglog {file} Same as |:Hglog|, but opens the log for the specified file or direcotry instead of the whole repository. + *:Hglogline* +:Hglogline Gets the last revision that changed the line currently + under the cursor and shows the log entry for it, as if + running |:Hgannotate| followed by `Hglog `. + *:Hglogthis* :Hglogthis Same as |:Hglog| but opens the history (log) for the currently edited file instead of the whole repository.