Patchwork [06,of,13] revlog: introduce a tiny mock of a revlog class

login
register
mail settings
Submitter Boris Feld
Date July 10, 2018, 1:27 p.m.
Message ID <10b76b9c8c2bba4d653c.1531229235@FB-lair>
Download mbox | patch
Permalink /patch/32745/
State Accepted
Headers show

Comments

Boris Feld - July 10, 2018, 1:27 p.m.
# HG changeset patch
# User Boris Feld <boris.feld@octobus.net>
# Date 1531209871 -7200
#      Tue Jul 10 10:04:31 2018 +0200
# Node ID 10b76b9c8c2bba4d653ce72565236a005ceab6a6
# Parent  3a5b4001c68a7d56793e2a3b8028609932e36abc
# EXP-Topic write-for-sparse-read
# Available At https://bitbucket.org/octobus/mercurial-devel/
#              hg pull https://bitbucket.org/octobus/mercurial-devel/ -r 10b76b9c8c2b
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.

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -196,6 +196,26 @@  def hash(text, p1, p2):
     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
     """