mercurial/txnutil.py
author Pierre-Yves David <pierre-yves.david@octobus.net>
Sun, 25 Feb 2024 16:14:15 +0100
changeset 51456 19b2736c8e45
parent 49306 2e726c934fcd
permissions -rw-r--r--
branchcache: drop the unused `_verifyclosed` This code appears dead since its introduction about 5 years ago in this three consecutive commits: - 6578654916ae → introduce the method with two calls - 7c9d4cf23adf → remove first call - be5eeaf5c24a → remove second call o changeset: be5eeaf5c24a | user: Pulkit Goyal <pulkit@yandex-team.ru> | date: Fri Apr 05 15:57:09 2019 +0300 | summary: branchcache: don't verify closed nodes in _branchtip() | o changeset: 7c9d4cf23adf | user: Pulkit Goyal <pulkit@yandex-team.ru> | date: Fri Apr 05 15:56:33 2019 +0300 | summary: branchcache: don't verify closed nodes in iteropen() | o changeset: 6578654916ae | user: Pulkit Goyal <pulkit@yandex-team.ru> ~ date: Mon Apr 01 13:56:47 2019 +0300 summary: branchcache: lazily validate nodes from the branchmap

# 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 . 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 FileNotFoundError:
            pass
    return (vfs(filename, **kwargs), False)