Patchwork D10887: deltas: at a `target_rev` parameter to finddeltainfo

login
register
mail settings
Submitter phabricator
Date June 20, 2021, 9:22 p.m.
Message ID <differential-rev-PHID-DREV-fxrfpd664poyomhsdyte-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/49201/
State Superseded
Headers show

Comments

phabricator - June 20, 2021, 9:22 p.m.
marmoute created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Otherwise, recomputing a delta for a revision might result in a delta against a
  later revision or a full snapshot thinking we are appending a new revision.
  
  We will make use of this during censoring (and later, stripping).

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/revlogutils/deltas.py

CHANGE DETAILS




To: marmoute, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/revlogutils/deltas.py b/mercurial/revlogutils/deltas.py
--- a/mercurial/revlogutils/deltas.py
+++ b/mercurial/revlogutils/deltas.py
@@ -1030,8 +1030,7 @@ 
             snapshotdepth,
         )
 
-    def _fullsnapshotinfo(self, fh, revinfo):
-        curr = len(self.revlog)
+    def _fullsnapshotinfo(self, fh, revinfo, curr):
         rawtext = self.buildtext(revinfo, fh)
         data = self.revlog.compress(rawtext)
         compresseddeltalen = deltalen = dist = len(data[1]) + len(data[0])
@@ -1050,7 +1049,7 @@ 
             snapshotdepth,
         )
 
-    def finddeltainfo(self, revinfo, fh, excluded_bases=None):
+    def finddeltainfo(self, revinfo, fh, excluded_bases=None, target_rev=None):
         """Find an acceptable delta against a candidate revision
 
         revinfo: information about the revision (instance of _revisioninfo)
@@ -1067,8 +1066,11 @@ 
         a delta base. Use this to recompute delta suitable in censor or strip
         context.
         """
+        if target_rev is None:
+            curr = len(self.revlog)
+
         if not revinfo.textlen:
-            return self._fullsnapshotinfo(fh, revinfo)
+            return self._fullsnapshotinfo(fh, revinfo, target_rev)
 
         if excluded_bases is None:
             excluded_bases = set()
@@ -1077,7 +1079,7 @@ 
         # not calling candelta since only one revision needs test, also to
         # avoid overhead fetching flags again.
         if revinfo.flags & REVIDX_RAWTEXT_CHANGING_FLAGS:
-            return self._fullsnapshotinfo(fh, revinfo)
+            return self._fullsnapshotinfo(fh, revinfo, target_rev)
 
         cachedelta = revinfo.cachedelta
         p1 = revinfo.p1
@@ -1099,6 +1101,8 @@ 
             for candidaterev in candidaterevs:
                 if candidaterev in excluded_bases:
                     continue
+                if candidaterev >= target_rev:
+                    continue
                 candidatedelta = self._builddeltainfo(revinfo, candidaterev, fh)
                 if candidatedelta is not None:
                     if isgooddeltainfo(self.revlog, candidatedelta, revinfo):
@@ -1111,5 +1115,5 @@ 
                 candidaterevs = next(groups)
 
         if deltainfo is None:
-            deltainfo = self._fullsnapshotinfo(fh, revinfo)
+            deltainfo = self._fullsnapshotinfo(fh, revinfo, target_rev)
         return deltainfo