@@ -1971,13 +1971,13 @@ proc longid {prefix} {
19711971}
19721972
19731973proc readrefs {} {
1974- global tagids idtags headids idheads tagobjid
1974+ global tagids idtags headids idheads tagobjid upstreamofref
19751975 global otherrefids idotherrefs mainhead mainheadid
19761976 global selecthead selectheadid
19771977 global hideremotes
19781978 global tclencoding
19791979
1980- foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
1980+ foreach v {tagids idtags headids idheads otherrefids idotherrefs upstreamofref } {
19811981 unset -nocomplain $v
19821982 }
19831983 set refd [ safe_open_command [list git show-ref -d] ]
@@ -2031,6 +2031,17 @@ proc readrefs {} {
20312031 set selectheadid [ safe_exec [list git rev-parse --verify $selecthead ] ]
20322032 }
20332033 }
2034+ #load the local_branch->upstream mapping
2035+ # the result of the for-each-ref command produces: local_branch NUL upstream
2036+ set refd [ safe_open_command [list git for-each-ref {--format=%(refname:short)%00%(upstream)} refs/heads/] ]
2037+ while {[ gets $refd local_tracking] >= 0} {
2038+ set line [ split $local_tracking \0 ]
2039+ if {[ lindex $line 1] ne {}} {
2040+ set upstream_ref [ string map {" refs/" " " } [lindex $line 1] ]
2041+ set upstreamofref([ lindex $line 0] ) $upstream_ref
2042+ }
2043+ }
2044+ catch {close $refd }
20342045}
20352046
20362047# skip over fake commits
@@ -10308,29 +10319,36 @@ proc reflistfilter_change {n1 n2 op} {
1030810319
1030910320proc refill_reflist {} {
1031010321 global reflist reflistfilter showrefstop headids tagids otherrefids sortrefsbytype
10311- global curview
10322+ global curview upstreamofref
1031210323
1031310324 if {![ info exists showrefstop] || ![ winfo exists $showrefstop ] } return
1031410325 set localrefs {}
1031510326 set remoterefs {}
10327+ set trackedremoterefs {}
1031610328 set tagrefs {}
1031710329 set otherrefs {}
1031810330
1031910331 foreach n [ array names headids] {
1032010332 if {![ string match " remotes/*" $n ] && [ string match $reflistfilter $n ] } {
1032110333 if {[ commitinview $headids($n) $curview ] } {
1032210334 lappend localrefs [ list $n H]
10335+ if {[ info exists upstreamofref($n )] } {
10336+ lappend trackedremoterefs [ list $upstreamofref($n) R]
10337+ }
1032310338 } else {
1032410339 interestedin $headids($n) {run refill_reflist}
1032510340 }
1032610341 }
1032710342 }
10343+ set trackedremoterefs [ lsort -index 0 $trackedremoterefs ]
1032810344 set localrefs [ lsort -index 0 $localrefs ]
1032910345
1033010346 foreach n [ array names headids] {
1033110347 if {[ string match " remotes/*" $n ] && [ string match $reflistfilter $n ] } {
1033210348 if {[ commitinview $headids($n) $curview ] } {
10333- lappend remoterefs [ list $n R]
10349+ if {[ lsearch -exact $trackedremoterefs [list $n R] ] < 0} {
10350+ lappend remoterefs [ list $n R]
10351+ }
1033410352 } else {
1033510353 interestedin $headids($n) {run refill_reflist}
1033610354 }
@@ -10360,7 +10378,7 @@ proc refill_reflist {} {
1036010378 }
1036110379 set otherrefs [ lsort -index 0 $otherrefs ]
1036210380
10363- set refs [ concat $localrefs $remoterefs $tagrefs $otherrefs ]
10381+ set refs [ concat $localrefs $trackedremoterefs $ remoterefs $tagrefs $otherrefs ]
1036410382 if {!$sortrefsbytype } {
1036510383 set refs [ lsort -index 0 $refs ]
1036610384 }
0 commit comments