Patchwork D8365: manifest: introduce new exception to signal unavailability of fastdelta()

login
register
mail settings
Submitter phabricator
Date April 2, 2020, 5:16 p.m.
Message ID <differential-rev-PHID-DREV-ngqwgm6x7ek2josgtl33-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/45998/
State Superseded
Headers show

Comments

phabricator - April 2, 2020, 5:16 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  I've spent some time reflecting on this, and I think this is the best
  we can do in this API contract for now. This opens the door to adding
  treemanifest's implementation to the list of implementers of
  imanifestdict.

REPOSITORY
  rHG Mercurial

BRANCH
  default

REVISION DETAIL
  https://phab.mercurial-scm.org/D8365

AFFECTED FILES
  mercurial/interfaces/repository.py
  mercurial/manifest.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel
phabricator - April 3, 2020, 9:21 a.m.
pulkit added inline comments.

INLINE COMMENTS

> manifest.py:1632
>  
>              _checkforbidden(added)
>              # combine the changed lists into one sorted iterator

this will lead us to running this and next `heapq.merge` call on treemanifest, but I am not sure how costly that will be.

REPOSITORY
  rHG Mercurial

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D8365/new/

REVISION DETAIL
  https://phab.mercurial-scm.org/D8365

To: durin42, #hg-reviewers, pulkit
Cc: mercurial-devel

Patch

diff --git a/mercurial/manifest.py b/mercurial/manifest.py
--- a/mercurial/manifest.py
+++ b/mercurial/manifest.py
@@ -1212,6 +1212,9 @@ 
             ret._dirty = True
         return ret
 
+    def fastdelta(self, base, changes):
+        raise FastdeltaUnavailable()
+
     def diff(self, m2, match=None, clean=False):
         '''Finds changes between the current manifest and m2.
 
@@ -1488,6 +1491,10 @@ 
 MAXCOMPRESSION = 3
 
 
+class FastdeltaUnavailable(Exception):
+    """Exception raised when fastdelta isn't usable on a manifest."""
+
+
 @interfaceutil.implementer(repository.imanifeststorage)
 class manifestrevlog(object):
     '''A revlog that stores manifest texts. This is responsible for caching the
@@ -1614,7 +1621,9 @@ 
         readtree=None,
         match=None,
     ):
-        if p1 in self.fulltextcache and util.safehasattr(m, b'fastdelta'):
+        try:
+            if p1 not in self.fulltextcache:
+                raise FastdeltaUnavailable()
             # If our first parent is in the manifest cache, we can
             # compute a delta here using properties we know about the
             # manifest up-front, which may save time later for the
@@ -1633,11 +1642,12 @@ 
             n = self._revlog.addrevision(
                 text, transaction, link, p1, p2, cachedelta
             )
-        else:
-            # The first parent manifest isn't already loaded, so we'll
-            # just encode a fulltext of the manifest and pass that
-            # through to the revlog layer, and let it handle the delta
-            # process.
+        except FastdeltaUnavailable:
+            # The first parent manifest isn't already loaded or the
+            # manifest implementation doesn't support fastdelta, so
+            # we'll just encode a fulltext of the manifest and pass
+            # that through to the revlog layer, and let it handle the
+            # delta process.
             if self._treeondisk:
                 assert readtree, b"readtree must be set for treemanifest writes"
                 assert match, b"match must be specified for treemanifest writes"
diff --git a/mercurial/interfaces/repository.py b/mercurial/interfaces/repository.py
--- a/mercurial/interfaces/repository.py
+++ b/mercurial/interfaces/repository.py
@@ -1052,6 +1052,9 @@ 
 
         Returns a 2-tuple containing ``bytearray(self.text())`` and the
         delta between ``base`` and this manifest.
+
+        If this manifest implementation can't support ``fastdelta()``,
+        raise ``mercurial.manifest.FastdeltaUnavailable``.
         """