Show More
@@ -1074,6 +1074,11 b' coreconfigitem(' | |||||
1074 | ) |
|
1074 | ) | |
1075 | coreconfigitem( |
|
1075 | coreconfigitem( | |
1076 | b'experimental', |
|
1076 | b'experimental', | |
|
1077 | b'sharesafe-auto-upgrade-shares', | |||
|
1078 | default=False, | |||
|
1079 | ) | |||
|
1080 | coreconfigitem( | |||
|
1081 | b'experimental', | |||
1077 | b'single-head-per-branch', |
|
1082 | b'single-head-per-branch', | |
1078 | default=False, |
|
1083 | default=False, | |
1079 | ) |
|
1084 | ) |
@@ -582,12 +582,23 b' def makelocalrepository(baseui, path, in' | |||||
582 | elif shared: |
|
582 | elif shared: | |
583 | sourcerequires = _readrequires(sharedvfs, False) |
|
583 | sourcerequires = _readrequires(sharedvfs, False) | |
584 | if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires: |
|
584 | if requirementsmod.SHARESAFE_REQUIREMENT in sourcerequires: | |
585 | ui.warn( |
|
585 | if ui.configbool(b'experimental', b'sharesafe-auto-upgrade-shares'): | |
586 | _( |
|
586 | # prevent cyclic import localrepo -> upgrade -> localrepo | |
587 | b'warning: source repository supports share-safe functionality.' |
|
587 | from . import upgrade | |
588 | b' Reshare to upgrade.\n' |
|
588 | ||
|
589 | upgrade.upgrade_share_to_safe( | |||
|
590 | ui, | |||
|
591 | hgvfs, | |||
|
592 | storevfs, | |||
|
593 | requirements, | |||
589 | ) |
|
594 | ) | |
590 |
|
|
595 | else: | |
|
596 | ui.warn( | |||
|
597 | _( | |||
|
598 | b'warning: source repository supports share-safe functionality.' | |||
|
599 | b' Reshare to upgrade.\n' | |||
|
600 | ) | |||
|
601 | ) | |||
591 |
|
602 | |||
592 | # The .hg/hgrc file may load extensions or contain config options |
|
603 | # The .hg/hgrc file may load extensions or contain config options | |
593 | # that influence repository construction. Attempt to load it and |
|
604 | # that influence repository construction. Attempt to load it and |
@@ -12,7 +12,10 b' from . import (' | |||||
12 | error, |
|
12 | error, | |
13 | hg, |
|
13 | hg, | |
14 | localrepo, |
|
14 | localrepo, | |
|
15 | lock as lockmod, | |||
15 | pycompat, |
|
16 | pycompat, | |
|
17 | requirements as requirementsmod, | |||
|
18 | scmutil, | |||
16 | ) |
|
19 | ) | |
17 |
|
20 | |||
18 | from .upgrade_utils import ( |
|
21 | from .upgrade_utils import ( | |
@@ -20,6 +23,10 b' from .upgrade_utils import (' | |||||
20 | engine as upgrade_engine, |
|
23 | engine as upgrade_engine, | |
21 | ) |
|
24 | ) | |
22 |
|
25 | |||
|
26 | from .utils import ( | |||
|
27 | stringutil, | |||
|
28 | ) | |||
|
29 | ||||
23 | allformatvariant = upgrade_actions.allformatvariant |
|
30 | allformatvariant = upgrade_actions.allformatvariant | |
24 |
|
31 | |||
25 |
|
32 | |||
@@ -232,3 +239,28 b' def upgraderepo(' | |||||
232 | ) |
|
239 | ) | |
233 |
|
240 | |||
234 | upgrade_op.print_post_op_messages() |
|
241 | upgrade_op.print_post_op_messages() | |
|
242 | ||||
|
243 | ||||
|
244 | def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements): | |||
|
245 | """Upgrades a share to use share-safe mechanism""" | |||
|
246 | wlock = None | |||
|
247 | try: | |||
|
248 | 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 | current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) | |||
|
258 | ui.warn(_(b'repository upgraded to use share-safe mode\n')) | |||
|
259 | except error.LockError as e: | |||
|
260 | ui.warn( | |||
|
261 | _(b'failed to upgrade share, got error: %s\n') | |||
|
262 | % stringutil.forcebytestr(e.strerror) | |||
|
263 | ) | |||
|
264 | finally: | |||
|
265 | if wlock: | |||
|
266 | wlock.release() |
@@ -479,8 +479,63 b' Make sure existing shares still works' | |||||
479 | | |
|
479 | | | |
480 | o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo |
|
480 | o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | |
481 |
|
481 | |||
482 | $ hg unshare -R ../nss-share |
|
|||
483 |
|
482 | |||
484 | $ hg log -GT "{node}: {desc}\n" -R ../ss-share |
|
483 | $ hg log -GT "{node}: {desc}\n" -R ../ss-share | |
485 | abort: share source does not support exp-sharesafe requirement |
|
484 | abort: share source does not support exp-sharesafe requirement | |
486 | [255] |
|
485 | [255] | |
|
486 | ||||
|
487 | ||||
|
488 | Testing automatic upgrade of shares when config is set | |||
|
489 | ||||
|
490 | $ hg debugupgraderepo -q --run --config format.exp-share-safe=True | |||
|
491 | upgrade will perform the following actions: | |||
|
492 | ||||
|
493 | requirements | |||
|
494 | preserved: dotencode, fncache, generaldelta, revlogv1, sparserevlog, store | |||
|
495 | added: exp-sharesafe | |||
|
496 | ||||
|
497 | processed revlogs: | |||
|
498 | - all-filelogs | |||
|
499 | - changelog | |||
|
500 | - manifest | |||
|
501 | ||||
|
502 | repository upgraded to share safe mode, existing shares will still work in old non-safe mode. Re-share existing shares to use them in safe mode New shares will be created in safe mode. | |||
|
503 | $ hg debugrequirements | |||
|
504 | dotencode | |||
|
505 | exp-sharesafe | |||
|
506 | fncache | |||
|
507 | generaldelta | |||
|
508 | revlogv1 | |||
|
509 | sparserevlog | |||
|
510 | store | |||
|
511 | $ hg log -GT "{node}: {desc}\n" -R ../nss-share | |||
|
512 | warning: source repository supports share-safe functionality. Reshare to upgrade. | |||
|
513 | @ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar | |||
|
514 | | | |||
|
515 | o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | |||
|
516 | ||||
|
517 | ||||
|
518 | Check that if lock is taken, upgrade fails but read operation are successful | |||
|
519 | $ touch ../nss-share/.hg/wlock | |||
|
520 | $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config experimental.sharesafe-auto-upgrade-shares=true | |||
|
521 | failed to upgrade share, got error: Lock held | |||
|
522 | @ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar | |||
|
523 | | | |||
|
524 | o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | |||
|
525 | ||||
|
526 | $ rm ../nss-share/.hg/wlock | |||
|
527 | $ hg log -GT "{node}: {desc}\n" -R ../nss-share --config experimental.sharesafe-auto-upgrade-shares=true | |||
|
528 | repository upgraded to use share-safe mode | |||
|
529 | @ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar | |||
|
530 | | | |||
|
531 | o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | |||
|
532 | ||||
|
533 | ||||
|
534 | Test that unshare works | |||
|
535 | ||||
|
536 | $ hg unshare -R ../nss-share | |||
|
537 | $ hg log -GT "{node}: {desc}\n" -R ../nss-share | |||
|
538 | @ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar | |||
|
539 | | | |||
|
540 | o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo | |||
|
541 |
General Comments 0
You need to be logged in to leave comments.
Login now