Skip to content

Commit e2874c6

Browse files
committed
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
2 parents cf9d3c1 + c0fb435 commit e2874c6

File tree

1 file changed

+57
-14
lines changed

1 file changed

+57
-14
lines changed

gitk

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1974,14 +1974,14 @@ proc longid {prefix} {
19741974
}
19751975
19761976
proc readrefs {} {
1977-
global tagids idtags headids idheads tagobjid
1977+
global tagids idtags headids idheads tagobjid upstreamofref
19781978
global otherrefids idotherrefs mainhead mainheadid
19791979
global selecthead selectheadid
19801980
global hideremotes
19811981
global tclencoding
19821982
global hashlength
19831983
1984-
foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
1984+
foreach v {tagids idtags headids idheads otherrefids idotherrefs upstreamofref} {
19851985
unset -nocomplain $v
19861986
}
19871987
set refd [safe_open_command [list git show-ref -d]]
@@ -2035,6 +2035,17 @@ proc readrefs {} {
20352035
set selectheadid [safe_exec [list git rev-parse --verify $selecthead]]
20362036
}
20372037
}
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}
20382049
}
20392050
20402051
# skip over fake commits
@@ -10281,6 +10292,9 @@ proc showrefs {} {
1028110292
pack $top.f.e -side right -fill x -expand 1
1028210293
pack $top.f.l -side left
1028310294
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
1028410298
${NS}::button $top.close -command [list destroy $top] -text [mc "Close"]
1028510299
bind $top <Key-Escape> [list destroy $top]
1028610300
grid $top.close -
@@ -10324,43 +10338,71 @@ proc reflistfilter_change {n1 n2 op} {
1032410338
}
1032510339
1032610340
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
1032910343
1033010344
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+
1033210351
foreach n [array names headids] {
10333-
if {[string match $reflistfilter $n]} {
10352+
if {![string match "remotes/*" $n] && [string match $reflistfilter $n]} {
1033410353
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]
10354+
lappend localrefs [list $n H]
10355+
if {[info exists upstreamofref($n)]} {
10356+
lappend trackedremoterefs [list $upstreamofref($n) R]
1033910357
}
1034010358
} else {
1034110359
interestedin $headids($n) {run refill_reflist}
1034210360
}
1034310361
}
1034410362
}
10363+
set trackedremoterefs [lsort -index 0 $trackedremoterefs]
10364+
set localrefs [lsort -index 0 $localrefs]
10365+
10366+
foreach n [array names headids] {
10367+
if {[string match "remotes/*" $n] && [string match $reflistfilter $n]} {
10368+
if {[commitinview $headids($n) $curview]} {
10369+
if {[lsearch -exact $trackedremoterefs [list $n R]] < 0} {
10370+
lappend remoterefs [list $n R]
10371+
}
10372+
} else {
10373+
interestedin $headids($n) {run refill_reflist}
10374+
}
10375+
}
10376+
}
10377+
set remoterefs [lsort -index 0 $remoterefs]
10378+
1034510379
foreach n [array names tagids] {
1034610380
if {[string match $reflistfilter $n]} {
1034710381
if {[commitinview $tagids($n) $curview]} {
10348-
lappend refs [list $n T]
10382+
lappend tagrefs [list $n T]
1034910383
} else {
1035010384
interestedin $tagids($n) {run refill_reflist}
1035110385
}
1035210386
}
1035310387
}
10388+
set tagrefs [lsort -index 0 $tagrefs]
10389+
1035410390
foreach n [array names otherrefids] {
1035510391
if {[string match $reflistfilter $n]} {
1035610392
if {[commitinview $otherrefids($n) $curview]} {
10357-
lappend refs [list $n o]
10393+
lappend otherrefs [list "$n" o]
1035810394
} else {
1035910395
interestedin $otherrefids($n) {run refill_reflist}
1036010396
}
1036110397
}
1036210398
}
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+
1036410406
if {$refs eq $reflist} return
1036510407
1036610408
# Update the contents of $showrefstop.list according to the
@@ -12634,6 +12676,7 @@ set wrapcomment "none"
1263412676
set wrapdefault "none"
1263512677
set showneartags 1
1263612678
set hideremotes 0
12679+
set sortrefsbytype 1
1263712680
set maxrefs 20
1263812681
set visiblerefs {"master"}
1263912682
set maxlinelen 200
@@ -12748,7 +12791,7 @@ set config_variables {
1274812791
filesepbgcolor filesepfgcolor linehoverbgcolor linehoverfgcolor
1274912792
linehoveroutlinecolor mainheadcirclecolor workingfilescirclecolor
1275012793
indexcirclecolor circlecolors linkfgcolor circleoutlinecolor diffbgcolors
12751-
web_browser
12794+
sortrefsbytype web_browser
1275212795
}
1275312796
foreach var $config_variables {
1275412797
config_init_trace $var

0 commit comments

Comments
 (0)