Show More
@@ -125,12 +125,12 b' def unidiff(a, ad, b, bd, fn1, fn2, r=No' | |||||
125 | else: |
|
125 | else: | |
126 | al = splitnewlines(a) |
|
126 | al = splitnewlines(a) | |
127 | bl = splitnewlines(b) |
|
127 | bl = splitnewlines(b) | |
128 |
l = list( |
|
128 | l = list(_unidiff(a, b, al, bl, opts=opts)) | |
129 | if not l: |
|
129 | if not l: | |
130 | return "" |
|
130 | return "" | |
131 | # difflib uses a space, rather than a tab |
|
131 | ||
132 |
l |
|
132 | l.insert(0, "--- a/%s%s" % (fn1, datetag(ad))) | |
133 |
l |
|
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': | |
@@ -141,11 +141,10 b' def unidiff(a, ad, b, bd, fn1, fn2, r=No' | |||||
141 |
|
141 | |||
142 | return "".join(l) |
|
142 | return "".join(l) | |
143 |
|
143 | |||
144 | # somewhat self contained replacement for difflib.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 | # header1 and header2 are the filenames for the diff output |
|
147 | def _unidiff(t1, t2, l1, l2, opts=defaultopts): | |
148 | def bunidiff(t1, t2, l1, l2, header1, header2, opts=defaultopts): |
|
|||
149 | def contextend(l, len): |
|
148 | def contextend(l, len): | |
150 | ret = l + opts.context |
|
149 | ret = l + opts.context | |
151 | if ret > len: |
|
150 | if ret > len: | |
@@ -158,10 +157,7 b' def bunidiff(t1, t2, l1, l2, header1, he' | |||||
158 | return 0 |
|
157 | return 0 | |
159 | return ret |
|
158 | return ret | |
160 |
|
159 | |||
161 |
def yieldhunk(hunk |
|
160 | def yieldhunk(hunk): | |
162 | if header: |
|
|||
163 | for x in header: |
|
|||
164 | yield x |
|
|||
165 | (astart, a2, bstart, b2, delta) = hunk |
|
161 | (astart, a2, bstart, b2, delta) = hunk | |
166 | aend = contextend(a2, len(l1)) |
|
162 | aend = contextend(a2, len(l1)) | |
167 | alen = aend - astart |
|
163 | alen = aend - astart | |
@@ -184,8 +180,6 b' def bunidiff(t1, t2, l1, l2, header1, he' | |||||
184 | for x in xrange(a2, aend): |
|
180 | for x in xrange(a2, aend): | |
185 | yield ' ' + l1[x] |
|
181 | yield ' ' + l1[x] | |
186 |
|
182 | |||
187 | header = ["--- %s\t\n" % header1, "+++ %s\t\n" % header2] |
|
|||
188 |
|
||||
189 | if opts.showfunc: |
|
183 | if opts.showfunc: | |
190 | funcre = re.compile('\w') |
|
184 | funcre = re.compile('\w') | |
191 |
|
185 | |||
@@ -236,11 +230,8 b' def bunidiff(t1, t2, l1, l2, header1, he' | |||||
236 | astart = hunk[1] |
|
230 | astart = hunk[1] | |
237 | bstart = hunk[3] |
|
231 | bstart = hunk[3] | |
238 | else: |
|
232 | else: | |
239 |
for x in yieldhunk(hunk |
|
233 | for x in yieldhunk(hunk): | |
240 | yield x |
|
234 | yield x | |
241 | # we only want to yield the header if the files differ, and |
|
|||
242 | # we only want to yield it once. |
|
|||
243 | header = None |
|
|||
244 | if prev: |
|
235 | if prev: | |
245 | # we've joined the previous hunk, record the new ending points. |
|
236 | # we've joined the previous hunk, record the new ending points. | |
246 | hunk[1] = a2 |
|
237 | hunk[1] = a2 | |
@@ -255,7 +246,7 b' def bunidiff(t1, t2, l1, l2, header1, he' | |||||
255 | delta[len(delta):] = ['+' + x for x in new] |
|
246 | delta[len(delta):] = ['+' + x for x in new] | |
256 |
|
247 | |||
257 | if hunk: |
|
248 | if hunk: | |
258 |
for x in yieldhunk(hunk |
|
249 | for x in yieldhunk(hunk): | |
259 | yield x |
|
250 | yield x | |
260 |
|
251 | |||
261 | def patchtext(bin): |
|
252 | def patchtext(bin): |
General Comments 0
You need to be logged in to leave comments.
Login now