# HG changeset patch # User Shane Harper # Date 1581155559 -39600 # Sat Feb 08 20:52:39 2020 +1100 # Node ID 5e72afea669c57e05e7508dddf8ace53d49e8ab9 # Parent fb65725f28720805f31f23f8852427e72e4823e1 Fix :Hgvdiff with a file that is a copy. Previously, :Hg rename old new :" (A rename is a copy and a deletion of the file with the old name.) :edit new :Hgvdiff " "new: no such file in rev NNNN" was displayed in the window to the right of the new vertical split. Now :Hgvdiff diffs new with old from the head revision. diff --git a/autoload/lawrencium/diff.vim b/autoload/lawrencium/diff.vim --- a/autoload/lawrencium/diff.vim +++ b/autoload/lawrencium/diff.vim @@ -88,7 +88,7 @@ " Make it part of the diff group. call s:HgDiff_DiffThis(l:diff_id) else - let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev1) + let l:rev_path = s:GetLawrenciumPath(l:path, l:rev1) if a:split == 2 " See comments above about avoiding `tabedit`. tabnew @@ -112,12 +112,34 @@ if l:rev2 == '' execute l:diffsplit . ' ' . fnameescape(l:path) else - let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev2) + let l:rev_path = s:GetLawrenciumPath(l:path, l:rev2) execute l:diffsplit . ' ' . fnameescape(l:rev_path) endif call s:HgDiff_DiffThis(l:diff_id) endfunction +function! s:GetLawrenciumPath(path, rev) + return lawrencium#hg_repo().GetLawrenciumPath(s:absolute_pathname(a:path, a:rev), 'rev', a:rev) +endfunction + +function! s:absolute_pathname(current_absolute_pathname, revision) + let l:repo = lawrencium#hg_repo() + if s:is_tip_revision(a:revision) + let name_of_copied_file = matchstr( + \ l:repo.RunCommand('status', '--copies', a:current_absolute_pathname), + \ '^A .\{-}\n \zs[^\n]\+') + return !empty(name_of_copied_file) + \ ? l:repo.root_dir . '/' . name_of_copied_file + \ : a:current_absolute_pathname + endif + " TODO: handle !s:is_tip_revision(a:revision) + return a:current_absolute_pathname +endfunction + +function! s:is_tip_revision(rev) + return a:rev ==# 'tip' || a:rev ==# 'p1()' || a:rev == '-1' " TODO: Check for other ways of specifying the tip revision. +endfunction + function! lawrencium#diff#HgDiffThis(diff_id) call s:HgDiff_DiffThis(a:diff_id) endfunction