author Yuya Nishihara <>
Tue, 05 Dec 2017 21:50:33 +0900
changeset 40931 c752fbe228fb5fb5338b4b90efcfed7c2046ef7b
parent 35943 2065327002135792df80eec820b59a305e3d1472
child 40616 aaafa1357c860ca02fcf1676349d317e3b166a3f
permissions -rw-r--r--
repoview: extract a factory function of proxy class This makes sure that dynamically-created class objects are isolated from local binding of repo instances. The type cache is moved to module level as it isn't tied to each instance.

# - transaction related utilities
#  Copyright FUJIWARA Katsunori <> 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 (

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