# HG changeset patch # User Augie Fackler # Date 1517526892 18000 # Node ID 94621656be9078e3b88963381e8eb631930b7b00 # Parent c0a6733f7e7afed248d7c23168f327ba623a2d1c 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 diff -r c0a6733f7e7a -r 94621656be90 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