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

[PATCH 09/13] gitk: shorten labels displayed for modern remote-tracking refs

From
Michael Haggerty <mhagger@alum.mit.edu>
Date
Dec 19, 2016, 16:45 UTC
Message-ID
<5dec4a22621a441099b187f081831bbe8f5cc05c.1482164633.git.mhagger@alum.mit.edu>
In-Reply-To
<cover.1482164633.git.mhagger@alum.mit.edu>
If a reference has the form
    refs/remotes/origin/foo
, then use the label
    origin/foo
    ^^^^^^^

, where the indicated part is displayed in `$remotebgcolor`. The old code would have displayed such a reference as

    remotes/origin/foo
    ^^^^^^^^^^^^^^^

, which wastes horizontal space displaying `remote/` for every remote reference. However, if a remote-tracking reference has only two slashes, like

    refs/remotes/baz
, render the label the same as before, namely
    remotes/baz
    ^^^^^^^^
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
---
 gitk | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/gitk b/gitk
index c146a15..d22ce5f 100755
--- a/gitk
+++ b/gitk
@@ -6558,7 +6558,9 @@ proc remotereftext {head textName prefixName} {
     upvar $textName text
     upvar $prefixName prefix
 
-    if {[regexp {^((remotes/([^/]+/|)).*)} $head match text prefix]} {
+    if {[regexp {^remotes/(([^/]+/).*)} $head match text prefix]} {
+	return 1
+    } elseif {[regexp {^((remotes/).*)} $head match text prefix]} {
 	return 1
     } else {
 	set text $head
@@ -6613,7 +6615,8 @@ proc drawtags {id x xt y1} {
 		lappend wvals [font measure mainfontbold $head]
 	    } else {
 		lappend types head
-		lappend wvals [font measure mainfont $head]
+		remotereftext $head text remoteprefix
+		lappend wvals [font measure mainfont $text]
 	    }
 	    lappend marks $head
 	}
@@ -6644,6 +6647,7 @@ proc drawtags {id x xt y1} {
 	set xl [expr {$x + $delta}]
 	set xr [expr {$x + $delta + $wid + $lthickness}]
 	set font mainfont
+	set text $tag
 	if {$type eq "tag" || $type eq "tags"} {
 	    # draw a tag
 	    set t [$canv create polygon $x [expr {$yt + $delta}] $xl $yt \
@@ -6679,7 +6683,7 @@ proc drawtags {id x xt y1} {
 			-width 0 -fill $remotebgcolor -tags tag.$id
 	    }
 	}
-	set t [$canv create text $xl $y1 -anchor w -text $tag -fill $headfgcolor \
+	set t [$canv create text $xl $y1 -anchor w -text $text -fill $headfgcolor \
 		   -font $font -tags [list tag.$id text]]
 	if {$type eq "tag" || $type eq "tags"} {
 	    $canv bind $t <1> $tagclick
-- 
2.9.3
Previous: Michael HaggertyNext: Michael Haggerty
Message 10 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.