Skip to content

Commit c4db1e5

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 db91954 commit c4db1e5

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
@@ -3806,6 +3806,27 @@ proc external_diff_get_one_file {diffid filename diffdir} {
38063806
"revision $diffid"]
38073807
}
38083808
3809+
proc check_for_renames_in_diff {filepath} {
3810+
global ctext
3811+
3812+
set renamed_filenames [list {}]
3813+
set filename [file tail $filepath]
3814+
set rename_from_text_identifier_length 12
3815+
set rename_to_text_identifier_length 10
3816+
set reg_expr_rename_from {^rename from (.*$filename)}
3817+
set reg_expr_rename_from [subst -nobackslashes -nocommands $reg_expr_rename_from]
3818+
set reg_expr_rename_to {^rename to (.*)}
3819+
set rename_from_text_index [$ctext search -elide -regexp -- $reg_expr_rename_from 0.0]
3820+
if { ($rename_from_text_index != {})} {
3821+
set rename_to_text_index [$ctext search -elide -regexp -- $reg_expr_rename_to $rename_from_text_index]
3822+
if { ($rename_from_text_index != {}) && ($rename_to_text_index != {}) } {
3823+
lappend renamed_filenames [$ctext get "$rename_from_text_index + $rename_from_text_identifier_length chars" "$rename_from_text_index lineend"]
3824+
lappend renamed_filenames [$ctext get "$rename_to_text_index + $rename_to_text_identifier_length chars" "$rename_to_text_index lineend"]
3825+
}
3826+
}
3827+
return $renamed_filenames
3828+
}
3829+
38093830
proc external_diff {} {
38103831
global nullid nullid2
38113832
global flist_menu_file
@@ -3836,8 +3857,16 @@ proc external_diff {} {
38363857
if {$diffdir eq {}} return
38373858
38383859
# gather files to diff
3839-
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3840-
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3860+
set renamed_filenames [check_for_renames_in_diff $flist_menu_file]
3861+
set rename_from_filename [lindex $renamed_filenames 1]
3862+
set rename_to_filename [lindex $renamed_filenames 2]
3863+
if { ($rename_from_filename != {}) && ($rename_to_filename != {}) } {
3864+
set difffromfile [external_diff_get_one_file $diffidfrom $rename_from_filename $diffdir]
3865+
set difftofile [external_diff_get_one_file $diffidto $rename_to_filename $diffdir]
3866+
} else {
3867+
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3868+
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3869+
}
38413870
38423871
if {$difffromfile ne {} && $difftofile ne {}} {
38433872
set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]

0 commit comments

Comments
 (0)