[PATCH 01 of 10] py3: get rid of character access from pure.diffhelpers

Yuya Nishihara yuya at tcha.org
Wed Apr 11 15:33:51 UTC 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1523274281 -32400
#      Mon Apr 09 20:44:41 2018 +0900
# Node ID da53a21e2b96040ca2005d627b6c69a91e83f938
# Parent  8475c9bf096d5f67b3a82de73b27a61ef53018f1
py3: get rid of character access from pure.diffhelpers

's' is a result of readline(), so 'c == "\n"' means 's == "\n"'.

diff --git a/mercurial/pure/diffhelpers.py b/mercurial/pure/diffhelpers.py
--- a/mercurial/pure/diffhelpers.py
+++ b/mercurial/pure/diffhelpers.py
@@ -16,18 +16,17 @@ def addlines(fp, hunk, lena, lenb, a, b)
             break
         for i in xrange(num):
             s = fp.readline()
-            c = s[0]
             if s == "\\ No newline at end of file\n":
                 fix_newline(hunk, a, b)
                 continue
-            if c == "\n":
+            if s == "\n":
                 # Some patches may be missing the control char
                 # on empty lines. Supply a leading space.
                 s = " \n"
             hunk.append(s)
-            if c == "+":
+            if s.startswith('+'):
                 b.append(s[1:])
-            elif c == "-":
+            elif s.startswith('-'):
                 a.append(s)
             else:
                 b.append(s[1:])
@@ -41,11 +40,10 @@ def fix_newline(hunk, a, b):
         hline = l[:-2]
     else:
         hline = l[:-1]
-    c = hline[0]
 
-    if c in " +":
+    if hline.startswith((' ', '+')):
         b[-1] = hline[1:]
-    if c in " -":
+    if hline.startswith((' ', '-')):
         a[-1] = hline
     hunk[-1] = hline
     return 0


More information about the Mercurial-devel mailing list