revlog: introduce a tiny mock of a revlog class
authorBoris Feld <boris.feld@octobus.net>
Tue, 10 Jul 2018 10:04:31 +0200
changeset 38637 e33f784f2a44
parent 38636 25534e0cf0d9
child 38638 740f7d447222
revlog: introduce a tiny mock of a revlog class This will be used in various function doctest added in the next changesets. The class seems small enough to live in the module directly.
mercurial/revlog.py
--- a/mercurial/revlog.py	Thu May 17 15:10:36 2018 +0200
+++ b/mercurial/revlog.py	Tue Jul 10 10:04:31 2018 +0200
@@ -196,6 +196,26 @@
     s.update(text)
     return s.digest()
 
+class _testrevlog(object):
+    """minimalist fake revlog to use in doctests"""
+
+    def __init__(self, data, density=0.5, mingap=0):
+        """data is an list of revision payload boundaries"""
+        self._data = data
+        self._srdensitythreshold = density
+        self._srmingapsize = mingap
+
+    def start(self, rev):
+        if rev == 0:
+            return 0
+        return self._data[rev - 1]
+
+    def end(self, rev):
+        return self._data[rev]
+
+    def length(self, rev):
+        return self.end(rev) - self.start(rev)
+
 def _trimchunk(revlog, revs, startidx, endidx=None):
     """returns revs[startidx:endidx] without empty trailing revs
     """