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

Re: gitk "hyperlinks" (was Re: Display of merges in gitk)

From
jepler@unpythonic.net <jepler@unpythonic.net>
Date
Aug 5, 2005, 18:51 UTC
Message-ID
<20050805185056.GF19009@unpythonic.net>
In-Reply-To
<Pine.LNX.4.58.0508050710460.3258@g5.osdl.org>
On Fri, Aug 05, 2005 at 07:37:41AM -0700, Linus Torvalds wrote:
Show 5 quoted lines
> For 2.6.13 we've been reverting some stuff lately, to make sure we get a 
> stable release. That's fine, and when I revert something I try to mention 
> the commit ID of the thing I revert in the message. Apparently others do 
> too, as indicated by a patch I just got from Petr Vandovec. So we've got 
> for example:
[snipped]

The following code worked for me on a toy commit. I'm not sure the regular expression in linkcommits is right if the SHA1 is followed by a colon or a comma, as I noticed it was in your examples. If it doesn, then removing the [[:<:]] and [[:>:]] will probably fix it.

Things that look like SHA1s are highlighted even if they don't actually exist.

There is probably a "more right" place to do the '$ctext tag bind Commit' commands but I didn't find it right away.

diff --git a/gitk b/gitk
--- a/gitk
+++ b/gitk
@@ -1753,6 +1753,11 @@ proc selectline {l} {
     $ctext conf -state disabled
     set commentend [$ctext index "end - 1c"]
 
+    linkcommits $ctext 0.0 $commentend
+    $ctext tag configure Commit -underline yes -foreground blue
+    $ctext tag bind Commit <Enter> { %W configure -cursor hand2 }
+    $ctext tag bind Commit <Leave> { %W configure -cursor {} }
+    $ctext tag bind Commit <Button-1><ButtonRelease-1> { linkclick %W %x %y }
     $cflist delete 0 end
     $cflist insert end "Comments"
     if {$nparents($id) == 1} {
@@ -1762,6 +1767,30 @@ proc selectline {l} {
     }
 }
 
+proc linkclick {w x y} {
+    set index [$w index @$x,$y]
+    set tags [$w tag names $index]
+    foreach c $tags {
+        if {![string match {C_*} $c]} { continue; }
+        global sha1string
+        set sha1string [string range $c 2 end]
+        gotocommit
+    }
+}
+
+proc linkcommits {w start end} {
+    while {1} {
+        set pos [$w search -regexp {[[:<:]][0-9a-fA-F]{40}[[:>:]]} $start $end]
+        if {$pos == {}} {break}
+        
+        set commit [$w get $pos "$pos+40c"]
+
+        $w tag add Commit $pos "$pos+40c"
+        $w tag add C_$commit $pos "$pos+40c"
+        set start [$w index "$pos+40c"]
+    }
+}
+
 proc selnextline {dir} {
     global selectedline
     if {![info exists selectedline]} return
Previous: Linus TorvaldsNext: Kay Sievers
Message 9 of 25 in “Display of merges in gitk”
  1. Paul MackerrasJul 30, 2005
  2. Junio C HamanoJul 30, 2005
  3. Shipping gitk as part of core git.Junio C Hamano, Jul 30, 2005
  4. Paul MackerrasJul 31, 2005
  5. Junio C HamanoJul 31, 2005
  6. gitk merge display bugs (was: Re: Display of merges in gitk)Sergey Vlasov, Jul 30, 2005
  7. Linus TorvaldsAug 5, 2005
  8. gitk "hyperlinks" (was Re: Display of merges in gitk)Linus Torvalds, Aug 5, 2005
  9. jepler@unpythonic.netAug 5, 2005
  10. Kay SieversAug 6, 2005
  11. Linus TorvaldsAug 6, 2005
  12. Kay SieversAug 7, 2005
  13. gitweb "tag" displayJunio C Hamano, Aug 6, 2005
  14. Junio C HamanoAug 6, 2005
  15. Paul MackerrasAug 19, 2005
  16. Johannes SchindelinAug 19, 2005
  17. Junio C HamanoAug 20, 2005
  18. Kay SieversAug 7, 2005
  19. Paul MackerrasAug 6, 2005
  20. Linus TorvaldsAug 6, 2005
  21. jepler@unpythonic.netAug 6, 2005
  22. gitk SHA link hoversLinus Torvalds, Aug 6, 2005
  23. Paul MackerrasAug 7, 2005
  24. Junio C HamanoAug 6, 2005
  25. Paul MackerrasAug 7, 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.