307 size = len(b) |
306 size = len(b) |
308 hunkrange = (0, 0, 1, size) |
307 hunkrange = (0, 0, 1, size) |
309 hunklines = [b"@@ -0,0 +1,%d @@\n" % size] + [b"+" + e for e in b] |
308 hunklines = [b"@@ -0,0 +1,%d @@\n" % size] + [b"+" + e for e in b] |
310 if without_newline: |
309 if without_newline: |
311 hunklines[-1] += b'\n' |
310 hunklines[-1] += b'\n' |
312 hunklines.append(_missing_newline_marker) |
311 hunklines.append(diffhelper.MISSING_NEWLINE_MARKER) |
313 hunks = ((hunkrange, hunklines),) |
312 hunks = ((hunkrange, hunklines),) |
314 elif not b: |
313 elif not b: |
315 without_newline = not a.endswith(b'\n') |
314 without_newline = not a.endswith(b'\n') |
316 a = splitnewlines(a) |
315 a = splitnewlines(a) |
317 l1 = b"--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1)) |
316 l1 = b"--- %s%s%s" % (aprefix, fn1, datetag(ad, fn1)) |
323 size = len(a) |
322 size = len(a) |
324 hunkrange = (1, size, 0, 0) |
323 hunkrange = (1, size, 0, 0) |
325 hunklines = [b"@@ -1,%d +0,0 @@\n" % size] + [b"-" + e for e in a] |
324 hunklines = [b"@@ -1,%d +0,0 @@\n" % size] + [b"-" + e for e in a] |
326 if without_newline: |
325 if without_newline: |
327 hunklines[-1] += b'\n' |
326 hunklines[-1] += b'\n' |
328 hunklines.append(_missing_newline_marker) |
327 hunklines.append(diffhelper.MISSING_NEWLINE_MARKER) |
329 hunks = ((hunkrange, hunklines),) |
328 hunks = ((hunkrange, hunklines),) |
330 else: |
329 else: |
331 hunks = _unidiff(a, b, opts=opts) |
330 hunks = _unidiff(a, b, opts=opts) |
332 if not next(hunks): |
331 if not next(hunks): |
333 return sentinel |
332 return sentinel |
416 for i in pycompat.xrange(len(hunklines) - 1, -1, -1): |
415 for i in pycompat.xrange(len(hunklines) - 1, -1, -1): |
417 if hunklines[i].startswith((b'-', b' ')): |
416 if hunklines[i].startswith((b'-', b' ')): |
418 if hunklines[i].startswith(b' '): |
417 if hunklines[i].startswith(b' '): |
419 skip = True |
418 skip = True |
420 hunklines[i] += b'\n' |
419 hunklines[i] += b'\n' |
421 hunklines.insert(i + 1, _missing_newline_marker) |
420 hunklines.insert(i + 1, diffhelper.MISSING_NEWLINE_MARKER) |
422 break |
421 break |
423 if not skip and not t2.endswith(b'\n') and bstart + blen == len(l2) + 1: |
422 if not skip and not t2.endswith(b'\n') and bstart + blen == len(l2) + 1: |
424 for i in pycompat.xrange(len(hunklines) - 1, -1, -1): |
423 for i in pycompat.xrange(len(hunklines) - 1, -1, -1): |
425 if hunklines[i].startswith(b'+'): |
424 if hunklines[i].startswith(b'+'): |
426 hunklines[i] += b'\n' |
425 hunklines[i] += b'\n' |
427 hunklines.insert(i + 1, _missing_newline_marker) |
426 hunklines.insert(i + 1, diffhelper.MISSING_NEWLINE_MARKER) |
428 break |
427 break |
429 yield hunkrange, hunklines |
428 yield hunkrange, hunklines |
430 |
429 |
431 # bdiff.blocks gives us the matching sequences in the files. The loop |
430 # bdiff.blocks gives us the matching sequences in the files. The loop |
432 # below finds the spaces between those matching sequences and translates |
431 # below finds the spaces between those matching sequences and translates |