[PATCH 1 of 3] hgk: read bookmarks

David Soria Parra dsp at php.net
Tue Feb 22 17:26:39 CST 2011


# HG changeset patch
# User David Soria Parra <dsp at php.net>
# Date 1298417061 -3600
# Node ID f8e097cac6fdb1a816ec3c2b10500d197bb69790
# Parent  b2e4e394d742ca3a948848dc2aa9d288c0eaa861
hgk: read bookmarks

diff --git a/contrib/hgk b/contrib/hgk
--- a/contrib/hgk
+++ b/contrib/hgk
@@ -276,6 +276,7 @@
     set comdate {}
     set rev {}
     set branch {}
+    set bookmark {}
     if {![info exists nchildren($id)]} {
 	set children($id) {}
 	set nchildren($id) 0
@@ -314,7 +315,9 @@
 		    set rev [lindex $line 1]
         } elseif {$tag == "branch"} {
 		    set branch [join [lrange $line 1 end]]
-		}
+        } elseif {$tag == "bookmark"} {
+		    set bookmark [join [lrange $line 1 end]]
+        }
 	    }
 	} else {
 	    if {$comment == {}} {
@@ -338,7 +341,7 @@
 	set comdate [clock format $comdate -format "%Y-%m-%d %H:%M:%S"]
     }
     set commitinfo($id) [list $headline $auname $audate \
-			     $comname $comdate $comment $rev $branch]
+			     $comname $comdate $comment $rev $branch $bookmark]
 
     if {[info exists firstparents]} {
         set i [lsearch $firstparents $id]
@@ -369,7 +372,7 @@
 }
 
 proc readrefs {} {
-    global tagids idtags headids idheads tagcontents env curid
+    global bookmarkcurrent bookmarkids tagids idtags idbookmarks headids idheads tagcontents env curid
 
     set status [catch {exec $env(HG) --config ui.report_untrusted=false id} curid]
     if { $status != 0 } {
@@ -417,6 +420,28 @@
         }
     }
 
+    set status [catch {exec $env(HG) --config ui.report_untrusted=false bookmarks} bookmarks]
+    if { $status != 0 } {
+        puts $::errorInfo
+        if { ![string equal $::errorCode NONE] } {
+            exit 2
+        }
+    }
+    set lines [split $bookmarks "\n"]
+    set bookmarkcurrent 0
+    foreach f $lines {
+	regexp {(\S+)$} $f full
+	regsub {\s+(\S+)$} $f "" direct
+	set sha [split $full ':']
+	set bookmark [lindex $sha 1]
+	set current [string first " * " $direct)]
+	regsub {^\s(\*|\s)\s} $direct "" direct
+	lappend bookmarkids($direct) $bookmark
+	lappend idbookmarks($bookmark) $direct
+	if {$current >= 0} {
+		set bookmarkcurrent $direct
+	}
+    }
 }
 
 proc readotherrefs {base dname excl} {
@@ -1042,7 +1067,7 @@
     global canv canv2 canv3 mainfont namefont canvy linespc
     global lineid linehtag linentag linedtag commitinfo
     global colormap numcommits currentparents dupparents
-    global idtags idline idheads idotherrefs
+    global idtags idline idheads idotherrefs idbookmarks
     global lineno lthickness mainline mainlinearrow sidelines
     global commitlisted rowtextx idpos lastuse displist
     global oldnlines olddlevel olddisplist
@@ -1100,7 +1125,7 @@
     set rowtextx($lineno) $xt
     set idpos($id) [list $x $xt $y1]
     if {[info exists idtags($id)] || [info exists idheads($id)]
-	|| [info exists idotherrefs($id)]} {
+	|| [info exists idotherrefs($id)] || [info exists idbookmarks($id)]} {
 	set xt [drawtags $id $x $xt $y1]
     }
     set headline [lindex $commitinfo($id) 0]
@@ -3840,8 +3865,12 @@
 }
 
 proc listrefs {id} {
-    global idtags idheads idotherrefs
-
+    global idtags idheads idotherrefs idbookmarks
+
+    set w {}
+    if {[info exists idbookmarks($id)]} {
+	set w $idbookmarks($id)
+    }
     set x {}
     if {[info exists idtags($id)]} {
 	set x $idtags($id)
@@ -3854,26 +3883,29 @@
     if {[info exists idotherrefs($id)]} {
 	set z $idotherrefs($id)
     }
-    return [list $x $y $z]
+    return [list $w $x $y $z]
 }
 
 proc rereadrefs {} {
-    global idtags idheads idotherrefs
-    global tagids headids otherrefids
+    global idbookmarks idtags idheads idotherrefs
+    global bookmarkids tagids headids otherrefids
 
     set refids [concat [array names idtags] \
-		    [array names idheads] [array names idotherrefs]]
+		    [array names idheads] [array names idotherrefs] \
+		    [array names idbookmarks]]
     foreach id $refids {
 	if {![info exists ref($id)]} {
 	    set ref($id) [listrefs $id]
 	}
     }
-    foreach v {tagids idtags headids idheads otherrefids idotherrefs} {
+    foreach v {tagids idtags headids idheads otherrefids idotherrefs \
+        bookmarkids idbookmarks} {
 	catch {unset $v}
     }
     readrefs
     set refids [lsort -unique [concat $refids [array names idtags] \
-			[array names idheads] [array names idotherrefs]]]
+			[array names idheads] [array names idotherrefs] \
+			[array names idbookmarks]]]
     foreach id $refids {
 	set v [listrefs $id]
 	if {![info exists ref($id)] || $ref($id) != $v} {


More information about the Mercurial-devel mailing list