aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Boesch <tobias.boesch@miele.com>2025-11-06 14:42:11 +0000
committerJohannes Sixt <j6t@kdbg.org>2025-11-06 19:03:26 +0100
commitbdb1cf831251b16d174f742178caac181add87f4 (patch)
tree6f10148302f77903a14a89c5faa7992bba4f21ec
parent4a6cc6a20eeb593f1ad0f60475a9867532d7c5d5 (diff)
downloadgit-bdb1cf831251b16d174f742178caac181add87f4.tar.xz
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>
-rwxr-xr-xgitk40
1 files changed, 38 insertions, 2 deletions
diff --git a/gitk b/gitk
index bc9efa1856..9659466052 100755
--- a/gitk
+++ b/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]