Patchwork cleanup: remove compatibility code for Python < 2.7.4

login
register
mail settings
Submitter Manuel Jacob
Date May 29, 2020, 2:12 a.m.
Message ID <bc05bbecf2c270b2b553.1590718349@tmp>
Download mbox | patch
Permalink /patch/46388/
State Accepted
Headers show

Comments

Manuel Jacob - May 29, 2020, 2:12 a.m.
# HG changeset patch
# User Manuel Jacob <me@manueljacob.de>
# Date 1590717976 -7200
#      Fri May 29 04:06:16 2020 +0200
# Node ID bc05bbecf2c270b2b5533be84d1311840abcba00
# Parent  34b43eef01ed4612512ce105ed2f85ce591fe005
# EXP-Topic minimum-python-2.7.4-cleanup
cleanup: remove compatibility code for Python < 2.7.4

The minimum supported Python version was recently raised to 2.7.4.
Yuya Nishihara - May 29, 2020, 10:17 a.m.
On Fri, 29 May 2020 04:12:29 +0200, Manuel Jacob wrote:
> # HG changeset patch
> # User Manuel Jacob <me@manueljacob.de>
> # Date 1590717976 -7200
> #      Fri May 29 04:06:16 2020 +0200
> # Node ID bc05bbecf2c270b2b5533be84d1311840abcba00
> # Parent  34b43eef01ed4612512ce105ed2f85ce591fe005
> # EXP-Topic minimum-python-2.7.4-cleanup
> cleanup: remove compatibility code for Python < 2.7.4

Queued for default, thanks.

Patch

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -2844,7 +2844,7 @@  if pyplatform.python_implementation() ==
     # [1]: fixed by changeset 67dc99a989cd in the cpython hg repo.
     #
     # Here we workaround the EINTR issue for fileobj.__iter__. Other methods
-    # like "read*" are ignored for now, as Python < 2.7.4 is a minority.
+    # like "read*" work fine, as we do not support Python < 2.7.4.
     #
     # Although we can workaround the EINTR issue for fp.__iter__, it is slower:
     # "for x in fp" is 4x faster than "for x in iter(fp.readline, '')" in
@@ -2856,39 +2856,6 @@  if pyplatform.python_implementation() ==
     # affects things like pipes, sockets, ttys etc. We treat "normal" (S_ISREG)
     # files approximately as "fast" files and use the fast (unsafe) code path,
     # to minimize the performance impact.
-    if sys.version_info >= (2, 7, 4):
-        # fp.readline deals with EINTR correctly, use it as a workaround.
-        def _safeiterfile(fp):
-            return iter(fp.readline, b'')
-
-    else:
-        # fp.read* are broken too, manually deal with EINTR in a stupid way.
-        # note: this may block longer than necessary because of bufsize.
-        def _safeiterfile(fp, bufsize=4096):
-            fd = fp.fileno()
-            line = b''
-            while True:
-                try:
-                    buf = os.read(fd, bufsize)
-                except OSError as ex:
-                    # os.read only raises EINTR before any data is read
-                    if ex.errno == errno.EINTR:
-                        continue
-                    else:
-                        raise
-                line += buf
-                if b'\n' in buf:
-                    splitted = line.splitlines(True)
-                    line = b''
-                    for l in splitted:
-                        if l[-1] == b'\n':
-                            yield l
-                        else:
-                            line = l
-                if not buf:
-                    break
-            if line:
-                yield line
 
     def iterfile(fp):
         fastpath = True
@@ -2897,7 +2864,8 @@  if pyplatform.python_implementation() ==
         if fastpath:
             return fp
         else:
-            return _safeiterfile(fp)
+            # fp.readline deals with EINTR correctly, use it as a workaround.
+            return iter(fp.readline, b'')
 
 
 else: