Skip to contentSkip to conversation

gitk: Add "Refs" menu

PATCH In review Pavel Roskin 5 participants 9 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitk: Add "Refs" menu

Hello, Paul!

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.

Known limitation: it's only possible to go to the refs present in the current view. Otherwise, gitk would have to re-run git-rev-list.

gitk +57 -0
@@ -285,6 +285,7 @@ proc readrefs {} {
 	}
     }
     readotherrefs refs {} {tags heads}
+    setrefsmenu
 }
 
 proc readotherrefs {base dname excl} {
@@ -538,6 +539,62 @@ proc makewindow {} {
     $rowctxmenu add command -label "Write commit to file" -command writecommit
 }
 
+proc gotocommit_menu {sha1} {
+    global idline
+
+    if {[info exists idline($sha1)]} {
+	selectline $idline($sha1) 1
+	return
+    } else {
+	# Should we re-run git-rev-list?
+	error_popup "$sha1 is not in the current view"
+    }
+}
+
+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 [concat [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 "gotocommit_menu $headids($v)"
+	}
+    }
+
+    set refids [lsort -unique [concat [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 "gotocommit_menu $tagids($v)"
+	}
+    }
+
+    set refids [lsort -unique [concat [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 "gotocommit_menu $otherrefids($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.
Signature · 2 lines
Regards,
Pavel Roskin
#1 lore raw

PATCH 1/1 gitk: Add "Refs" menu - revised

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.

gitk +60 -0
diff -u 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.
Signature · 2 lines
Regards,
Pavel Roskin
#2 lore raw
In reply to Pavel Roskin
Quoted 3 lines · Pavel Roskin

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.

Sorry I haven't responded before - I have got way behind with my email due to a vacation and to concentrating on the merge of the ppc32 and ppc64 kernel sources. It will probably be a bit longer before I can get to look at this.

Thanks,
Paul.

#3 lore raw

Hi, Paul!

Quoted 10 lines · Paul Mackerras
Quoted 3 lines · Pavel Roskin

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.

Sorry I haven't responded before - I have got way behind with my email due to a vacation and to concentrating on the merge of the ppc32 and ppc64 kernel sources. It will probably be a bit longer before I can get to look at this.

No problem. Thank you for letting me know.

I'm not a GUI designer and I'm not experienced in Tcl/Tk, so I'll appreciate critical look at the patches.

I think that gitk should move away from being just a frontend to git-rev-list. There is more information in the repository, such as tags, branches, stgit patches etc. All this information needs to be represented in some way, and using the menu was just the first approach.

Browsing trees and opening files for a given commit would be great and helpful from developers migrating from CVS.

And making gitk cooperate with stgit would be a killer application not just for gitk and stgit, but for git itself (i.e. it could be the reason why git is chosen for development over e.g. Mercurial for new projects).

I don't want to distract you from PPC work, but your return to gitk development would be very welcome :-)

Signature · 2 lines
Regards,
Pavel Roskin
#4 lore raw
Quoted 2 lines · Pavel Roskin

Browsing trees and opening files for a given commit would be great and helpful from developers migrating from CVS.

Something like this ?

From: Ingo Bormuth <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH] Gitk tree view (correction)
Message-ID: <20050824223550.GA23693@kruemel>

skimo

#5 lore raw
Quoted 11 lines · Sven Verdoolaege
Quoted 2 lines · Pavel Roskin

Browsing trees and opening files for a given commit would be great and helpful from developers migrating from CVS.

Something like this ?

From: Ingo Bormuth <[email protected]>
To: [email protected]
Cc: [email protected]
Subject: [PATCH] Gitk tree view (correction)
Message-ID: <20050824223550.GA23693@kruemel>

That's pretty good, thank you. Although I think "Tree" and "Commit" should be links on top of the view pane rather than a button. "Commit" button is especially confusing - one could think that it would commit something.

Also, it would be really great to put line numbers in a separate widget so that they are never selected with the text. When done correctly, most users will never want to turn the line numbers off.

Signature · 2 lines
Regards,
Pavel Roskin
#6 lore raw
In reply to Pavel Roskin
Quoted 5 lines

And making gitk cooperate with stgit would be a killer application not just for gitk and stgit, but for git itself (i.e. it could be the reason why git is chosen for development over e.g. Mercurial for new projects).

Not to advertise, but qgit (http://digilander.libero.it/mcostalba/) already offers stgit integration, among other things.

I plan to release a new version implementing various suggestion from the list this week, there are also important stgit fixes and upgrades.

To have a look at new features check the git arcihve: cg-clone
http://digilander.libero.it/mcostalba/qgit.git

Marco

__________________________________
Yahoo! Music Unlimited
Access over 1 million songs. Try it free.
http://music.yahoo.com/unlimited/

#7 lore raw
Quoted 7 lines · Marco Costalba
Quoted 4 lines

And making gitk cooperate with stgit would be a killer application not just for gitk and stgit, but for git itself (i.e. it could be the reason why git is chosen for development over e.g. Mercurial for new projects).

Not to advertise, but qgit (http://digilander.libero.it/mcostalba/) already offers stgit integration, among other things.

Very nice.

But it doesn't show correctly in the qt theme I was using (which must be the default theme in Fedora Core 4 because I never changed it):

http://red-bean.com/proski/qgit.png

The blame for the ugly default gray background should be on Qt or on Fedora, but it seems to me that qgit is hardcoding white and light gray (see ODD_LINE_COL and EVEN_LINE_COL in src/mainimpl.cpp).

The style selector in kcontrol has "Standard Background" and "Alternate Background for Lists". I don't know if it has an equivalent in qt. Maybe you could use the standard background and a slightly darkened version.

Also, please use months names on the homepage. I thought qgit 0.94 was released on October 9th.

Signature · 2 lines
Regards,
Pavel Roskin
#8 lore raw
In reply to Marco Costalba
Quoted 8 lines · Marco Costalba
Quoted 6 lines

And making gitk cooperate with stgit would be a killer application not just for gitk and stgit, but for git itself (i.e. it could be the reason why git is chosen for development over e.g. Mercurial for new projects).

Quoted 8 lines

Not to advertise, but qgit (http://digilander.libero.it/mcostalba/) already offers stgit integration, among other things.

I plan to release a new version implementing various suggestion from the list this week, there are also important stgit fixes and upgrades.

To have a look at new features check the git arcihve: cg-clone
http://digilander.libero.it/mcostalba/qgit.git

I looked at qgit at one time, and I find its UI to be much less pleasant to look at that gitk, which is unfortunate, because it's much faster. Both the graph and the color scheme are much less pleasant, which distracts from the information conveyed.

-hpa