revlog: fix pure python slicing test when chain contains nullrev
authorBoris Feld <boris.feld@octobus.net>
Thu, 20 Dec 2018 09:59:16 +0100
changeset 41079 88d813cd9acd
parent 41078 46e0563c67db
child 41080 9d35ae3d9999
revlog: fix pure python slicing test when chain contains nullrev The revlog mock used in the test was not behaving the same as its C counterpart.
mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py	Sun Dec 30 17:31:57 2018 +0900
+++ b/mercurial/revlogutils/deltas.py	Thu Dec 20 09:59:16 2018 +0100
@@ -47,11 +47,15 @@
         self.index = None
 
     def start(self, rev):
+        if rev == nullrev:
+            return 0
         if rev == 0:
             return 0
         return self._data[rev - 1]
 
     def end(self, rev):
+        if rev == nullrev:
+            return 0
         return self._data[rev]
 
     def length(self, rev):
@@ -61,6 +65,8 @@
         return len(self._data)
 
     def issnapshot(self, rev):
+        if rev == nullrev:
+            return True
         return rev in self._snapshot
 
 def slicechunk(revlog, revs, targetsize=None):
@@ -116,6 +122,12 @@
     [[0], [11], [13], [15]]
     >>> list(slicechunk(revlog, [0, 11, 13, 15], targetsize=20))
     [[0], [11], [13, 15]]
+
+    Slicing involving nullrev
+    >>> list(slicechunk(revlog, [-1, 0, 11, 13, 15], targetsize=20))
+    [[-1, 0], [11], [13, 15]]
+    >>> list(slicechunk(revlog, [-1, 13, 15], targetsize=5))
+    [[-1], [13], [15]]
     """
     if targetsize is not None:
         targetsize = max(targetsize, revlog._srmingapsize)