mdiff: use slice instead of index on bytestr when checking single bytes
authorAugie Fackler <augie@google.com>
Thu, 01 Feb 2018 18:14:52 -0500
changeset 35876 94621656be90
parent 35875 c0a6733f7e7a
child 35877 11fdf1486519
mdiff: use slice instead of index on bytestr when checking single bytes This is portable to Python 3. Differential Revision: https://phab.mercurial-scm.org/D1992
mercurial/mdiff.py
--- a/mercurial/mdiff.py	Thu Jan 18 13:04:16 2018 -0500
+++ b/mercurial/mdiff.py	Thu Feb 01 18:14:52 2018 -0500
@@ -275,7 +275,7 @@
         headerlines = []
         hunks = (None, ['Binary file %s has changed\n' % fn1]),
     elif not a:
-        without_newline = b[-1] != '\n'
+        without_newline = b[-1:] != '\n'
         b = splitnewlines(b)
         if a is None:
             l1 = '--- /dev/null%s' % datetag(epoch)
@@ -291,7 +291,7 @@
             hunklines.append(_missing_newline_marker)
         hunks = (hunkrange, hunklines),
     elif not b:
-        without_newline = a[-1] != '\n'
+        without_newline = a[-1:] != '\n'
         a = splitnewlines(a)
         l1 = "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1))
         if b is None:
@@ -384,17 +384,17 @@
         # a newline, print only one marker. That's the only case in
         # which the hunk can end in a shared line without a newline.
         skip = False
-        if t1[-1] != '\n' and astart + alen == len(l1) + 1:
+        if t1[-1:] != '\n' and astart + alen == len(l1) + 1:
             for i in xrange(len(hunklines) - 1, -1, -1):
-                if hunklines[i][0] in ('-', ' '):
-                    if hunklines[i][0] == ' ':
+                if hunklines[i][0:1] in ('-', ' '):
+                    if hunklines[i][0:1] == ' ':
                         skip = True
                     hunklines[i] += '\n'
                     hunklines.insert(i + 1, _missing_newline_marker)
                     break
-        if not skip and t2[-1] != '\n' and bstart + blen == len(l2) + 1:
+        if not skip and t2[-1:] != '\n' and bstart + blen == len(l2) + 1:
             for i in xrange(len(hunklines) - 1, -1, -1):
-                if hunklines[i][0] == '+':
+                if hunklines[i][0:1] == '+':
                     hunklines[i] += '\n'
                     hunklines.insert(i + 1, _missing_newline_marker)
                     break