upgrade: allow sidedata upgrade to modify revision flag
authorPierre-Yves David <pierre-yves.david@octobus.net>
Tue, 13 Oct 2020 05:14:37 +0200
changeset 45735 edf4fa06df94
parent 45734 53c265a6fc83
child 45736 2c6b054e22d0
upgrade: allow sidedata upgrade to modify revision flag In the process, we fix the lack of HAS_COPIES_INFO flag on upgrade, and test the results. Differential Revision: https://phab.mercurial-scm.org/D9199
mercurial/metadata.py
mercurial/revlog.py
mercurial/upgrade.py
tests/test-copies-chain-merge.t
tests/testlib/ext-sidedata.py
--- a/mercurial/metadata.py	Tue Oct 13 03:30:49 2020 +0200
+++ b/mercurial/metadata.py	Tue Oct 13 05:14:37 2020 +0200
@@ -893,8 +893,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
 
@@ -905,10 +908,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
 
@@ -924,6 +931,6 @@
                     sidedatamod.SD_FILESADDED,
                     sidedatamod.SD_FILESREMOVED,
                 )
-        return False, f, {}
+        return False, f, {}, 0, sidedataflag.REVIDX_HASCOPIESINFO
 
     return sidedatacompanion
--- a/mercurial/revlog.py	Tue Oct 13 03:30:49 2020 +0200
+++ b/mercurial/revlog.py	Tue Oct 13 05:14:37 2020 +0200
@@ -2705,14 +2705,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 +2785,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 +2794,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 +2807,10 @@
                 sidedata.update(update)
                 if not sidedata:
                     sidedata = None
+
+                flags |= new_flags
+                flags &= ~dropped_flags
+
                 destrevlog.addrevision(
                     text,
                     tr,
--- a/mercurial/upgrade.py	Tue Oct 13 03:30:49 2020 +0200
+++ b/mercurial/upgrade.py	Tue Oct 13 05:14:37 2020 +0200
@@ -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)
--- a/tests/test-copies-chain-merge.t	Tue Oct 13 03:30:49 2020 +0200
+++ b/tests/test-copies-chain-merge.t	Tue Oct 13 05:14:37 2020 +0200
@@ -1,4 +1,4 @@
-#testcases filelog compatibility changeset sidedata
+#testcases filelog compatibility changeset sidedata upgraded
 
 =====================================================
 Test Copy tracing for chain of copies involving merge
@@ -594,7 +594,7 @@
  commit time.
 
 
-#if filelog
+#if upgraded
   $ cat >> $HGRCPATH << EOF
   > [format]
   > exp-use-side-data = yes
@@ -622,7 +622,7 @@
 #endif
 
 
-#if no-compatibility no-changeset
+#if no-compatibility no-filelog no-changeset
 
   $ for rev in `hg log --rev 'all()' -T '{rev}\n'`; do
   >     echo "##### revision $rev #####"
@@ -804,35 +804,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
 ==============================
--- a/tests/testlib/ext-sidedata.py	Tue Oct 13 03:30:49 2020 +0200
+++ b/tests/testlib/ext-sidedata.py	Tue Oct 13 05:14:37 2020 +0200
@@ -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