355 if opts.showfunc: |
355 if opts.showfunc: |
356 lastpos, func = lastfunc |
356 lastpos, func = lastfunc |
357 # walk backwards from the start of the context up to the start of |
357 # walk backwards from the start of the context up to the start of |
358 # the previous hunk context until we find a line starting with an |
358 # the previous hunk context until we find a line starting with an |
359 # alphanumeric char. |
359 # alphanumeric char. |
360 for i in xrange(astart - 1, lastpos - 1, -1): |
360 for i in pycompat.xrange(astart - 1, lastpos - 1, -1): |
361 if l1[i][0:1].isalnum(): |
361 if l1[i][0:1].isalnum(): |
362 func = b' ' + l1[i].rstrip() |
362 func = b' ' + l1[i].rstrip() |
363 # split long function name if ASCII. otherwise we have no |
363 # split long function name if ASCII. otherwise we have no |
364 # idea where the multi-byte boundary is, so just leave it. |
364 # idea where the multi-byte boundary is, so just leave it. |
365 if encoding.isasciistr(func): |
365 if encoding.isasciistr(func): |
379 |
379 |
380 hunkrange = astart, alen, bstart, blen |
380 hunkrange = astart, alen, bstart, blen |
381 hunklines = ( |
381 hunklines = ( |
382 ["@@ -%d,%d +%d,%d @@%s\n" % (hunkrange + (func,))] |
382 ["@@ -%d,%d +%d,%d @@%s\n" % (hunkrange + (func,))] |
383 + delta |
383 + delta |
384 + [' ' + l1[x] for x in xrange(a2, aend)] |
384 + [' ' + l1[x] for x in pycompat.xrange(a2, aend)] |
385 ) |
385 ) |
386 # If either file ends without a newline and the last line of |
386 # If either file ends without a newline and the last line of |
387 # that file is part of a hunk, a marker is printed. If the |
387 # that file is part of a hunk, a marker is printed. If the |
388 # last line of both files is identical and neither ends in |
388 # last line of both files is identical and neither ends in |
389 # a newline, print only one marker. That's the only case in |
389 # a newline, print only one marker. That's the only case in |
390 # which the hunk can end in a shared line without a newline. |
390 # which the hunk can end in a shared line without a newline. |
391 skip = False |
391 skip = False |
392 if not t1.endswith('\n') and astart + alen == len(l1) + 1: |
392 if not t1.endswith('\n') and astart + alen == len(l1) + 1: |
393 for i in xrange(len(hunklines) - 1, -1, -1): |
393 for i in pycompat.xrange(len(hunklines) - 1, -1, -1): |
394 if hunklines[i].startswith(('-', ' ')): |
394 if hunklines[i].startswith(('-', ' ')): |
395 if hunklines[i].startswith(' '): |
395 if hunklines[i].startswith(' '): |
396 skip = True |
396 skip = True |
397 hunklines[i] += '\n' |
397 hunklines[i] += '\n' |
398 hunklines.insert(i + 1, _missing_newline_marker) |
398 hunklines.insert(i + 1, _missing_newline_marker) |
399 break |
399 break |
400 if not skip and not t2.endswith('\n') and bstart + blen == len(l2) + 1: |
400 if not skip and not t2.endswith('\n') and bstart + blen == len(l2) + 1: |
401 for i in xrange(len(hunklines) - 1, -1, -1): |
401 for i in pycompat.xrange(len(hunklines) - 1, -1, -1): |
402 if hunklines[i].startswith('+'): |
402 if hunklines[i].startswith('+'): |
403 hunklines[i] += '\n' |
403 hunklines[i] += '\n' |
404 hunklines.insert(i + 1, _missing_newline_marker) |
404 hunklines.insert(i + 1, _missing_newline_marker) |
405 break |
405 break |
406 yield hunkrange, hunklines |
406 yield hunkrange, hunklines |