comparison autoload/lawrencium/diff.vim @ 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 4d5f4233b04e
children 7aa118f73e8c
comparison
equal deleted inserted replaced
148:fb65725f2872 149:5e72afea669c
86 endif 86 endif
87 endif 87 endif
88 " Make it part of the diff group. 88 " Make it part of the diff group.
89 call s:HgDiff_DiffThis(l:diff_id) 89 call s:HgDiff_DiffThis(l:diff_id)
90 else 90 else
91 let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev1) 91 let l:rev_path = s:GetLawrenciumPath(l:path, l:rev1)
92 if a:split == 2 92 if a:split == 2
93 " See comments above about avoiding `tabedit`. 93 " See comments above about avoiding `tabedit`.
94 tabnew 94 tabnew
95 let l:cleanupbufnr = bufnr('%') 95 let l:cleanupbufnr = bufnr('%')
96 endif 96 endif
110 let l:diffsplit = 'vsplit' 110 let l:diffsplit = 'vsplit'
111 endif 111 endif
112 if l:rev2 == '' 112 if l:rev2 == ''
113 execute l:diffsplit . ' ' . fnameescape(l:path) 113 execute l:diffsplit . ' ' . fnameescape(l:path)
114 else 114 else
115 let l:rev_path = l:repo.GetLawrenciumPath(l:path, 'rev', l:rev2) 115 let l:rev_path = s:GetLawrenciumPath(l:path, l:rev2)
116 execute l:diffsplit . ' ' . fnameescape(l:rev_path) 116 execute l:diffsplit . ' ' . fnameescape(l:rev_path)
117 endif 117 endif
118 call s:HgDiff_DiffThis(l:diff_id) 118 call s:HgDiff_DiffThis(l:diff_id)
119 endfunction
120
121 function! s:GetLawrenciumPath(path, rev)
122 return lawrencium#hg_repo().GetLawrenciumPath(s:absolute_pathname(a:path, a:rev), 'rev', a:rev)
123 endfunction
124
125 function! s:absolute_pathname(current_absolute_pathname, revision)
126 let l:repo = lawrencium#hg_repo()
127 if s:is_tip_revision(a:revision)
128 let name_of_copied_file = matchstr(
129 \ l:repo.RunCommand('status', '--copies', a:current_absolute_pathname),
130 \ '^A .\{-}\n \zs[^\n]\+')
131 return !empty(name_of_copied_file)
132 \ ? l:repo.root_dir . '/' . name_of_copied_file
133 \ : a:current_absolute_pathname
134 endif
135 " TODO: handle !s:is_tip_revision(a:revision)
136 return a:current_absolute_pathname
137 endfunction
138
139 function! s:is_tip_revision(rev)
140 return a:rev ==# 'tip' || a:rev ==# 'p1()' || a:rev == '-1' " TODO: Check for other ways of specifying the tip revision.
119 endfunction 141 endfunction
120 142
121 function! lawrencium#diff#HgDiffThis(diff_id) 143 function! lawrencium#diff#HgDiffThis(diff_id)
122 call s:HgDiff_DiffThis(a:diff_id) 144 call s:HgDiff_DiffThis(a:diff_id)
123 endfunction 145 endfunction