hgk: simplify tags parser
authorAndrew Shadura <bugzilla@tut.by>
Tue, 16 Oct 2012 22:41:44 +0200
changeset 18808 962844e8dd8e
parent 18807 cf72fd8b3072
child 18809 3131c9da8bf6
hgk: simplify tags parser As when hg tags is being called without -v option, it returns lines with two elements in each, we can just interate them as if it were a usual Tcl list using foreach and two variables. Line endings and whitespace don't matter when doing so, so we may keep them as is. When we're processing the lines, tag variable is assigned a tag name, and rev is a string in form of revision:hash which we can split on colon. As Tcl8.4 lacks lassign command, and using lindex makes code a bit less readable, we use foreach to iterate over two-element list.
contrib/hgk
--- a/contrib/hgk	Fri Mar 22 09:19:41 2013 -0700
+++ b/contrib/hgk	Tue Oct 16 22:41:44 2012 +0200
@@ -456,16 +456,13 @@
             exit 2
         }
     }
-    regsub -all "\r\n" $tags "\n" tags
-
-    set lines [split $tags "\n"]
-    foreach f $lines {
-	regexp {(\S+)$} $f full
-	regsub {\s+(\S+)$} $f "" direct
-	set sha [split $full ':']
-	set tag [lindex $sha 1]
-	lappend tagids($direct) $tag
-	lappend idtags($tag) $direct
+
+    foreach {tag rev} $tags {
+        # we use foreach as Tcl8.4 doesn't support lassign
+        foreach {- id} [split $rev :] {
+            lappend tagids($tag) $id
+            lappend idtags($id) $tag
+        }
     }
 
     set status [catch {exec $env(HG) --config ui.report_untrusted=false heads} heads]