pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  Reasoning is same as previous patch which adds automatic upgrade support.
  
  Downgrade is required as if automatic upgrade is enabled, all shares upgrade 
and
  then source repository downgrades, shares won't work. We need to downgrade 
them.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/configitems.py
  mercurial/localrepo.py
  mercurial/scmutil.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/scmutil.py b/mercurial/scmutil.py
--- a/mercurial/scmutil.py
+++ b/mercurial/scmutil.py
@@ -1613,6 +1613,23 @@
     return current_requirements
 
 
+def downgrade_share_to_non_safe(
+    hgvfs, current_requirements, source_requirements
+):
+    """Downgrades a share which use share-safe to not use it
+
+    Returns the set of new repository requirements
+    """
+    # 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)
+    writerequires(hgvfs, current_requirements)
+    return current_requirements
+
+
 class filecachesubentry(object):
     def __init__(self, path, stat):
         self.path = path
diff --git a/mercurial/localrepo.py b/mercurial/localrepo.py
--- a/mercurial/localrepo.py
+++ b/mercurial/localrepo.py
@@ -574,11 +574,24 @@
             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'
+            ):
+                sourcerequires = _readrequires(sharedvfs, True)
+                requirements = scmutil.downgrade_share_to_non_safe(
+                    hgvfs, requirements, sourcerequires
+                )
+                ui.warn(
+                    _(b'repository downgraded to not use share-safe mode\n')
+                )
+            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
Cc: mercurial-patches, mercurial-devel
_______________________________________________
Mercurial-devel mailing list
Mercurial-devel@mercurial-scm.org
https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel

Reply via email to