Show More
@@ -1,333 +1,342 b'' | |||||
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 = bdiff.fixws(text, 1) |
|
70 | text = bdiff.fixws(text, 1) | |
71 | elif opts.ignorewsamount: |
|
71 | elif opts.ignorewsamount: | |
72 | text = bdiff.fixws(text, 0) |
|
72 | text = bdiff.fixws(text, 0) | |
73 | if blank and opts.ignoreblanklines: |
|
73 | if blank and opts.ignoreblanklines: | |
74 | text = re.sub('\n+', '\n', text).strip('\n') |
|
74 | text = re.sub('\n+', '\n', text).strip('\n') | |
75 | return text |
|
75 | return text | |
76 |
|
76 | |||
77 | def splitblock(base1, lines1, base2, lines2, opts): |
|
77 | def splitblock(base1, lines1, base2, lines2, opts): | |
78 | # The input lines matches except for interwoven blank lines. We |
|
78 | # The input lines matches except for interwoven blank lines. We | |
79 | # transform it into a sequence of matching blocks and blank blocks. |
|
79 | # transform it into a sequence of matching blocks and blank blocks. | |
80 | lines1 = [(wsclean(opts, l) and 1 or 0) for l in lines1] |
|
80 | lines1 = [(wsclean(opts, l) and 1 or 0) for l in lines1] | |
81 | lines2 = [(wsclean(opts, l) and 1 or 0) for l in lines2] |
|
81 | lines2 = [(wsclean(opts, l) and 1 or 0) for l in lines2] | |
82 | s1, e1 = 0, len(lines1) |
|
82 | s1, e1 = 0, len(lines1) | |
83 | s2, e2 = 0, len(lines2) |
|
83 | s2, e2 = 0, len(lines2) | |
84 | while s1 < e1 or s2 < e2: |
|
84 | while s1 < e1 or s2 < e2: | |
85 | i1, i2, btype = s1, s2, '=' |
|
85 | i1, i2, btype = s1, s2, '=' | |
86 | if (i1 >= e1 or lines1[i1] == 0 |
|
86 | if (i1 >= e1 or lines1[i1] == 0 | |
87 | or i2 >= e2 or lines2[i2] == 0): |
|
87 | or i2 >= e2 or lines2[i2] == 0): | |
88 | # Consume the block of blank lines |
|
88 | # Consume the block of blank lines | |
89 | btype = '~' |
|
89 | btype = '~' | |
90 | while i1 < e1 and lines1[i1] == 0: |
|
90 | while i1 < e1 and lines1[i1] == 0: | |
91 | i1 += 1 |
|
91 | i1 += 1 | |
92 | while i2 < e2 and lines2[i2] == 0: |
|
92 | while i2 < e2 and lines2[i2] == 0: | |
93 | i2 += 1 |
|
93 | i2 += 1 | |
94 | else: |
|
94 | else: | |
95 | # Consume the matching lines |
|
95 | # Consume the matching lines | |
96 | while i1 < e1 and lines1[i1] == 1 and lines2[i2] == 1: |
|
96 | while i1 < e1 and lines1[i1] == 1 and lines2[i2] == 1: | |
97 | i1 += 1 |
|
97 | i1 += 1 | |
98 | i2 += 1 |
|
98 | i2 += 1 | |
99 | yield [base1 + s1, base1 + i1, base2 + s2, base2 + i2], btype |
|
99 | yield [base1 + s1, base1 + i1, base2 + s2, base2 + i2], btype | |
100 | s1 = i1 |
|
100 | s1 = i1 | |
101 | s2 = i2 |
|
101 | s2 = i2 | |
102 |
|
102 | |||
103 | def allblocks(text1, text2, opts=None, lines1=None, lines2=None, refine=False): |
|
103 | def allblocks(text1, text2, opts=None, lines1=None, lines2=None, refine=False): | |
104 | """Return (block, type) tuples, where block is an mdiff.blocks |
|
104 | """Return (block, type) tuples, where block is an mdiff.blocks | |
105 | line entry. type is '=' for blocks matching exactly one another |
|
105 | line entry. type is '=' for blocks matching exactly one another | |
106 | (bdiff blocks), '!' for non-matching blocks and '~' for blocks |
|
106 | (bdiff blocks), '!' for non-matching blocks and '~' for blocks | |
107 | matching only after having filtered blank lines. If refine is True, |
|
107 | matching only after having filtered blank lines. If refine is True, | |
108 | then '~' blocks are refined and are only made of blank lines. |
|
108 | then '~' blocks are refined and are only made of blank lines. | |
109 | line1 and line2 are text1 and text2 split with splitnewlines() if |
|
109 | line1 and line2 are text1 and text2 split with splitnewlines() if | |
110 | they are already available. |
|
110 | they are already available. | |
111 | """ |
|
111 | """ | |
112 | if opts is None: |
|
112 | if opts is None: | |
113 | opts = defaultopts |
|
113 | opts = defaultopts | |
114 | if opts.ignorews or opts.ignorewsamount: |
|
114 | if opts.ignorews or opts.ignorewsamount: | |
115 | text1 = wsclean(opts, text1, False) |
|
115 | text1 = wsclean(opts, text1, False) | |
116 | text2 = wsclean(opts, text2, False) |
|
116 | text2 = wsclean(opts, text2, False) | |
117 | diff = bdiff.blocks(text1, text2) |
|
117 | diff = bdiff.blocks(text1, text2) | |
118 | for i, s1 in enumerate(diff): |
|
118 | for i, s1 in enumerate(diff): | |
119 | # The first match is special. |
|
119 | # The first match is special. | |
120 | # we've either found a match starting at line 0 or a match later |
|
120 | # we've either found a match starting at line 0 or a match later | |
121 | # in the file. If it starts later, old and new below will both be |
|
121 | # in the file. If it starts later, old and new below will both be | |
122 | # empty and we'll continue to the next match. |
|
122 | # empty and we'll continue to the next match. | |
123 | if i > 0: |
|
123 | if i > 0: | |
124 | s = diff[i - 1] |
|
124 | s = diff[i - 1] | |
125 | else: |
|
125 | else: | |
126 | s = [0, 0, 0, 0] |
|
126 | s = [0, 0, 0, 0] | |
127 | s = [s[1], s1[0], s[3], s1[2]] |
|
127 | s = [s[1], s1[0], s[3], s1[2]] | |
128 |
|
128 | |||
129 | # bdiff sometimes gives huge matches past eof, this check eats them, |
|
129 | # bdiff sometimes gives huge matches past eof, this check eats them, | |
130 | # and deals with the special first match case described above |
|
130 | # and deals with the special first match case described above | |
131 | if s[0] != s[1] or s[2] != s[3]: |
|
131 | if s[0] != s[1] or s[2] != s[3]: | |
132 | type = '!' |
|
132 | type = '!' | |
133 | if opts.ignoreblanklines: |
|
133 | if opts.ignoreblanklines: | |
134 | if lines1 is None: |
|
134 | if lines1 is None: | |
135 | lines1 = splitnewlines(text1) |
|
135 | lines1 = splitnewlines(text1) | |
136 | if lines2 is None: |
|
136 | if lines2 is None: | |
137 | lines2 = splitnewlines(text2) |
|
137 | lines2 = splitnewlines(text2) | |
138 | old = wsclean(opts, "".join(lines1[s[0]:s[1]])) |
|
138 | old = wsclean(opts, "".join(lines1[s[0]:s[1]])) | |
139 | new = wsclean(opts, "".join(lines2[s[2]:s[3]])) |
|
139 | new = wsclean(opts, "".join(lines2[s[2]:s[3]])) | |
140 | if old == new: |
|
140 | if old == new: | |
141 | type = '~' |
|
141 | type = '~' | |
142 | yield s, type |
|
142 | yield s, type | |
143 | yield s1, '=' |
|
143 | yield s1, '=' | |
144 |
|
144 | |||
145 | def diffline(revs, a, b, opts): |
|
145 | def diffline(revs, a, b, opts): | |
146 | parts = ['diff'] |
|
146 | parts = ['diff'] | |
147 | if opts.git: |
|
147 | if opts.git: | |
148 | parts.append('--git') |
|
148 | parts.append('--git') | |
149 | if revs and not opts.git: |
|
149 | if revs and not opts.git: | |
150 | parts.append(' '.join(["-r %s" % rev for rev in revs])) |
|
150 | parts.append(' '.join(["-r %s" % rev for rev in revs])) | |
151 | if opts.git: |
|
151 | if opts.git: | |
152 | parts.append('a/%s' % a) |
|
152 | parts.append('a/%s' % a) | |
153 | parts.append('b/%s' % b) |
|
153 | parts.append('b/%s' % b) | |
154 | else: |
|
154 | else: | |
155 | parts.append(a) |
|
155 | parts.append(a) | |
156 | return ' '.join(parts) + '\n' |
|
156 | return ' '.join(parts) + '\n' | |
157 |
|
157 | |||
158 | def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts): |
|
158 | def unidiff(a, ad, b, bd, fn1, fn2, r=None, opts=defaultopts): | |
159 | def datetag(date, addtab=True): |
|
159 | def datetag(date, addtab=True): | |
160 | if not opts.git and not opts.nodates: |
|
160 | if not opts.git and not opts.nodates: | |
161 | return '\t%s\n' % date |
|
161 | return '\t%s\n' % date | |
162 | if addtab and ' ' in fn1: |
|
162 | if addtab and ' ' in fn1: | |
163 | return '\t\n' |
|
163 | return '\t\n' | |
164 | return '\n' |
|
164 | return '\n' | |
165 |
|
165 | |||
166 | if not a and not b: |
|
166 | if not a and not b: | |
167 | return "" |
|
167 | return "" | |
168 | epoch = util.datestr((0, 0)) |
|
168 | epoch = util.datestr((0, 0)) | |
169 |
|
169 | |||
170 | fn1 = util.pconvert(fn1) |
|
170 | fn1 = util.pconvert(fn1) | |
171 | fn2 = util.pconvert(fn2) |
|
171 | fn2 = util.pconvert(fn2) | |
172 |
|
172 | |||
173 | if not opts.text and (util.binary(a) or util.binary(b)): |
|
173 | if not opts.text and (util.binary(a) or util.binary(b)): | |
174 | if a and b and len(a) == len(b) and a == b: |
|
174 | if a and b and len(a) == len(b) and a == b: | |
175 | return "" |
|
175 | return "" | |
176 | l = ['Binary file %s has changed\n' % fn1] |
|
176 | l = ['Binary file %s has changed\n' % fn1] | |
177 | elif not a: |
|
177 | elif not a: | |
178 | b = splitnewlines(b) |
|
178 | b = splitnewlines(b) | |
179 | if a is None: |
|
179 | if a is None: | |
180 | l1 = '--- /dev/null%s' % datetag(epoch, False) |
|
180 | l1 = '--- /dev/null%s' % datetag(epoch, False) | |
181 | else: |
|
181 | else: | |
182 | l1 = "--- %s%s" % ("a/" + fn1, datetag(ad)) |
|
182 | l1 = "--- %s%s" % ("a/" + fn1, datetag(ad)) | |
183 | l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd)) |
|
183 | l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd)) | |
184 | l3 = "@@ -0,0 +1,%d @@\n" % len(b) |
|
184 | l3 = "@@ -0,0 +1,%d @@\n" % len(b) | |
185 | l = [l1, l2, l3] + ["+" + e for e in b] |
|
185 | l = [l1, l2, l3] + ["+" + e for e in b] | |
186 | elif not b: |
|
186 | elif not b: | |
187 | a = splitnewlines(a) |
|
187 | a = splitnewlines(a) | |
188 | l1 = "--- %s%s" % ("a/" + fn1, datetag(ad)) |
|
188 | l1 = "--- %s%s" % ("a/" + fn1, datetag(ad)) | |
189 | if b is None: |
|
189 | if b is None: | |
190 | l2 = '+++ /dev/null%s' % datetag(epoch, False) |
|
190 | l2 = '+++ /dev/null%s' % datetag(epoch, False) | |
191 | else: |
|
191 | else: | |
192 | l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd)) |
|
192 | l2 = "+++ %s%s" % ("b/" + fn2, datetag(bd)) | |
193 | l3 = "@@ -1,%d +0,0 @@\n" % len(a) |
|
193 | l3 = "@@ -1,%d +0,0 @@\n" % len(a) | |
194 | l = [l1, l2, l3] + ["-" + e for e in a] |
|
194 | l = [l1, l2, l3] + ["-" + e for e in a] | |
195 | else: |
|
195 | else: | |
196 | al = splitnewlines(a) |
|
196 | al = splitnewlines(a) | |
197 | bl = splitnewlines(b) |
|
197 | bl = splitnewlines(b) | |
198 | l = list(_unidiff(a, b, al, bl, opts=opts)) |
|
198 | l = list(_unidiff(a, b, al, bl, opts=opts)) | |
199 | if not l: |
|
199 | if not l: | |
200 | return "" |
|
200 | return "" | |
201 |
|
201 | |||
202 | l.insert(0, "--- a/%s%s" % (fn1, datetag(ad))) |
|
202 | l.insert(0, "--- a/%s%s" % (fn1, datetag(ad))) | |
203 | l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd))) |
|
203 | l.insert(1, "+++ b/%s%s" % (fn2, datetag(bd))) | |
204 |
|
204 | |||
205 | for ln in xrange(len(l)): |
|
205 | for ln in xrange(len(l)): | |
206 | if l[ln][-1] != '\n': |
|
206 | if l[ln][-1] != '\n': | |
207 | l[ln] += "\n\ No newline at end of file\n" |
|
207 | l[ln] += "\n\ No newline at end of file\n" | |
208 |
|
208 | |||
209 | if r: |
|
209 | if r: | |
210 | l.insert(0, diffline(r, fn1, fn2, opts)) |
|
210 | l.insert(0, diffline(r, fn1, fn2, opts)) | |
211 |
|
211 | |||
212 | return "".join(l) |
|
212 | return "".join(l) | |
213 |
|
213 | |||
214 | # creates a headerless unified diff |
|
214 | # creates a headerless unified diff | |
215 | # t1 and t2 are the text to be diffed |
|
215 | # t1 and t2 are the text to be diffed | |
216 | # l1 and l2 are the text broken up into lines |
|
216 | # l1 and l2 are the text broken up into lines | |
217 | def _unidiff(t1, t2, l1, l2, opts=defaultopts): |
|
217 | def _unidiff(t1, t2, l1, l2, opts=defaultopts): | |
218 | def contextend(l, len): |
|
218 | def contextend(l, len): | |
219 | ret = l + opts.context |
|
219 | ret = l + opts.context | |
220 | if ret > len: |
|
220 | if ret > len: | |
221 | ret = len |
|
221 | ret = len | |
222 | return ret |
|
222 | return ret | |
223 |
|
223 | |||
224 | def contextstart(l): |
|
224 | def contextstart(l): | |
225 | ret = l - opts.context |
|
225 | ret = l - opts.context | |
226 | if ret < 0: |
|
226 | if ret < 0: | |
227 | return 0 |
|
227 | return 0 | |
228 | return ret |
|
228 | return ret | |
229 |
|
229 | |||
230 | lastfunc = [0, ''] |
|
230 | lastfunc = [0, ''] | |
231 | def yieldhunk(hunk): |
|
231 | def yieldhunk(hunk): | |
232 | (astart, a2, bstart, b2, delta) = hunk |
|
232 | (astart, a2, bstart, b2, delta) = hunk | |
233 | aend = contextend(a2, len(l1)) |
|
233 | aend = contextend(a2, len(l1)) | |
234 | alen = aend - astart |
|
234 | alen = aend - astart | |
235 | blen = b2 - bstart + aend - a2 |
|
235 | blen = b2 - bstart + aend - a2 | |
236 |
|
236 | |||
237 | func = "" |
|
237 | func = "" | |
238 | if opts.showfunc: |
|
238 | if opts.showfunc: | |
239 | lastpos, func = lastfunc |
|
239 | lastpos, func = lastfunc | |
240 | # walk backwards from the start of the context up to the start of |
|
240 | # walk backwards from the start of the context up to the start of | |
241 | # the previous hunk context until we find a line starting with an |
|
241 | # the previous hunk context until we find a line starting with an | |
242 | # alphanumeric char. |
|
242 | # alphanumeric char. | |
243 | for i in xrange(astart - 1, lastpos - 1, -1): |
|
243 | for i in xrange(astart - 1, lastpos - 1, -1): | |
244 | if l1[i][0].isalnum(): |
|
244 | if l1[i][0].isalnum(): | |
245 | func = ' ' + l1[i].rstrip()[:40] |
|
245 | func = ' ' + l1[i].rstrip()[:40] | |
246 | lastfunc[1] = func |
|
246 | lastfunc[1] = func | |
247 | break |
|
247 | break | |
248 | # by recording this hunk's starting point as the next place to |
|
248 | # by recording this hunk's starting point as the next place to | |
249 | # start looking for function lines, we avoid reading any line in |
|
249 | # start looking for function lines, we avoid reading any line in | |
250 | # the file more than once. |
|
250 | # the file more than once. | |
251 | lastfunc[0] = astart |
|
251 | lastfunc[0] = astart | |
252 |
|
252 | |||
253 | # zero-length hunk ranges report their start line as one less |
|
253 | # zero-length hunk ranges report their start line as one less | |
254 | if alen: |
|
254 | if alen: | |
255 | astart += 1 |
|
255 | astart += 1 | |
256 | if blen: |
|
256 | if blen: | |
257 | bstart += 1 |
|
257 | bstart += 1 | |
258 |
|
258 | |||
259 | yield "@@ -%d,%d +%d,%d @@%s\n" % (astart, alen, |
|
259 | yield "@@ -%d,%d +%d,%d @@%s\n" % (astart, alen, | |
260 | bstart, blen, func) |
|
260 | bstart, blen, func) | |
261 | for x in delta: |
|
261 | for x in delta: | |
262 | yield x |
|
262 | yield x | |
263 | for x in xrange(a2, aend): |
|
263 | for x in xrange(a2, aend): | |
264 | yield ' ' + l1[x] |
|
264 | yield ' ' + l1[x] | |
265 |
|
265 | |||
266 | # bdiff.blocks gives us the matching sequences in the files. The loop |
|
266 | # bdiff.blocks gives us the matching sequences in the files. The loop | |
267 | # below finds the spaces between those matching sequences and translates |
|
267 | # below finds the spaces between those matching sequences and translates | |
268 | # them into diff output. |
|
268 | # them into diff output. | |
269 | # |
|
269 | # | |
270 | hunk = None |
|
270 | hunk = None | |
|
271 | ignoredlines = 0 | |||
271 | for s, stype in allblocks(t1, t2, opts, l1, l2): |
|
272 | for s, stype in allblocks(t1, t2, opts, l1, l2): | |
|
273 | a1, a2, b1, b2 = s | |||
272 | if stype != '!': |
|
274 | if stype != '!': | |
|
275 | if stype == '~': | |||
|
276 | # The diff context lines are based on t1 content. When | |||
|
277 | # blank lines are ignored, the new lines offsets must | |||
|
278 | # be adjusted as if equivalent blocks ('~') had the | |||
|
279 | # same sizes on both sides. | |||
|
280 | ignoredlines += (b2 - b1) - (a2 - a1) | |||
273 | continue |
|
281 | continue | |
274 | delta = [] |
|
282 | delta = [] | |
275 | a1, a2, b1, b2 = s |
|
|||
276 | old = l1[a1:a2] |
|
283 | old = l1[a1:a2] | |
277 | new = l2[b1:b2] |
|
284 | new = l2[b1:b2] | |
278 |
|
285 | |||
|
286 | b1 -= ignoredlines | |||
|
287 | b2 -= ignoredlines | |||
279 | astart = contextstart(a1) |
|
288 | astart = contextstart(a1) | |
280 | bstart = contextstart(b1) |
|
289 | bstart = contextstart(b1) | |
281 | prev = None |
|
290 | prev = None | |
282 | if hunk: |
|
291 | if hunk: | |
283 | # join with the previous hunk if it falls inside the context |
|
292 | # join with the previous hunk if it falls inside the context | |
284 | if astart < hunk[1] + opts.context + 1: |
|
293 | if astart < hunk[1] + opts.context + 1: | |
285 | prev = hunk |
|
294 | prev = hunk | |
286 | astart = hunk[1] |
|
295 | astart = hunk[1] | |
287 | bstart = hunk[3] |
|
296 | bstart = hunk[3] | |
288 | else: |
|
297 | else: | |
289 | for x in yieldhunk(hunk): |
|
298 | for x in yieldhunk(hunk): | |
290 | yield x |
|
299 | yield x | |
291 | if prev: |
|
300 | if prev: | |
292 | # we've joined the previous hunk, record the new ending points. |
|
301 | # we've joined the previous hunk, record the new ending points. | |
293 | hunk[1] = a2 |
|
302 | hunk[1] = a2 | |
294 | hunk[3] = b2 |
|
303 | hunk[3] = b2 | |
295 | delta = hunk[4] |
|
304 | delta = hunk[4] | |
296 | else: |
|
305 | else: | |
297 | # create a new hunk |
|
306 | # create a new hunk | |
298 | hunk = [astart, a2, bstart, b2, delta] |
|
307 | hunk = [astart, a2, bstart, b2, delta] | |
299 |
|
308 | |||
300 | delta[len(delta):] = [' ' + x for x in l1[astart:a1]] |
|
309 | delta[len(delta):] = [' ' + x for x in l1[astart:a1]] | |
301 | delta[len(delta):] = ['-' + x for x in old] |
|
310 | delta[len(delta):] = ['-' + x for x in old] | |
302 | delta[len(delta):] = ['+' + x for x in new] |
|
311 | delta[len(delta):] = ['+' + x for x in new] | |
303 |
|
312 | |||
304 | if hunk: |
|
313 | if hunk: | |
305 | for x in yieldhunk(hunk): |
|
314 | for x in yieldhunk(hunk): | |
306 | yield x |
|
315 | yield x | |
307 |
|
316 | |||
308 | def patchtext(bin): |
|
317 | def patchtext(bin): | |
309 | pos = 0 |
|
318 | pos = 0 | |
310 | t = [] |
|
319 | t = [] | |
311 | while pos < len(bin): |
|
320 | while pos < len(bin): | |
312 | p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) |
|
321 | p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) | |
313 | pos += 12 |
|
322 | pos += 12 | |
314 | t.append(bin[pos:pos + l]) |
|
323 | t.append(bin[pos:pos + l]) | |
315 | pos += l |
|
324 | pos += l | |
316 | return "".join(t) |
|
325 | return "".join(t) | |
317 |
|
326 | |||
318 | def patch(a, bin): |
|
327 | def patch(a, bin): | |
319 | if len(a) == 0: |
|
328 | if len(a) == 0: | |
320 | # skip over trivial delta header |
|
329 | # skip over trivial delta header | |
321 | return util.buffer(bin, 12) |
|
330 | return util.buffer(bin, 12) | |
322 | return mpatch.patches(a, [bin]) |
|
331 | return mpatch.patches(a, [bin]) | |
323 |
|
332 | |||
324 | # similar to difflib.SequenceMatcher.get_matching_blocks |
|
333 | # similar to difflib.SequenceMatcher.get_matching_blocks | |
325 | def get_matching_blocks(a, b): |
|
334 | def get_matching_blocks(a, b): | |
326 | return [(d[0], d[2], d[1] - d[0]) for d in bdiff.blocks(a, b)] |
|
335 | return [(d[0], d[2], d[1] - d[0]) for d in bdiff.blocks(a, b)] | |
327 |
|
336 | |||
328 | def trivialdiffheader(length): |
|
337 | def trivialdiffheader(length): | |
329 | return struct.pack(">lll", 0, 0, length) |
|
338 | return struct.pack(">lll", 0, 0, length) | |
330 |
|
339 | |||
331 | patches = mpatch.patches |
|
340 | patches = mpatch.patches | |
332 | patchedsize = mpatch.patchedsize |
|
341 | patchedsize = mpatch.patchedsize | |
333 | textdiff = bdiff.bdiff |
|
342 | textdiff = bdiff.bdiff |
@@ -1,457 +1,500 b'' | |||||
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 |
|
393 | |||
394 | Test \r (carriage return) as used in "DOS" line endings: |
|
394 | Test \r (carriage return) as used in "DOS" line endings: | |
395 |
|
395 | |||
396 | $ printf 'hello world\r\n\r\ngoodbye\rworld\n' >foo |
|
396 | $ printf 'hello world\r\n\r\ngoodbye\rworld\n' >foo | |
397 |
|
397 | |||
398 | $ hg ndiff |
|
398 | $ hg ndiff | |
399 | diff -r 540c40a65b78 foo |
|
399 | diff -r 540c40a65b78 foo | |
400 | --- a/foo |
|
400 | --- a/foo | |
401 | +++ b/foo |
|
401 | +++ b/foo | |
402 | @@ -1,2 +1,3 @@ |
|
402 | @@ -1,2 +1,3 @@ | |
403 | -hello world |
|
403 | -hello world | |
404 | -goodbye world |
|
404 | -goodbye world | |
405 | +hello world\r (esc) |
|
405 | +hello world\r (esc) | |
406 | +\r (esc) |
|
406 | +\r (esc) | |
407 | +goodbye\rworld (esc) |
|
407 | +goodbye\rworld (esc) | |
408 |
|
408 | |||
409 | No completely blank lines to ignore: |
|
409 | No completely blank lines to ignore: | |
410 |
|
410 | |||
411 | $ hg ndiff --ignore-blank-lines |
|
411 | $ hg ndiff --ignore-blank-lines | |
412 | diff -r 540c40a65b78 foo |
|
412 | diff -r 540c40a65b78 foo | |
413 | --- a/foo |
|
413 | --- a/foo | |
414 | +++ b/foo |
|
414 | +++ b/foo | |
415 | @@ -1,2 +1,3 @@ |
|
415 | @@ -1,2 +1,3 @@ | |
416 | -hello world |
|
416 | -hello world | |
417 | -goodbye world |
|
417 | -goodbye world | |
418 | +hello world\r (esc) |
|
418 | +hello world\r (esc) | |
419 | +\r (esc) |
|
419 | +\r (esc) | |
420 | +goodbye\rworld (esc) |
|
420 | +goodbye\rworld (esc) | |
421 |
|
421 | |||
422 | Only new line noticed: |
|
422 | Only new line noticed: | |
423 |
|
423 | |||
424 | $ hg ndiff --ignore-space-change |
|
424 | $ hg ndiff --ignore-space-change | |
425 | diff -r 540c40a65b78 foo |
|
425 | diff -r 540c40a65b78 foo | |
426 | --- a/foo |
|
426 | --- a/foo | |
427 | +++ b/foo |
|
427 | +++ b/foo | |
428 | @@ -1,2 +1,3 @@ |
|
428 | @@ -1,2 +1,3 @@ | |
429 | hello world |
|
429 | hello world | |
430 | +\r (esc) |
|
430 | +\r (esc) | |
431 | goodbye world |
|
431 | goodbye world | |
432 |
|
432 | |||
433 | $ hg ndiff --ignore-all-space |
|
433 | $ hg ndiff --ignore-all-space | |
434 | diff -r 540c40a65b78 foo |
|
434 | diff -r 540c40a65b78 foo | |
435 | --- a/foo |
|
435 | --- a/foo | |
436 | +++ b/foo |
|
436 | +++ b/foo | |
437 | @@ -1,2 +1,3 @@ |
|
437 | @@ -1,2 +1,3 @@ | |
438 | hello world |
|
438 | hello world | |
439 | +\r (esc) |
|
439 | +\r (esc) | |
440 | goodbye world |
|
440 | goodbye world | |
441 |
|
441 | |||
442 | New line not noticed when space change ignored: |
|
442 | New line not noticed when space change ignored: | |
443 |
|
443 | |||
444 | $ hg ndiff --ignore-blank-lines --ignore-all-space |
|
444 | $ hg ndiff --ignore-blank-lines --ignore-all-space | |
445 |
|
445 | |||
446 | Do not ignore all newlines, only blank lines |
|
446 | Do not ignore all newlines, only blank lines | |
447 |
|
447 | |||
448 | $ printf 'hello \nworld\ngoodbye world\n' > foo |
|
448 | $ printf 'hello \nworld\ngoodbye world\n' > foo | |
449 | $ hg ndiff --ignore-blank-lines |
|
449 | $ hg ndiff --ignore-blank-lines | |
450 | diff -r 540c40a65b78 foo |
|
450 | diff -r 540c40a65b78 foo | |
451 | --- a/foo |
|
451 | --- a/foo | |
452 | +++ b/foo |
|
452 | +++ b/foo | |
453 | @@ -1,2 +1,3 @@ |
|
453 | @@ -1,2 +1,3 @@ | |
454 | -hello world |
|
454 | -hello world | |
455 | +hello |
|
455 | +hello | |
456 | +world |
|
456 | +world | |
457 | goodbye world |
|
457 | goodbye world | |
|
458 | ||||
|
459 | Test hunk offsets adjustments with --ignore-blank-lines | |||
|
460 | ||||
|
461 | $ hg revert -aC | |||
|
462 | reverting foo | |||
|
463 | $ printf '\nb\nx\nd\n' > a | |||
|
464 | $ printf 'b\ny\nd\n' > b | |||
|
465 | $ hg add a b | |||
|
466 | $ hg ci -m add | |||
|
467 | $ hg cat -r . a > b | |||
|
468 | $ hg cat -r . b > a | |||
|
469 | $ hg diff -B --nodates a > ../diffa | |||
|
470 | $ cat ../diffa | |||
|
471 | diff -r 0e66aa54f318 a | |||
|
472 | --- a/a | |||
|
473 | +++ b/a | |||
|
474 | @@ -1,4 +1,4 @@ | |||
|
475 | ||||
|
476 | b | |||
|
477 | -x | |||
|
478 | +y | |||
|
479 | d | |||
|
480 | $ hg diff -B --nodates b > ../diffb | |||
|
481 | $ cat ../diffb | |||
|
482 | diff -r 0e66aa54f318 b | |||
|
483 | --- a/b | |||
|
484 | +++ b/b | |||
|
485 | @@ -1,3 +1,3 @@ | |||
|
486 | b | |||
|
487 | -y | |||
|
488 | +x | |||
|
489 | d | |||
|
490 | $ hg revert -aC | |||
|
491 | reverting a | |||
|
492 | reverting b | |||
|
493 | $ hg import --no-commit ../diffa | |||
|
494 | applying ../diffa | |||
|
495 | $ hg revert -aC | |||
|
496 | reverting a | |||
|
497 | $ hg import --no-commit ../diffb | |||
|
498 | applying ../diffb | |||
|
499 | $ hg revert -aC | |||
|
500 | reverting b |
@@ -1,175 +1,175 b'' | |||||
1 | $ echo "[extensions]" >> $HGRCPATH |
|
1 | $ echo "[extensions]" >> $HGRCPATH | |
2 | $ echo "mq=" >> $HGRCPATH |
|
2 | $ echo "mq=" >> $HGRCPATH | |
3 | $ echo "[mq]" >> $HGRCPATH |
|
3 | $ echo "[mq]" >> $HGRCPATH | |
4 | $ echo "git=keep" >> $HGRCPATH |
|
4 | $ echo "git=keep" >> $HGRCPATH | |
5 |
|
5 | |||
6 | $ hg init a |
|
6 | $ hg init a | |
7 | $ cd a |
|
7 | $ cd a | |
8 |
|
8 | |||
9 | $ echo 'base' > base |
|
9 | $ echo 'base' > base | |
10 | $ hg ci -Ambase |
|
10 | $ hg ci -Ambase | |
11 | adding base |
|
11 | adding base | |
12 |
|
12 | |||
13 | $ hg qnew -mmqbase mqbase |
|
13 | $ hg qnew -mmqbase mqbase | |
14 |
|
14 | |||
15 | $ echo 'patched' > base |
|
15 | $ echo 'patched' > base | |
16 | $ hg qrefresh |
|
16 | $ hg qrefresh | |
17 |
|
17 | |||
18 | qdiff: |
|
18 | qdiff: | |
19 |
|
19 | |||
20 | $ hg qdiff |
|
20 | $ hg qdiff | |
21 | diff -r d20a80d4def3 base |
|
21 | diff -r d20a80d4def3 base | |
22 | --- a/base Thu Jan 01 00:00:00 1970 +0000 |
|
22 | --- a/base Thu Jan 01 00:00:00 1970 +0000 | |
23 | +++ b/base* (glob) |
|
23 | +++ b/base* (glob) | |
24 | @@ -1,1 +1,1 @@ |
|
24 | @@ -1,1 +1,1 @@ | |
25 | -base |
|
25 | -base | |
26 | +patched |
|
26 | +patched | |
27 |
|
27 | |||
28 | qdiff dirname: |
|
28 | qdiff dirname: | |
29 |
|
29 | |||
30 | $ hg qdiff --nodates . |
|
30 | $ hg qdiff --nodates . | |
31 | diff -r d20a80d4def3 base |
|
31 | diff -r d20a80d4def3 base | |
32 | --- a/base |
|
32 | --- a/base | |
33 | +++ b/base |
|
33 | +++ b/base | |
34 | @@ -1,1 +1,1 @@ |
|
34 | @@ -1,1 +1,1 @@ | |
35 | -base |
|
35 | -base | |
36 | +patched |
|
36 | +patched | |
37 |
|
37 | |||
38 | qdiff filename: |
|
38 | qdiff filename: | |
39 |
|
39 | |||
40 | $ hg qdiff --nodates base |
|
40 | $ hg qdiff --nodates base | |
41 | diff -r d20a80d4def3 base |
|
41 | diff -r d20a80d4def3 base | |
42 | --- a/base |
|
42 | --- a/base | |
43 | +++ b/base |
|
43 | +++ b/base | |
44 | @@ -1,1 +1,1 @@ |
|
44 | @@ -1,1 +1,1 @@ | |
45 | -base |
|
45 | -base | |
46 | +patched |
|
46 | +patched | |
47 |
|
47 | |||
48 | $ hg revert -a |
|
48 | $ hg revert -a | |
49 |
|
49 | |||
50 | $ hg qpop |
|
50 | $ hg qpop | |
51 | popping mqbase |
|
51 | popping mqbase | |
52 | patch queue now empty |
|
52 | patch queue now empty | |
53 |
|
53 | |||
54 | $ hg qdelete mqbase |
|
54 | $ hg qdelete mqbase | |
55 |
|
55 | |||
56 | $ printf '1\n2\n3\n4\nhello world\ngoodbye world\n7\n8\n9\n' > lines |
|
56 | $ printf '1\n2\n3\n4\nhello world\ngoodbye world\n7\n8\n9\n' > lines | |
57 | $ hg ci -Amlines -d '2 0' |
|
57 | $ hg ci -Amlines -d '2 0' | |
58 | adding lines |
|
58 | adding lines | |
59 |
|
59 | |||
60 | $ hg qnew -mmqbase2 mqbase2 |
|
60 | $ hg qnew -mmqbase2 mqbase2 | |
61 | $ printf '\n\n1\n2\n3\n4\nhello world\n goodbye world\n7\n8\n9\n' > lines |
|
61 | $ printf '\n\n1\n2\n3\n4\nhello world\n goodbye world\n7\n8\n9\n' > lines | |
62 |
|
62 | |||
63 | $ hg qdiff --nodates -U 1 |
|
63 | $ hg qdiff --nodates -U 1 | |
64 | diff -r b0c220e1cf43 lines |
|
64 | diff -r b0c220e1cf43 lines | |
65 | --- a/lines |
|
65 | --- a/lines | |
66 | +++ b/lines |
|
66 | +++ b/lines | |
67 | @@ -1,1 +1,3 @@ |
|
67 | @@ -1,1 +1,3 @@ | |
68 | + |
|
68 | + | |
69 | + |
|
69 | + | |
70 | 1 |
|
70 | 1 | |
71 | @@ -4,4 +6,4 @@ |
|
71 | @@ -4,4 +6,4 @@ | |
72 | 4 |
|
72 | 4 | |
73 | -hello world |
|
73 | -hello world | |
74 | -goodbye world |
|
74 | -goodbye world | |
75 | +hello world |
|
75 | +hello world | |
76 | + goodbye world |
|
76 | + goodbye world | |
77 | 7 |
|
77 | 7 | |
78 |
|
78 | |||
79 | $ hg qdiff --nodates -b |
|
79 | $ hg qdiff --nodates -b | |
80 | diff -r b0c220e1cf43 lines |
|
80 | diff -r b0c220e1cf43 lines | |
81 | --- a/lines |
|
81 | --- a/lines | |
82 | +++ b/lines |
|
82 | +++ b/lines | |
83 | @@ -1,9 +1,11 @@ |
|
83 | @@ -1,9 +1,11 @@ | |
84 | + |
|
84 | + | |
85 | + |
|
85 | + | |
86 | 1 |
|
86 | 1 | |
87 | 2 |
|
87 | 2 | |
88 | 3 |
|
88 | 3 | |
89 | 4 |
|
89 | 4 | |
90 | hello world |
|
90 | hello world | |
91 | -goodbye world |
|
91 | -goodbye world | |
92 | + goodbye world |
|
92 | + goodbye world | |
93 | 7 |
|
93 | 7 | |
94 | 8 |
|
94 | 8 | |
95 | 9 |
|
95 | 9 | |
96 |
|
96 | |||
97 | $ hg qdiff --nodates -U 1 -B |
|
97 | $ hg qdiff --nodates -U 1 -B | |
98 | diff -r b0c220e1cf43 lines |
|
98 | diff -r b0c220e1cf43 lines | |
99 | --- a/lines |
|
99 | --- a/lines | |
100 | +++ b/lines |
|
100 | +++ b/lines | |
101 |
@@ -4,4 + |
|
101 | @@ -4,4 +4,4 @@ | |
102 | 4 |
|
102 | 4 | |
103 | -hello world |
|
103 | -hello world | |
104 | -goodbye world |
|
104 | -goodbye world | |
105 | +hello world |
|
105 | +hello world | |
106 | + goodbye world |
|
106 | + goodbye world | |
107 | 7 |
|
107 | 7 | |
108 |
|
108 | |||
109 | $ hg qdiff --nodates -w |
|
109 | $ hg qdiff --nodates -w | |
110 | diff -r b0c220e1cf43 lines |
|
110 | diff -r b0c220e1cf43 lines | |
111 | --- a/lines |
|
111 | --- a/lines | |
112 | +++ b/lines |
|
112 | +++ b/lines | |
113 | @@ -1,3 +1,5 @@ |
|
113 | @@ -1,3 +1,5 @@ | |
114 | + |
|
114 | + | |
115 | + |
|
115 | + | |
116 | 1 |
|
116 | 1 | |
117 | 2 |
|
117 | 2 | |
118 | 3 |
|
118 | 3 | |
119 |
|
119 | |||
120 | $ hg qdiff --nodates --reverse |
|
120 | $ hg qdiff --nodates --reverse | |
121 | diff -r b0c220e1cf43 lines |
|
121 | diff -r b0c220e1cf43 lines | |
122 | --- a/lines |
|
122 | --- a/lines | |
123 | +++ b/lines |
|
123 | +++ b/lines | |
124 | @@ -1,11 +1,9 @@ |
|
124 | @@ -1,11 +1,9 @@ | |
125 | - |
|
125 | - | |
126 | - |
|
126 | - | |
127 | 1 |
|
127 | 1 | |
128 | 2 |
|
128 | 2 | |
129 | 3 |
|
129 | 3 | |
130 | 4 |
|
130 | 4 | |
131 | -hello world |
|
131 | -hello world | |
132 | - goodbye world |
|
132 | - goodbye world | |
133 | +hello world |
|
133 | +hello world | |
134 | +goodbye world |
|
134 | +goodbye world | |
135 | 7 |
|
135 | 7 | |
136 | 8 |
|
136 | 8 | |
137 | 9 |
|
137 | 9 | |
138 |
|
138 | |||
139 | qdiff preserve existing git flag: |
|
139 | qdiff preserve existing git flag: | |
140 |
|
140 | |||
141 | $ hg qrefresh --git |
|
141 | $ hg qrefresh --git | |
142 | $ echo a >> lines |
|
142 | $ echo a >> lines | |
143 | $ hg qdiff |
|
143 | $ hg qdiff | |
144 | diff --git a/lines b/lines |
|
144 | diff --git a/lines b/lines | |
145 | --- a/lines |
|
145 | --- a/lines | |
146 | +++ b/lines |
|
146 | +++ b/lines | |
147 | @@ -1,9 +1,12 @@ |
|
147 | @@ -1,9 +1,12 @@ | |
148 | + |
|
148 | + | |
149 | + |
|
149 | + | |
150 | 1 |
|
150 | 1 | |
151 | 2 |
|
151 | 2 | |
152 | 3 |
|
152 | 3 | |
153 | 4 |
|
153 | 4 | |
154 | -hello world |
|
154 | -hello world | |
155 | -goodbye world |
|
155 | -goodbye world | |
156 | +hello world |
|
156 | +hello world | |
157 | + goodbye world |
|
157 | + goodbye world | |
158 | 7 |
|
158 | 7 | |
159 | 8 |
|
159 | 8 | |
160 | 9 |
|
160 | 9 | |
161 | +a |
|
161 | +a | |
162 |
|
162 | |||
163 | $ hg qdiff --stat |
|
163 | $ hg qdiff --stat | |
164 | lines | 7 +++++-- |
|
164 | lines | 7 +++++-- | |
165 | 1 files changed, 5 insertions(+), 2 deletions(-) |
|
165 | 1 files changed, 5 insertions(+), 2 deletions(-) | |
166 | $ hg qrefresh |
|
166 | $ hg qrefresh | |
167 |
|
167 | |||
168 | qdiff when file deleted (but not removed) in working dir: |
|
168 | qdiff when file deleted (but not removed) in working dir: | |
169 |
|
169 | |||
170 | $ hg qnew deleted-file |
|
170 | $ hg qnew deleted-file | |
171 | $ echo a > newfile |
|
171 | $ echo a > newfile | |
172 | $ hg add newfile |
|
172 | $ hg add newfile | |
173 | $ hg qrefresh |
|
173 | $ hg qrefresh | |
174 | $ rm newfile |
|
174 | $ rm newfile | |
175 | $ hg qdiff |
|
175 | $ hg qdiff |
General Comments 0
You need to be logged in to leave comments.
Login now