upgrade: add support to downgrade share safe mode
authorPulkit Goyal <7895pulkit@gmail.com>
Fri, 16 Oct 2020 18:57:55 +0530
changeset 46003 c6a1fa42e325
parent 46002 705c37f22859
child 46004 49b4ab1d9f5e
upgrade: add support to downgrade share safe mode In previous patch we added support to upgrade current repository to use share safe mode. This patch adds support to downgrade to remove share-safe mode. Differential Revision: https://phab.mercurial-scm.org/D9358
mercurial/localrepo.py
mercurial/upgrade.py
tests/test-share-safe.t
--- a/mercurial/localrepo.py	Thu Jun 25 13:13:21 2020 +0530
+++ b/mercurial/localrepo.py	Fri Oct 16 18:57:55 2020 +0530
@@ -558,6 +558,16 @@
     # is present. We never write SHARESAFE_REQUIREMENT for a repo if store
     # is not present, refer checkrequirementscompat() for that
     if requirementsmod.SHARESAFE_REQUIREMENT in requirements:
+
+        if (
+            shared
+            and requirementsmod.SHARESAFE_REQUIREMENT
+            not in _readrequires(sharedvfs, True)
+        ):
+            raise error.Abort(
+                _(b"share source does not support exp-sharesafe requirement")
+            )
+
         if shared:
             # This is a shared repo
             storevfs = vfsmod.vfs(sharedvfs.join(b'store'))
--- a/mercurial/upgrade.py	Thu Jun 25 13:13:21 2020 +0530
+++ b/mercurial/upgrade.py	Fri Oct 16 18:57:55 2020 +0530
@@ -80,6 +80,7 @@
         requirements.SIDEDATA_REQUIREMENT,
         requirements.COPIESSDC_REQUIREMENT,
         requirements.NODEMAP_REQUIREMENT,
+        requirements.SHARESAFE_REQUIREMENT,
     }
     for name in compression.compengines:
         engine = compression.compengines[name]
@@ -1470,3 +1471,11 @@
                         b' New shares will be created in safe mode.\n'
                     )
                 )
+            if sharedsafe.name in removedreqs:
+                ui.warn(
+                    _(
+                        b'repository downgraded to not use share safe mode, '
+                        b'existing shares will not work and needs to'
+                        b' be reshared.\n'
+                    )
+                )
--- a/tests/test-share-safe.t	Thu Jun 25 13:13:21 2020 +0530
+++ b/tests/test-share-safe.t	Fri Oct 16 18:57:55 2020 +0530
@@ -377,4 +377,79 @@
   |
   o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
   
+
+
+Create a safe share from upgrade one
+
+  $ cd ..
+  $ hg share non-share-safe ss-share
+  updating working directory
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ cd ss-share
+  $ hg log -GT "{node}: {desc}\n"
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+  $ cd ../non-share-safe
+
+Test that downgrading works too
+
+  $ cat >> $HGRCPATH <<EOF
+  > [extensions]
+  > share =
+  > [format]
+  > exp-share-safe = False
+  > EOF
+
+  $ hg debugupgraderepo -q
+  requirements
+     preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
+     removed: exp-sharesafe
+  
+  $ hg debugupgraderepo -q --run
+  upgrade will perform the following actions:
+  
+  requirements
+     preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
+     removed: exp-sharesafe
+  
+  repository downgraded to not use share safe mode, existing shares will not work and needs to be reshared.
+
+  $ hg debugrequirements
+  dotencode
+  fncache
+  generaldelta
+  revlogv1
+  sparserevlog
+  store
+
+  $ cat .hg/requires
+  dotencode
+  fncache
+  generaldelta
+  revlogv1
+  sparserevlog
+  store
+
+  $ test -f .hg/store/requires
+  [1]
+
+  $ hg log -GT "{node}: {desc}\n"
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
+Make sure existing shares still works
+
+  $ hg log -GT "{node}: {desc}\n" -R ../nss-share
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
   $ hg unshare -R ../nss-share
+
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share
+  abort: share source does not support exp-sharesafe requirement
+  [255]