D6955: sidedatacopies: deal with upgrading and downgrading to that format

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Thu Oct 3 05:56:24 UTC 2019


marmoute created this revision.
Herald added subscribers: mercurial-devel, mjpieters.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is quite useful to test this on real life data.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/copies.py
  mercurial/upgrade.py
  tests/test-copies-in-changeset.t

CHANGE DETAILS

diff --git a/tests/test-copies-in-changeset.t b/tests/test-copies-in-changeset.t
--- a/tests/test-copies-in-changeset.t
+++ b/tests/test-copies-in-changeset.t
@@ -450,4 +450,91 @@
   $ hg ci -Aqm 'add a'
   $ hg mv a b
   $ hg ci -m 'remove a' a
+
+#if sidedata
+
+Test upgrading/downgrading to sidedata storage
+==============================================
+
+downgrading (keeping some sidedata)
+
+  $ 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    yes      no
+  copies-sdc:        yes    yes      no
+  plain-cl-delta:    yes    yes     yes
+  compression:       zlib   zlib    zlib
+  compression-level: default default default
+  $ hg debugsidedata -c -- 0
+  4 sidedata entries
+   entry-0010 size 0
+   entry-0011 size 0
+   entry-0012 size 1
+   entry-0013 size 0
+  $ hg debugsidedata -c -- 1
+  4 sidedata entries
+   entry-0010 size 0
+   entry-0011 size 0
+   entry-0012 size 0
+   entry-0013 size 1
+  $ hg debugsidedata -m -- 0
+  $ cat << EOF > .hg/hgrc
+  > [format]
+  > use-side-data = yes
+  > exp-use-copies-side-data-changeset = no
+  > EOF
+  $ hg debugupgraderepo --run --quiet --no-backup > /dev/null
+  $ 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    yes      no
+  copies-sdc:         no     no      no
+  plain-cl-delta:    yes    yes     yes
+  compression:       zlib   zlib    zlib
+  compression-level: default default default
+  $ hg debugsidedata -c -- 0
+  $ hg debugsidedata -c -- 1
+  $ hg debugsidedata -m -- 0
+
+upgrading
+
+  $ cat << EOF > .hg/hgrc
+  > [format]
+  > exp-use-copies-side-data-changeset = yes
+  > EOF
+  $ hg debugupgraderepo --run --quiet --no-backup > /dev/null
+  $ 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    yes      no
+  copies-sdc:        yes    yes      no
+  plain-cl-delta:    yes    yes     yes
+  compression:       zlib   zlib    zlib
+  compression-level: default default default
+  $ hg debugsidedata -c -- 0
+  4 sidedata entries
+   entry-0010 size 0
+   entry-0011 size 0
+   entry-0012 size 1
+   entry-0013 size 0
+  $ hg debugsidedata -c -- 1
+  4 sidedata entries
+   entry-0010 size 0
+   entry-0011 size 0
+   entry-0012 size 0
+   entry-0013 size 1
+  $ hg debugsidedata -m -- 0
+
+#endif
+
   $ cd ..
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -12,6 +12,7 @@
 from .i18n import _
 from . import (
     changelog,
+    copies,
     error,
     filelog,
     hg,
@@ -32,7 +33,6 @@
 RECLONES_REQUIREMENTS = {
     'generaldelta',
     localrepo.SPARSEREVLOG_REQUIREMENT,
-    localrepo.SIDEDATA_REQUIREMENT,
 }
 
 def requiredsourcerequirements(repo):
@@ -75,6 +75,7 @@
     supported = {
         localrepo.SPARSEREVLOG_REQUIREMENT,
         localrepo.SIDEDATA_REQUIREMENT,
+        localrepo.COPIESSDC_REQUIREMENT,
     }
     for name in compression.compengines:
         engine = compression.compengines[name]
@@ -100,6 +101,7 @@
         'store',
         localrepo.SPARSEREVLOG_REQUIREMENT,
         localrepo.SIDEDATA_REQUIREMENT,
+        localrepo.COPIESSDC_REQUIREMENT,
     }
     for name in compression.compengines:
         engine = compression.compengines[name]
@@ -125,6 +127,7 @@
         'generaldelta',
         localrepo.SPARSEREVLOG_REQUIREMENT,
         localrepo.SIDEDATA_REQUIREMENT,
+        localrepo.COPIESSDC_REQUIREMENT,
     }
     for name in compression.compengines:
         engine = compression.compengines[name]
@@ -612,12 +615,17 @@
 def getsidedatacompanion(srcrepo, dstrepo):
     sidedatacompanion = None
     removedreqs = srcrepo.requirements - dstrepo.requirements
+    addedreqs = dstrepo.requirements - srcrepo.requirements
     if localrepo.SIDEDATA_REQUIREMENT in removedreqs:
         def sidedatacompanion(rl, rev):
             rl = getattr(rl, '_revlog', rl)
             if rl.flags(rev) & revlog.REVIDX_SIDEDATA:
                 return True, (), {}
             return False, (), {}
+    elif localrepo.COPIESSDC_REQUIREMENT in addedreqs:
+        sidedatacompanion = copies.getsidedataadder(srcrepo, dstrepo)
+    elif localrepo.COPIESSDC_REQUIREMENT in removedreqs:
+        sidedatacompanion = copies.getsidedataremover(srcrepo, dstrepo)
     return sidedatacompanion
 
 def matchrevlog(revlogfilter, entry):
diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -13,6 +13,11 @@
 
 from .i18n import _
 
+
+from .revlogutils.flagutil import (
+    REVIDX_SIDEDATA,
+)
+
 from . import (
     error,
     match as matchmod,
@@ -20,6 +25,11 @@
     pathutil,
     util,
 )
+
+from .revlogutils import (
+    sidedata as sidedatamod,
+)
+
 from .utils import (
     stringutil,
 )
@@ -906,3 +916,43 @@
         # Perhaps someone had chosen the same key name (e.g. "added") and
         # used different syntax for the value.
         return None
+
+def _getsidedata(srcrepo, rev):
+    ctx = srcrepo[rev]
+    filescopies = computechangesetcopies(ctx)
+    filesadded = computechangesetfilesadded(ctx)
+    filesremoved = computechangesetfilesremoved(ctx)
+    sidedata = {}
+    if any([filescopies, filesadded, filesremoved]):
+        sortedfiles = sorted(ctx.files())
+        p1copies, p2copies = filescopies
+        p1copies = encodecopies(sortedfiles, p1copies)
+        p2copies = encodecopies(sortedfiles, p2copies)
+        filesadded = encodefileindices(sortedfiles, filesadded)
+        filesremoved = encodefileindices(sortedfiles, filesremoved)
+        sidedata[sidedatamod.SD_P1COPIES] = p1copies
+        sidedata[sidedatamod.SD_P2COPIES] = p2copies
+        sidedata[sidedatamod.SD_FILESADDED] = filesadded
+        sidedata[sidedatamod.SD_FILESREMOVED] = filesremoved
+    return sidedata
+
+def getsidedataadder(srcrepo, destrepo):
+    def sidedatacompanion(revlog, rev):
+        sidedata = {}
+        if util.safehasattr(revlog, 'filteredrevs'): # this is a changelog
+            sidedata = _getsidedata(srcrepo, rev)
+        return False, (), sidedata
+    return sidedatacompanion
+
+def getsidedataremover(srcrepo, destrepo):
+    def sidedatacompanion(revlog, rev):
+        f = ()
+        if util.safehasattr(revlog, 'filteredrevs'): # this is a changelog
+            if revlog.flags(rev) & REVIDX_SIDEDATA:
+                f = (sidedatamod.SD_P1COPIES,
+                     sidedatamod.SD_P2COPIES,
+                     sidedatamod.SD_FILESADDED,
+                     sidedatamod.SD_FILESREMOVED,
+                )
+        return False, f, {}
+    return sidedatacompanion



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


More information about the Mercurial-devel mailing list