[Updated] [++- ] D9680: sharesafe: add functionality to automatically downgrade shares

pulkit (Pulkit Goyal) phabricator at mercurial-scm.org
Fri Jan 8 13:50:11 UTC 2021


pulkit updated this revision to Diff 24633.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D9680?vs=24631&id=24633

BRANCH
  default

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D9680/new/

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  mercurial/upgrade.py
  tests/test-share-safe.t

CHANGE DETAILS

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
@@ -484,6 +484,20 @@
   abort: share source does not support exp-sharesafe requirement
   [255]
 
+Testing automatic downgrade of shares when config is set
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config experimental.sharesafe-auto-downgrade-shares=true
+  repository downgraded to not use share-safe mode
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
+  $ hg log -GT "{node}: {desc}\n" -R ../ss-share
+  @  f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
+  |
+  o  f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
+  
+
 
 Testing automatic upgrade of shares when config is set
 
diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -307,3 +307,36 @@
         if wlock:
             wlock.release()
         return current_requirements
+
+
+def downgrade_share_to_non_safe(
+    ui, hgvfs, sharedvfs, current_requirements,
+):
+    """Downgrades a share which use share-safe to not use it
+
+    The downgrade will change the requirement of current repository that we are
+    loading. It may also fails to downgrade if we fails to get a lock. Hence
+    we need to update the caller about new set of repository requirements.
+    Therefore returns the set of new repository requirement.
+    """
+    wlock = None
+    try:
+        wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
+        source_requirements = localrepo._readrequires(sharedvfs, True)
+        # we cannot be 100% sure on which requirements were present in store when
+        # the source supported share-safe. However, we do know that working
+        # directory requirements were not there. Hence we remove them
+        source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
+        current_requirements |= source_requirements
+        current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
+        scmutil.writerequires(hgvfs, current_requirements)
+        ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
+    except Exception as e:
+        ui.warn(
+            _(b'failed to downgrade share, got error: %s\n')
+            % stringutil.forcebytestr(e.strerror)
+        )
+    finally:
+        if wlock:
+            wlock.release()
+        return current_requirements
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -574,11 +574,22 @@
             and requirementsmod.SHARESAFE_REQUIREMENT
             not in _readrequires(sharedvfs, True)
         ):
-            raise error.Abort(
-                _(b"share source does not support exp-sharesafe requirement")
-            )
-
-        requirements |= _readrequires(storevfs, False)
+            if ui.configbool(
+                b'experimental', b'sharesafe-auto-downgrade-shares'
+            ):
+                # prevent cyclic import localrepo -> upgrade -> localrepo
+                from . import upgrade
+                requirements = upgrade.downgrade_share_to_non_safe(
+                    ui, hgvfs, sharedvfs, requirements,
+                )
+            else:
+                raise error.Abort(
+                    _(
+                        b"share source does not support exp-sharesafe requirement"
+                    )
+                )
+        else:
+            requirements |= _readrequires(storevfs, False)
     elif shared:
         sourcerequires = _readrequires(sharedvfs, False)
         if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires:
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -1074,6 +1074,11 @@
 )
 coreconfigitem(
     b'experimental',
+    b'sharesafe-auto-downgrade-shares',
+    default=False,
+)
+coreconfigitem(
+    b'experimental',
     b'sharesafe-auto-upgrade-shares',
     default=False,
 )



To: pulkit, #hg-reviewers, marmoute
Cc: marmoute, mercurial-patches
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurial-scm.org/pipermail/mercurial-patches/attachments/20210108/c826d8da/attachment-0002.html>


More information about the Mercurial-patches mailing list