##// END OF EJS Templates
mdiff: use str.startswith/endswith() instead of slicing
Yuya Nishihara -
r35970:9e641c45 default
parent child Browse files
Show More
@@ -274,7 +274,7 b' def unidiff(a, ad, b, bd, fn1, fn2, bina'
274 274 headerlines = []
275 275 hunks = (None, ['Binary file %s has changed\n' % fn1]),
276 276 elif not a:
277 without_newline = b[-1:] != '\n'
277 without_newline = not b.endswith('\n')
278 278 b = splitnewlines(b)
279 279 if a is None:
280 280 l1 = '--- /dev/null%s' % datetag(epoch)
@@ -290,7 +290,7 b' def unidiff(a, ad, b, bd, fn1, fn2, bina'
290 290 hunklines.append(_missing_newline_marker)
291 291 hunks = (hunkrange, hunklines),
292 292 elif not b:
293 without_newline = a[-1:] != '\n'
293 without_newline = not a.endswith('\n')
294 294 a = splitnewlines(a)
295 295 l1 = "--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1))
296 296 if b is None:
@@ -383,17 +383,17 b' def _unidiff(t1, t2, opts=defaultopts):'
383 383 # a newline, print only one marker. That's the only case in
384 384 # which the hunk can end in a shared line without a newline.
385 385 skip = False
386 if t1[-1:] != '\n' and astart + alen == len(l1) + 1:
386 if not t1.endswith('\n') and astart + alen == len(l1) + 1:
387 387 for i in xrange(len(hunklines) - 1, -1, -1):
388 if hunklines[i][0:1] in ('-', ' '):
389 if hunklines[i][0:1] == ' ':
388 if hunklines[i].startswith(('-', ' ')):
389 if hunklines[i].startswith(' '):
390 390 skip = True
391 391 hunklines[i] += '\n'
392 392 hunklines.insert(i + 1, _missing_newline_marker)
393 393 break
394 if not skip and t2[-1:] != '\n' and bstart + blen == len(l2) + 1:
394 if not skip and not t2.endswith('\n') and bstart + blen == len(l2) + 1:
395 395 for i in xrange(len(hunklines) - 1, -1, -1):
396 if hunklines[i][0:1] == '+':
396 if hunklines[i].startswith('+'):
397 397 hunklines[i] += '\n'
398 398 hunklines.insert(i + 1, _missing_newline_marker)
399 399 break
General Comments 0
You need to be logged in to leave comments. Login now