5e72afea669c — Shane Harper 5 years ago
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.
1 files changed, 24 insertions(+), 2 deletions(-)

M autoload/lawrencium/diff.vim
M autoload/lawrencium/diff.vim +24 -2
@@ 88,7 88,7 @@ function! lawrencium#diff#HgDiff(filenam
         " 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 @@ function! lawrencium#diff#HgDiff(filenam
     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