Patchwork D6941: revlog: add a way to control sidedata changes during revlog.clone

login
register
mail settings
Submitter phabricator
Date Oct. 8, 2019, 12:36 a.m.
Message ID <cbf10f79696610a429a20e2a8c21e383@localhost.localdomain>
Download mbox | patch
Permalink /patch/42080/
State Not Applicable
Headers show

Comments

phabricator - Oct. 8, 2019, 12:36 a.m.
marmoute updated this revision to Diff 16945.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D6941?vs=16772&id=16945

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

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

AFFECTED FILES
  mercurial/revlog.py

CHANGE DETAILS




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

Patch

diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -2540,6 +2540,7 @@ 
         addrevisioncb=None,
         deltareuse=DELTAREUSESAMEREVS,
         forcedeltabothparents=None,
+        sidedatacompanion=None,
     ):
         """Copy this revlog to another, possibly with format changes.
 
@@ -2581,6 +2582,20 @@ 
         In addition to the delta policy, the ``forcedeltabothparents``
         argument controls whether to force compute deltas against both parents
         for merges. By default, the current default is used.
+
+        If not None, the `sidedatacompanion` is callable that accept two
+        arguments:
+
+            (srcrevlog, rev)
+
+        and return a triplet that control changes to sidedata content from the
+        old revision to the new clone result:
+
+            (dropall, filterout, update)
+
+        * if `dropall` is True, all sidedata should be dropped
+        * `filterout` is a set of sidedata keys that should be dropped
+        * `update` is a mapping of additionnal/new key -> value
         """
         if deltareuse not in self.DELTAREUSEALL:
             raise ValueError(
@@ -2615,7 +2630,12 @@ 
             destrevlog._deltabothparents = forcedeltabothparents or oldamd
 
             self._clone(
-                tr, destrevlog, addrevisioncb, deltareuse, forcedeltabothparents
+                tr,
+                destrevlog,
+                addrevisioncb,
+                deltareuse,
+                forcedeltabothparents,
+                sidedatacompanion,
             )
 
         finally:
@@ -2624,7 +2644,13 @@ 
             destrevlog._deltabothparents = oldamd
 
     def _clone(
-        self, tr, destrevlog, addrevisioncb, deltareuse, forcedeltabothparents
+        self,
+        tr,
+        destrevlog,
+        addrevisioncb,
+        deltareuse,
+        forcedeltabothparents,
+        sidedatacompanion,
     ):
         """perform the core duty of `revlog.clone` after parameter processing"""
         deltacomputer = deltautil.deltacomputer(destrevlog)
@@ -2640,12 +2666,24 @@ 
             p2 = index[entry[6]][7]
             node = entry[7]
 
+            sidedataactions = (False, [], {})
+            if sidedatacompanion is not None:
+                sidedataactions = sidedatacompanion(self, rev)
+
             # (Possibly) reuse the delta from the revlog if allowed and
             # the revlog chunk is a delta.
             cachedelta = None
             rawtext = None
-            if deltareuse == self.DELTAREUSEFULLADD:
-                text = self.revision(rev)
+            if any(sidedataactions) or deltareuse == self.DELTAREUSEFULLADD:
+                dropall, filterout, update = sidedataactions
+                text, sidedata = self._revisiondata(rev)
+                if dropall:
+                    sidedata = {}
+                for key in filterout:
+                    sidedata.pop(key, None)
+                sidedata.update(update)
+                if not sidedata:
+                    sidedata = None
                 destrevlog.addrevision(
                     text,
                     tr,
@@ -2656,6 +2694,7 @@ 
                     node=node,
                     flags=flags,
                     deltacomputer=deltacomputer,
+                    sidedata=sidedata,
                 )
             else:
                 if destrevlog._lazydelta: