gitk: make 'sort-refs-by-type' optional and persistent

On the 'tags and heads' view, add an option to enable or disable 'Sort refs by type'. This option is read from and written to the config file. Clicking on the option will update the refs in the view. Signed-off-by: Michael Rappazzo <michael.rappazzo@infor.com> Signed-off-by: Johannes Sixt <j6t@kdbg.org>

Michael Rappazzo committed Jul 18, 2025 at 16:33 UTC 9abe70db6cf916e32a4dbbb593cc361cfd67dd65
1 file changed +10 -2
gitk
+10 -2
@@ -10261,6 +10261,9 @@ proc showrefs {} {
10261 pack $top.f.e -side right -fill x -expand 1
10262 pack $top.f.l -side left
10263 grid $top.f - -sticky ew -pady 2
10264 + ${NS}::checkbutton $top.sort -text [mc "Sort refs by type"] \
10265 + -variable sortrefsbytype -command {refill_reflist}
10266 + grid $top.sort - -sticky w -pady 2
10267 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
10268 bind $top <Key-Escape> [list destroy $top]
10269 grid $top.close -
@@ -10304,7 +10307,7 @@ proc reflistfilter_change {n1 n2 op} {
10307 }
10308
10309 proc refill_reflist {} {
10307 - global reflist reflistfilter showrefstop headids tagids otherrefids
10310 + global reflist reflistfilter showrefstop headids tagids otherrefids sortrefsbytype
10311 global curview
10312
10313 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return
@@ -10356,7 +10359,11 @@ proc refill_reflist {} {
10359 }
10360 }
10361 set otherrefs [lsort -index 0 $otherrefs]
10362 +
10363 set refs [concat $localrefs $remoterefs $tagrefs $otherrefs]
10364 + if {!$sortrefsbytype} {
10365 + set refs [lsort -index 0 $refs]
10366 + }
10367
10368 if {$refs eq $reflist} return
10369
@@ -12618,6 +12625,7 @@ set wrapcomment "none"
12625 set wrapdefault "none"
12626 set showneartags 1
12627 set hideremotes 0
12628 +set sortrefsbytype 1
12629 set maxrefs 20
12630 set visiblerefs {"master"}
12631 set maxlinelen 200
@@ -12732,7 +12740,7 @@ set config_variables {
12740 filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor
12741 linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
12742 indexcirclecolor circlecolors linkfgcolor circleoutlinecolor diffbgcolors
12735 - web_browser
12743 + sortrefsbytype web_browser
12744 }
12745 foreach var $config_variables {
12746 config_init_trace $var