diff --git a/mercurial/posix.py b/mercurial/posix.py --- a/mercurial/posix.py +++ b/mercurial/posix.py @@ -30,7 +30,6 @@ from . import ( osutil = policy.importmod(r'osutil') -posixfile = open normpath = os.path.normpath samestat = os.path.samestat try: @@ -52,6 +51,19 @@ expandglobs = False umask = os.umask(0) os.umask(umask) +if not pycompat.ispy3: + def posixfile(name, mode=r'r', buffering=-1): + fp = open(name, mode=mode, buffering=buffering) + # The position when opening in append mode is implementation defined, so + # make it consistent by always seeking to the end. + if r'a' in mode: + fp.seek(0, os.SEEK_END) + return fp +else: + # The underlying file object seeks as required in Python 3: + # https://github.com/python/cpython/blob/v3.7.3/Modules/_io/fileio.c#L474 + posixfile = open + def split(p): '''Same as posixpath.split, but faster