Skip to content

Commit 829b37b

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 * External diff detection and usage is optional and has to be enabled in gitk settings * External rename detection ist marked EXPERIMENTAL in the settings and disabled by default * 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: deboeto <[email protected]>
1 parent 477ce5c commit 829b37b

File tree

1 file changed

+47
-7
lines changed

1 file changed

+47
-7
lines changed

gitk-git/gitk

+47-7
Original file line numberDiff line numberDiff line change
@@ -3662,11 +3662,33 @@ proc external_diff_get_one_file {diffid filename diffdir} {
36623662
"revision $diffid"]
36633663
}
36643664

3665+
proc check_for_renames_in_diff {filepath} {
3666+
global ctext
3667+
3668+
set renamed_filenames [list {}]
3669+
set filename [file tail $filepath]
3670+
set rename_from_text_length 12
3671+
set rename_to_text_length 10
3672+
set reg_expr_rename_from {^rename from (.*$filename)}
3673+
set reg_expr_rename_from [subst -nobackslashes -nocommands $reg_expr_rename_from]
3674+
set reg_expr_rename_to {^rename to (.*)}
3675+
set rename_from_text_index [$ctext search -elide -regexp -- $reg_expr_rename_from 0.0]
3676+
if { ($rename_from_text_index != {})} {
3677+
set rename_to_text_index [$ctext search -elide -regexp -- $reg_expr_rename_to $rename_from_text_index]
3678+
if { ($rename_from_text_index != {}) && ($rename_to_text_index != {}) } {
3679+
lappend renamed_filenames [$ctext get "$rename_from_text_index + $rename_from_text_length chars" "$rename_from_text_index lineend"]
3680+
lappend renamed_filenames [$ctext get "$rename_to_text_index + $rename_to_text_length chars" "$rename_to_text_index lineend"]
3681+
}
3682+
}
3683+
return $renamed_filenames
3684+
}
3685+
36653686
proc external_diff {} {
36663687
global nullid nullid2
36673688
global flist_menu_file
36683689
global diffids
36693690
global extdifftool
3691+
global file_rename_detection
36703692

36713693
if {[llength $diffids] == 1} {
36723694
# no reference commit given
@@ -3692,8 +3714,21 @@ proc external_diff {} {
36923714
if {$diffdir eq {}} return
36933715

36943716
# gather files to diff
3695-
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3696-
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3717+
if {$file_rename_detection} {
3718+
set renamed_filenames [check_for_renames_in_diff $flist_menu_file]
3719+
set rename_from_filename [lindex $renamed_filenames 1]
3720+
set rename_to_filename [lindex $renamed_filenames 2]
3721+
if { ($rename_from_filename != {}) && ($rename_to_filename != {}) } {
3722+
set difffromfile [external_diff_get_one_file $diffidfrom $rename_from_filename $diffdir]
3723+
set difftofile [external_diff_get_one_file $diffidto $rename_to_filename $diffdir]
3724+
} else {
3725+
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3726+
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3727+
}
3728+
} else {
3729+
set difffromfile [external_diff_get_one_file $diffidfrom $flist_menu_file $diffdir]
3730+
set difftofile [external_diff_get_one_file $diffidto $flist_menu_file $diffdir]
3731+
}
36973732

36983733
if {$difffromfile ne {} && $difftofile ne {}} {
36993734
set cmd [list [shellsplit $extdifftool] $difffromfile $difftofile]
@@ -11577,7 +11612,7 @@ proc create_prefs_page {w} {
1157711612
proc prefspage_general {notebook} {
1157811613
global NS maxwidth maxgraphpct showneartags showlocalchanges
1157911614
global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11580-
global hideremotes want_ttk have_ttk maxrefs web_browser
11615+
global hideremotes want_ttk have_ttk maxrefs web_browser file_rename_detection
1158111616

1158211617
set page [create_prefs_page $notebook.general]
1158311618

@@ -11639,12 +11674,16 @@ proc prefspage_general {notebook} {
1163911674
grid $page.lgen - -sticky w -pady 10
1164011675
${NS}::checkbutton $page.want_ttk -variable want_ttk \
1164111676
-text [mc "Use themed widgets"]
11677+
${NS}::checkbutton $page.file_rename_detection -variable file_rename_detection \
11678+
-text [mc "Use ext diff file rename detection"]
11679+
${NS}::label $page.file_rename_detection_note -text [mc "(EXPERIMENTAL\nTries to find the file path of a\nrenamed file in external diff)"]
1164211680
if {$have_ttk} {
1164311681
${NS}::label $page.ttk_note -text [mc "(change requires restart)"]
1164411682
} else {
1164511683
${NS}::label $page.ttk_note -text [mc "(currently unavailable)"]
1164611684
}
1164711685
grid x $page.want_ttk $page.ttk_note -sticky w
11686+
grid x $page.file_rename_detection $page.file_rename_detection_note -sticky w
1164811687
return $page
1164911688
}
1165011689

@@ -11725,7 +11764,7 @@ proc doprefs {} {
1172511764
global oldprefs prefstop showneartags showlocalchanges
1172611765
global uicolor bgcolor fgcolor ctext diffcolors selectbgcolor markbgcolor
1172711766
global tabstop limitdiffs autoselect autosellen extdifftool perfile_attrs
11728-
global hideremotes want_ttk have_ttk
11767+
global hideremotes want_ttk have_ttk file_rename_detection
1172911768

1173011769
set top .gitkprefs
1173111770
set prefstop $top
@@ -11734,7 +11773,7 @@ proc doprefs {} {
1173411773
return
1173511774
}
1173611775
foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11737-
limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11776+
limitdiffs tabstop perfile_attrs hideremotes want_ttk file_rename_detection} {
1173811777
set oldprefs($v) [set $v]
1173911778
}
1174011779
ttk_toplevel $top
@@ -11860,7 +11899,7 @@ proc prefscan {} {
1186011899
global oldprefs prefstop
1186111900

1186211901
foreach v {maxwidth maxgraphpct showneartags showlocalchanges \
11863-
limitdiffs tabstop perfile_attrs hideremotes want_ttk} {
11902+
limitdiffs tabstop perfile_attrs hideremotes want_ttk file_rename_detection} {
1186411903
global $v
1186511904
set $v $oldprefs($v)
1186611905
}
@@ -12404,6 +12443,7 @@ set autoselect 1
1240412443
set autosellen 40
1240512444
set perfile_attrs 0
1240612445
set want_ttk 1
12446+
set file_rename_detection 0
1240712447

1240812448
if {[tk windowingsystem] eq "aqua"} {
1240912449
set extdifftool "opendiff"
@@ -12498,7 +12538,7 @@ config_check_tmp_exists 50
1249812538
set config_variables {
1249912539
mainfont textfont uifont tabstop findmergefiles maxgraphpct maxwidth
1250012540
cmitmode wrapcomment autoselect autosellen showneartags maxrefs visiblerefs
12501-
hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk
12541+
hideremotes showlocalchanges datetimeformat limitdiffs uicolor want_ttk file_rename_detection
1250212542
bgcolor fgcolor uifgcolor uifgdisabledcolor colors diffcolors mergecolors
1250312543
markbgcolor diffcontext selectbgcolor foundbgcolor currentsearchhitbgcolor
1250412544
extdifftool perfile_attrs headbgcolor headfgcolor headoutlinecolor

0 commit comments

Comments
 (0)