diff --git a/contrib/hgk b/contrib/hgk
index 35bfe5405fb42df8e750bd5c7497c1c6a3d4a91d_Y29udHJpYi9oZ2s=..970394b6bd9748925ae5fb1f45e8e99af016b2df_Y29udHJpYi9oZ2s= 100755
--- a/contrib/hgk
+++ b/contrib/hgk
@@ -457,5 +457,5 @@
         }
     }
 
-    foreach {tag rev} $tags {
+    foreach {- tag rev id} [regexp -inline -all -line {^(.+\S)\s+(\d+):(\S+)} $tags] {
         # we use foreach as Tcl8.4 doesn't support lassign
@@ -461,8 +461,6 @@
         # we use foreach as Tcl8.4 doesn't support lassign
-        foreach {- id} [split $rev :] {
-            lappend tagids($tag) $id
-            lappend idtags($id) $tag
-        }
+        lappend tagids($tag) $id
+        lappend idtags($id) $tag
     }
 
     set status [catch {exec $env(HG) --config ui.report_untrusted=false heads} heads]