Mercurial > hg
comparison contrib/hgk @ 18808:962844e8dd8e
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.
author | Andrew Shadura <bugzilla@tut.by> |
---|---|
date | Tue, 16 Oct 2012 22:41:44 +0200 |
parents | 932f5d3587c9 |
children | 3131c9da8bf6 |
comparison
equal
deleted
inserted
replaced
18807:cf72fd8b3072 | 18808:962844e8dd8e |
---|---|
454 puts $::errorInfo | 454 puts $::errorInfo |
455 if { ![string equal $::errorCode NONE] } { | 455 if { ![string equal $::errorCode NONE] } { |
456 exit 2 | 456 exit 2 |
457 } | 457 } |
458 } | 458 } |
459 regsub -all "\r\n" $tags "\n" tags | 459 |
460 | 460 foreach {tag rev} $tags { |
461 set lines [split $tags "\n"] | 461 # we use foreach as Tcl8.4 doesn't support lassign |
462 foreach f $lines { | 462 foreach {- id} [split $rev :] { |
463 regexp {(\S+)$} $f full | 463 lappend tagids($tag) $id |
464 regsub {\s+(\S+)$} $f "" direct | 464 lappend idtags($id) $tag |
465 set sha [split $full ':'] | 465 } |
466 set tag [lindex $sha 1] | |
467 lappend tagids($direct) $tag | |
468 lappend idtags($tag) $direct | |
469 } | 466 } |
470 | 467 |
471 set status [catch {exec $env(HG) --config ui.report_untrusted=false heads} heads] | 468 set status [catch {exec $env(HG) --config ui.report_untrusted=false heads} heads] |
472 if { $status != 0 } { | 469 if { $status != 0 } { |
473 puts $::errorInfo | 470 puts $::errorInfo |