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: