##// END OF EJS Templates
sharesafe: add functionality to automatically downgrade shares...
Pulkit Goyal -
r46853:eec47efe default
parent child Browse files
Show More
@@ -1074,6 +1074,11 b' coreconfigitem('
1074 )
1074 )
1075 coreconfigitem(
1075 coreconfigitem(
1076 b'experimental',
1076 b'experimental',
1077 b'sharesafe-auto-downgrade-shares',
1078 default=False,
1079 )
1080 coreconfigitem(
1081 b'experimental',
1077 b'sharesafe-auto-upgrade-shares',
1082 b'sharesafe-auto-upgrade-shares',
1078 default=False,
1083 default=False,
1079 )
1084 )
@@ -574,11 +574,26 b' def makelocalrepository(baseui, path, in'
574 and requirementsmod.SHARESAFE_REQUIREMENT
574 and requirementsmod.SHARESAFE_REQUIREMENT
575 not in _readrequires(sharedvfs, True)
575 not in _readrequires(sharedvfs, True)
576 ):
576 ):
577 raise error.Abort(
577 if ui.configbool(
578 _(b"share source does not support exp-sharesafe requirement")
578 b'experimental', b'sharesafe-auto-downgrade-shares'
579 )
579 ):
580
580 # prevent cyclic import localrepo -> upgrade -> localrepo
581 requirements |= _readrequires(storevfs, False)
581 from . import upgrade
582
583 upgrade.downgrade_share_to_non_safe(
584 ui,
585 hgvfs,
586 sharedvfs,
587 requirements,
588 )
589 else:
590 raise error.Abort(
591 _(
592 b"share source does not support exp-sharesafe requirement"
593 )
594 )
595 else:
596 requirements |= _readrequires(storevfs, False)
582 elif shared:
597 elif shared:
583 sourcerequires = _readrequires(sharedvfs, False)
598 sourcerequires = _readrequires(sharedvfs, False)
584 if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires:
599 if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires:
@@ -264,3 +264,34 b' def upgrade_share_to_safe(ui, hgvfs, sto'
264 finally:
264 finally:
265 if wlock:
265 if wlock:
266 wlock.release()
266 wlock.release()
267
268
269 def downgrade_share_to_non_safe(
270 ui,
271 hgvfs,
272 sharedvfs,
273 current_requirements,
274 ):
275 """Downgrades a share which use share-safe to not use it"""
276 wlock = None
277 try:
278 wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0)
279 source_requirements = localrepo._readrequires(sharedvfs, True)
280 # we cannot be 100% sure on which requirements were present in store when
281 # the source supported share-safe. However, we do know that working
282 # directory requirements were not there. Hence we remove them
283 source_requirements -= requirementsmod.WORKING_DIR_REQUIREMENTS
284 current_requirements |= source_requirements
285 current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT)
286 scmutil.writerequires(hgvfs, current_requirements)
287 ui.warn(_(b'repository downgraded to not use share-safe mode\n'))
288 except error.LockError as e:
289 # raise error right away because if downgrade failed, we cannot load
290 # the repository because it does not have complete set of requirements
291 raise error.Abort(
292 _(b'failed to downgrade share, got error: %s')
293 % stringutil.forcebytestr(e.strerror)
294 )
295 finally:
296 if wlock:
297 wlock.release()
@@ -484,6 +484,27 b' Make sure existing shares still works'
484 abort: share source does not support exp-sharesafe requirement
484 abort: share source does not support exp-sharesafe requirement
485 [255]
485 [255]
486
486
487 Testing automatic downgrade of shares when config is set
488
489 $ touch ../ss-share/.hg/wlock
490 $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config experimental.sharesafe-auto-downgrade-shares=true
491 abort: failed to downgrade share, got error: Lock held
492 [255]
493 $ rm ../ss-share/.hg/wlock
494
495 $ hg log -GT "{node}: {desc}\n" -R ../ss-share --config experimental.sharesafe-auto-downgrade-shares=true
496 repository downgraded to not use share-safe mode
497 @ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
498 |
499 o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
500
501
502 $ hg log -GT "{node}: {desc}\n" -R ../ss-share
503 @ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar
504 |
505 o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo
506
507
487
508
488 Testing automatic upgrade of shares when config is set
509 Testing automatic upgrade of shares when config is set
489
510
General Comments 0
You need to be logged in to leave comments. Login now