@@ -1974,14 +1974,14 @@ proc longid {prefix} {
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,6 +2035,17 @@ proc readrefs {} {
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,6 +10292,9 @@ proc showrefs {} {
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,43 +10338,71 @@ proc reflistfilter_change {n1 n2 op} {
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
+
10332
10351
foreach n [ array names headids] {
10333
- if {[ string match $reflistfilter $n ] } {
10352
+ if {! [ string match " remotes/* " $n ] && [ string match $reflistfilter $n ] } {
10334
10353
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]
10339
10357
}
10340
10358
} else {
10341
10359
interestedin $headids($n) {run refill_reflist}
10342
10360
}
10343
10361
}
10344
10362
}
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
+
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,6 +12676,7 @@ set wrapcomment "none"
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,7 +12791,7 @@ set config_variables {
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
0 commit comments