Mercurial > public > mercurial-scm > hg-stable
diff mercurial/upgrade.py @ 46235:0babe12ef35d
sharesafe: introduce functionality to automatically upgrade shares
In past few months, we have developed a `share-safe` mode for sharing repository
in which share source requirements and config values are shared with the shares.
To get it rolling, an important task is to get these shares automatically
upgraded. We are focusing on an installation where shares are created by scripts
and test jobs. It will be difficult to manually upgrade these and we need some
functionality to do so automatically.
This patch introduces a config option to deal with it. If all of the following
conditions are met, we upgrade the share repository automatically:
* If the config option is enabled
* Share source repository is share-safe enabled
* Share is not share-safe enabled
* Any command is run in the share
Upgrading the share is pretty easy as it involves only editing the requirements
file.
Differential Revision: https://phab.mercurial-scm.org/D9679
author | Pulkit Goyal <7895pulkit@gmail.com> |
---|---|
date | Wed, 06 Jan 2021 16:18:06 +0530 |
parents | d3113c4cf52c |
children | eec47efe219d |
line wrap: on
line diff
--- a/mercurial/upgrade.py Wed Jan 06 16:01:19 2021 +0530 +++ b/mercurial/upgrade.py Wed Jan 06 16:18:06 2021 +0530 @@ -12,7 +12,10 @@ error, hg, localrepo, + lock as lockmod, pycompat, + requirements as requirementsmod, + scmutil, ) from .upgrade_utils import ( @@ -20,6 +23,10 @@ engine as upgrade_engine, ) +from .utils import ( + stringutil, +) + allformatvariant = upgrade_actions.allformatvariant @@ -232,3 +239,28 @@ ) upgrade_op.print_post_op_messages() + + +def upgrade_share_to_safe(ui, hgvfs, storevfs, current_requirements): + """Upgrades a share to use share-safe mechanism""" + wlock = None + try: + wlock = lockmod.trylock(ui, hgvfs, b'wlock', 0, 0) + store_requirements = localrepo._readrequires(storevfs, 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 - store_requirements + # add share-safe requirement as it will mark the share as share-safe + diffrequires.add(requirementsmod.SHARESAFE_REQUIREMENT) + scmutil.writerequires(hgvfs, diffrequires) + current_requirements.add(requirementsmod.SHARESAFE_REQUIREMENT) + ui.warn(_(b'repository upgraded to use share-safe mode\n')) + except error.LockError as e: + ui.warn( + _(b'failed to upgrade share, got error: %s\n') + % stringutil.forcebytestr(e.strerror) + ) + finally: + if wlock: + wlock.release()