mercurial/upgrade.py
changeset 46236 eec47efe219d
parent 46235 0babe12ef35d
child 46238 9796cf108e4e
--- a/mercurial/upgrade.py	Wed Jan 06 16:18:06 2021 +0530
+++ b/mercurial/upgrade.py	Wed Jan 06 18:31:16 2021 +0530
@@ -264,3 +264,34 @@
     finally:
         if wlock:
             wlock.release()
+
+
+def downgrade_share_to_non_safe(
+    ui,
+    hgvfs,
+    sharedvfs,
+    current_requirements,
+):
+    """Downgrades a share which use share-safe to not use it"""
+    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 error.LockError as e:
+        # raise error right away because if downgrade failed, we cannot load
+        # the repository because it does not have complete set of requirements
+        raise error.Abort(
+            _(b'failed to downgrade share, got error: %s')
+            % stringutil.forcebytestr(e.strerror)
+        )
+    finally:
+        if wlock:
+            wlock.release()