view mercurial/txnutil.py @ 40396:973ff03d9bc0

exewrapper: convert to _tcsxxx functions for Unicode compatability This fixes more than 50 tests on py3 on Windows when enabled, mostly hooks and such that invoked `hg` directly. 187 left to go. I skipped doing the abort printing with Unicode because of apparent issues with MinGW [1]. It may be moot though, as MinGW isn't listed as a supported compiler after 3.4 [2]. [1] https://stackoverflow.com/questions/17700797/printf-wprintf-s-s-ls-char-and-wchar-errors-not-announced-by-a-compil [2] https://wiki.python.org/moin/WindowsCompilers
author Matt Harbison <matt_harbison@yahoo.com>
date Fri, 19 Oct 2018 18:32:13 -0400
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)