Patchwork D9783: upgrade: take lock only for part where it's required

login
register
mail settings
Submitter phabricator
Date Jan. 15, 2021, 6:47 a.m.
Message ID <differential-rev-PHID-DREV-i4wsy5pzt5dl5kckvviy-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/48094/
State Superseded
Headers show

Comments

phabricator - Jan. 15, 2021, 6:47 a.m.
pulkit created this revision.
Herald added a reviewer: hg-reviewers.
Herald added a subscriber: mercurial-patches.

REVISION SUMMARY
  The final config calculation code does not require a lock, only writing it back
  does require one.

REPOSITORY
  rHG Mercurial

BRANCH
  default

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

AFFECTED FILES
  mercurial/upgrade.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel

Patch

diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py
--- a/mercurial/upgrade.py
+++ b/mercurial/upgrade.py
@@ -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: