Fix in command parser: allow for 'invalid brancheads' message in command output.
authorJan Vrany <jan.vrany@fit.cvut.cz>
Wed, 08 Oct 2014 21:31:39 +0100
changeset 458 52063f8ab1db
parent 457 232338f718ab
child 460 8aab3366d378
Fix in command parser: allow for 'invalid brancheads' message in command output. Mercurial 3.1.1 may print `invalid branchheads cache (visible): tip differs` to *stdout* when it's internal chache differs (may happen after history rewriting such as rebasing) Affects `hg branches` and `hg log`.
mercurial/HGCommandParser.st
mercurial/HGCommandParserTests.st
--- a/mercurial/HGCommandParser.st	Mon Sep 29 12:09:38 2014 +0100
+++ b/mercurial/HGCommandParser.st	Wed Oct 08 21:31:39 2014 +0100
@@ -226,24 +226,43 @@
     "Parse output of 'hg branches' command. Return collection
      of orphaned HGBranch"
 
-    | branches |
+    | branches branch |
 
     branches := OrderedCollection new.
+    stream atEnd ifFalse:[ 
+        branch := self parseBranchesEntryAllowForInvalidBranchheadsMessage: true.
+        branch notNil ifTrue:[ 
+            branches add: branch.
+        ].
+    ].
     [ stream atEnd ] whileFalse:[
-        branches add: self parseBranchesEntry
+        branch := self parseBranchesEntryAllowForInvalidBranchheadsMessage: false.  
+        branches add:  branch.
     ].
     ^branches
 
     "Created: / 27-11-2012 / 20:20:56 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-10-2014 / 20:56:29 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
-parseBranchesEntry
-    | branch |
+parseBranchesEntryAllowForInvalidBranchheadsMessage: allowForInvalidBrancheadsMessage
+    | name branch |
 
+    name := self parseName.
+    stream skipSeparators.
+    allowForInvalidBrancheadsMessage ifTrue:[ 
+        stream peek isDigit ifFalse:[ 
+            | message |
+
+            message := name , ' ', stream nextLine.
+            self notify: message.  
+            name := self parseName.
+            stream skipSeparators.   
+        ].
+    ].                
     branch := HGBranch new.
-    branch setName: self parseName.
-
-    stream skipSeparators.
+    branch setName: name.
+ 
     self parseNodeId.
     stream peek == Character space ifTrue:[
         stream next.
@@ -264,7 +283,7 @@
     self expectLineEnd.
     ^branch
 
-    "Created: / 27-11-2012 / 19:23:12 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Created: / 08-10-2014 / 20:54:46 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 parseConfig
@@ -765,10 +784,16 @@
     "Parse output of 'hg log' command, assuming the template given
      was HGCommandParser templateLog. Return a list of HGChangeset."
 
+    "/ As of mercurial 3.1.1, a message like
+    "/ 'invalid branchheads cache (visible): tip differs
+    "/ may be written to the stdout. Following code test for it
+    stream peek == $i ifTrue:[ 
+        self notify: stream nextLine.  
+    ].
     ^self parseLog
 
     "Created: / 13-11-2012 / 09:09:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified (comment): / 27-11-2012 / 21:24:50 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 08-10-2014 / 21:22:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 parseCommandLogChildren
--- a/mercurial/HGCommandParserTests.st	Mon Sep 29 12:09:38 2014 +0100
+++ b/mercurial/HGCommandParserTests.st	Wed Oct 08 21:31:39 2014 +0100
@@ -130,6 +130,28 @@
     "Created: / 27-11-2012 / 19:00:30 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+test_cmd_branches_02
+
+    | branches |
+
+    branches := (HGCommandParser on: 'invalid branchheads cache (visible): tip differs
+default                     5694:756610fa329d48cd8b225524016713485aefbb95
+jv                          5684:2c32b6c5d3543cd0381f9b346d62bfeabb95e6c6
+') parseCommandBranches.
+
+    self assert: branches size == 2.
+
+    self assert: branches first name = 'default'.
+    self assert: branches first isActive.
+    self assert: branches first isClosed not.
+
+    self assert: branches second name = 'jv'.
+    self assert: branches second isActive.
+    self assert: branches second isClosed not.
+
+    "Created: / 08-10-2014 / 20:39:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 test_cmd_err_branches_01
 
     (HGCommandParser on: 'invalidating branch cache (tip differs)