# HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1607425873 -19800 # Tue Dec 08 16:41:13 2020 +0530 # Node ID 593ac40c58209c5b9c91aa936c82eb0215e63171 # Parent 4d1cec4e5e1fe4e4d9379954fbedd5c8d302aa99 # EXP-Topic share-safe scmutil: improve documentation of writereporequirements() This makes it easier to understand the difference between `writerequires()` and `writereporequirements()`. Differential Revision: https://phab.mercurial-scm.org/D9568 diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- 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) # HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1607427002 -19800 # Tue Dec 08 17:00:02 2020 +0530 # Node ID fcaf13895656c311a3a7ac94947a496ba5312ab6 # Parent 593ac40c58209c5b9c91aa936c82eb0215e63171 # EXP-Topic share-safe debugcommands: introduce command to upgrade/downgrade shares In past few months, we have developed functionality to share requirements and configs of share-source and a way to upgrade repository from old format to share-safe format using `debugupgraderepo` command. However there is still no way to upgrade the shares as `debugupgraderepo` does not support upgrading that. Having share-safe rolled out in existing setup is quite important and hence we need a way to upgrade existing shares once share-source upgrades. This patch introduces a new debug command `debugsharesafe` which can be used to upgrade or downgrade shares. Functionality to upgrade shares to use the new method is the last thing left in the whole work. Differential Revision: https://phab.mercurial-scm.org/D9570 diff --git a/mercurial/debugcommands.py b/mercurial/debugcommands.py --- 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/tests/test-completion.t b/tests/test-completion.t --- 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 --- 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 --- 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 @@ -399,6 +409,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 # HG changeset patch # User Pulkit Goyal <7895pulkit@gmail.com> # Date 1607766553 -19800 # Sat Dec 12 15:19:13 2020 +0530 # Node ID 1ac7d704a93b999ad4b7204fc4bbb645767ed878 # Parent fcaf13895656c311a3a7ac94947a496ba5312ab6 # EXP-Topic share-safe debugsharesafe: recommend from `debugupgraderepo` and `help -e share -v` Recommending one debug command from another one sounds fine to me. Also documentation about share-safe in `hg help -e share -v` was lacking correct description on how upgrade existing shares. This fixes that and also start mentioning about debugsharesafe. Differential Revision: https://phab.mercurial-scm.org/D9571 diff --git a/hgext/share.py b/hgext/share.py --- 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/upgrade.py b/mercurial/upgrade.py --- a/mercurial/upgrade.py +++ b/mercurial/upgrade.py @@ -255,16 +255,17 @@ 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, ' - 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-share-safe.t b/tests/test-share-safe.t --- a/tests/test-share-safe.t +++ b/tests/test-share-safe.t @@ -372,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 @@ -475,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