Mercurial > hg > mercurial-crew-with-dirclash
annotate mercurial/mdiff.py @ 3105:ef4e5d05bac4
Merge with mainline
author | Matt Mackall <mpm@selenic.com> |
---|---|
date | Sun, 17 Sep 2006 16:02:09 -0500 |
parents | d838bfac668d |
children | 096f1c73cdc3 |
rev | line source |
---|---|
239
75840796e8e2
mdiff.py: kill #! line, add copyright notice
mpm@selenic.com
parents:
184
diff
changeset
|
1 # mdiff.py - diff and patch routines for mercurial |
75840796e8e2
mdiff.py: kill #! line, add copyright notice
mpm@selenic.com
parents:
184
diff
changeset
|
2 # |
2858 | 3 # Copyright 2005, 2006 Matt Mackall <mpm@selenic.com> |
239
75840796e8e2
mdiff.py: kill #! line, add copyright notice
mpm@selenic.com
parents:
184
diff
changeset
|
4 # |
75840796e8e2
mdiff.py: kill #! line, add copyright notice
mpm@selenic.com
parents:
184
diff
changeset
|
5 # This software may be used and distributed according to the terms |
75840796e8e2
mdiff.py: kill #! line, add copyright notice
mpm@selenic.com
parents:
184
diff
changeset
|
6 # of the GNU General Public License, incorporated herein by reference. |
75840796e8e2
mdiff.py: kill #! line, add copyright notice
mpm@selenic.com
parents:
184
diff
changeset
|
7 |
1637 | 8 from demandload import demandload |
2470
fe1689273f84
use demandload more.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2251
diff
changeset
|
9 import bdiff, mpatch |
fe1689273f84
use demandload more.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2251
diff
changeset
|
10 demandload(globals(), "re struct util") |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
11 |
2251
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
12 def splitnewlines(text): |
2248
b914f0557832
fix diffs containing embedded "\r".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2078
diff
changeset
|
13 '''like str.splitlines, but only split on newlines.''' |
2251
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
14 lines = [l + '\n' for l in text.split('\n')] |
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
15 if lines: |
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
16 if lines[-1] == '\n': |
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
17 lines.pop() |
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
18 else: |
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
19 lines[-1] = lines[-1][:-1] |
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
20 return lines |
2248
b914f0557832
fix diffs containing embedded "\r".
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2078
diff
changeset
|
21 |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
22 class diffopts(object): |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
23 '''context is the number of context lines |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
24 text treats all files as text |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
25 showfunc enables diff -p output |
2892 | 26 git enables the git extended patch format |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
27 ignorews ignores all whitespace changes in the diff |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
28 ignorewsamount ignores changes in the amount of whitespace |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
29 ignoreblanklines ignores changes whose lines are all blank''' |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
361
diff
changeset
|
30 |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
31 defaults = { |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
32 'context': 3, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
33 'text': False, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
34 'showfunc': True, |
2892 | 35 'git': False, |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
36 'ignorews': False, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
37 'ignorewsamount': False, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
38 'ignoreblanklines': False, |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
39 } |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
40 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
41 __slots__ = defaults.keys() |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
42 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
43 def __init__(self, **opts): |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
44 for k in self.__slots__: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
45 v = opts.get(k) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
46 if v is None: |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
47 v = self.defaults[k] |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
48 setattr(self, k, v) |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
49 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
50 defaultopts = diffopts() |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
51 |
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
52 def unidiff(a, ad, b, bd, fn, r=None, opts=defaultopts): |
3023
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
53 def datetag(date): |
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
54 return opts.git and '\n' or '\t%s\n' % date |
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
55 |
35 | 56 if not a and not b: return "" |
1379 | 57 epoch = util.datestr((0, 0)) |
264
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
249
diff
changeset
|
58 |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
59 if not opts.text and (util.binary(a) or util.binary(b)): |
1015
22571b8d35d3
Add automatic binary file detection to diff and export
mpm@selenic.com
parents:
582
diff
changeset
|
60 l = ['Binary file %s has changed\n' % fn] |
1723
fde8fb2cbede
Fix diff against an empty file (issue124) and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1637
diff
changeset
|
61 elif not a: |
2251
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
62 b = splitnewlines(b) |
1723
fde8fb2cbede
Fix diff against an empty file (issue124) and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1637
diff
changeset
|
63 if a is None: |
3023
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
64 l1 = '--- /dev/null%s' % datetag(epoch) |
1723
fde8fb2cbede
Fix diff against an empty file (issue124) and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1637
diff
changeset
|
65 else: |
3023
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
66 l1 = "--- %s%s" % ("a/" + fn, datetag(ad)) |
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
67 l2 = "+++ %s%s" % ("b/" + fn, datetag(bd)) |
264
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
249
diff
changeset
|
68 l3 = "@@ -0,0 +1,%d @@\n" % len(b) |
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
249
diff
changeset
|
69 l = [l1, l2, l3] + ["+" + e for e in b] |
1723
fde8fb2cbede
Fix diff against an empty file (issue124) and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1637
diff
changeset
|
70 elif not b: |
2251
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
71 a = splitnewlines(a) |
3023
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
72 l1 = "--- %s%s" % ("a/" + fn, datetag(ad)) |
1723
fde8fb2cbede
Fix diff against an empty file (issue124) and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1637
diff
changeset
|
73 if b is None: |
3023
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
74 l2 = '+++ /dev/null%s' % datetag(epoch) |
1723
fde8fb2cbede
Fix diff against an empty file (issue124) and add a test for this.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
1637
diff
changeset
|
75 else: |
3023
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
76 l2 = "+++ %s%s" % ("b/" + fn, datetag(bd)) |
264
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
249
diff
changeset
|
77 l3 = "@@ -1,%d +0,0 @@\n" % len(a) |
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
249
diff
changeset
|
78 l = [l1, l2, l3] + ["-" + e for e in a] |
4c1d7072d5cd
Attempt to make diff deal with null sources properly
mpm@selenic.com
parents:
249
diff
changeset
|
79 else: |
2251
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
80 al = splitnewlines(a) |
35fb62a3a673
fix speed regression in mdiff caused by line split bugfix.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2248
diff
changeset
|
81 bl = splitnewlines(b) |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
82 l = list(bunidiff(a, b, al, bl, "a/" + fn, "b/" + fn, opts=opts)) |
278
777e388c06d6
unidiff: handle empty diffs more gracefully
mpm@selenic.com
parents:
272
diff
changeset
|
83 if not l: return "" |
272
467cea2bf2d8
diff: use tab to separate date from filename
mpm@selenic.com
parents:
264
diff
changeset
|
84 # difflib uses a space, rather than a tab |
3023
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
85 l[0] = "%s%s" % (l[0][:-2], datetag(ad)) |
d838bfac668d
Remove dates from git export file lines - they confuse git-apply
Brendan Cully <brendan@kublai.com>
parents:
2892
diff
changeset
|
86 l[1] = "%s%s" % (l[1][:-2], datetag(bd)) |
170 | 87 |
88 for ln in xrange(len(l)): | |
89 if l[ln][-1] != '\n': | |
90 l[ln] += "\n\ No newline at end of file\n" | |
91 | |
396
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
361
diff
changeset
|
92 if r: |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
361
diff
changeset
|
93 l.insert(0, "diff %s %s\n" % |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
361
diff
changeset
|
94 (' '.join(["-r %s" % rev for rev in r]), fn)) |
8f8bb77d560e
Show revisions in diffs like CVS, based on a patch from Goffredo Baroncelli.
Thomas Arendsen Hein <thomas@intevation.de>
parents:
361
diff
changeset
|
95 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
96 return "".join(l) |
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
97 |
1637 | 98 # somewhat self contained replacement for difflib.unified_diff |
99 # t1 and t2 are the text to be diffed | |
100 # l1 and l2 are the text broken up into lines | |
101 # header1 and header2 are the filenames for the diff output | |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
102 def bunidiff(t1, t2, l1, l2, header1, header2, opts=defaultopts): |
1637 | 103 def contextend(l, len): |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
104 ret = l + opts.context |
1637 | 105 if ret > len: |
106 ret = len | |
107 return ret | |
108 | |
109 def contextstart(l): | |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
110 ret = l - opts.context |
1637 | 111 if ret < 0: |
112 return 0 | |
113 return ret | |
114 | |
115 def yieldhunk(hunk, header): | |
116 if header: | |
117 for x in header: | |
118 yield x | |
119 (astart, a2, bstart, b2, delta) = hunk | |
120 aend = contextend(a2, len(l1)) | |
121 alen = aend - astart | |
122 blen = b2 - bstart + aend - a2 | |
123 | |
124 func = "" | |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
125 if opts.showfunc: |
1637 | 126 # walk backwards from the start of the context |
127 # to find a line starting with an alphanumeric char. | |
128 for x in xrange(astart, -1, -1): | |
129 t = l1[x].rstrip() | |
130 if funcre.match(t): | |
131 func = ' ' + t[:40] | |
132 break | |
133 | |
134 yield "@@ -%d,%d +%d,%d @@%s\n" % (astart + 1, alen, | |
135 bstart + 1, blen, func) | |
136 for x in delta: | |
137 yield x | |
138 for x in xrange(a2, aend): | |
139 yield ' ' + l1[x] | |
140 | |
141 header = [ "--- %s\t\n" % header1, "+++ %s\t\n" % header2 ] | |
142 | |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
143 if opts.showfunc: |
1637 | 144 funcre = re.compile('\w') |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
145 if opts.ignorewsamount: |
2580
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
146 wsamountre = re.compile('[ \t]+') |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
147 wsappendedre = re.compile(' \n') |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
148 if opts.ignoreblanklines: |
2580
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
149 wsblanklinesre = re.compile('\n') |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
150 if opts.ignorews: |
1637 | 151 wsre = re.compile('[ \t]') |
152 | |
153 # bdiff.blocks gives us the matching sequences in the files. The loop | |
154 # below finds the spaces between those matching sequences and translates | |
155 # them into diff output. | |
156 # | |
157 diff = bdiff.blocks(t1, t2) | |
158 hunk = None | |
159 for i in xrange(len(diff)): | |
160 # The first match is special. | |
161 # we've either found a match starting at line 0 or a match later | |
162 # in the file. If it starts later, old and new below will both be | |
163 # empty and we'll continue to the next match. | |
164 if i > 0: | |
165 s = diff[i-1] | |
166 else: | |
167 s = [0, 0, 0, 0] | |
168 delta = [] | |
169 s1 = diff[i] | |
170 a1 = s[1] | |
171 a2 = s1[0] | |
172 b1 = s[3] | |
173 b2 = s1[2] | |
174 | |
175 old = l1[a1:a2] | |
176 new = l2[b1:b2] | |
177 | |
178 # bdiff sometimes gives huge matches past eof, this check eats them, | |
179 # and deals with the special first match case described above | |
180 if not old and not new: | |
181 continue | |
182 | |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
183 if opts.ignoreblanklines: |
2580
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
184 wsold = wsblanklinesre.sub('', "".join(old)) |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
185 wsnew = wsblanklinesre.sub('', "".join(new)) |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
186 if wsold == wsnew: |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
187 continue |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
188 |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
189 if opts.ignorewsamount: |
2580
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
190 wsold = wsamountre.sub(' ', "".join(old)) |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
191 wsold = wsappendedre.sub('\n', wsold) |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
192 wsnew = wsamountre.sub(' ', "".join(new)) |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
193 wsnew = wsappendedre.sub('\n', wsnew) |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
194 if wsold == wsnew: |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
195 continue |
a20a1bb0c396
diff: add -b/-B options
Haakon Riiser <haakon.riiser@fys.uio.no>
parents:
2470
diff
changeset
|
196 |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
197 if opts.ignorews: |
1637 | 198 wsold = wsre.sub('', "".join(old)) |
199 wsnew = wsre.sub('', "".join(new)) | |
200 if wsold == wsnew: | |
201 continue | |
202 | |
203 astart = contextstart(a1) | |
204 bstart = contextstart(b1) | |
205 prev = None | |
206 if hunk: | |
207 # join with the previous hunk if it falls inside the context | |
2873
4ec58b157265
refactor text diff/patch code.
Vadim Gelfer <vadim.gelfer@gmail.com>
parents:
2858
diff
changeset
|
208 if astart < hunk[1] + opts.context + 1: |
1637 | 209 prev = hunk |
210 astart = hunk[1] | |
211 bstart = hunk[3] | |
212 else: | |
213 for x in yieldhunk(hunk, header): | |
214 yield x | |
215 # we only want to yield the header if the files differ, and | |
216 # we only want to yield it once. | |
217 header = None | |
218 if prev: | |
219 # we've joined the previous hunk, record the new ending points. | |
220 hunk[1] = a2 | |
221 hunk[3] = b2 | |
222 delta = hunk[4] | |
223 else: | |
224 # create a new hunk | |
225 hunk = [ astart, a2, bstart, b2, delta ] | |
226 | |
227 delta[len(delta):] = [ ' ' + x for x in l1[astart:a1] ] | |
228 delta[len(delta):] = [ '-' + x for x in old ] | |
229 delta[len(delta):] = [ '+' + x for x in new ] | |
230 | |
231 if hunk: | |
232 for x in yieldhunk(hunk, header): | |
233 yield x | |
234 | |
120
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
235 def patchtext(bin): |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
236 pos = 0 |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
237 t = [] |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
238 while pos < len(bin): |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
239 p1, p2, l = struct.unpack(">lll", bin[pos:pos + 12]) |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
240 pos += 12 |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
241 t.append(bin[pos:pos + l]) |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
242 pos += l |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
243 return "".join(t) |
bae6f0328f63
Add a function to return the new text from a binary diff
mpm@selenic.com
parents:
75
diff
changeset
|
244 |
0
9117c6561b0b
Add back links from file revisions to changeset revisions
mpm@selenic.com
parents:
diff
changeset
|
245 def patch(a, bin): |
1379 | 246 return mpatch.patches(a, [bin]) |
432 | 247 |
1379 | 248 patches = mpatch.patches |
2078
441ea218414e
Fill in the uncompressed size during revlog.addgroup
mason@suse.com
parents:
1723
diff
changeset
|
249 patchedsize = mpatch.patchedsize |
432 | 250 textdiff = bdiff.bdiff |