Mercurial > public > mercurial-scm > hg
comparison mercurial/upgrade.py @ 46330:02f3badf9011
upgrade: re-read current requirements after taking lock
Since we are writing to repository, it's better to re-read after taking the
lock.
Differential Revision: https://phab.mercurial-scm.org/D9822
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Mon, 18 Jan 2021 19:50:21 +0530 |
parents | 17176f64a03d |
children | cc3452d2dfa4 |
comparison
equal
deleted
inserted
replaced
46329:17176f64a03d | 46330:02f3badf9011 |
---|---|
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) | 247 store_requirements = localrepo._readrequires(storevfs, False) |
248 original_crequirements = current_requirements.copy() | |
248 # after upgrade, store requires will be shared, so lets find | 249 # after upgrade, store requires will be shared, so lets find |
249 # the requirements which are not present in store and | 250 # the requirements which are not present in store and |
250 # write them to share's .hg/requires | 251 # write them to share's .hg/requires |
251 diffrequires = current_requirements - store_requirements | 252 diffrequires = current_requirements - store_requirements |
252 # add share-safe requirement as it will mark the share as share-safe | 253 # add share-safe requirement as it will mark the share as share-safe |
253 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) | 254 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) |
254 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) | 255 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) |
255 try: | 256 try: |
256 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) | 257 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) |
258 # some process might change the requirement in between, re-read | |
259 # and update current_requirements | |
260 locked_requirements = localrepo._readrequires(hgvfs, True) | |
261 if locked_requirements != original_crequirements: | |
262 removed = current_requirements - locked_requirements | |
263 # update current_requirements in place because it's passed | |
264 # as reference | |
265 current_requirements -= removed | |
266 current_requirements |= locked_requirements | |
267 diffrequires = current_requirements - store_requirements | |
268 # add share-safe requirement as it will mark the share as share-safe | |
269 diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) | |
270 current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) | |
257 scmutil.writerequires(hgvfs, diffrequires) | 271 scmutil.writerequires(hgvfs, diffrequires) |
258 ui.warn(_(b'repository upgraded to use share-safe mode\n')) | 272 ui.warn(_(b'repository upgraded to use share-safe mode\n')) |
259 except error.LockError as e: | 273 except error.LockError as e: |
260 if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-fail-error'): | 274 if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-fail-error'): |
261 raise error.Abort( | 275 raise error.Abort( |
279 current_requirements, | 293 current_requirements, |
280 ): | 294 ): |
281 """Downgrades a share which use share-safe to not use it""" | 295 """Downgrades a share which use share-safe to not use it""" |
282 wlock = None | 296 wlock = None |
283 source_requirements = localrepo._readrequires(sharedvfs, True) | 297 source_requirements = localrepo._readrequires(sharedvfs, True) |
298 original_crequirements = current_requirements.copy() | |
284 # we cannot be 100% sure on which requirements were present in store when | 299 # 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 | 300 # the source supported share-safe. However, we do know that working |
286 # directory requirements were not there. Hence we remove them | 301 # directory requirements were not there. Hence we remove them |
287 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS | 302 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS |
288 current_requirements |= source_requirements | 303 current_requirements |= source_requirements |
289 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT) | 304 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT) |
290 | 305 |
291 try: | 306 try: |
292 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) | 307 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) |
308 # some process might change the requirement in between, re-read | |
309 # and update current_requirements | |
310 locked_requirements = localrepo._readrequires(hgvfs, True) | |
311 if locked_requirements != original_crequirements: | |
312 removed = current_requirements - locked_requirements | |
313 # update current_requirements in place because it's passed | |
314 # as reference | |
315 current_requirements -= removed | |
316 current_requirements |= locked_requirements | |
317 current_requirements |= source_requirements | |
318 current_requirements -= set(requirementsmod.SHARESAFE_REQUIREMENT) | |
293 scmutil.writerequires(hgvfs, current_requirements) | 319 scmutil.writerequires(hgvfs, current_requirements) |
294 ui.warn(_(b'repository downgraded to not use share-safe mode\n')) | 320 ui.warn(_(b'repository downgraded to not use share-safe mode\n')) |
295 except error.LockError as e: | 321 except error.LockError as e: |
296 # raise error right away because if downgrade failed, we cannot load | 322 # raise error right away because if downgrade failed, we cannot load |
297 # the repository because it does not have complete set of requirements | 323 # the repository because it does not have complete set of requirements |