Mercurial > public > mercurial-scm > hg
comparison mercurial/upgrade.py @ 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 | d159d0fafa78 |
children | 02f3badf9011 |
comparison
equal
deleted
inserted
replaced
46328:0216abfb2d3e | 46329:17176f64a03d |
---|---|
242 | 242 |
243 | 243 |
244 def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements): | 244 def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements): |
245 """Upgrades a share to use share-safe mechanism""" | 245 """Upgrades a share to use share-safe mechanism""" |
246 wlock = None | 246 wlock = None |
247 store_requirements = localrepo._readrequires(storevfs, False) | |
248 # after upgrade, store requires will be shared, so lets find | |
249 # the requirements which are not present in store and | |
250 # write them to share's .hg/requires | |
251 diffrequires = current_requirements - store_requirements | |
252 # add share-safe requirement as it will mark the share as share-safe | |
253 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) | |
254 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) | |
247 try: | 255 try: |
248 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) | 256 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) |
249 store_requirements = localrepo._readrequires(storevfs, False) | |
250 # after upgrade, store requires will be shared, so lets find | |
251 # the requirements which are not present in store and | |
252 # write them to share's .hg/requires | |
253 diffrequires = current_requirements - store_requirements | |
254 # add share-safe requirement as it will mark the share as share-safe | |
255 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) | |
256 scmutil.writerequires(hgvfs, diffrequires) | 257 scmutil.writerequires(hgvfs, diffrequires) |
257 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) | |
258 ui.warn(_(b'repository upgraded to use share-safe mode\n')) | 258 ui.warn(_(b'repository upgraded to use share-safe mode\n')) |
259 except error.LockError as e: | 259 except error.LockError as e: |
260 if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-fail-error'): | 260 if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-fail-error'): |
261 raise error.Abort( | 261 raise error.Abort( |
262 _(b'failed to upgrade share, got error: %s') | 262 _(b'failed to upgrade share, got error: %s') |
278 sharedvfs, | 278 sharedvfs, |
279 current_requirements, | 279 current_requirements, |
280 ): | 280 ): |
281 """Downgrades a share which use share-safe to not use it""" | 281 """Downgrades a share which use share-safe to not use it""" |
282 wlock = None | 282 wlock = None |
283 source_requirements = localrepo._readrequires(sharedvfs, True) | |
284 # we cannot be 100% sure on which requirements were present in store when | |
285 # the source supported share-safe. However, we do know that working | |
286 # directory requirements were not there. Hence we remove them | |
287 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS | |
288 current_requirements |= source_requirements | |
289 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT) | |
290 | |
283 try: | 291 try: |
284 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) | 292 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) |
285 source_requirements = localrepo._readrequires(sharedvfs, True) | |
286 # we cannot be 100% sure on which requirements were present in store when | |
287 # the source supported share-safe. However, we do know that working | |
288 # directory requirements were not there. Hence we remove them | |
289 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS | |
290 current_requirements |= source_requirements | |
291 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT) | |
292 scmutil.writerequires(hgvfs, current_requirements) | 293 scmutil.writerequires(hgvfs, current_requirements) |
293 ui.warn(_(b'repository downgraded to not use share-safe mode\n')) | 294 ui.warn(_(b'repository downgraded to not use share-safe mode\n')) |
294 except error.LockError as e: | 295 except error.LockError as e: |
295 # raise error right away because if downgrade failed, we cannot load | 296 # raise error right away because if downgrade failed, we cannot load |
296 # the repository because it does not have complete set of requirements | 297 # the repository because it does not have complete set of requirements |