##// END OF EJS Templates
mdiff: carriage return (\r) is also ignorable whitespace
Mads Kiilerich -
r12751:8eb758ea default
parent child Browse files
Show More
@@ -1,277 +1,277
1 # mdiff.py - diff and patch routines for mercurial
1 # mdiff.py - diff and patch routines for mercurial
2 #
2 #
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com>
4 #
4 #
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 from i18n import _
8 from i18n import _
9 import bdiff, mpatch, util
9 import bdiff, mpatch, util
10 import re, struct
10 import re, struct
11
11
12 def splitnewlines(text):
12 def splitnewlines(text):
13 '''like str.splitlines, but only split on newlines.'''
13 '''like str.splitlines, but only split on newlines.'''
14 lines = [l + '\n' for l in text.split('\n')]
14 lines = [l + '\n' for l in text.split('\n')]
15 if lines:
15 if lines:
16 if lines[-1] == '\n':
16 if lines[-1] == '\n':
17 lines.pop()
17 lines.pop()
18 else:
18 else:
19 lines[-1] = lines[-1][:-1]
19 lines[-1] = lines[-1][:-1]
20 return lines
20 return lines
21
21
22 class diffopts(object):
22 class diffopts(object):
23 '''context is the number of context lines
23 '''context is the number of context lines
24 text treats all files as text
24 text treats all files as text
25 showfunc enables diff -p output
25 showfunc enables diff -p output
26 git enables the git extended patch format
26 git enables the git extended patch format
27 nodates removes dates from diff headers
27 nodates removes dates from diff headers
28 ignorews ignores all whitespace changes in the diff
28 ignorews ignores all whitespace changes in the diff
29 ignorewsamount ignores changes in the amount of whitespace
29 ignorewsamount ignores changes in the amount of whitespace
30 ignoreblanklines ignores changes whose lines are all blank
30 ignoreblanklines ignores changes whose lines are all blank
31 upgrade generates git diffs to avoid data loss
31 upgrade generates git diffs to avoid data loss
32 '''
32 '''
33
33
34 defaults = {
34 defaults = {
35 'context': 3,
35 'context': 3,
36 'text': False,
36 'text': False,
37 'showfunc': False,
37 'showfunc': False,
38 'git': False,
38 'git': False,
39 'nodates': False,
39 'nodates': False,
40 'ignorews': False,
40 'ignorews': False,
41 'ignorewsamount': False,
41 'ignorewsamount': False,
42 'ignoreblanklines': False,
42 'ignoreblanklines': False,
43 'upgrade': False,
43 'upgrade': False,
44 }
44 }
45
45
46 __slots__ = defaults.keys()
46 __slots__ = defaults.keys()
47
47
48 def __init__(self, **opts):
48 def __init__(self, **opts):
49 for k in self.__slots__:
49 for k in self.__slots__:
50 v = opts.get(k)
50 v = opts.get(k)
51 if v is None:
51 if v is None:
52 v = self.defaults[k]
52 v = self.defaults[k]
53 setattr(self, k, v)
53 setattr(self, k, v)
54
54
55 try:
55 try:
56 self.context = int(self.context)
56 self.context = int(self.context)
57 except ValueError:
57 except ValueError:
58 raise util.Abort(_('diff context lines count must be '
58 raise util.Abort(_('diff context lines count must be '
59 'an integer, not %r') % self.context)
59 'an integer, not %r') % self.context)
60
60
61 def copy(self, **kwargs):
61 def copy(self, **kwargs):
62 opts = dict((k, getattr(self, k)) for k in self.defaults)
62 opts = dict((k, getattr(self, k)) for k in self.defaults)
63 opts.update(kwargs)
63 opts.update(kwargs)
64 return diffopts(**opts)
64 return diffopts(**opts)
65
65
66 defaultopts = diffopts()
66 defaultopts = diffopts()
67
67
68 def wsclean(opts, text, blank=True):
68 def wsclean(opts, text, blank=True):
69 if opts.ignorews:
69 if opts.ignorews:
70 text = re.sub('[ \t]+', '', text)
70 text = re.sub('[ \t\r]+', '', text)
71 elif opts.ignorewsamount:
71 elif opts.ignorewsamount:
72 text = re.sub('[ \t]+', ' ', text)
72 text = re.sub('[ \t\r]+', ' ', text)
73 text = re.sub('[ \t]+\n', '\n', text)
73 text = text.replace(' \n', '\n')
74 if blank and opts.ignoreblanklines:
74 if blank and opts.ignoreblanklines:
75 text = re.sub('\n+', '', text)
75 text = re.sub('\n+', '', text)
76 return text
76 return text
77
77
78 def diffline(revs, a, b, opts):
78 def diffline(revs, a, b, opts):
79 parts = ['diff']
79 parts = ['diff']
80 if opts.git:
80 if opts.git:
81 parts.append('--git')
81 parts.append('--git')
82 if revs and not opts.git:
82 if revs and not opts.git:
83 parts.append(' '.join(["-r %s" % rev for rev in revs]))
83 parts.append(' '.join(["-r %s" % rev for rev in revs]))
84 if opts.git:
84 if opts.git:
85 parts.append('a/%s' % a)
85 parts.append('a/%s' % a)
86 parts.append('b/%s' % b)
86 parts.append('b/%s' % b)
87 else:
87 else:
88 parts.append(a)
88 parts.append(a)
89 return ' '.join(parts) + '\n'
89 return ' '.join(parts) + '\n'
90
90
91 def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts):
91 def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts):
92 def datetag(date, addtab=True):
92 def datetag(date, addtab=True):
93 if not opts.git and not opts.nodates:
93 if not opts.git and not opts.nodates:
94 return '\t%s\n' % date
94 return '\t%s\n' % date
95 if addtab and ' ' in fn1:
95 if addtab and ' ' in fn1:
96 return '\t\n'
96 return '\t\n'
97 return '\n'
97 return '\n'
98
98
99 if not a and not b:
99 if not a and not b:
100 return ""
100 return ""
101 epoch = util.datestr((0, 0))
101 epoch = util.datestr((0, 0))
102
102
103 if not opts.text and (util.binary(a) or util.binary(b)):
103 if not opts.text and (util.binary(a) or util.binary(b)):
104 if a and b and len(a) == len(b) and a == b:
104 if a and b and len(a) == len(b) and a == b:
105 return ""
105 return ""
106 l = ['Binary file %s has changed\n' % fn1]
106 l = ['Binary file %s has changed\n' % fn1]
107 elif not a:
107 elif not a:
108 b = splitnewlines(b)
108 b = splitnewlines(b)
109 if a is None:
109 if a is None:
110 l1 = '--- /dev/null%s' % datetag(epoch, False)
110 l1 = '--- /dev/null%s' % datetag(epoch, False)
111 else:
111 else:
112 l1 = "--- %s%s" % ("a/" + fn1, datetag(ad))
112 l1 = "--- %s%s" % ("a/" + fn1, datetag(ad))
113 l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd))
113 l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd))
114 l3 = "@@ -0,0 +1,%d @@\n" % len(b)
114 l3 = "@@ -0,0 +1,%d @@\n" % len(b)
115 l = [l1, l2, l3] + ["+" + e for e in b]
115 l = [l1, l2, l3] + ["+" + e for e in b]
116 elif not b:
116 elif not b:
117 a = splitnewlines(a)
117 a = splitnewlines(a)
118 l1 = "--- %s%s" % ("a/" + fn1, datetag(ad))
118 l1 = "--- %s%s" % ("a/" + fn1, datetag(ad))
119 if b is None:
119 if b is None:
120 l2 = '+++ /dev/null%s' % datetag(epoch, False)
120 l2 = '+++ /dev/null%s' % datetag(epoch, False)
121 else:
121 else:
122 l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd))
122 l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd))
123 l3 = "@@ -1,%d +0,0 @@\n" % len(a)
123 l3 = "@@ -1,%d +0,0 @@\n" % len(a)
124 l = [l1, l2, l3] + ["-" + e for e in a]
124 l = [l1, l2, l3] + ["-" + e for e in a]
125 else:
125 else:
126 al = splitnewlines(a)
126 al = splitnewlines(a)
127 bl = splitnewlines(b)
127 bl = splitnewlines(b)
128 l = list(_unidiff(a, b, al, bl, opts=opts))
128 l = list(_unidiff(a, b, al, bl, opts=opts))
129 if not l:
129 if not l:
130 return ""
130 return ""
131
131
132 l.insert(0, "--- a/%s%s" % (fn1, datetag(ad)))
132 l.insert(0, "--- a/%s%s" % (fn1, datetag(ad)))
133 l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd)))
133 l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd)))
134
134
135 for ln in xrange(len(l)):
135 for ln in xrange(len(l)):
136 if l[ln][-1] != '\n':
136 if l[ln][-1] != '\n':
137 l[ln] += "\n\ No newline at end of file\n"
137 l[ln] += "\n\ No newline at end of file\n"
138
138
139 if r:
139 if r:
140 l.insert(0, diffline(r, fn1, fn2, opts))
140 l.insert(0, diffline(r, fn1, fn2, opts))
141
141
142 return "".join(l)
142 return "".join(l)
143
143
144 # creates a headerless unified diff
144 # creates a headerless unified diff
145 # t1 and t2 are the text to be diffed
145 # t1 and t2 are the text to be diffed
146 # l1 and l2 are the text broken up into lines
146 # l1 and l2 are the text broken up into lines
147 def _unidiff(t1, t2, l1, l2, opts=defaultopts):
147 def _unidiff(t1, t2, l1, l2, opts=defaultopts):
148 def contextend(l, len):
148 def contextend(l, len):
149 ret = l + opts.context
149 ret = l + opts.context
150 if ret > len:
150 if ret > len:
151 ret = len
151 ret = len
152 return ret
152 return ret
153
153
154 def contextstart(l):
154 def contextstart(l):
155 ret = l - opts.context
155 ret = l - opts.context
156 if ret < 0:
156 if ret < 0:
157 return 0
157 return 0
158 return ret
158 return ret
159
159
160 def yieldhunk(hunk):
160 def yieldhunk(hunk):
161 (astart, a2, bstart, b2, delta) = hunk
161 (astart, a2, bstart, b2, delta) = hunk
162 aend = contextend(a2, len(l1))
162 aend = contextend(a2, len(l1))
163 alen = aend - astart
163 alen = aend - astart
164 blen = b2 - bstart + aend - a2
164 blen = b2 - bstart + aend - a2
165
165
166 func = ""
166 func = ""
167 if opts.showfunc:
167 if opts.showfunc:
168 # walk backwards from the start of the context
168 # walk backwards from the start of the context
169 # to find a line starting with an alphanumeric char.
169 # to find a line starting with an alphanumeric char.
170 for x in xrange(astart - 1, -1, -1):
170 for x in xrange(astart - 1, -1, -1):
171 t = l1[x].rstrip()
171 t = l1[x].rstrip()
172 if funcre.match(t):
172 if funcre.match(t):
173 func = ' ' + t[:40]
173 func = ' ' + t[:40]
174 break
174 break
175
175
176 yield "@@ -%d,%d +%d,%d @@%s\n" % (astart + 1, alen,
176 yield "@@ -%d,%d +%d,%d @@%s\n" % (astart + 1, alen,
177 bstart + 1, blen, func)
177 bstart + 1, blen, func)
178 for x in delta:
178 for x in delta:
179 yield x
179 yield x
180 for x in xrange(a2, aend):
180 for x in xrange(a2, aend):
181 yield ' ' + l1[x]
181 yield ' ' + l1[x]
182
182
183 if opts.showfunc:
183 if opts.showfunc:
184 funcre = re.compile('\w')
184 funcre = re.compile('\w')
185
185
186 # bdiff.blocks gives us the matching sequences in the files. The loop
186 # bdiff.blocks gives us the matching sequences in the files. The loop
187 # below finds the spaces between those matching sequences and translates
187 # below finds the spaces between those matching sequences and translates
188 # them into diff output.
188 # them into diff output.
189 #
189 #
190 if opts.ignorews or opts.ignorewsamount:
190 if opts.ignorews or opts.ignorewsamount:
191 t1 = wsclean(opts, t1, False)
191 t1 = wsclean(opts, t1, False)
192 t2 = wsclean(opts, t2, False)
192 t2 = wsclean(opts, t2, False)
193
193
194 diff = bdiff.blocks(t1, t2)
194 diff = bdiff.blocks(t1, t2)
195 hunk = None
195 hunk = None
196 for i, s1 in enumerate(diff):
196 for i, s1 in enumerate(diff):
197 # The first match is special.
197 # The first match is special.
198 # we've either found a match starting at line 0 or a match later
198 # we've either found a match starting at line 0 or a match later
199 # in the file. If it starts later, old and new below will both be
199 # in the file. If it starts later, old and new below will both be
200 # empty and we'll continue to the next match.
200 # empty and we'll continue to the next match.
201 if i > 0:
201 if i > 0:
202 s = diff[i - 1]
202 s = diff[i - 1]
203 else:
203 else:
204 s = [0, 0, 0, 0]
204 s = [0, 0, 0, 0]
205 delta = []
205 delta = []
206 a1 = s[1]
206 a1 = s[1]
207 a2 = s1[0]
207 a2 = s1[0]
208 b1 = s[3]
208 b1 = s[3]
209 b2 = s1[2]
209 b2 = s1[2]
210
210
211 old = l1[a1:a2]
211 old = l1[a1:a2]
212 new = l2[b1:b2]
212 new = l2[b1:b2]
213
213
214 # bdiff sometimes gives huge matches past eof, this check eats them,
214 # bdiff sometimes gives huge matches past eof, this check eats them,
215 # and deals with the special first match case described above
215 # and deals with the special first match case described above
216 if not old and not new:
216 if not old and not new:
217 continue
217 continue
218
218
219 if opts.ignoreblanklines:
219 if opts.ignoreblanklines:
220 if wsclean(opts, "".join(old)) == wsclean(opts, "".join(new)):
220 if wsclean(opts, "".join(old)) == wsclean(opts, "".join(new)):
221 continue
221 continue
222
222
223 astart = contextstart(a1)
223 astart = contextstart(a1)
224 bstart = contextstart(b1)
224 bstart = contextstart(b1)
225 prev = None
225 prev = None
226 if hunk:
226 if hunk:
227 # join with the previous hunk if it falls inside the context
227 # join with the previous hunk if it falls inside the context
228 if astart < hunk[1] + opts.context + 1:
228 if astart < hunk[1] + opts.context + 1:
229 prev = hunk
229 prev = hunk
230 astart = hunk[1]
230 astart = hunk[1]
231 bstart = hunk[3]
231 bstart = hunk[3]
232 else:
232 else:
233 for x in yieldhunk(hunk):
233 for x in yieldhunk(hunk):
234 yield x
234 yield x
235 if prev:
235 if prev:
236 # we've joined the previous hunk, record the new ending points.
236 # we've joined the previous hunk, record the new ending points.
237 hunk[1] = a2
237 hunk[1] = a2
238 hunk[3] = b2
238 hunk[3] = b2
239 delta = hunk[4]
239 delta = hunk[4]
240 else:
240 else:
241 # create a new hunk
241 # create a new hunk
242 hunk = [astart, a2, bstart, b2, delta]
242 hunk = [astart, a2, bstart, b2, delta]
243
243
244 delta[len(delta):] = [' ' + x for x in l1[astart:a1]]
244 delta[len(delta):] = [' ' + x for x in l1[astart:a1]]
245 delta[len(delta):] = ['-' + x for x in old]
245 delta[len(delta):] = ['-' + x for x in old]
246 delta[len(delta):] = ['+' + x for x in new]
246 delta[len(delta):] = ['+' + x for x in new]
247
247
248 if hunk:
248 if hunk:
249 for x in yieldhunk(hunk):
249 for x in yieldhunk(hunk):
250 yield x
250 yield x
251
251
252 def patchtext(bin):
252 def patchtext(bin):
253 pos = 0
253 pos = 0
254 t = []
254 t = []
255 while pos < len(bin):
255 while pos < len(bin):
256 p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
256 p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12])
257 pos += 12
257 pos += 12
258 t.append(bin[pos:pos + l])
258 t.append(bin[pos:pos + l])
259 pos += l
259 pos += l
260 return "".join(t)
260 return "".join(t)
261
261
262 def patch(a, bin):
262 def patch(a, bin):
263 if len(a) == 0:
263 if len(a) == 0:
264 # skip over trivial delta header
264 # skip over trivial delta header
265 return buffer(bin, 12)
265 return buffer(bin, 12)
266 return mpatch.patches(a, [bin])
266 return mpatch.patches(a, [bin])
267
267
268 # similar to difflib.SequenceMatcher.get_matching_blocks
268 # similar to difflib.SequenceMatcher.get_matching_blocks
269 def get_matching_blocks(a, b):
269 def get_matching_blocks(a, b):
270 return [(d[0], d[2], d[1] - d[0]) for d in bdiff.blocks(a, b)]
270 return [(d[0], d[2], d[1] - d[0]) for d in bdiff.blocks(a, b)]
271
271
272 def trivialdiffheader(length):
272 def trivialdiffheader(length):
273 return struct.pack(">lll", 0, 0, length)
273 return struct.pack(">lll", 0, 0, length)
274
274
275 patches = mpatch.patches
275 patches = mpatch.patches
276 patchedsize = mpatch.patchedsize
276 patchedsize = mpatch.patchedsize
277 textdiff = bdiff.bdiff
277 textdiff = bdiff.bdiff
@@ -1,392 +1,446
1 GNU diff is the reference for all of these results.
1 GNU diff is the reference for all of these results.
2
2
3 Prepare tests:
3 Prepare tests:
4
4
5 $ echo '[alias]' >> $HGRCPATH
5 $ echo '[alias]' >> $HGRCPATH
6 $ echo 'ndiff = diff --nodates' >> $HGRCPATH
6 $ echo 'ndiff = diff --nodates' >> $HGRCPATH
7
7
8 $ hg init
8 $ hg init
9 $ printf 'hello world\ngoodbye world\n' >foo
9 $ printf 'hello world\ngoodbye world\n' >foo
10 $ hg ci -Amfoo -ufoo
10 $ hg ci -Amfoo -ufoo
11 adding foo
11 adding foo
12
12
13
13
14 Test added blank lines:
14 Test added blank lines:
15
15
16 $ printf '\nhello world\n\ngoodbye world\n\n' >foo
16 $ printf '\nhello world\n\ngoodbye world\n\n' >foo
17
17
18 >>> two diffs showing three added lines <<<
18 >>> two diffs showing three added lines <<<
19
19
20 $ hg ndiff
20 $ hg ndiff
21 diff -r 540c40a65b78 foo
21 diff -r 540c40a65b78 foo
22 --- a/foo
22 --- a/foo
23 +++ b/foo
23 +++ b/foo
24 @@ -1,2 +1,5 @@
24 @@ -1,2 +1,5 @@
25 +
25 +
26 hello world
26 hello world
27 +
27 +
28 goodbye world
28 goodbye world
29 +
29 +
30 $ hg ndiff -b
30 $ hg ndiff -b
31 diff -r 540c40a65b78 foo
31 diff -r 540c40a65b78 foo
32 --- a/foo
32 --- a/foo
33 +++ b/foo
33 +++ b/foo
34 @@ -1,2 +1,5 @@
34 @@ -1,2 +1,5 @@
35 +
35 +
36 hello world
36 hello world
37 +
37 +
38 goodbye world
38 goodbye world
39 +
39 +
40
40
41 >>> no diffs <<<
41 >>> no diffs <<<
42
42
43 $ hg ndiff -B
43 $ hg ndiff -B
44 $ hg ndiff -Bb
44 $ hg ndiff -Bb
45
45
46
46
47 Test added horizontal space first on a line():
47 Test added horizontal space first on a line():
48
48
49 $ printf '\t hello world\ngoodbye world\n' >foo
49 $ printf '\t hello world\ngoodbye world\n' >foo
50
50
51 >>> four diffs showing added space first on the first line <<<
51 >>> four diffs showing added space first on the first line <<<
52
52
53 $ hg ndiff
53 $ hg ndiff
54 diff -r 540c40a65b78 foo
54 diff -r 540c40a65b78 foo
55 --- a/foo
55 --- a/foo
56 +++ b/foo
56 +++ b/foo
57 @@ -1,2 +1,2 @@
57 @@ -1,2 +1,2 @@
58 -hello world
58 -hello world
59 + hello world
59 + hello world
60 goodbye world
60 goodbye world
61
61
62 $ hg ndiff -b
62 $ hg ndiff -b
63 diff -r 540c40a65b78 foo
63 diff -r 540c40a65b78 foo
64 --- a/foo
64 --- a/foo
65 +++ b/foo
65 +++ b/foo
66 @@ -1,2 +1,2 @@
66 @@ -1,2 +1,2 @@
67 -hello world
67 -hello world
68 + hello world
68 + hello world
69 goodbye world
69 goodbye world
70
70
71 $ hg ndiff -B
71 $ hg ndiff -B
72 diff -r 540c40a65b78 foo
72 diff -r 540c40a65b78 foo
73 --- a/foo
73 --- a/foo
74 +++ b/foo
74 +++ b/foo
75 @@ -1,2 +1,2 @@
75 @@ -1,2 +1,2 @@
76 -hello world
76 -hello world
77 + hello world
77 + hello world
78 goodbye world
78 goodbye world
79
79
80 $ hg ndiff -Bb
80 $ hg ndiff -Bb
81 diff -r 540c40a65b78 foo
81 diff -r 540c40a65b78 foo
82 --- a/foo
82 --- a/foo
83 +++ b/foo
83 +++ b/foo
84 @@ -1,2 +1,2 @@
84 @@ -1,2 +1,2 @@
85 -hello world
85 -hello world
86 + hello world
86 + hello world
87 goodbye world
87 goodbye world
88
88
89
89
90 Test added horizontal space last on a line:
90 Test added horizontal space last on a line:
91
91
92 $ printf 'hello world\t \ngoodbye world\n' >foo
92 $ printf 'hello world\t \ngoodbye world\n' >foo
93
93
94 >>> two diffs showing space appended to the first line <<<
94 >>> two diffs showing space appended to the first line <<<
95
95
96 $ hg ndiff
96 $ hg ndiff
97 diff -r 540c40a65b78 foo
97 diff -r 540c40a65b78 foo
98 --- a/foo
98 --- a/foo
99 +++ b/foo
99 +++ b/foo
100 @@ -1,2 +1,2 @@
100 @@ -1,2 +1,2 @@
101 -hello world
101 -hello world
102 +hello world
102 +hello world
103 goodbye world
103 goodbye world
104
104
105 $ hg ndiff -B
105 $ hg ndiff -B
106 diff -r 540c40a65b78 foo
106 diff -r 540c40a65b78 foo
107 --- a/foo
107 --- a/foo
108 +++ b/foo
108 +++ b/foo
109 @@ -1,2 +1,2 @@
109 @@ -1,2 +1,2 @@
110 -hello world
110 -hello world
111 +hello world
111 +hello world
112 goodbye world
112 goodbye world
113
113
114 >>> no diffs <<<
114 >>> no diffs <<<
115
115
116 $ hg ndiff -b
116 $ hg ndiff -b
117 $ hg ndiff -Bb
117 $ hg ndiff -Bb
118
118
119
119
120 Test added horizontal space in the middle of a word:
120 Test added horizontal space in the middle of a word:
121
121
122 $ printf 'hello world\ngood bye world\n' >foo
122 $ printf 'hello world\ngood bye world\n' >foo
123
123
124 >>> four diffs showing space inserted into "goodbye" <<<
124 >>> four diffs showing space inserted into "goodbye" <<<
125
125
126 $ hg ndiff
126 $ hg ndiff
127 diff -r 540c40a65b78 foo
127 diff -r 540c40a65b78 foo
128 --- a/foo
128 --- a/foo
129 +++ b/foo
129 +++ b/foo
130 @@ -1,2 +1,2 @@
130 @@ -1,2 +1,2 @@
131 hello world
131 hello world
132 -goodbye world
132 -goodbye world
133 +good bye world
133 +good bye world
134
134
135 $ hg ndiff -B
135 $ hg ndiff -B
136 diff -r 540c40a65b78 foo
136 diff -r 540c40a65b78 foo
137 --- a/foo
137 --- a/foo
138 +++ b/foo
138 +++ b/foo
139 @@ -1,2 +1,2 @@
139 @@ -1,2 +1,2 @@
140 hello world
140 hello world
141 -goodbye world
141 -goodbye world
142 +good bye world
142 +good bye world
143
143
144 $ hg ndiff -b
144 $ hg ndiff -b
145 diff -r 540c40a65b78 foo
145 diff -r 540c40a65b78 foo
146 --- a/foo
146 --- a/foo
147 +++ b/foo
147 +++ b/foo
148 @@ -1,2 +1,2 @@
148 @@ -1,2 +1,2 @@
149 hello world
149 hello world
150 -goodbye world
150 -goodbye world
151 +good bye world
151 +good bye world
152
152
153 $ hg ndiff -Bb
153 $ hg ndiff -Bb
154 diff -r 540c40a65b78 foo
154 diff -r 540c40a65b78 foo
155 --- a/foo
155 --- a/foo
156 +++ b/foo
156 +++ b/foo
157 @@ -1,2 +1,2 @@
157 @@ -1,2 +1,2 @@
158 hello world
158 hello world
159 -goodbye world
159 -goodbye world
160 +good bye world
160 +good bye world
161
161
162
162
163 Test increased horizontal whitespace amount:
163 Test increased horizontal whitespace amount:
164
164
165 $ printf 'hello world\ngoodbye\t\t \tworld\n' >foo
165 $ printf 'hello world\ngoodbye\t\t \tworld\n' >foo
166
166
167 >>> two diffs showing changed whitespace amount in the last line <<<
167 >>> two diffs showing changed whitespace amount in the last line <<<
168
168
169 $ hg ndiff
169 $ hg ndiff
170 diff -r 540c40a65b78 foo
170 diff -r 540c40a65b78 foo
171 --- a/foo
171 --- a/foo
172 +++ b/foo
172 +++ b/foo
173 @@ -1,2 +1,2 @@
173 @@ -1,2 +1,2 @@
174 hello world
174 hello world
175 -goodbye world
175 -goodbye world
176 +goodbye world
176 +goodbye world
177
177
178 $ hg ndiff -B
178 $ hg ndiff -B
179 diff -r 540c40a65b78 foo
179 diff -r 540c40a65b78 foo
180 --- a/foo
180 --- a/foo
181 +++ b/foo
181 +++ b/foo
182 @@ -1,2 +1,2 @@
182 @@ -1,2 +1,2 @@
183 hello world
183 hello world
184 -goodbye world
184 -goodbye world
185 +goodbye world
185 +goodbye world
186
186
187 >>> no diffs <<<
187 >>> no diffs <<<
188
188
189 $ hg ndiff -b
189 $ hg ndiff -b
190 $ hg ndiff -Bb
190 $ hg ndiff -Bb
191
191
192
192
193 Test added blank line with horizontal whitespace:
193 Test added blank line with horizontal whitespace:
194
194
195 $ printf 'hello world\n \t\ngoodbye world\n' >foo
195 $ printf 'hello world\n \t\ngoodbye world\n' >foo
196
196
197 >>> three diffs showing added blank line with horizontal space <<<
197 >>> three diffs showing added blank line with horizontal space <<<
198
198
199 $ hg ndiff
199 $ hg ndiff
200 diff -r 540c40a65b78 foo
200 diff -r 540c40a65b78 foo
201 --- a/foo
201 --- a/foo
202 +++ b/foo
202 +++ b/foo
203 @@ -1,2 +1,3 @@
203 @@ -1,2 +1,3 @@
204 hello world
204 hello world
205 +
205 +
206 goodbye world
206 goodbye world
207
207
208 $ hg ndiff -B
208 $ hg ndiff -B
209 diff -r 540c40a65b78 foo
209 diff -r 540c40a65b78 foo
210 --- a/foo
210 --- a/foo
211 +++ b/foo
211 +++ b/foo
212 @@ -1,2 +1,3 @@
212 @@ -1,2 +1,3 @@
213 hello world
213 hello world
214 +
214 +
215 goodbye world
215 goodbye world
216
216
217 $ hg ndiff -b
217 $ hg ndiff -b
218 diff -r 540c40a65b78 foo
218 diff -r 540c40a65b78 foo
219 --- a/foo
219 --- a/foo
220 +++ b/foo
220 +++ b/foo
221 @@ -1,2 +1,3 @@
221 @@ -1,2 +1,3 @@
222 hello world
222 hello world
223 +
223 +
224 goodbye world
224 goodbye world
225
225
226 >>> no diffs <<<
226 >>> no diffs <<<
227
227
228 $ hg ndiff -Bb
228 $ hg ndiff -Bb
229
229
230
230
231 Test added blank line with other whitespace:
231 Test added blank line with other whitespace:
232
232
233 $ printf 'hello world\n \t\ngoodbye world \n' >foo
233 $ printf 'hello world\n \t\ngoodbye world \n' >foo
234
234
235 >>> three diffs showing added blank line with other space <<<
235 >>> three diffs showing added blank line with other space <<<
236
236
237 $ hg ndiff
237 $ hg ndiff
238 diff -r 540c40a65b78 foo
238 diff -r 540c40a65b78 foo
239 --- a/foo
239 --- a/foo
240 +++ b/foo
240 +++ b/foo
241 @@ -1,2 +1,3 @@
241 @@ -1,2 +1,3 @@
242 -hello world
242 -hello world
243 -goodbye world
243 -goodbye world
244 +hello world
244 +hello world
245 +
245 +
246 +goodbye world
246 +goodbye world
247
247
248 $ hg ndiff -B
248 $ hg ndiff -B
249 diff -r 540c40a65b78 foo
249 diff -r 540c40a65b78 foo
250 --- a/foo
250 --- a/foo
251 +++ b/foo
251 +++ b/foo
252 @@ -1,2 +1,3 @@
252 @@ -1,2 +1,3 @@
253 -hello world
253 -hello world
254 -goodbye world
254 -goodbye world
255 +hello world
255 +hello world
256 +
256 +
257 +goodbye world
257 +goodbye world
258
258
259 $ hg ndiff -b
259 $ hg ndiff -b
260 diff -r 540c40a65b78 foo
260 diff -r 540c40a65b78 foo
261 --- a/foo
261 --- a/foo
262 +++ b/foo
262 +++ b/foo
263 @@ -1,2 +1,3 @@
263 @@ -1,2 +1,3 @@
264 hello world
264 hello world
265 +
265 +
266 goodbye world
266 goodbye world
267
267
268 >>> no diffs <<<
268 >>> no diffs <<<
269
269
270 $ hg ndiff -Bb
270 $ hg ndiff -Bb
271
271
272
272
273 Test whitespace changes:
273 Test whitespace changes:
274
274
275 $ printf 'helloworld\ngoodbye\tworld \n' >foo
275 $ printf 'helloworld\ngoodbye\tworld \n' >foo
276
276
277 >>> four diffs showing changed whitespace <<<
277 >>> four diffs showing changed whitespace <<<
278
278
279 $ hg ndiff
279 $ hg ndiff
280 diff -r 540c40a65b78 foo
280 diff -r 540c40a65b78 foo
281 --- a/foo
281 --- a/foo
282 +++ b/foo
282 +++ b/foo
283 @@ -1,2 +1,2 @@
283 @@ -1,2 +1,2 @@
284 -hello world
284 -hello world
285 -goodbye world
285 -goodbye world
286 +helloworld
286 +helloworld
287 +goodbye world
287 +goodbye world
288
288
289 $ hg ndiff -B
289 $ hg ndiff -B
290 diff -r 540c40a65b78 foo
290 diff -r 540c40a65b78 foo
291 --- a/foo
291 --- a/foo
292 +++ b/foo
292 +++ b/foo
293 @@ -1,2 +1,2 @@
293 @@ -1,2 +1,2 @@
294 -hello world
294 -hello world
295 -goodbye world
295 -goodbye world
296 +helloworld
296 +helloworld
297 +goodbye world
297 +goodbye world
298
298
299 $ hg ndiff -b
299 $ hg ndiff -b
300 diff -r 540c40a65b78 foo
300 diff -r 540c40a65b78 foo
301 --- a/foo
301 --- a/foo
302 +++ b/foo
302 +++ b/foo
303 @@ -1,2 +1,2 @@
303 @@ -1,2 +1,2 @@
304 -hello world
304 -hello world
305 +helloworld
305 +helloworld
306 goodbye world
306 goodbye world
307
307
308 $ hg ndiff -Bb
308 $ hg ndiff -Bb
309 diff -r 540c40a65b78 foo
309 diff -r 540c40a65b78 foo
310 --- a/foo
310 --- a/foo
311 +++ b/foo
311 +++ b/foo
312 @@ -1,2 +1,2 @@
312 @@ -1,2 +1,2 @@
313 -hello world
313 -hello world
314 +helloworld
314 +helloworld
315 goodbye world
315 goodbye world
316
316
317 >>> no diffs <<<
317 >>> no diffs <<<
318
318
319 $ hg ndiff -w
319 $ hg ndiff -w
320
320
321
321
322 Test whitespace changes and blank lines:
322 Test whitespace changes and blank lines:
323
323
324 $ printf 'helloworld\n\n\n\ngoodbye\tworld \n' >foo
324 $ printf 'helloworld\n\n\n\ngoodbye\tworld \n' >foo
325
325
326 >>> five diffs showing changed whitespace <<<
326 >>> five diffs showing changed whitespace <<<
327
327
328 $ hg ndiff
328 $ hg ndiff
329 diff -r 540c40a65b78 foo
329 diff -r 540c40a65b78 foo
330 --- a/foo
330 --- a/foo
331 +++ b/foo
331 +++ b/foo
332 @@ -1,2 +1,5 @@
332 @@ -1,2 +1,5 @@
333 -hello world
333 -hello world
334 -goodbye world
334 -goodbye world
335 +helloworld
335 +helloworld
336 +
336 +
337 +
337 +
338 +
338 +
339 +goodbye world
339 +goodbye world
340
340
341 $ hg ndiff -B
341 $ hg ndiff -B
342 diff -r 540c40a65b78 foo
342 diff -r 540c40a65b78 foo
343 --- a/foo
343 --- a/foo
344 +++ b/foo
344 +++ b/foo
345 @@ -1,2 +1,5 @@
345 @@ -1,2 +1,5 @@
346 -hello world
346 -hello world
347 -goodbye world
347 -goodbye world
348 +helloworld
348 +helloworld
349 +
349 +
350 +
350 +
351 +
351 +
352 +goodbye world
352 +goodbye world
353
353
354 $ hg ndiff -b
354 $ hg ndiff -b
355 diff -r 540c40a65b78 foo
355 diff -r 540c40a65b78 foo
356 --- a/foo
356 --- a/foo
357 +++ b/foo
357 +++ b/foo
358 @@ -1,2 +1,5 @@
358 @@ -1,2 +1,5 @@
359 -hello world
359 -hello world
360 +helloworld
360 +helloworld
361 +
361 +
362 +
362 +
363 +
363 +
364 goodbye world
364 goodbye world
365
365
366 $ hg ndiff -Bb
366 $ hg ndiff -Bb
367 diff -r 540c40a65b78 foo
367 diff -r 540c40a65b78 foo
368 --- a/foo
368 --- a/foo
369 +++ b/foo
369 +++ b/foo
370 @@ -1,2 +1,5 @@
370 @@ -1,2 +1,5 @@
371 -hello world
371 -hello world
372 +helloworld
372 +helloworld
373 +
373 +
374 +
374 +
375 +
375 +
376 goodbye world
376 goodbye world
377
377
378 $ hg ndiff -w
378 $ hg ndiff -w
379 diff -r 540c40a65b78 foo
379 diff -r 540c40a65b78 foo
380 --- a/foo
380 --- a/foo
381 +++ b/foo
381 +++ b/foo
382 @@ -1,2 +1,5 @@
382 @@ -1,2 +1,5 @@
383 hello world
383 hello world
384 +
384 +
385 +
385 +
386 +
386 +
387 goodbye world
387 goodbye world
388
388
389 >>> no diffs <<<
389 >>> no diffs <<<
390
390
391 $ hg ndiff -wB
391 $ hg ndiff -wB
392
392
393
394 Test \r (carriage return) as used in "DOS" line endings:
395
396 $ printf 'hello world\r\n\r\ngoodbye\rworld\n' >foo
397
398 $ hg ndiff
399 diff -r 540c40a65b78 foo
400 --- a/foo
401 +++ b/foo
402 @@ -1,2 +1,3 @@
403 -hello world
404 -goodbye world
405 +hello world
406 +
407 +goodbye
408 world
409 world
410
411 No completely blank lines to ignore:
412
413 $ hg ndiff --ignore-blank-lines
414 diff -r 540c40a65b78 foo
415 --- a/foo
416 +++ b/foo
417 @@ -1,2 +1,3 @@
418 -hello world
419 -goodbye world
420 +hello world
421 +
422 +goodbye
423 world
424 world
425
426 Only new line noticed:
427
428 $ hg ndiff --ignore-space-change
429 diff -r 540c40a65b78 foo
430 --- a/foo
431 +++ b/foo
432 @@ -1,2 +1,3 @@
433 hello world
434 +
435 goodbye world
436
437 $ hg ndiff --ignore-all-space
438 diff -r 540c40a65b78 foo
439 --- a/foo
440 +++ b/foo
441 @@ -1,2 +1,3 @@
442 hello world
443 +
444 goodbye world
445
446 New line not noticed when space change ignored:
General Comments 0
You need to be logged in to leave comments. Login now