changeset 149:5e72afea669c

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.
author Shane Harper <shane@shaneharper.net>
date Sat, 08 Feb 2020 20:52:39 +1100
parents fb65725f2872
children 7aa118f73e8c
files autoload/lawrencium/diff.vim
diffstat 1 files changed, 24 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/autoload/lawrencium/diff.vim	Sat Jan 11 14:29:47 2020 +1100
+++ b/autoload/lawrencium/diff.vim	Sat Feb 08 20:52:39 2020 +1100
@@ -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