##// END OF EJS Templates
fix diffs containing embedded "\r"....
Vadim Gelfer -
r2248:b914f055 default
parent child Browse files
Show More
@@ -0,0 +1,8 b''
1 #!/bin/sh
2
3 hg init
4 python -c 'print "confuse str.splitlines\nembedded\rnewline"' > a
5 hg ci -Ama -d '1 0'
6 echo clean diff >> a
7 hg ci -mb -d '2 0'
8 hg diff -r0 -r1
@@ -0,0 +1,8 b''
1 adding a
2 diff -r 107ba6f817b5 -r 310ce7989cdc a
3 --- a/a Thu Jan 01 00:00:01 1970 +0000
4 +++ b/a Thu Jan 01 00:00:02 1970 +0000
5 @@ -1,2 +1,3 @@ confuse str.splitlines
6 confuse str.splitlines
7 embedded newline
8 +clean diff
@@ -10,6 +10,20 b' import struct, bdiff, util, mpatch'
10 demandload(globals(), "re")
10 demandload(globals(), "re")
11
11
12
12
13 def splitnewlines(text, keepends=False):
14 '''like str.splitlines, but only split on newlines.'''
15 i = 0
16 lines = []
17 while True:
18 n = text.find('\n', i)
19 if n == -1:
20 last = text[i:]
21 if last:
22 lines.append(last)
23 return lines
24 lines.append(text[i:keepends and n+1 or n])
25 i = n + 1
26
13 def unidiff(a, ad, b, bd, fn, r=None, text=False,
27 def unidiff(a, ad, b, bd, fn, r=None, text=False,
14 showfunc=False, ignorews=False):
28 showfunc=False, ignorews=False):
15
29
@@ -19,7 +33,7 b' def unidiff(a, ad, b, bd, fn, r=None, te'
19 if not text and (util.binary(a) or util.binary(b)):
33 if not text and (util.binary(a) or util.binary(b)):
20 l = ['Binary file %s has changed\n' % fn]
34 l = ['Binary file %s has changed\n' % fn]
21 elif not a:
35 elif not a:
22 b = b.splitlines(1)
36 b = splitnewlines(b, keepends=True)
23 if a is None:
37 if a is None:
24 l1 = "--- %s\t%s\n" % ("/dev/null", epoch)
38 l1 = "--- %s\t%s\n" % ("/dev/null", epoch)
25 else:
39 else:
@@ -28,7 +42,7 b' def unidiff(a, ad, b, bd, fn, r=None, te'
28 l3 = "@@ -0,0 +1,%d @@\n" % len(b)
42 l3 = "@@ -0,0 +1,%d @@\n" % len(b)
29 l = [l1, l2, l3] + ["+" + e for e in b]
43 l = [l1, l2, l3] + ["+" + e for e in b]
30 elif not b:
44 elif not b:
31 a = a.splitlines(1)
45 a = splitnewlines(a, keepends=True)
32 l1 = "--- %s\t%s\n" % ("a/" + fn, ad)
46 l1 = "--- %s\t%s\n" % ("a/" + fn, ad)
33 if b is None:
47 if b is None:
34 l2 = "+++ %s\t%s\n" % ("/dev/null", epoch)
48 l2 = "+++ %s\t%s\n" % ("/dev/null", epoch)
@@ -37,8 +51,8 b' def unidiff(a, ad, b, bd, fn, r=None, te'
37 l3 = "@@ -1,%d +0,0 @@\n" % len(a)
51 l3 = "@@ -1,%d +0,0 @@\n" % len(a)
38 l = [l1, l2, l3] + ["-" + e for e in a]
52 l = [l1, l2, l3] + ["-" + e for e in a]
39 else:
53 else:
40 al = a.splitlines(1)
54 al = splitnewlines(a, keepends=True)
41 bl = b.splitlines(1)
55 bl = splitnewlines(b, keepends=True)
42 l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn,
56 l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn,
43 showfunc=showfunc, ignorews=ignorews))
57 showfunc=showfunc, ignorews=ignorews))
44 if not l: return ""
58 if not l: return ""
General Comments 0
You need to be logged in to leave comments. Login now