Patchwork D9199: upgrade: allow sidedata upgrade to modify revision flag

login
register
mail settings
Submitter phabricator
Date Oct. 13, 2020, 10:40 a.m.
Message ID <differential-rev-PHID-DREV-tlapfp5pvsi6ndv3eljr-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/47448/
State Superseded
Headers show

Comments

phabricator - Oct. 13, 2020, 10:40 a.m.
marmoute created this revision.
Herald added a reviewer: indygreg.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  In the process, we fix the lack of HAS_COPIES_INFO flag on upgrade, and test the
  results.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/metadata.py
  mercurial/revlog.py
  mercurial/upgrade.py
  tests/test-copies-chain-merge.t
  tests/testlib/ext-sidedata.py

CHANGE DETAILS




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

Patch

diff --git a/tests/testlib/ext-sidedata.py b/tests/testlib/ext-sidedata.py
--- a/tests/testlib/ext-sidedata.py
+++ b/tests/testlib/ext-sidedata.py
@@ -70,7 +70,7 @@ 
             # and sha2 hashes
             sha256 = hashlib.sha256(text).digest()
             update[sidedata.SD_TEST2] = struct.pack('>32s', sha256)
-            return False, (), update
+            return False, (), update, 0, 0
 
     return sidedatacompanion
 
diff --git a/tests/test-copies-chain-merge.t b/tests/test-copies-chain-merge.t
--- a/tests/test-copies-chain-merge.t
+++ b/tests/test-copies-chain-merge.t
@@ -1,4 +1,4 @@ 
-#testcases filelog compatibility sidedata
+#testcases filelog compatibility sidedata upgraded
 
 =====================================================
 Test Copy tracing for chain of copies involving merge
@@ -580,7 +580,7 @@ 
  commit time.
 
 
-#if filelog
+#if upgraded
   $ cat >> $HGRCPATH << EOF
   > [format]
   > exp-use-side-data = yes
@@ -608,7 +608,7 @@ 
 #endif
 
 
-#if no-compatibility
+#if no-compatibility no-filelog
 
   $ for rev in `hg log --rev 'all()' -T '{rev}\n'`; do
   >     echo "##### revision $rev #####"
@@ -790,35 +790,6 @@ 
 
 #endif
 
-Downgrade to keep testing the filelog algorithm
-(This can be removed once we have an explicite "upgrade" tests case_
-
-#if filelog
-  $ cat >> $HGRCPATH << EOF
-  > [format]
-  > exp-use-side-data = no
-  > exp-use-copies-side-data-changeset = no
-  > EOF
-  $ hg debugformat -v
-  format-variant     repo config default
-  fncache:            yes    yes     yes
-  dotencode:          yes    yes     yes
-  generaldelta:       yes    yes     yes
-  sparserevlog:       yes    yes     yes
-  sidedata:           yes     no      no
-  persistent-nodemap:  no     no      no
-  copies-sdc:         yes     no      no
-  plain-cl-delta:     yes    yes     yes
-  compression:        * (glob)
-  compression-level:  default default default
-  $ hg debugupgraderepo --run --quiet
-  upgrade will perform the following actions:
-  
-  requirements
-     preserved: * (glob)
-     removed: exp-copies-sidedata-changeset, exp-sidedata-flag
-  
-#endif
 
 Test copy information chaining
 ==============================
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -732,8 +732,8 @@ 
         def sidedatacompanion(rl, rev):
             rl = getattr(rl, '_revlog', rl)
             if rl.flags(rev) & revlog.REVIDX_SIDEDATA:
-                return True, (), {}
-            return False, (), {}
+                return True, (), {}, 0, 0
+            return False, (), {}, 0, 0
 
     elif requirements.COPIESSDC_REQUIREMENT in addedreqs:
         sidedatacompanion = metadata.getsidedataadder(srcrepo, dstrepo)
diff --git a/mercurial/revlog.py b/mercurial/revlog.py
--- a/mercurial/revlog.py
+++ b/mercurial/revlog.py
@@ -1491,8 +1491,8 @@ 
 
     def lookup(self, id):
         """locate a node based on:
-            - revision number or str(revision number)
-            - nodeid or subset of hex nodeid
+        - revision number or str(revision number)
+        - nodeid or subset of hex nodeid
         """
         n = self._match(id)
         if n is not None:
@@ -1771,8 +1771,7 @@ 
             return rev - 1
 
     def issnapshot(self, rev):
-        """tells whether rev is a snapshot
-        """
+        """tells whether rev is a snapshot"""
         if not self._sparserevlog:
             return self.deltaparent(rev) == nullrev
         elif util.safehasattr(self.index, b'issnapshot'):
@@ -2043,8 +2042,7 @@ 
         self._chunkclear()
 
     def _nodeduplicatecallback(self, transaction, node):
-        """called when trying to add a node already stored.
-        """
+        """called when trying to add a node already stored."""
 
     def addrevision(
         self,
@@ -2705,14 +2703,16 @@ 
 
             (srcrevlog, rev)
 
-        and return a triplet that control changes to sidedata content from the
+        and return a quintet that control changes to sidedata content from the
         old revision to the new clone result:
 
-            (dropall, filterout, update)
+            (dropall, filterout, update, new_flags, dropped_flags)
 
         * 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
+        * new_flags is a bitfields of new flags that the revision should get
+        * dropped_flags is a bitfields of new flags that the revision shoudl not longer have
         """
         if deltareuse not in self.DELTAREUSEALL:
             raise ValueError(
@@ -2783,7 +2783,7 @@ 
             p2 = index[entry[6]][7]
             node = entry[7]
 
-            sidedataactions = (False, [], {})
+            sidedataactions = (False, [], {}, 0, 0)
             if sidedatacompanion is not None:
                 sidedataactions = sidedatacompanion(self, rev)
 
@@ -2792,7 +2792,11 @@ 
             cachedelta = None
             rawtext = None
             if any(sidedataactions) or deltareuse == self.DELTAREUSEFULLADD:
-                dropall, filterout, update = sidedataactions
+                dropall = sidedataactions[0]
+                filterout = sidedataactions[1]
+                update = sidedataactions[2]
+                new_flags = sidedataactions[3]
+                dropped_flags = sidedataactions[4]
                 text, sidedata = self._revisiondata(rev)
                 if dropall:
                     sidedata = {}
@@ -2801,6 +2805,10 @@ 
                 sidedata.update(update)
                 if not sidedata:
                     sidedata = None
+
+                flags |= new_flags
+                flags &= ~dropped_flags
+
                 destrevlog.addrevision(
                     text,
                     tr,
diff --git a/mercurial/metadata.py b/mercurial/metadata.py
--- a/mercurial/metadata.py
+++ b/mercurial/metadata.py
@@ -888,8 +888,11 @@ 
                     staging[r] = data
                     r, sidedata = sidedataq.get()
             tokens.release()
-        sidedataq, has_copies_info = data
-        return False, (), sidedata
+        sidedata, has_copies_info = data
+        new_flag = 0
+        if has_copies_info:
+            new_flag = sidedataflag.REVIDX_HASCOPIESINFO
+        return False, (), sidedata, new_flag, 0
 
     return sidedata_companion
 
@@ -900,10 +903,14 @@ 
     It just compute it in the same thread on request"""
 
     def sidedatacompanion(revlog, rev):
-        sidedata = {}
+        sidedata, has_copies_info = {}, False
         if util.safehasattr(revlog, 'filteredrevs'):  # this is a changelog
             sidedata, has_copies_info = _getsidedata(srcrepo, rev)
-        return False, (), sidedata
+        new_flag = 0
+        if has_copies_info:
+            new_flag = sidedataflag.REVIDX_HASCOPIESINFO
+
+        return False, (), sidedata, new_flag, 0
 
     return sidedatacompanion
 
@@ -919,6 +926,6 @@ 
                     sidedatamod.SD_FILESADDED,
                     sidedatamod.SD_FILESREMOVED,
                 )
-        return False, f, {}
+        return False, f, {}, 0, sidedataflag.REVIDX_HASCOPIESINFO
 
     return sidedatacompanion