diff --git a/hgext/share.py b/hgext/share.py index 4d1cec4e5e1fe4e4d9379954fbedd5c8d302aa99_aGdleHQvc2hhcmUucHk=..1ac7d704a93b999ad4b7204fc4bbb645767ed878_aGdleHQvc2hhcmUucHk= 100644 --- a/hgext/share.py +++ b/hgext/share.py @@ -59,10 +59,9 @@ requirements. This only applies to shares which are done after enabling the config option. - For enabling this in existing shares, enable the config option and reshare. - - For resharing existing shares, make sure your working directory is clean - and there are no untracked files, delete that share and create a new share. + For enabling this in existing shares, upgrade the shared-source using + `hg debugupgraderepo` and then upgrade shares using + `hg debugsharesafe --upgrade` command. ''' from __future__ import absolute_import diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py index 4d1cec4e5e1fe4e4d9379954fbedd5c8d302aa99_bWVyY3VyaWFsL2RlYnVnY29tbWFuZHMucHk=..1ac7d704a93b999ad4b7204fc4bbb645767ed878_bWVyY3VyaWFsL2RlYnVnY29tbWFuZHMucHk= 100644 --- a/mercurial/debugcommands.py +++ b/mercurial/debugcommands.py @@ -69,6 +69,7 @@ pycompat, registrar, repair, + requirements as requirementsmod, revlog, revset, revsetlang, @@ -3695,6 +3696,107 @@ @command( + b'debugsharesafe', + [ + (b'', b'upgrade', False, _(b'upgrade current share to share safe')), + (b'', b'downgrade', False, _(b'downgrade current share')), + (b'', b'force', False, _(b'forcefully perform operation')), + ], +) +def debugsharesafe(ui, repo, *args, **opts): + """upgrade or downgrade shares to enable/disable share-safe mode""" + if not repo.shared(): + raise error.InputError(_(b"current repository is not shared one")) + + cmdutil.check_at_most_one_arg(opts, 'upgrade', 'downgrade') + upgrade = opts.get('upgrade') + downgrade = opts.get('downgrade') + + if not upgrade and not downgrade: + raise error.InputError(_(b"nothing specified")) + + current_requirements = repo.requirements + if upgrade: + if requirementsmod.SHARESAFE_REQUIREMENT in current_requirements: + raise error.StateError( + _(b"repository already uses share-safe method") + ) + + sharesourcerequires = localrepo._readrequires( + localrepo._getsharedvfs(repo.vfs, current_requirements), False + ) + if requirementsmod.SHARESAFE_REQUIREMENT not in sharesourcerequires: + raise error.StateError( + _( + b"share source does not support share-safe, unable to upgrade" + ) + ) + + # share source has SHARESAFE requirement present, hence all the + # requirements will be store requires + storerequires = localrepo._readrequires(repo.svfs, 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 - storerequires + # add share-safe requirement as it will mark the share as share-safe + diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) + scmutil.writerequires(repo.vfs, diffrequires) + ui.status(_(b"repository upgraded to use share-safe functionality\n")) + ui.status( + _( + b"requirements and configs of shared-source will be " + b"read from now onwards\n" + ) + ) + else: + if requirementsmod.SHARESAFE_REQUIREMENT not in current_requirements: + raise error.StateError( + _(b"repository does not uses share safe method, nothing to do") + ) + + sharesourcerequires = localrepo._readrequires( + localrepo._getsharedvfs(repo.vfs, current_requirements), False + ) + + if requirementsmod.SHARESAFE_REQUIREMENT in sharesourcerequires: + # we should copy the store requires in .hg/requires and remove + # share-safe requirement + storerequires = localrepo._readrequires(repo.svfs, False) + current_requirements |= storerequires + current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT) + scmutil.writerequires(repo.vfs, current_requirements) + ui.status( + _( + b"repository downgraded to not use share-safe functionality\n" + ) + ) + else: + # share source does not use share-safe and has requirements in + # .hg/requires. We cannot be sure which requirement were shared + # earlier in share-safe mode. In other words, there can be wdir + # specific requirements which should not be copied but we have + # no way to detect them + if not opts.get('force'): + raise error.Abort( + _( + b"shared source does not support share-safe " + b"functionality, downgrading may not lead correct result" + ), + hint=_(b"use --force to still downgrade"), + ) + current_requirements |= sharesourcerequires + current_requirements.remove(requirementsmod.SHARESAFE_REQUIREMENT) + scmutil.writerequires(repo.vfs, current_requirements) + ui.status( + _( + b"repository downgraded to not use share-safe functionality\n" + ) + ) + + +@command( b'debugsub', [(b'r', b'rev', b'', _(b'revision to check'), _(b'REV'))], _(b'[-r REV] [REV]'), diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py index 4d1cec4e5e1fe4e4d9379954fbedd5c8d302aa99_bWVyY3VyaWFsL3NjbXV0aWwucHk=..1ac7d704a93b999ad4b7204fc4bbb645767ed878_bWVyY3VyaWFsL3NjbXV0aWwucHk= 100644 --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -1573,7 +1573,12 @@ def writereporequirements(repo, requirements=None): - """ writes requirements for the repo to .hg/requires """ + """writes requirements for the repo + + Requirements are written to .hg/requires and .hg/store/requires based + on whether share-safe mode is enabled and which requirements are wdir + requirements and which are store requirements + """ if requirements: repo.requirements = requirements wcreq, storereq = filterrequirements(repo.requirements) diff --git a/mercurial/upgrade.py b/mercurial/upgrade.py index 4d1cec4e5e1fe4e4d9379954fbedd5c8d302aa99_bWVyY3VyaWFsL3VwZ3JhZGUucHk=..1ac7d704a93b999ad4b7204fc4bbb645767ed878_bWVyY3VyaWFsL3VwZ3JhZGUucHk= 100644 --- a/mercurial/upgrade.py +++ b/mercurial/upgrade.py @@ -255,12 +255,12 @@ ui.warn( _( b'repository upgraded to share safe mode, existing' - b' shares will still work in old non-safe mode. ' - b'Re-share existing shares to use them in safe mode' - b' New shares will be created in safe mode.\n' + b' shares will still work in old non-safe mode.\n' + b'(Run `hg debugsharesafe --upgrade` in shares to ' + b' update them to use share safe mode.)\n' ) ) if upgrade_actions.sharesafe.name in removedreqs: ui.warn( _( b'repository downgraded to not use share safe mode, ' @@ -261,10 +261,11 @@ ) ) if upgrade_actions.sharesafe.name in removedreqs: ui.warn( _( b'repository downgraded to not use share safe mode, ' - b'existing shares will not work and needs to' - b' be reshared.\n' + b'existing shares will not work.\n(Run `hg ' + b'debugsharesafe --downgrade` in shares ' + b'to downgrade them.)\n' ) ) diff --git a/tests/test-completion.t b/tests/test-completion.t index 4d1cec4e5e1fe4e4d9379954fbedd5c8d302aa99_dGVzdHMvdGVzdC1jb21wbGV0aW9uLnQ=..1ac7d704a93b999ad4b7204fc4bbb645767ed878_dGVzdHMvdGVzdC1jb21wbGV0aW9uLnQ= 100644 --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -129,6 +129,7 @@ debugrevspec debugserve debugsetparents + debugsharesafe debugsidedata debugssl debugstrip @@ -318,6 +319,7 @@ debugrevspec: optimize, show-revs, show-set, show-stage, no-optimized, verify-optimized debugserve: sshstdio, logiofd, logiofile debugsetparents: + debugsharesafe: upgrade, downgrade, force debugsidedata: changelog, manifest, dir debugssl: debugstrip: rev, force, no-backup, nobackup, , keep, bookmark, soft diff --git a/tests/test-help.t b/tests/test-help.t index 4d1cec4e5e1fe4e4d9379954fbedd5c8d302aa99_dGVzdHMvdGVzdC1oZWxwLnQ=..1ac7d704a93b999ad4b7204fc4bbb645767ed878_dGVzdHMvdGVzdC1oZWxwLnQ= 100644 --- a/tests/test-help.t +++ b/tests/test-help.t @@ -1068,6 +1068,8 @@ debugserve run a server with advanced settings debugsetparents manually set the parents of the current working directory + debugsharesafe + upgrade or downgrade shares to enable/disable share-safe mode debugsidedata dump the side data for a cl/manifest/file revision debugssl test a secure connection to a server diff --git a/tests/test-share-safe.t b/tests/test-share-safe.t index 4d1cec4e5e1fe4e4d9379954fbedd5c8d302aa99_dGVzdHMvdGVzdC1zaGFyZS1zYWZlLnQ=..1ac7d704a93b999ad4b7204fc4bbb645767ed878_dGVzdHMvdGVzdC1zaGFyZS1zYWZlLnQ= 100644 --- a/tests/test-share-safe.t +++ b/tests/test-share-safe.t @@ -70,6 +70,16 @@ $ echo c > c $ hg ci -Aqm "added c" + $ hg debugsharesafe + abort: nothing specified + [10] + $ hg debugsharesafe --upgrade --downgrade + abort: cannot specify both --upgrade and --downgrade + [10] + $ hg debugsharesafe --upgrade + abort: repository already uses share-safe method + [20] + Check that config of the source repository is also loaded $ hg showconfig ui.curses @@ -362,7 +372,8 @@ - changelog - manifest - 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. + repository upgraded to share safe mode, existing shares will still work in old non-safe mode. + (Run `hg debugsharesafe --upgrade` in shares to update them to use share safe mode.) $ hg debugrequirements dotencode @@ -399,6 +410,26 @@ o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo + $ hg debugsharesafe -R ../nss-share --downgrade + warning: source repository supports share-safe functionality. Reshare to upgrade. + abort: repository does not uses share safe method, nothing to do + [20] + + $ hg debugsharesafe -R ../nss-share --upgrade + warning: source repository supports share-safe functionality. Reshare to upgrade. + repository upgraded to use share-safe functionality + requirements and configs of shared-source will be read from now onwards + + $ hg log -GT "{node}: {desc}\n" -R ../nss-share + @ f63db81e6dde1d9c78814167f77fb1fb49283f4f: added bar + | + o f3ba8b99bb6f897c87bbc1c07b75c6ddf43a4f77: added foo + + + $ hg debugsharesafe -R ../nss-share --downgrade + repository downgraded to not use share-safe functionality + + Create a safe share from upgrade one @@ -445,7 +476,8 @@ - changelog - manifest - repository downgraded to not use share safe mode, existing shares will not work and needs to be reshared. + repository downgraded to not use share safe mode, existing shares will not work. + (Run `hg debugsharesafe --downgrade` in shares to downgrade them.) $ hg debugrequirements dotencode