Show More
@@ -9,20 +9,15 b' from demandload import demandload' | |||||
9 | import struct, bdiff, util, mpatch |
|
9 | import struct, bdiff, util, mpatch | |
10 | demandload(globals(), "re") |
|
10 | demandload(globals(), "re") | |
11 |
|
11 | |||
12 |
|
12 | def splitnewlines(text): | ||
13 | def splitnewlines(text, keepends=False): |
|
|||
14 | '''like str.splitlines, but only split on newlines.''' |
|
13 | '''like str.splitlines, but only split on newlines.''' | |
15 | i = 0 |
|
14 | lines = [l + '\n' for l in text.split('\n')] | |
16 |
lines |
|
15 | if lines: | |
17 | while True: |
|
16 | if lines[-1] == '\n': | |
18 | n = text.find('\n', i) |
|
17 | lines.pop() | |
19 | if n == -1: |
|
18 | else: | |
20 |
l |
|
19 | lines[-1] = lines[-1][:-1] | |
21 | if last: |
|
20 | return lines | |
22 | lines.append(last) |
|
|||
23 | return lines |
|
|||
24 | lines.append(text[i:keepends and n+1 or n]) |
|
|||
25 | i = n + 1 |
|
|||
26 |
|
21 | |||
27 | def unidiff(a, ad, b, bd, fn, r=None, text=False, |
|
22 | def unidiff(a, ad, b, bd, fn, r=None, text=False, | |
28 | showfunc=False, ignorews=False): |
|
23 | showfunc=False, ignorews=False): | |
@@ -33,7 +28,7 b' def unidiff(a, ad, b, bd, fn, r=None, te' | |||||
33 | if not text and (util.binary(a) or util.binary(b)): |
|
28 | if not text and (util.binary(a) or util.binary(b)): | |
34 | l = ['Binary file %s has changed\n' % fn] |
|
29 | l = ['Binary file %s has changed\n' % fn] | |
35 | elif not a: |
|
30 | elif not a: | |
36 |
b = splitnewlines(b |
|
31 | b = splitnewlines(b) | |
37 | if a is None: |
|
32 | if a is None: | |
38 | l1 = "--- %s\t%s\n" % ("/dev/null", epoch) |
|
33 | l1 = "--- %s\t%s\n" % ("/dev/null", epoch) | |
39 | else: |
|
34 | else: | |
@@ -42,7 +37,7 b' def unidiff(a, ad, b, bd, fn, r=None, te' | |||||
42 | l3 = "@@ -0,0 +1,%d @@\n" % len(b) |
|
37 | l3 = "@@ -0,0 +1,%d @@\n" % len(b) | |
43 | l = [l1, l2, l3] + ["+" + e for e in b] |
|
38 | l = [l1, l2, l3] + ["+" + e for e in b] | |
44 | elif not b: |
|
39 | elif not b: | |
45 |
a = splitnewlines(a |
|
40 | a = splitnewlines(a) | |
46 | l1 = "--- %s\t%s\n" % ("a/" + fn, ad) |
|
41 | l1 = "--- %s\t%s\n" % ("a/" + fn, ad) | |
47 | if b is None: |
|
42 | if b is None: | |
48 | l2 = "+++ %s\t%s\n" % ("/dev/null", epoch) |
|
43 | l2 = "+++ %s\t%s\n" % ("/dev/null", epoch) | |
@@ -51,8 +46,8 b' def unidiff(a, ad, b, bd, fn, r=None, te' | |||||
51 | l3 = "@@ -1,%d +0,0 @@\n" % len(a) |
|
46 | l3 = "@@ -1,%d +0,0 @@\n" % len(a) | |
52 | l = [l1, l2, l3] + ["-" + e for e in a] |
|
47 | l = [l1, l2, l3] + ["-" + e for e in a] | |
53 | else: |
|
48 | else: | |
54 |
al = splitnewlines(a |
|
49 | al = splitnewlines(a) | |
55 |
bl = splitnewlines(b |
|
50 | bl = splitnewlines(b) | |
56 | l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn, |
|
51 | l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn, | |
57 | showfunc=showfunc, ignorews=ignorews)) |
|
52 | showfunc=showfunc, ignorews=ignorews)) | |
58 | if not l: return "" |
|
53 | if not l: return "" |
General Comments 0
You need to be logged in to leave comments.
Login now