Mercurial > public > mercurial-scm > hg
comparison mercurial/mdiff.py @ 45154:10f48720ef95
diff: move no-eol text constant to a common location
Differential Revision: https://phab.mercurial-scm.org/D8763
author | Rodrigo Damazio Bovendorp <rdamazio@google.com> |
---|---|
date | Fri, 17 Jul 2020 03:53:19 -0700 |
parents | 9d2b2df2c2ba |
children | c8860a212770 |
comparison
equal
deleted
inserted
replaced
45153:8b6a446508c2 | 45154:10f48720ef95 |
---|---|
15 from .pycompat import ( | 15 from .pycompat import ( |
16 getattr, | 16 getattr, |
17 setattr, | 17 setattr, |
18 ) | 18 ) |
19 from . import ( | 19 from . import ( |
20 diffhelper, | |
20 encoding, | 21 encoding, |
21 error, | 22 error, |
22 policy, | 23 policy, |
23 pycompat, | 24 pycompat, |
24 util, | 25 util, |
25 ) | 26 ) |
26 from .utils import dateutil | 27 from .utils import dateutil |
27 | |
28 _missing_newline_marker = b"\\ No newline at end of file\n" | |
29 | 28 |
30 bdiff = policy.importmod('bdiff') | 29 bdiff = policy.importmod('bdiff') |
31 mpatch = policy.importmod('mpatch') | 30 mpatch = policy.importmod('mpatch') |
32 | 31 |
33 blocks = bdiff.blocks | 32 blocks = bdiff.blocks |
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 |