D9783: upgrade: take lock only for part where it's required
pulkit (Pulkit Goyal)
phabricator at mercurial-scm.org
Fri Jan 15 06:47:31 UTC 2021
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
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:
To: pulkit, #hg-reviewers
Cc: mercurial-patches, mercurial-devel
More information about the Mercurial-devel
mailing list