Patchwork [4,of,4] upgrade: add support for experimental safe share mode

login
register
mail settings
Submitter Pulkit Goyal
Date Oct. 16, 2020, 7:56 a.m.
Message ID <117999a831af597e4bd0.1602834994@workspace>
Download mbox | patch
Permalink /patch/47486/
State New
Headers show

Comments

Pulkit Goyal - Oct. 16, 2020, 7:56 a.m.
# HG changeset patch
# User Pulkit Goyal <7895pulkit@gmail.com>
# Date 1593071001 -19800
#      Thu Jun 25 13:13:21 2020 +0530
# Node ID 117999a831af597e4bd08e2d7bea68d3f3c38347
# Parent  aea9b1e5192225f9d88773b3c3039dd307b3ad89
# EXP-Topic share-safe
upgrade: add support for experimental safe share mode

Recently we introduce the share-safe functionality which makes shares share
requirements and config of share source. This patch adds support to
`debugupgraderepo` command to upgrade repository to share-safe mode when
`format.exp-share-safe` config is enabled.

Differential Revision: https://phab.mercurial-scm.org/D9144

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -137,6 +137,7 @@  def allowednewrequirements(repo):
         requirements.SIDEDATA_REQUIREMENT,
         requirements.COPIESSDC_REQUIREMENT,
         requirements.NODEMAP_REQUIREMENT,
+        requirements.SHARESAFE_REQUIREMENT,
     }
     for name in compression.compengines:
         engine = compression.compengines[name]
@@ -337,6 +338,27 @@  class generaldelta(requirementformatvari
 
 
 @registerformatvariant
+class sharedsafe(requirementformatvariant):
+    name = b'exp-sharesafe'
+    _requirement = requirements.SHARESAFE_REQUIREMENT
+
+    default = False
+
+    description = _(
+        b'old shared repositories do not share source repository '
+        b'requirements and config. This leads to various problems '
+        b'when the source repository format is upgraded or some new '
+        b'extensions are enabled.'
+    )
+
+    upgrademessage = _(
+        b'Upgrades the shared source and current shared repository '
+        b'to use safe method of sharing which will make requirements '
+        b'and configs being shared.'
+    )
+
+
+@registerformatvariant
 class sparserevlog(requirementformatvariant):
     name = b'sparserevlog'
 
@@ -1434,3 +1456,12 @@  def upgraderepo(
                         b'repository is verified\n'
                     )
                 )
+
+            if sharedsafe.name in upgradeactions:
+                ui.warn(
+                    _(
+                        b'repository upgraded to share safe mode, existing'
+                        b' shares will still work in old non-safe mode. '
+                        b'New shares will be created in safe mode.\n'
+                    )
+                )
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
@@ -37,6 +37,7 @@  Check that copies are recorded correctly
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:           yes    yes      no
   persistent-nodemap:  no     no      no
@@ -50,6 +51,7 @@  Check that copies are recorded correctly
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -417,6 +419,7 @@  downgrading (keeping some sidedata)
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:           yes    yes      no
   persistent-nodemap:  no     no      no
@@ -442,6 +445,7 @@  downgrading (keeping some sidedata)
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:           yes    yes      no
   persistent-nodemap:  no     no      no
@@ -469,6 +473,7 @@  upgrading
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:           yes    yes      no
   persistent-nodemap:  no     no      no
diff --git a/tests/test-persistent-nodemap.t b/tests/test-persistent-nodemap.t
--- a/tests/test-persistent-nodemap.t
+++ b/tests/test-persistent-nodemap.t
@@ -15,6 +15,7 @@  Test the persistent on-disk nodemap
   fncache:            yes
   dotencode:          yes
   generaldelta:       yes
+  exp-sharesafe:       no
   sparserevlog:       yes
   sidedata:            no
   persistent-nodemap: yes
@@ -476,6 +477,7 @@  downgrading
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap: yes     no      no
@@ -506,6 +508,7 @@  upgrading
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no    yes      no
diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t
--- a/tests/test-share-safe.t
+++ b/tests/test-share-safe.t
@@ -292,3 +292,83 @@  of current repo is still respected over 
   [255]
   $ hg showconfig ui.curses -R ../shared1
   false
+
+  $ cd ../
+
+Test that upgrading using debugupgraderepo works
+=================================================
+
+  $ hg init non-share-safe --config format.exp-share-safe=false
+  $ cd non-share-safe
+  $ hg debugrequirements
+  dotencode
+  fncache
+  generaldelta
+  revlogv1
+  sparserevlog
+  store
+  $ echo foo > foo
+  $ hg ci -Aqm 'added foo'
+  $ echo bar > bar
+  $ hg ci -Aqm 'added bar'
+
+Create a share before upgrading
+
+  $ cd ..
+  $ hg share non-share-safe nss-share
+  updating working directory
+  2 files updated, 0 files merged, 0 files removed, 0 files unresolved
+  $ hg debugrequirements -R nss-share
+  dotencode
+  fncache
+  generaldelta
+  revlogv1
+  shared
+  sparserevlog
+  store
+  $ cd non-share-safe
+
+Upgrade
+
+  $ hg debugupgraderepo -q
+  requirements
+     preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
+     added: exp-sharesafe
+  
+  $ hg debugupgraderepo --run -q
+  upgrade will perform the following actions:
+  
+  requirements
+     preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store
+     added: exp-sharesafe
+  
+  repository upgraded to share safe mode, existing shares will still work in old non-safe mode. New shares will be created in safe mode.
+
+  $ hg debugrequirements
+  dotencode
+  exp-sharesafe
+  fncache
+  generaldelta
+  revlogv1
+  sparserevlog
+  store
+
+  $ cat .hg/requires
+  exp-sharesafe
+
+  $ cat .hg/store/requires
+  dotencode
+  fncache
+  generaldelta
+  revlogv1
+  sparserevlog
+  store
+
+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
diff --git a/tests/test-sidedata.t b/tests/test-sidedata.t
--- a/tests/test-sidedata.t
+++ b/tests/test-sidedata.t
@@ -54,6 +54,7 @@  Check that we can upgrade to sidedata
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -66,6 +67,7 @@  Check that we can upgrade to sidedata
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no    yes      no
   persistent-nodemap:  no     no      no
@@ -84,6 +86,7 @@  Check that we can downgrade from sidedat
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:           yes     no      no
   persistent-nodemap:  no     no      no
@@ -96,6 +99,7 @@  Check that we can downgrade from sidedat
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:           yes     no      no
   persistent-nodemap:  no     no      no
diff --git a/tests/test-upgrade-repo.t b/tests/test-upgrade-repo.t
--- a/tests/test-upgrade-repo.t
+++ b/tests/test-upgrade-repo.t
@@ -56,6 +56,7 @@  An upgrade of a repository created with 
   fncache:            yes
   dotencode:          yes
   generaldelta:       yes
+  exp-sharesafe:       no
   sparserevlog:       yes
   sidedata:            no
   persistent-nodemap:  no
@@ -68,6 +69,7 @@  An upgrade of a repository created with 
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -80,6 +82,7 @@  An upgrade of a repository created with 
   fncache:            yes     no     yes
   dotencode:          yes     no     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -92,6 +95,7 @@  An upgrade of a repository created with 
   [formatvariant.name.mismatchconfig|fncache:           ][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special|     no][formatvariant.default|     yes]
   [formatvariant.name.mismatchconfig|dotencode:         ][formatvariant.repo.mismatchconfig| yes][formatvariant.config.special|     no][formatvariant.default|     yes]
   [formatvariant.name.uptodate|generaldelta:      ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
+  [formatvariant.name.uptodate|exp-sharesafe:     ][formatvariant.repo.uptodate|  no][formatvariant.config.default|     no][formatvariant.default|      no]
   [formatvariant.name.uptodate|sparserevlog:      ][formatvariant.repo.uptodate| yes][formatvariant.config.default|    yes][formatvariant.default|     yes]
   [formatvariant.name.uptodate|sidedata:          ][formatvariant.repo.uptodate|  no][formatvariant.config.default|     no][formatvariant.default|      no]
   [formatvariant.name.uptodate|persistent-nodemap:][formatvariant.repo.uptodate|  no][formatvariant.config.default|     no][formatvariant.default|      no]
@@ -120,6 +124,12 @@  An upgrade of a repository created with 
     "repo": true
    },
    {
+    "config": false,
+    "default": false,
+    "name": "exp-sharesafe",
+    "repo": false
+   },
+   {
     "config": true,
     "default": true,
     "name": "sparserevlog",
@@ -266,6 +276,7 @@  Various sub-optimal detections work
   fncache:             no
   dotencode:           no
   generaldelta:        no
+  exp-sharesafe:       no
   sparserevlog:        no
   sidedata:            no
   persistent-nodemap:  no
@@ -278,6 +289,7 @@  Various sub-optimal detections work
   fncache:             no    yes     yes
   dotencode:           no    yes     yes
   generaldelta:        no    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:        no    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -290,6 +302,7 @@  Various sub-optimal detections work
   fncache:             no    yes     yes
   dotencode:           no    yes     yes
   generaldelta:        no     no     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:        no     no     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -302,6 +315,7 @@  Various sub-optimal detections work
   [formatvariant.name.mismatchconfig|fncache:           ][formatvariant.repo.mismatchconfig|  no][formatvariant.config.default|    yes][formatvariant.default|     yes]
   [formatvariant.name.mismatchconfig|dotencode:         ][formatvariant.repo.mismatchconfig|  no][formatvariant.config.default|    yes][formatvariant.default|     yes]
   [formatvariant.name.mismatchdefault|generaldelta:      ][formatvariant.repo.mismatchdefault|  no][formatvariant.config.special|     no][formatvariant.default|     yes]
+  [formatvariant.name.uptodate|exp-sharesafe:     ][formatvariant.repo.uptodate|  no][formatvariant.config.default|     no][formatvariant.default|      no]
   [formatvariant.name.mismatchdefault|sparserevlog:      ][formatvariant.repo.mismatchdefault|  no][formatvariant.config.special|     no][formatvariant.default|     yes]
   [formatvariant.name.uptodate|sidedata:          ][formatvariant.repo.uptodate|  no][formatvariant.config.default|     no][formatvariant.default|      no]
   [formatvariant.name.uptodate|persistent-nodemap:][formatvariant.repo.uptodate|  no][formatvariant.config.default|     no][formatvariant.default|      no]
@@ -1289,6 +1303,7 @@  upgrade
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -1319,6 +1334,7 @@  downgrade
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -1352,6 +1368,7 @@  upgrade from hgrc
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -1389,6 +1406,7 @@  upgrade
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:           yes     no      no
   persistent-nodemap:  no     no      no
@@ -1426,6 +1444,7 @@  downgrade
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:            no     no      no
   persistent-nodemap:  no     no      no
@@ -1463,6 +1482,7 @@  upgrade from hgrc
   fncache:            yes    yes     yes
   dotencode:          yes    yes     yes
   generaldelta:       yes    yes     yes
+  exp-sharesafe:       no     no      no
   sparserevlog:       yes    yes     yes
   sidedata:           yes    yes      no
   persistent-nodemap:  no     no      no