mercurial/HGChangesetId.st
changeset 688 c3cb04bed338
parent 567 3f2109adb65c
child 738 e65bff22316f
--- a/mercurial/HGChangesetId.st	Mon Jun 27 12:00:16 2016 +0100
+++ b/mercurial/HGChangesetId.st	Wed Jul 13 18:29:10 2016 +0100
@@ -138,10 +138,11 @@
     "Parses node id from stream and returns it. Support both,
      short and full node ids"
 
-    | stream c c1 c2 sign revno hash hashPos short |
+    | stream c c1 c2 sign revno hash hashPos charPos short |
 
     hash := ByteArray new: 20.
     hashPos := 1.
+    charPos := 0.
     short := true.
     revno := 0.
 
@@ -168,9 +169,22 @@
             c1 := c2 := nil.
         ].
         stream next.
+        charPos := charPos + 1.
     ].
     revno := revno * sign.
-    (stream atEnd or:[stream peek isSeparator]) ifTrue:[
+    stream atEnd ifTrue:[
+        "/ We might have read revno or a short hash that by chance
+        "/ consist of only digits and not leading with 0. In this case
+        "/ we actually cannot distinguish. 
+        "/ In case we have read less than 12 characters (size of a short id), 
+        "/ treat it as revno. A conservative guess...
+        charPos < 12 ifTrue:[ 
+            ^(HGChangesetId new: 0)
+                revno: revno;
+                yourself
+        ]
+    ].
+    (stream atEnd not and:[stream peek isSeparator]) ifTrue:[
         ^(HGChangesetId new: 0)
             revno: revno;
             yourself
@@ -257,7 +271,7 @@
     "
 
     "Created: / 13-11-2012 / 16:49:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 22-01-2013 / 12:00:18 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 13-07-2016 / 18:15:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGChangesetId class methodsFor:'accessing'!