Show More
@@ -240,7 +240,7 b' def unidiff(a, ad, b, bd, fn1, fn2, opts' | |||||
240 | l3 = "@@ -1,%d +0,0 @@\n" % len(a) |
|
240 | l3 = "@@ -1,%d +0,0 @@\n" % len(a) | |
241 | l = [l1, l2, l3] + ["-" + e for e in a] |
|
241 | l = [l1, l2, l3] + ["-" + e for e in a] | |
242 | else: |
|
242 | else: | |
243 |
l = |
|
243 | l = sum((hlines for hrange, hlines in _unidiff(a, b, opts=opts)), []) | |
244 | if not l: |
|
244 | if not l: | |
245 | return "" |
|
245 | return "" | |
246 |
|
246 | |||
@@ -254,7 +254,14 b' def unidiff(a, ad, b, bd, fn1, fn2, opts' | |||||
254 | return "".join(l) |
|
254 | return "".join(l) | |
255 |
|
255 | |||
256 | def _unidiff(t1, t2, opts=defaultopts): |
|
256 | def _unidiff(t1, t2, opts=defaultopts): | |
257 |
"""Yield hunks of a headerless unified diff from t1 and t2 texts. |
|
257 | """Yield hunks of a headerless unified diff from t1 and t2 texts. | |
|
258 | ||||
|
259 | Each hunk consists of a (hunkrange, hunklines) tuple where `hunkrange` is a | |||
|
260 | tuple (s1, l1, s2, l2) representing the range information of the hunk to | |||
|
261 | form the '@@ -s1,l1 +s2,l2 @@' header and `hunklines` is a list of lines | |||
|
262 | of the hunk combining said header followed by line additions and | |||
|
263 | deletions. | |||
|
264 | """ | |||
258 | l1 = splitnewlines(t1) |
|
265 | l1 = splitnewlines(t1) | |
259 | l2 = splitnewlines(t2) |
|
266 | l2 = splitnewlines(t2) | |
260 | def contextend(l, len): |
|
267 | def contextend(l, len): | |
@@ -298,12 +305,13 b' def _unidiff(t1, t2, opts=defaultopts):' | |||||
298 | if blen: |
|
305 | if blen: | |
299 | bstart += 1 |
|
306 | bstart += 1 | |
300 |
|
307 | |||
301 | yield "@@ -%d,%d +%d,%d @@%s\n" % (astart, alen, |
|
308 | hunkrange = astart, alen, bstart, blen | |
302 | bstart, blen, func) |
|
309 | hunklines = ( | |
303 | for x in delta: |
|
310 | ["@@ -%d,%d +%d,%d @@%s\n" % (hunkrange + (func,))] | |
304 |
|
|
311 | + delta | |
305 |
for x in xrange(a2, aend) |
|
312 | + [' ' + l1[x] for x in xrange(a2, aend)] | |
306 | yield ' ' + l1[x] |
|
313 | ) | |
|
314 | yield hunkrange, hunklines | |||
307 |
|
315 | |||
308 | # bdiff.blocks gives us the matching sequences in the files. The loop |
|
316 | # bdiff.blocks gives us the matching sequences in the files. The loop | |
309 | # below finds the spaces between those matching sequences and translates |
|
317 | # below finds the spaces between those matching sequences and translates |
General Comments 0
You need to be logged in to leave comments.
Login now