view mercurial/txnutil.py @ 52059:b332ae615714

merge: improve working-copy mtime race handling Explanations inline. This also makes use of `make_mtime_reliable`, which unifies our mtime raciness logic from the status. On top of this, this fixes the handling of the pure dirstate status to better catch racy status, as we've been doing in Rust for a long time now.
author Raphaël Gomès <rgomes@octobus.net>
date Wed, 16 Oct 2024 19:14:30 +0200
parents f4733654f144
children
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 annotations

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)