@matheusbsbs / matheus-bagliano / commits / ef030b8547
Fork 0

gitk: Show branch name(s) as well, if "show nearby tags" is enabled

This is a small extension to the code that reads the complete commit graph, to make it compute descendent heads as well as descendent tags. We don't exclude descendent heads that are descendents of other descendent heads as we do for tags, since it is useful to know all the branches that a commit is on. Signed-off-by: Paul Mackerras <paulus@samba.org>

Paul Mackerras committed Jun 4, 2006 at 11:50 UTC ef030b8547eaeea1ef992310536b0b637e0c9431
1 file changed +43 -11
gitk
+43 -11
@@ -3568,14 +3568,17 @@ proc viewnextline {dir} {
3568 allcanvs yview moveto [expr {$newtop * 1.0 / $ymax}]
3569 }
3570
3571 -# add a list of tag names at position pos
3572 -proc appendrefs {pos l} {
3573 - global ctext commitrow linknum curview idtags
3571 +# add a list of tag or branch names at position pos
3572 +# returns the number of names inserted
3573 +proc appendrefs {pos l var} {
3574 + global ctext commitrow linknum curview idtags $var
3575
3575 - if {[catch {$ctext index $pos}]} return
3576 + if {[catch {$ctext index $pos}]} {
3577 + return 0
3578 + }
3579 set tags {}
3580 foreach id $l {
3578 - foreach tag $idtags($id) {
3581 + foreach tag [set $var\($id\)] {
3582 lappend tags [concat $tag $id]
3583 }
3584 }
@@ -3598,20 +3601,27 @@ proc appendrefs {pos l} {
3601 }
3602 set sep ", "
3603 }
3604 + return [llength $tags]
3605 }
3606
3607 # called when we have finished computing the nearby tags
3608 proc dispneartags {} {
3609 global selectedline currentid ctext anc_tags desc_tags showneartags
3610 + global desc_heads
3611
3612 if {![info exists selectedline] || !$showneartags} return
3613 set id $currentid
3614 $ctext conf -state normal
3615 + if {[info exists desc_heads($id)]} {
3616 + if {[appendrefs branch $desc_heads($id) idheads] > 1} {
3617 + $ctext insert "branch -2c" "es"
3618 + }
3619 + }
3620 if {[info exists anc_tags($id)]} {
3611 - appendrefs follows $anc_tags($id)
3621 + appendrefs follows $anc_tags($id) idtags
3622 }
3623 if {[info exists desc_tags($id)]} {
3614 - appendrefs precedes $desc_tags($id)
3624 + appendrefs precedes $desc_tags($id) idtags
3625 }
3626 $ctext conf -state disabled
3627 }
@@ -3623,7 +3633,7 @@ proc selectline {l isnew} {
3633 global currentid sha1entry
3634 global commentend idtags linknum
3635 global mergemax numcommits pending_select
3626 - global cmitmode desc_tags anc_tags showneartags allcommits
3636 + global cmitmode desc_tags anc_tags showneartags allcommits desc_heads
3637
3638 catch {unset pending_select}
3639 $canv delete hover
@@ -3740,17 +3750,26 @@ proc selectline {l isnew} {
3750 if {![info exists allcommits]} {
3751 getallcommits
3752 }
3743 - $ctext insert end "Follows: "
3753 + $ctext insert end "Branch: "
3754 + $ctext mark set branch "end -1c"
3755 + $ctext mark gravity branch left
3756 + if {[info exists desc_heads($id)]} {
3757 + if {[appendrefs branch $desc_heads($id) idheads] > 1} {
3758 + # turn "Branch" into "Branches"
3759 + $ctext insert "branch -2c" "es"
3760 + }
3761 + }
3762 + $ctext insert end "\nFollows: "
3763 $ctext mark set follows "end -1c"
3764 $ctext mark gravity follows left
3765 if {[info exists anc_tags($id)]} {
3747 - appendrefs follows $anc_tags($id)
3766 + appendrefs follows $anc_tags($id) idtags
3767 }
3768 $ctext insert end "\nPrecedes: "
3769 $ctext mark set precedes "end -1c"
3770 $ctext mark gravity precedes left
3771 if {[info exists desc_tags($id)]} {
3753 - appendrefs precedes $desc_tags($id)
3772 + appendrefs precedes $desc_tags($id) idtags
3773 }
3774 $ctext insert end "\n"
3775 }
@@ -5042,6 +5061,7 @@ proc combine_atags {l1 l2} {
5061 proc getallclines {fd} {
5062 global allparents allchildren allcommits allcstart
5063 global desc_tags anc_tags idtags alldtags tagisdesc allids
5064 + global desc_heads idheads
5065
5066 while {[gets $fd line] >= 0} {
5067 set id [lindex $line 0]
@@ -5055,7 +5075,9 @@ proc getallclines {fd} {
5075 lappend allchildren($p) $id
5076 }
5077 # compute nearest tagged descendents as we go
5078 + # also compute descendent heads
5079 set dtags {}
5080 + set dheads {}
5081 foreach child $allchildren($id) {
5082 if {[info exists idtags($child)]} {
5083 set ctags [list $child]
@@ -5067,6 +5089,12 @@ proc getallclines {fd} {
5089 } elseif {$ctags ne $dtags} {
5090 set dtags [combine_dtags $dtags $ctags]
5091 }
5092 + set cheads $desc_heads($child)
5093 + if {$dheads eq {}} {
5094 + set dheads $cheads
5095 + } elseif {$cheads ne $dheads} {
5096 + set dheads [lsort -unique [concat $dheads $cheads]]
5097 + }
5098 }
5099 set desc_tags($id) $dtags
5100 if {[info exists idtags($id)]} {
@@ -5081,6 +5109,10 @@ proc getallclines {fd} {
5109 set tagisdesc($tag,$id) 1
5110 }
5111 }
5112 + if {[info exists idheads($id)]} {
5113 + lappend dheads $id
5114 + }
5115 + set desc_heads($id) $dheads
5116 if {[clock clicks -milliseconds] - $allcstart >= 50} {
5117 fileevent $fd readable {}
5118 after idle restartgetall $fd