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

[PATCH] gitk: Add "Refs" menu - revised

From
PRPavel Roskin <proski@gnu.org>
Date
Oct 6, 2005, 04:11 UTC
Message-ID
<1128571883.32103.48.camel@dv>
In-Reply-To
<1128559088.32103.8.camel@dv>
Hello!

This is an updated revision of the original patch. Unneeded concat has been removed. Error message uses name, not SHA1 ID. If there is information for the tag, it's displayed even in the ID is not in the list. Thanks to Brett Schwarz for help.

---------------------------------

This patch adds "Refs" menu to gitk. It makes all branches, tags and other ref objects appear as menu items. Selecting one of the items selects the corresponding line in the view.

It's only possible to go to the refs present in the current view. However, information for tags is shown even if the corresponding ID is not available.

Signed-off-by: Pavel Roskin <proski@gnu.org>

diff -u b/gitk b/gitk --- b/gitk

+++ b/gitk
@@ -285,6 +285,7 @@
 	}
     }
     readotherrefs refs {} {tags heads}
+    setrefsmenu
 }
 
 proc readotherrefs {base dname excl} {
@@ -538,6 +539,65 @@
     $rowctxmenu add command -label "Write commit to file" -command writecommit
 }
 
+proc gotocommit_menu {sha1 name} {
+    global idline tagids tagcontents
+
+    if {[info exists idline($sha1)]} {
+	selectline $idline($sha1) 1
+    } else {
+	# Should we re-run git-rev-list?
+	error_popup "$name is not in the current view"
+    }
+
+    if {[info exists tagcontents($name)]} {
+	showtag $name 1
+    }
+}
+
+proc setrefsmenu {} {
+    global headids tagids otherrefids
+
+    if {[winfo exists .bar.refs]} {
+	foreach w [winfo children .bar.refs] {
+	    destroy $w
+	}
+	.bar.refs delete 1 3
+    } else {
+	.bar add cascade -label "Refs" -menu .bar.refs
+	menu .bar.refs
+    }
+
+    set refids [lsort -unique [array names headids]]
+    if {[llength $refids] > 0} {
+	.bar.refs add cascade -label "Branches" -menu .bar.refs.heads
+	menu .bar.refs.heads
+	foreach v $refids {
+	    .bar.refs.heads add command -label $v \
+		-command [list gotocommit_menu $headids($v) $v]
+	}
+    }
+
+    set refids [lsort -unique [array names tagids]]
+    if {[llength $refids] > 0} {
+	.bar.refs add cascade -label "Tags" -menu .bar.refs.tags
+	menu .bar.refs.tags
+	foreach v $refids {
+	    .bar.refs.tags add command -label $v \
+		-command [list gotocommit_menu $tagids($v) $v]
+	}
+    }
+
+    set refids [lsort -unique [array names otherrefids]]
+    if {[llength $refids] > 0} {
+	.bar.refs add cascade -label "Other" -menu .bar.refs.other
+	menu .bar.refs.other
+	foreach v $refids {
+	    .bar.refs.other add command -label $v \
+		-command [list gotocommit_menu $otherrefids($v) $v]
+	}
+    }
+}
+
 # when we make a key binding for the toplevel, make sure
 # it doesn't get triggered when that key is pressed in the
 # find string entry widget.
-- 
Regards,
Pavel Roskin
Previous: Pavel RoskinNext: Paul Mackerras
Message 2 of 9 in “gitk: Add "Refs" menu”
  1. gitk: Add "Refs" menuPavel Roskin, Oct 6, 2005
  2. gitk: Add "Refs" menu - revisedPavel Roskin, Oct 6, 2005
  3. Paul MackerrasOct 11, 2005
  4. Pavel RoskinOct 12, 2005
  5. Sven VerdoolaegeOct 12, 2005
  6. Pavel RoskinOct 12, 2005
  7. Marco CostalbaOct 12, 2005
  8. Pavel RoskinOct 12, 2005
  9. H. Peter AnvinOct 12, 2005

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.