Skip to content

Commit 386befb

Browse files
committed
gitk: Display important heads even when there are many
When there are more than $maxrefs descendant heads to display in the Branches field of the commit display, we currently just display "many", which is not very informative. To make the display more informative, we now look for "master" and whichever head is currently checked out, and display them even if there are too many heads to display them all. The display then looks like "Branches: master and many more (33)" for instance. Signed-off-by: Paul Mackerras <[email protected]>
1 parent d34835c commit 386befb

File tree

1 file changed

+44
-15
lines changed

1 file changed

+44
-15
lines changed

gitk

Lines changed: 44 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6879,7 +6879,7 @@ proc viewnextline {dir} {
68796879
# add a list of tag or branch names at position pos
68806880
# returns the number of names inserted
68816881
proc appendrefs {pos ids var} {
6882-
global ctext linknum curview $var maxrefs
6882+
global ctext linknum curview $var maxrefs mainheadid
68836883

68846884
if {[catch {$ctext index $pos}]} {
68856885
return 0
@@ -6892,25 +6892,54 @@ proc appendrefs {pos ids var} {
68926892
lappend tags [list $tag $id]
68936893
}
68946894
}
6895+
6896+
set sep {}
6897+
set tags [lsort -index 0 -decreasing $tags]
6898+
set nutags 0
6899+
68956900
if {[llength $tags] > $maxrefs} {
6896-
$ctext insert $pos "[mc "many"] ([llength $tags])"
6897-
} else {
6898-
set tags [lsort -index 0 -decreasing $tags]
6899-
set sep {}
6900-
foreach ti $tags {
6901-
set id [lindex $ti 1]
6902-
set lk link$linknum
6903-
incr linknum
6904-
$ctext tag delete $lk
6905-
$ctext insert $pos $sep
6906-
$ctext insert $pos [lindex $ti 0] $lk
6907-
setlink $id $lk
6908-
set sep ", "
6901+
# If we are displaying heads, and there are too many,
6902+
# see if there are some important heads to display.
6903+
# Currently this means "master" and the current head.
6904+
set itags {}
6905+
if {$var eq "idheads"} {
6906+
set utags {}
6907+
foreach ti $tags {
6908+
set hname [lindex $ti 0]
6909+
set id [lindex $ti 1]
6910+
if {($hname eq "master" || $id eq $mainheadid) &&
6911+
[llength $itags] < $maxrefs} {
6912+
lappend itags $ti
6913+
} else {
6914+
lappend utags $ti
6915+
}
6916+
}
6917+
set tags $utags
69096918
}
6919+
if {$itags ne {}} {
6920+
set str [mc "and many more"]
6921+
set sep " "
6922+
} else {
6923+
set str [mc "many"]
6924+
}
6925+
$ctext insert $pos "$str ([llength $tags])"
6926+
set nutags [llength $tags]
6927+
set tags $itags
6928+
}
6929+
6930+
foreach ti $tags {
6931+
set id [lindex $ti 1]
6932+
set lk link$linknum
6933+
incr linknum
6934+
$ctext tag delete $lk
6935+
$ctext insert $pos $sep
6936+
$ctext insert $pos [lindex $ti 0] $lk
6937+
setlink $id $lk
6938+
set sep ", "
69106939
}
69116940
$ctext tag add wwrap "$pos linestart" "$pos lineend"
69126941
$ctext conf -state disabled
6913-
return [llength $tags]
6942+
return [expr {[llength $tags] + $nutags}]
69146943
}
69156944

69166945
# called when we have finished computing the nearby tags

0 commit comments

Comments
 (0)