Skip to content

Commit

Permalink
gitk: Display important heads even when there are many
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
paulusmack committed Jan 2, 2013
1 parent d34835c commit 386befb
Showing 1 changed file with 44 additions and 15 deletions.
59 changes: 44 additions & 15 deletions gitk
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 386befb

Please sign in to comment.