From: Paul Mackerras Date: Wed, 2 Jan 2013 04:25:29 +0000 (+1100) Subject: gitk: Display important heads even when there are many X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=386befb773e2b4a7cc31135f22555e27597392c1;p=git.git 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 --- diff --git a/gitk b/gitk index 1dd5137d7..b3706fc9b 100755 --- a/gitk +++ b/gitk @@ -6879,7 +6879,7 @@ proc viewnextline {dir} { # add a list of tag or branch names at position pos # returns the number of names inserted proc appendrefs {pos ids var} { - global ctext linknum curview $var maxrefs + global ctext linknum curview $var maxrefs mainheadid if {[catch {$ctext index $pos}]} { return 0 @@ -6892,25 +6892,54 @@ proc appendrefs {pos ids var} { lappend tags [list $tag $id] } } + + set sep {} + set tags [lsort -index 0 -decreasing $tags] + set nutags 0 + if {[llength $tags] > $maxrefs} { - $ctext insert $pos "[mc "many"] ([llength $tags])" - } else { - set tags [lsort -index 0 -decreasing $tags] - set sep {} - foreach ti $tags { - set id [lindex $ti 1] - set lk link$linknum - incr linknum - $ctext tag delete $lk - $ctext insert $pos $sep - $ctext insert $pos [lindex $ti 0] $lk - setlink $id $lk - set sep ", " + # If we are displaying heads, and there are too many, + # see if there are some important heads to display. + # Currently this means "master" and the current head. + set itags {} + if {$var eq "idheads"} { + set utags {} + foreach ti $tags { + set hname [lindex $ti 0] + set id [lindex $ti 1] + if {($hname eq "master" || $id eq $mainheadid) && + [llength $itags] < $maxrefs} { + lappend itags $ti + } else { + lappend utags $ti + } + } + set tags $utags } + if {$itags ne {}} { + set str [mc "and many more"] + set sep " " + } else { + set str [mc "many"] + } + $ctext insert $pos "$str ([llength $tags])" + set nutags [llength $tags] + set tags $itags + } + + foreach ti $tags { + set id [lindex $ti 1] + set lk link$linknum + incr linknum + $ctext tag delete $lk + $ctext insert $pos $sep + $ctext insert $pos [lindex $ti 0] $lk + setlink $id $lk + set sep ", " } $ctext tag add wwrap "$pos linestart" "$pos lineend" $ctext conf -state disabled - return [llength $tags] + return [expr {[llength $tags] + $nutags}] } # called when we have finished computing the nearby tags