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