git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 02/13] gitk: keep track of tag types in a separate `types` array

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Dec 19, 2016, 16:45 UTC
Message-ID
<e9d546743245a59925fa0ab762a8a1e88ccfc360.1482164633.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1482164633.git.mhagger@alum.mit.edu>

The resulting code is easier to follow than the old counting-based code, plus in a moment we will add some more specific types.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 gitk | 37 +++++++++++++++++++++----------------
 1 file changed, 21 insertions(+), 16 deletions(-)
diff --git a/gitk b/gitk
index 296efb3..7c830c3 100755
--- a/gitk
+++ b/gitk
@@ -6560,8 +6560,7 @@ proc drawtags {id x xt y1} {
     global reflinecolor
 
     set marks {}
-    set ntags 0
-    set nheads 0
+    set types {}
     set singletag 0
     set maxtags 3
     set maxtagpct 25
@@ -6576,22 +6575,30 @@ proc drawtags {id x xt y1} {
 	    [totalwidth $tags mainfont $extra] > $maxwidth} {
 	    # show just a single "n tags..." tag
 	    set singletag 1
+	    lappend types tag
 	    if {$ntags == 1} {
 		lappend marks "tag..."
 	    } else {
 		lappend marks [format "%d tags..." $ntags]
-		set ntags 1
 	    }
 	} else {
-	    set marks [concat $marks $tags]
+	    foreach tag $tags {
+		lappend types tag
+		lappend marks $tag
+	    }
 	}
     }
     if {[info exists idheads($id)]} {
-	set marks [concat $marks $idheads($id)]
-	set nheads [llength $idheads($id)]
+	foreach head $idheads($id) {
+	    lappend types head
+	    lappend marks $head
+	}
     }
     if {[info exists idotherrefs($id)]} {
-	set marks [concat $marks $idotherrefs($id)]
+	foreach other $idotherrefs($id) {
+	    lappend types other
+	    lappend marks $other
+	}
     }
     if {$marks eq {}} {
 	return $xt
@@ -6601,10 +6608,8 @@ proc drawtags {id x xt y1} {
     set yb [expr {$yt + $linespc - 1}]
     set xvals {}
     set wvals {}
-    set i -1
-    foreach tag $marks {
-	incr i
-	if {$i >= $ntags && $i < $ntags + $nheads && $tag eq $mainhead} {
+    foreach tag $marks type $types {
+	if {$type eq "head" && $tag eq $mainhead} {
 	    set wid [font measure mainfontbold $tag]
 	} else {
 	    set wid [font measure mainfont $tag]
@@ -6616,12 +6621,12 @@ proc drawtags {id x xt y1} {
     set t [$canv create line $x $y1 [lindex $xvals end] $y1 \
 	       -width $lthickness -fill $reflinecolor -tags tag.$id]
     $canv lower $t
-    foreach tag $marks x $xvals wid $wvals {
+    foreach tag $marks type $types x $xvals wid $wvals {
 	set tag_quoted [string map {% %%} $tag]
 	set xl [expr {$x + $delta}]
 	set xr [expr {$x + $delta + $wid + $lthickness}]
 	set font mainfont
-	if {[incr ntags -1] >= 0} {
+	if {$type eq "tag"} {
 	    # draw a tag
 	    set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
 		       $xr $yt $xr $yb $xl $yb $x [expr {$yb - $delta}] \
@@ -6636,7 +6641,7 @@ proc drawtags {id x xt y1} {
 	    set rowtextx([rowofcommit $id]) [expr {$xr + $linespc}]
 	} else {
 	    # draw a head or other ref
-	    if {[incr nheads -1] >= 0} {
+	    if {$type eq "head"} {
 		set col $headbgcolor
 		if {$tag eq $mainhead} {
 		    set font mainfontbold
@@ -6658,9 +6663,9 @@ proc drawtags {id x xt y1} {
 	}
 	set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
 		   -font $font -tags [list tag.$id text]]
-	if {$ntags >= 0} {
+	if {$type eq "tag"} {
 	    $canv bind $t <1> $tagclick
-	} elseif {$nheads >= 0} {
+	} elseif {$type eq "head"} {
 	    $canv bind $t $ctxbut [list headmenu %X %Y $id $tag_quoted]
 	}
     }
-- 
2.9.3
Previous: Michael HaggertyNext: Michael Haggerty
Message 3 of 24 in “gitk: tweak rendering of remote-tracking references”
  1. 00/13 gitk: tweak rendering of remote-tracking referencesMichael Haggerty, Dec 19, 2016
  2. 01/13 gitk: when processing tag labels, don't use `marks` as scratch spaceMichael Haggerty, Dec 19, 2016
  3. 02/13 gitk: keep track of tag types in a separate `types` arrayMichael Haggerty, Dec 19, 2016
  4. 12/13 gitk: add a configuration setting `remoterefbgcolor`Michael Haggerty, Dec 19, 2016
  5. 07/13 gitk: extract a method `remotereftext`Michael Haggerty, Dec 19, 2016
  6. 06/13 gitk: simplify regexpMichael Haggerty, Dec 19, 2016
  7. 04/13 gitk: use a type "mainhead" to indicate the main HEAD branchMichael Haggerty, Dec 19, 2016
  8. 08/13 gitk: only change the color of the "remote" part of remote refsMichael Haggerty, Dec 19, 2016
  9. 05/13 gitk: fill in `wvals` as the tags are first processedMichael Haggerty, Dec 19, 2016
  10. 09/13 gitk: shorten labels displayed for modern remote-tracking refsMichael Haggerty, Dec 19, 2016
  11. 10/13 gitk: use type "remote" for remote-tracking referencesMichael Haggerty, Dec 19, 2016
  12. 11/13 gitk: introduce a constant otherrefbgcolorMichael Haggerty, Dec 19, 2016
  13. 13/13 gitk: change the default colors for remote-tracking referencesMichael Haggerty, Dec 19, 2016
  14. 03/13 gitk: use a type "tags" to indicate abbreviated tagsMichael Haggerty, Dec 19, 2016
  15. Philip OakleyDec 19, 2016
  16. Michael HaggertyDec 20, 2016
  17. Marc BranchaudDec 20, 2016
  18. Paul MackerrasDec 20, 2016
  19. Marc BranchaudDec 20, 2016
  20. Michael HaggertyDec 21, 2016
  21. Marc BranchaudDec 21, 2016
  22. Michael HaggertyDec 22, 2016
  23. Marc BranchaudJan 9, 2017
  24. Marc BranchaudFeb 6, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.