changeset 46329:17176f64a03d

upgrade: take lock only for part where it's required The final config calculation code does not require a lock, only writing it back does require one. Differential Revision: https://phab.mercurial-scm.org/D9783
author Pulkit Goyal <7895pulkit@gmail.com>
date Thu, 14 Jan 2021 21:29:46 +0530
parents 0216abfb2d3e
children 02f3badf9011
files mercurial/upgrade.py
diffstat 1 files changed, 16 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/upgrade.py	Mon Jan 18 19:19:47 2021 +0100
+++ b/mercurial/upgrade.py	Thu Jan 14 21:29:46 2021 +0530
@@ -244,17 +244,17 @@
 def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements):
     """Upgrades a share to use share-safe mechanism"""
     wlock = None
+    store_requirements = localrepo._readrequires(storevfs, False)
+    # after upgrade, store requires will be shared, so lets find
+    # the requirements which are not present in store and
+    # write them to share's .hg/requires
+    diffrequires = current_requirements - store_requirements
+    # add share-safe requirement as it will mark the share as share-safe
+    diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
+    current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
     try:
         wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
-        store_requirements = localrepo._readrequires(storevfs, False)
-        # after upgrade, store requires will be shared, so lets find
-        # the requirements which are not present in store and
-        # write them to share's .hg/requires
-        diffrequires = current_requirements - store_requirements
-        # add share-safe requirement as it will mark the share as share-safe
-        diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT)
         scmutil.writerequires(hgvfs, diffrequires)
-        current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT)
         ui.warn(_(b'repository upgraded to use share-safe mode\n'))
     except error.LockError as e:
         if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-fail-error'):
@@ -280,15 +280,16 @@
 ):
     """Downgrades a share which use share-safe to not use it"""
     wlock = None
+    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)
+
     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: