D1992: mdiff: use slice instead of index on bytestr when checking single bytes

durin42 (Augie Fackler) phabricator at mercurial-scm.org
Thu Feb 1 18:34:50 EST 2018


This revision was automatically updated to reflect the committed changes.
Closed by commit rHG2713f62fd898: mdiff: use slice instead of index on bytestr when checking single bytes (authored by durin42, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D1992?vs=5116&id=5132

REVISION DETAIL
  https://phab.mercurial-scm.org/D1992

AFFECTED FILES
  mercurial/mdiff.py

CHANGE DETAILS

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -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



To: durin42, #hg-reviewers, indygreg
Cc: indygreg, mercurial-devel


More information about the Mercurial-devel mailing list