view mercurial/txnutil.py @ 33699:50c44dee741a

filemerge: move decorator definition for internal merge tools to registrar This patch also adds extra loading entry for internal merge tools to extensions.py, for similarity to other decorators defined in registrar.py. This patch uses "internalmerge" for decorator class name, instead of original "internaltool", because the latter is too generic. BTW, after this patch, 4-spaces indentation is added to the 1st line of internal merge tool description docstring, and this may make already translated entries in *.po fuzzy. Even though this indentation is required for "definition list" in reST syntax, absence of it has been overlooked, because help.makeitemsdoc() forcibly inserts it at generation of online help. But this forcible insertion causes formatting issue (I'll send another patch series for this). Therefore, this additional indentation should be reasonable.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Sun, 06 Aug 2017 01:13:57 +0900
parents 206532700213
children 2372284d9457
line wrap: on
line source

# 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('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('%s.pending' % filename, **kwargs), True)
        except IOError as inst:
            if inst.errno != errno.ENOENT:
                raise
    return (vfs(filename, **kwargs), False)