revlog: drop emitrevisiondeltas() and associated functionality (API)
authorGregory Szorc <gregory.szorc@gmail.com>
Mon, 24 Sep 2018 09:59:19 -0700
changeset 39866 e23c03dc5cf9
parent 39865 31b7e8e7132e
child 39867 4b816a83e17e
revlog: drop emitrevisiondeltas() and associated functionality (API) emitrevisions() is the future! Differential Revision: https://phab.mercurial-scm.org/D4726
mercurial/changegroup.py
mercurial/filelog.py
mercurial/manifest.py
mercurial/repository.py
mercurial/revlog.py
mercurial/testing/storage.py
tests/simplestorerepo.py
tests/test-check-interfaces.py
--- a/mercurial/changegroup.py	Fri Sep 21 18:47:04 2018 -0700
+++ b/mercurial/changegroup.py	Mon Sep 24 09:59:19 2018 -0700
@@ -19,10 +19,6 @@
     short,
 )
 
-from .thirdparty import (
-    attr,
-)
-
 from . import (
     error,
     match as matchmod,
@@ -34,10 +30,6 @@
     util,
 )
 
-from .utils import (
-    interfaceutil,
-)
-
 _CHANGEGROUPV1_DELTA_HEADER = struct.Struct("20s20s20s20s")
 _CHANGEGROUPV2_DELTA_HEADER = struct.Struct("20s20s20s20s20s")
 _CHANGEGROUPV3_DELTA_HEADER = struct.Struct(">20s20s20s20s20sH")
@@ -499,16 +491,6 @@
             return d
         return readexactly(self._fh, n)
 
-@interfaceutil.implementer(repository.irevisiondeltarequest)
-@attr.s(slots=True, frozen=True)
-class revisiondeltarequest(object):
-    node = attr.ib()
-    linknode = attr.ib()
-    p1node = attr.ib()
-    p2node = attr.ib()
-    basenode = attr.ib()
-    ellipsis = attr.ib(default=False)
-
 def _revisiondeltatochunks(delta, headerfn):
     """Serialize a revisiondelta to changegroup chunks."""
 
--- a/mercurial/filelog.py	Fri Sep 21 18:47:04 2018 -0700
+++ b/mercurial/filelog.py	Mon Sep 24 09:59:19 2018 -0700
@@ -93,9 +93,6 @@
     def revdiff(self, rev1, rev2):
         return self._revlog.revdiff(rev1, rev2)
 
-    def emitrevisiondeltas(self, requests):
-        return self._revlog.emitrevisiondeltas(requests)
-
     def emitrevisions(self, nodes, nodesorder=None,
                       revisiondata=False, assumehaveparentrevisions=False,
                       deltaprevious=False):
--- a/mercurial/manifest.py	Fri Sep 21 18:47:04 2018 -0700
+++ b/mercurial/manifest.py	Mon Sep 24 09:59:19 2018 -0700
@@ -1562,9 +1562,6 @@
     def deltaparent(self, rev):
         return self._revlog.deltaparent(rev)
 
-    def emitrevisiondeltas(self, requests):
-        return self._revlog.emitrevisiondeltas(requests)
-
     def emitrevisions(self, nodes, nodesorder=None,
                       revisiondata=False, assumehaveparentrevisions=False,
                       deltaprevious=False):
--- a/mercurial/repository.py	Fri Sep 21 18:47:04 2018 -0700
+++ b/mercurial/repository.py	Mon Sep 24 09:59:19 2018 -0700
@@ -391,37 +391,6 @@
         Stored in the bdiff delta format.
         """)
 
-class irevisiondeltarequest(interfaceutil.Interface):
-    """Represents a request to generate an ``irevisiondelta``."""
-
-    node = interfaceutil.Attribute(
-        """20 byte node of revision being requested.""")
-
-    p1node = interfaceutil.Attribute(
-        """20 byte node of 1st parent of revision.""")
-
-    p2node = interfaceutil.Attribute(
-        """20 byte node of 2nd parent of revision.""")
-
-    linknode = interfaceutil.Attribute(
-        """20 byte node to store in ``linknode`` attribute.""")
-
-    basenode = interfaceutil.Attribute(
-        """Base revision that delta should be generated against.
-
-        If ``nullid``, the derived ``irevisiondelta`` should have its
-        ``revision`` field populated and no delta should be generated.
-
-        If ``None``, the delta may be generated against any revision that
-        is an ancestor of this revision. Or a full revision may be used.
-
-        If any other value, the delta should be produced against that
-        revision.
-        """)
-
-    ellipsis = interfaceutil.Attribute(
-        """Boolean on whether the ellipsis flag should be set.""")
-
 class ifilerevisionssequence(interfaceutil.Interface):
     """Contains index data for all revisions of a file.
 
@@ -630,30 +599,6 @@
         revision data.
         """
 
-    def emitrevisiondeltas(requests):
-        """Produce ``irevisiondelta`` from ``irevisiondeltarequest``s.
-
-        Given an iterable of objects conforming to the ``irevisiondeltarequest``
-        interface, emits objects conforming to the ``irevisiondelta``
-        interface.
-
-        This method is a generator.
-
-        ``irevisiondelta`` should be emitted in the same order of
-        ``irevisiondeltarequest`` that was passed in.
-
-        The emitted objects MUST conform by the results of
-        ``irevisiondeltarequest``. Namely, they must respect any requests
-        for building a delta from a specific ``basenode`` if defined.
-
-        When sending deltas, implementations must take into account whether
-        the client has the base delta before encoding a delta against that
-        revision. A revision encountered previously in ``requests`` is
-        always a suitable base revision. An example of a bad delta is a delta
-        against a non-ancestor revision. Another example of a bad delta is a
-        delta against a censored revision.
-        """
-
     def emitrevisions(nodes,
                       nodesorder=None,
                       revisiondata=False,
@@ -1174,12 +1119,6 @@
         Returns True if the fulltext is different from what is stored.
         """
 
-    def emitrevisiondeltas(requests):
-        """Produce ``irevisiondelta`` from ``irevisiondeltarequest``s.
-
-        See the documentation for ``ifiledata`` for more.
-        """
-
     def emitrevisions(nodes,
                       nodesorder=None,
                       revisiondata=False,
--- a/mercurial/revlog.py	Fri Sep 21 18:47:04 2018 -0700
+++ b/mercurial/revlog.py	Mon Sep 24 09:59:19 2018 -0700
@@ -2294,87 +2294,6 @@
             res.append(self.datafile)
         return res
 
-    def emitrevisiondeltas(self, requests):
-        frev = self.rev
-
-        prevrev = None
-        for request in requests:
-            node = request.node
-            rev = frev(node)
-
-            if prevrev is None:
-                prevrev = self.index[rev][5]
-
-            # Requesting a full revision.
-            if request.basenode == nullid:
-                baserev = nullrev
-            # Requesting an explicit revision.
-            elif request.basenode is not None:
-                baserev = frev(request.basenode)
-            # Allowing us to choose.
-            else:
-                p1rev, p2rev = self.parentrevs(rev)
-                deltaparentrev = self.deltaparent(rev)
-
-                # Avoid sending full revisions when delta parent is null. Pick
-                # prev in that case. It's tempting to pick p1 in this case, as
-                # p1 will be smaller in the common case. However, computing a
-                # delta against p1 may require resolving the raw text of p1,
-                # which could be expensive. The revlog caches should have prev
-                # cached, meaning less CPU for delta generation. There is
-                # likely room to add a flag and/or config option to control this
-                # behavior.
-                if deltaparentrev == nullrev and self._storedeltachains:
-                    baserev = prevrev
-
-                # Revlog is configured to use full snapshot for a reason.
-                # Stick to full snapshot.
-                elif deltaparentrev == nullrev:
-                    baserev = nullrev
-
-                # Pick previous when we can't be sure the base is available
-                # on consumer.
-                elif deltaparentrev not in (p1rev, p2rev, prevrev):
-                    baserev = prevrev
-                else:
-                    baserev = deltaparentrev
-
-                if baserev != nullrev and not self.candelta(baserev, rev):
-                    baserev = nullrev
-
-            revision = None
-            delta = None
-            baserevisionsize = None
-
-            if self.iscensored(baserev) or self.iscensored(rev):
-                try:
-                    revision = self.revision(node, raw=True)
-                except error.CensoredNodeError as e:
-                    revision = e.tombstone
-
-                if baserev != nullrev:
-                    baserevisionsize = self.rawsize(baserev)
-
-            elif baserev == nullrev:
-                revision = self.revision(node, raw=True)
-            else:
-                delta = self.revdiff(baserev, rev)
-
-            extraflags = REVIDX_ELLIPSIS if request.ellipsis else 0
-
-            yield revlogrevisiondelta(
-                node=node,
-                p1node=request.p1node,
-                p2node=request.p2node,
-                linknode=request.linknode,
-                basenode=self.node(baserev),
-                flags=self.flags(rev) | extraflags,
-                baserevisionsize=baserevisionsize,
-                revision=revision,
-                delta=delta)
-
-            prevrev = rev
-
     def emitrevisions(self, nodes, nodesorder=None, revisiondata=False,
                       assumehaveparentrevisions=False, deltaprevious=False):
         if nodesorder not in ('nodes', 'storage', None):
--- a/mercurial/testing/storage.py	Fri Sep 21 18:47:04 2018 -0700
+++ b/mercurial/testing/storage.py	Mon Sep 24 09:59:19 2018 -0700
@@ -25,15 +25,6 @@
         assertRaisesRegex = (# camelcase-required
             unittest.TestCase.assertRaisesRegexp)
 
-class revisiondeltarequest(object):
-    def __init__(self, node, p1, p2, linknode, basenode, ellipsis):
-        self.node = node
-        self.p1node = p1
-        self.p2node = p2
-        self.linknode = linknode
-        self.basenode = basenode
-        self.ellipsis = ellipsis
-
 class ifileindextests(basetestcase):
     """Generic tests for the ifileindex interface.
 
@@ -454,52 +445,6 @@
         with self.assertRaises(IndexError):
             f.revdiff(0, 0)
 
-        gen = f.emitrevisiondeltas([])
-        with self.assertRaises(StopIteration):
-            next(gen)
-
-        requests = [
-            revisiondeltarequest(nullid, nullid, nullid, nullid, nullid, False),
-        ]
-        gen = f.emitrevisiondeltas(requests)
-
-        delta = next(gen)
-
-        self.assertEqual(delta.node, nullid)
-        self.assertEqual(delta.p1node, nullid)
-        self.assertEqual(delta.p2node, nullid)
-        self.assertEqual(delta.linknode, nullid)
-        self.assertEqual(delta.basenode, nullid)
-        self.assertIsNone(delta.baserevisionsize)
-        self.assertEqual(delta.revision, b'')
-        self.assertIsNone(delta.delta)
-
-        with self.assertRaises(StopIteration):
-            next(gen)
-
-        requests = [
-            revisiondeltarequest(nullid, nullid, nullid, nullid, nullid, False),
-            revisiondeltarequest(nullid, b'\x01' * 20, b'\x02' * 20,
-                                 b'\x03' * 20, nullid, False)
-        ]
-
-        gen = f.emitrevisiondeltas(requests)
-
-        next(gen)
-        delta = next(gen)
-
-        self.assertEqual(delta.node, nullid)
-        self.assertEqual(delta.p1node, b'\x01' * 20)
-        self.assertEqual(delta.p2node, b'\x02' * 20)
-        self.assertEqual(delta.linknode, b'\x03' * 20)
-        self.assertEqual(delta.basenode, nullid)
-        self.assertIsNone(delta.baserevisionsize)
-        self.assertEqual(delta.revision, b'')
-        self.assertIsNone(delta.delta)
-
-        with self.assertRaises(StopIteration):
-            next(gen)
-
         # Emitting empty list is an empty generator.
         gen = f.emitrevisions([])
         with self.assertRaises(StopIteration):
@@ -561,25 +506,6 @@
         self.assertEqual(f.revdiff(0, nullrev),
                          b'\x00\x00\x00\x00\x00\x00\x00\x07\x00\x00\x00\x00')
 
-        requests = [
-            revisiondeltarequest(node, nullid, nullid, nullid, nullid, False),
-        ]
-        gen = f.emitrevisiondeltas(requests)
-
-        delta = next(gen)
-
-        self.assertEqual(delta.node, node)
-        self.assertEqual(delta.p1node, nullid)
-        self.assertEqual(delta.p2node, nullid)
-        self.assertEqual(delta.linknode, nullid)
-        self.assertEqual(delta.basenode, nullid)
-        self.assertIsNone(delta.baserevisionsize)
-        self.assertEqual(delta.revision, fulltext)
-        self.assertIsNone(delta.delta)
-
-        with self.assertRaises(StopIteration):
-            next(gen)
-
         # Emitting a single revision works.
         gen = f.emitrevisions([node])
         rev = next(gen)
@@ -697,56 +623,6 @@
                          b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x02' +
                          fulltext2)
 
-        requests = [
-            revisiondeltarequest(node0, nullid, nullid, b'\x01' * 20, nullid,
-                                 False),
-            revisiondeltarequest(node1, node0, nullid, b'\x02' * 20, node0,
-                                 False),
-            revisiondeltarequest(node2, node1, nullid, b'\x03' * 20, node1,
-                                 False),
-        ]
-        gen = f.emitrevisiondeltas(requests)
-
-        delta = next(gen)
-
-        self.assertEqual(delta.node, node0)
-        self.assertEqual(delta.p1node, nullid)
-        self.assertEqual(delta.p2node, nullid)
-        self.assertEqual(delta.linknode, b'\x01' * 20)
-        self.assertEqual(delta.basenode, nullid)
-        self.assertIsNone(delta.baserevisionsize)
-        self.assertEqual(delta.revision, fulltext0)
-        self.assertIsNone(delta.delta)
-
-        delta = next(gen)
-
-        self.assertEqual(delta.node, node1)
-        self.assertEqual(delta.p1node, node0)
-        self.assertEqual(delta.p2node, nullid)
-        self.assertEqual(delta.linknode, b'\x02' * 20)
-        self.assertEqual(delta.basenode, node0)
-        self.assertIsNone(delta.baserevisionsize)
-        self.assertIsNone(delta.revision)
-        self.assertEqual(delta.delta,
-                         b'\x00\x00\x00\x00\x00\x00\x04\x00\x00\x00\x04\x01' +
-                         fulltext1)
-
-        delta = next(gen)
-
-        self.assertEqual(delta.node, node2)
-        self.assertEqual(delta.p1node, node1)
-        self.assertEqual(delta.p2node, nullid)
-        self.assertEqual(delta.linknode, b'\x03' * 20)
-        self.assertEqual(delta.basenode, node1)
-        self.assertIsNone(delta.baserevisionsize)
-        self.assertIsNone(delta.revision)
-        self.assertEqual(delta.delta,
-                         b'\x00\x00\x00\x00\x00\x00\x04\x01\x00\x00\x04\x02' +
-                         fulltext2)
-
-        with self.assertRaises(StopIteration):
-            next(gen)
-
         # Nodes should be emitted in order.
         gen = f.emitrevisions([node0, node1, node2], revisiondata=True)
 
--- a/tests/simplestorerepo.py	Fri Sep 21 18:47:04 2018 -0700
+++ b/tests/simplestorerepo.py	Mon Sep 24 09:59:19 2018 -0700
@@ -510,54 +510,6 @@
         return mdiff.textdiff(self.revision(node1, raw=True),
                               self.revision(node2, raw=True))
 
-    def emitrevisiondeltas(self, requests):
-        for request in requests:
-            node = request.node
-            rev = self.rev(node)
-
-            if request.basenode == nullid:
-                baserev = nullrev
-            elif request.basenode is not None:
-                baserev = self.rev(request.basenode)
-            else:
-                # This is a test extension and we can do simple things
-                # for choosing a delta parent.
-                baserev = self.deltaparent(rev)
-
-                if baserev != nullrev and not self._candelta(baserev, rev):
-                    baserev = nullrev
-
-            revision = None
-            delta = None
-            baserevisionsize = None
-
-            if self.iscensored(baserev) or self.iscensored(rev):
-                try:
-                    revision = self.revision(node, raw=True)
-                except error.CensoredNodeError as e:
-                    revision = e.tombstone
-
-                if baserev != nullrev:
-                    baserevisionsize = self.rawsize(baserev)
-
-            elif baserev == nullrev:
-                revision = self.revision(node, raw=True)
-            else:
-                delta = self.revdiff(baserev, rev)
-
-            extraflags = revlog.REVIDX_ELLIPSIS if request.ellipsis else 0
-
-            yield simplestorerevisiondelta(
-                node=node,
-                p1node=request.p1node,
-                p2node=request.p2node,
-                linknode=request.linknode,
-                basenode=self.node(baserev),
-                flags=self.flags(rev) | extraflags,
-                baserevisionsize=baserevisionsize,
-                revision=revision,
-                delta=delta)
-
     def heads(self, start=None, stop=None):
         # This is copied from revlog.py.
         if start is None and stop is None:
--- a/tests/test-check-interfaces.py	Fri Sep 21 18:47:04 2018 -0700
+++ b/tests/test-check-interfaces.py	Mon Sep 24 09:59:19 2018 -0700
@@ -21,7 +21,6 @@
     verify as ziverify,
 )
 from mercurial import (
-    changegroup,
     bundlerepo,
     filelog,
     httppeer,
@@ -206,8 +205,6 @@
 
     ziverify.verifyClass(repository.irevisiondelta,
                          revlog.revlogrevisiondelta)
-    ziverify.verifyClass(repository.irevisiondeltarequest,
-                         changegroup.revisiondeltarequest)
 
     rd = revlog.revlogrevisiondelta(
         node=b'',
@@ -221,14 +218,6 @@
         delta=None)
     checkzobject(rd)
 
-    rdr = changegroup.revisiondeltarequest(
-        node=b'',
-        linknode=b'',
-        p1node=b'',
-        p2node=b'',
-        basenode=b'')
-    checkzobject(rdr)
-
     ziverify.verifyClass(repository.iverifyproblem,
                          revlog.revlogproblem)
     checkzobject(revlog.revlogproblem())