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
# txnutil.py - transaction related utilities
#
# Copyright FUJIWARA Katsunori <foozy@lares.dti.ne.jp> and others
#
# This software may be used and distributed according to the terms of the
# GNU General Public License version 2 or any later version.
from __future__ import absolute_import
import errno
from . import encoding
def mayhavepending(root):
"""return whether 'root' may have pending changes, which are
visible to this process.
"""
return root == encoding.environ.get(b'HG_PENDING')
def trypending(root, vfs, filename, **kwargs):
"""Open file to be read according to HG_PENDING environment variable
This opens '.pending' of specified 'filename' only when HG_PENDING
is equal to 'root'.
This returns '(fp, is_pending_opened)' tuple.
"""
if mayhavepending(root):
try:
return (vfs(b'%s.pending' % filename, **kwargs), True)
except IOError as inst:
if inst.errno != errno.ENOENT:
raise
return (vfs(filename, **kwargs), False)