# HG changeset patch # User Andrew Shadura # Date 2012-10-16 20:41:44 # Node ID 962844e8dd8ecc6b1fbdaf73cbfd2963f937d7df # Parent cf72fd8b3072158e1eb00a9131f57f803a763f72 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. diff --git a/contrib/hgk b/contrib/hgk --- a/contrib/hgk +++ b/contrib/hgk @@ -456,16 +456,13 @@ proc readrefs {} { 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]