mercurial/mdiff.py
changeset 35952 9e641c4525a2
parent 35951 8b6dd3922f70
child 36146 29dd37a418aa
--- a/mercurial/mdiff.py	Sun Feb 04 10:28:03 2018 +0900
+++ b/mercurial/mdiff.py	Sun Feb 04 10:33:14 2018 +0900
@@ -274,7 +274,7 @@
         headerlines = []
         hunks = (None, ['Binary file %s has changed\n' % fn1]),
     elif not a:
-        without_newline = b[-1:] != '\n'
+        without_newline = not b.endswith('\n')
         b = splitnewlines(b)
         if a is None:
             l1 = '--- /dev/null%s' % datetag(epoch)
@@ -290,7 +290,7 @@
             hunklines.append(_missing_newline_marker)
         hunks = (hunkrange, hunklines),
     elif not b:
-        without_newline = a[-1:] != '\n'
+        without_newline = not a.endswith('\n')
         a = splitnewlines(a)
         l1 = "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1))
         if b is None:
@@ -383,17 +383,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 not t1.endswith('\n') and astart + alen == len(l1) + 1:
             for i in xrange(len(hunklines) - 1, -1, -1):
-                if hunklines[i][0:1] in ('-', ' '):
-                    if hunklines[i][0:1] == ' ':
+                if hunklines[i].startswith(('-', ' ')):
+                    if hunklines[i].startswith(' '):
                         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 not t2.endswith('\n') and bstart + blen == len(l2) + 1:
             for i in xrange(len(hunklines) - 1, -1, -1):
-                if hunklines[i][0:1] == '+':
+                if hunklines[i].startswith('+'):
                     hunklines[i] += '\n'
                     hunklines.insert(i + 1, _missing_newline_marker)
                     break