mirror of
https://github.com/git/git.git
synced 2026-01-11 21:33:13 +09:00
gitk: add external diff file rename detection
If a file is renamed between commits and an external diff is started through gitk on the original or the renamed file name, gitk is unable to open the renamed file in the external diff editor. It fails to fetch the renamed file from git, because it fetches it using its original path in contrast to using the renamed path of the file. Detect the rename and open the external diff with the original and the renamed file instead of no file (fetch the renamed file path and name from git) no matter if the original or the renamed file is selected in gitk. Signed-off-by: Tobias Boesch <tobias.boesch@miele.com> Signed-off-by: Johannes Sixt <j6t@kdbg.org>
This commit is contained in:
parent
4a6cc6a20e
commit
bdb1cf8312
40
gitk
40
gitk
@ -3806,6 +3806,34 @@ proc external_diff_get_one_file {diffid filename diffdir} {
|
||||
"revision $diffid"]
|
||||
}
|
||||
|
||||
proc check_for_renames_in_diff {filepath} { # renames
|
||||
global difffilestart ctext
|
||||
|
||||
set filename [file tail $filepath]
|
||||
set renames {}
|
||||
|
||||
foreach loc $difffilestart {
|
||||
set loclineend [string map {.0 .end} $loc]
|
||||
set fromlineloc "$loc + 2 lines"
|
||||
set tolineloc "$loc + 3 lines"
|
||||
set renfromline [$ctext get $fromlineloc [string map {.0 .end} $fromlineloc]]
|
||||
set rentoline [$ctext get $tolineloc [string map {.0 .end} $tolineloc]]
|
||||
if {[string equal -length 12 "rename from " $renfromline]
|
||||
&& [string equal -length 10 "rename to " $rentoline]} {
|
||||
set renfrom [string range $renfromline 12 end]
|
||||
set rento [string range $rentoline 10 end]
|
||||
if {[string first $filename $renfrom] != -1
|
||||
|| [string first $filename $rento] != -1} {
|
||||
lappend renames $renfrom
|
||||
lappend renames $rento
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $renames
|
||||
}
|
||||
|
||||
proc external_diff {} {
|
||||
global nullid nullid2
|
||||
global flist_menu_file
|
||||
@ -3836,8 +3864,16 @@ proc external_diff {} {
|
||||
if {$diffdir eq {}} return
|
||||
|
||||
# gather files to diff
|
||||
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
|
||||
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
|
||||
set renames [check_for_renames_in_diff $flist_menu_file]
|
||||
set renamefrom [lindex $renames 0]
|
||||
set renameto [lindex $renames 1]
|
||||
if {$renamefrom ne {} && $renameto ne {}} {
|
||||
set difffromfile [external_diff_get_one_file $diffidfrom $renamefrom $diffdir]
|
||||
set difftofile [external_diff_get_one_file $diffidto $renameto $diffdir]
|
||||
} else {
|
||||
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
|
||||
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
|
||||
}
|
||||
|
||||
if {$difffromfile ne {} && $difftofile ne {}} {
|
||||
set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user