mercurial/txnutil.py
changeset 31050 206532700213
child 43076 2372284d9457
equal deleted inserted replaced
31049:20027be9f23d 31050:206532700213
       
     1 # txnutil.py - transaction related utilities
       
     2 #
       
     3 #  Copyright FUJIWARA Katsunori <foozy@lares.dti.ne.jp> and others
       
     4 #
       
     5 # This software may be used and distributed according to the terms of the
       
     6 # GNU General Public License version 2 or any later version.
       
     7 
       
     8 from __future__ import absolute_import
       
     9 
       
    10 import errno
       
    11 
       
    12 from . import (
       
    13     encoding,
       
    14 )
       
    15 
       
    16 def mayhavepending(root):
       
    17     '''return whether 'root' may have pending changes, which are
       
    18     visible to this process.
       
    19     '''
       
    20     return root == encoding.environ.get('HG_PENDING')
       
    21 
       
    22 def trypending(root, vfs, filename, **kwargs):
       
    23     '''Open  file to be read according to HG_PENDING environment variable
       
    24 
       
    25     This opens '.pending' of specified 'filename' only when HG_PENDING
       
    26     is equal to 'root'.
       
    27 
       
    28     This returns '(fp, is_pending_opened)' tuple.
       
    29     '''
       
    30     if mayhavepending(root):
       
    31         try:
       
    32             return (vfs('%s.pending' % filename, **kwargs), True)
       
    33         except IOError as inst:
       
    34             if inst.errno != errno.ENOENT:
       
    35                 raise
       
    36     return (vfs(filename, **kwargs), False)