On Fri, Aug 05, 2005 at 07:37:41AM -0700, Linus Torvalds wrote:
> 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 { %W configure -cursor hand2 }
+$ctext tag bind Commit { %W configure -cursor {} }
+$ctext tag bind Commit { 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
pgppDwXRz0T1l.pgp
Description: PGP signature