Slightly older version of master from https://github.com/j6t/gitk

Merge branch 'mr/sort-refs-by-type'

* mr/sort-refs-by-type:
gitk: separate upstream refs when using the sort-by-type option
gitk: make 'sort-refs-by-type' optional and persistent
gitk: sort by ref type on the 'tags and heads' view

+57 -14
+57 -14
gitk
··· 1974 1974 } 1975 1975 1976 1976 proc readrefs {} { 1977 - global tagids idtags headids idheads tagobjid 1977 + global tagids idtags headids idheads tagobjid upstreamofref 1978 1978 global otherrefids idotherrefs mainhead mainheadid 1979 1979 global selecthead selectheadid 1980 1980 global hideremotes 1981 1981 global tclencoding 1982 1982 global hashlength 1983 1983 1984 - foreach v {tagids idtags headids idheads otherrefids idotherrefs} { 1984 + foreach v {tagids idtags headids idheads otherrefids idotherrefs upstreamofref} { 1985 1985 unset -nocomplain $v 1986 1986 } 1987 1987 set refd [safe_open_command [list git show-ref -d]] ··· 2035 2035 set selectheadid [safe_exec [list git rev-parse --verify $selecthead]] 2036 2036 } 2037 2037 } 2038 + #load the local_branch->upstream mapping 2039 + # the result of the for-each-ref command produces: local_branch NUL upstream 2040 + set refd [safe_open_command [list git for-each-ref {--format=%(refname:short)%00%(upstream)} refs/heads/]] 2041 + while {[gets $refd local_tracking] >= 0} { 2042 + set line [split $local_tracking \0] 2043 + if {[lindex $line 1] ne {}} { 2044 + set upstream_ref [string map {"refs/" ""} [lindex $line 1]] 2045 + set upstreamofref([lindex $line 0]) $upstream_ref 2046 + } 2047 + } 2048 + catch {close $refd} 2038 2049 } 2039 2050 2040 2051 # skip over fake commits ··· 10281 10292 pack $top.f.e -side right -fill x -expand 1 10282 10293 pack $top.f.l -side left 10283 10294 grid $top.f - -sticky ew -pady 2 10295 + ${NS}::checkbutton $top.sort -text [mc "Sort refs by type"] \ 10296 + -variable sortrefsbytype -command {refill_reflist} 10297 + grid $top.sort - -sticky w -pady 2 10284 10298 ${NS}::button $top.close -command [list destroy $top] -text [mc "Close"] 10285 10299 bind $top <Key-Escape> [list destroy $top] 10286 10300 grid $top.close - ··· 10324 10338 } 10325 10339 10326 10340 proc refill_reflist {} { 10327 - global reflist reflistfilter showrefstop headids tagids otherrefids 10328 - global curview 10341 + global reflist reflistfilter showrefstop headids tagids otherrefids sortrefsbytype 10342 + global curview upstreamofref 10329 10343 10330 10344 if {![info exists showrefstop] || ![winfo exists $showrefstop]} return 10331 - set refs {} 10345 + set localrefs {} 10346 + set remoterefs {} 10347 + set trackedremoterefs {} 10348 + set tagrefs {} 10349 + set otherrefs {} 10350 + 10351 + foreach n [array names headids] { 10352 + if {![string match "remotes/*" $n] && [string match $reflistfilter $n]} { 10353 + if {[commitinview $headids($n) $curview]} { 10354 + lappend localrefs [list $n H] 10355 + if {[info exists upstreamofref($n)]} { 10356 + lappend trackedremoterefs [list $upstreamofref($n) R] 10357 + } 10358 + } else { 10359 + interestedin $headids($n) {run refill_reflist} 10360 + } 10361 + } 10362 + } 10363 + set trackedremoterefs [lsort -index 0 $trackedremoterefs] 10364 + set localrefs [lsort -index 0 $localrefs] 10365 + 10332 10366 foreach n [array names headids] { 10333 - if {[string match $reflistfilter $n]} { 10367 + if {[string match "remotes/*" $n] && [string match $reflistfilter $n]} { 10334 10368 if {[commitinview $headids($n) $curview]} { 10335 - if {[string match "remotes/*" $n]} { 10336 - lappend refs [list $n R] 10337 - } else { 10338 - lappend refs [list $n H] 10369 + if {[lsearch -exact $trackedremoterefs [list $n R]] < 0} { 10370 + lappend remoterefs [list $n R] 10339 10371 } 10340 10372 } else { 10341 10373 interestedin $headids($n) {run refill_reflist} 10342 10374 } 10343 10375 } 10344 10376 } 10377 + set remoterefs [lsort -index 0 $remoterefs] 10378 + 10345 10379 foreach n [array names tagids] { 10346 10380 if {[string match $reflistfilter $n]} { 10347 10381 if {[commitinview $tagids($n) $curview]} { 10348 - lappend refs [list $n T] 10382 + lappend tagrefs [list $n T] 10349 10383 } else { 10350 10384 interestedin $tagids($n) {run refill_reflist} 10351 10385 } 10352 10386 } 10353 10387 } 10388 + set tagrefs [lsort -index 0 $tagrefs] 10389 + 10354 10390 foreach n [array names otherrefids] { 10355 10391 if {[string match $reflistfilter $n]} { 10356 10392 if {[commitinview $otherrefids($n) $curview]} { 10357 - lappend refs [list $n o] 10393 + lappend otherrefs [list "$n" o] 10358 10394 } else { 10359 10395 interestedin $otherrefids($n) {run refill_reflist} 10360 10396 } 10361 10397 } 10362 10398 } 10363 - set refs [lsort -index 0 $refs] 10399 + set otherrefs [lsort -index 0 $otherrefs] 10400 + 10401 + set refs [concat $localrefs $trackedremoterefs $remoterefs $tagrefs $otherrefs] 10402 + if {!$sortrefsbytype} { 10403 + set refs [lsort -index 0 $refs] 10404 + } 10405 + 10364 10406 if {$refs eq $reflist} return 10365 10407 10366 10408 # Update the contents of $showrefstop.list according to the ··· 12634 12676 set wrapdefault "none" 12635 12677 set showneartags 1 12636 12678 set hideremotes 0 12679 + set sortrefsbytype 1 12637 12680 set maxrefs 20 12638 12681 set visiblerefs {"master"} 12639 12682 set maxlinelen 200 ··· 12748 12791 filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor 12749 12792 linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor 12750 12793 indexcirclecolor circlecolors linkfgcolor circleoutlinecolor diffbgcolors 12751 - web_browser 12794 + sortrefsbytype web_browser 12752 12795 } 12753 12796 foreach var $config_variables { 12754 12797 config_init_trace $var