Skip to content

Commit c585fd5

Browse files
committed
gitk: added external diff file rename detection
* If a file was renamed between commits and an external diff is started through gitk on the THE ORIGINAL FILE NAME (not the renamed one), gitk was unable to open the renamed file in the external diff editor. It failed to fetch the renamed file from git, because it fetched it with the original path in contrast to using the renamed path * gitk now detects the rename and opens the external diff with the original and the RENAMED file instead of no file (it is able to fetch the renamed file now from git with the renamed path/filename) * Since git doesn't destinguish between move or rename this also works for moved files * Showing the renamed file doesn't work when THE RENAMED FILE is selected in gitk and an external diff ist started on that file, because the selected file is not renamed in that commit. It already IS the renamed file. Signed-off-by: Tobias Boeesch <[email protected]>
1 parent 388218f commit c585fd5

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

gitk-git/gitk

+31-2
Original file line numberDiff line numberDiff line change
@@ -3666,6 +3666,27 @@ proc external_diff_get_one_file {diffid filename diffdir} {
36663666
"revision $diffid"]
36673667
}
36683668

3669+
proc check_for_renames_in_diff {filepath} {
3670+
global ctext
3671+
3672+
set renamed_filenames [list {}]
3673+
set filename [file tail $filepath]
3674+
set rename_from_text_identifier_length 12
3675+
set rename_to_text_identifier_length 10
3676+
set reg_expr_rename_from {^rename from (.*$filename)}
3677+
set reg_expr_rename_from [subst -nobackslashes -nocommands $reg_expr_rename_from]
3678+
set reg_expr_rename_to {^rename to (.*)}
3679+
set rename_from_text_index [$ctext search -elide -regexp -- $reg_expr_rename_from 0.0]
3680+
if { ($rename_from_text_index != {})} {
3681+
set rename_to_text_index [$ctext search -elide -regexp -- $reg_expr_rename_to $rename_from_text_index]
3682+
if { ($rename_from_text_index != {}) && ($rename_to_text_index != {}) } {
3683+
lappend renamed_filenames [$ctext get "$rename_from_text_index + $rename_from_text_identifier_length chars" "$rename_from_text_index lineend"]
3684+
lappend renamed_filenames [$ctext get "$rename_to_text_index + $rename_to_text_identifier_length chars" "$rename_to_text_index lineend"]
3685+
}
3686+
}
3687+
return $renamed_filenames
3688+
}
3689+
36693690
proc external_diff {} {
36703691
global nullid nullid2
36713692
global flist_menu_file
@@ -3696,8 +3717,16 @@ proc external_diff {} {
36963717
if {$diffdir eq {}} return
36973718

36983719
# gather files to diff
3699-
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3700-
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3720+
set renamed_filenames [check_for_renames_in_diff $flist_menu_file]
3721+
set rename_from_filename [lindex $renamed_filenames 1]
3722+
set rename_to_filename [lindex $renamed_filenames 2]
3723+
if { ($rename_from_filename != {}) && ($rename_to_filename != {}) } {
3724+
set difffromfile [external_diff_get_one_file $diffidfrom $rename_from_filename $diffdir]
3725+
set difftofile [external_diff_get_one_file $diffidto $rename_to_filename $diffdir]
3726+
} else {
3727+
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3728+
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3729+
}
37013730

37023731
if {$difffromfile ne {} && $difftofile ne {}} {
37033732
set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]

0 commit comments

Comments
 (0)