Partial fix for "null" `HGChangeset`
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 25 Sep 2018 12:33:31 +0100
changeset 861 e1e8c087aaef
parent 860 2ceb125a0fc7
child 862 458a462cc9ff
Partial fix for "null" `HGChangeset` "null" changeset is currently kept as a singleton instance, i.e., `HGChangeset null` always return the same object. However, some queries (such as `#isObsolete` or `#successors`) require repository to be set - obviously, for "null" changeset there's no repository. Therefore these queries resulted into DNU. To paetially fix this, short-circuit these query methods to answer trasonable values for "null" changeset. Better solution would be to make "null" changeset a normal changeset within a repository.
mercurial/HGChangeset.st
mercurial/HGTests.st
--- a/mercurial/HGChangeset.st	Thu Aug 30 09:19:13 2018 +0100
+++ b/mercurial/HGChangeset.st	Tue Sep 25 12:33:31 2018 +0100
@@ -84,10 +84,11 @@
         NullChangeset 
             setNonLazy;
             setId: HGChangesetId null;
-            setParent1: NullChangeset;
-            setParent2: NullChangeset;
+            setParent1: nil;
+            setParent2: nil;
             setAuthor: '';
             setMessage: '';
+            setBranches: #();
             setTimestamp: (Timestamp utcSecondsSince1970:0).
     ].
     ^NullChangeset
@@ -97,7 +98,7 @@
     "
 
     "Created: / 19-10-2012 / 15:51:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 10-06-2016 / 10:41:16 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-09-2018 / 10:34:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGChangeset methodsFor:'accessing'!
@@ -121,9 +122,13 @@
 !
 
 bookmarks
+    "
+    Return a list of bookmarks set on this changeset.
+    "
+    self == NullChangeset ifTrue:[ ^ #() ].
     ^ repository bookmarks select:[:bookmark | bookmark changesetId = id ]
 
-    "Modified: / 20-03-2014 / 02:32:27 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-09-2018 / 10:24:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 branch
@@ -341,6 +346,7 @@
     "
     | ids |    
 
+    self == NullChangeset ifTrue:[ ^ #() ].
     HGCommand hgVersionIsGreaterOrEqualThan_4_1 ifFalse:[ ^ #() ].
 
     "/ In theory, we coould (and should) use HGCachedFileData, however
@@ -376,7 +382,7 @@
     ^ids reject: [ :each | each id = id ] thenCollect:[ :each | repository changesetWithId: each id ]
 
     "Created: / 08-02-2018 / 15:27:42 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 28-03-2018 / 15:32:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-09-2018 / 11:58:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 summary
@@ -667,6 +673,8 @@
 isObsolete
     "Return `true`, if the changeset is obsolete, `false` otherwise."
 
+    self == NullChangeset ifTrue:[ ^ false ].
+
     "/ In theory, we coould (and should) use HGCachedFileData, however
     "/ at least on UNIX systems the timestamp resolution is only 1sec
     "/ which is too coarse to work reliably on modern fast machines.
@@ -696,7 +704,7 @@
     ]
 
     "Created: / 08-02-2018 / 09:14:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
-    "Modified: / 22-03-2018 / 22:53:19 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 25-09-2018 / 10:22:24 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 ! !
 
 !HGChangeset methodsFor:'utilities'!
--- a/mercurial/HGTests.st	Thu Aug 30 09:19:13 2018 +0100
+++ b/mercurial/HGTests.st	Tue Sep 25 12:33:31 2018 +0100
@@ -815,14 +815,15 @@
 
     cs := HGChangeset null.
     self assert: cs id = HGChangesetId null.
-    self assert: cs parent1 == cs.
-    self assert: cs parent2 == cs.
+    self assert: cs parent1 isNil.
+    self assert: cs parent2 isNil.
     self assert: cs user = ''.
     self assert: cs message = ''.
     self assert: cs summary = ''.
     self assert: cs timestamp = (Timestamp secondsSince1970:0)
 
     "Created: / 10-06-2016 / 10:22:25 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-10-2018 / 07:45:33 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
 test_changeset_12
@@ -839,6 +840,26 @@
     "Created: / 22-03-2018 / 22:41:48 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+test_changeset_null
+    "
+    Test walking history though parents
+    "
+
+    | cs |
+
+    cs := HGChangeset null.
+
+    self assert: cs id = HGChangesetId null.
+    self assert: cs parent1 isNil.
+    self assert: cs parent2 isNil.
+    self assert: cs branches isEmpty.
+    self assert: cs bookmarks isEmpty.
+    self assert: cs isObsolete not.
+
+    "Created: / 25-09-2018 / 10:31:40 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+    "Modified: / 05-10-2018 / 07:50:37 / Jan Vrany <jan.vrany@fit.cvut.cz>"
+!
+
 test_csentry_newer_01
 
     | repo cs csentry newer |