|
@@ -132,6 +132,11 @@ class Hunk(object):
|
132
|
132
|
out.append(line)
|
133
|
133
|
return out
|
134
|
134
|
|
|
135
|
+ def is_completed(self):
|
|
136
|
+ old_completed = self._old_addr[1] == len(self._get_old_text())
|
|
137
|
+ new_completed = self._new_addr[1] == len(self._get_new_text())
|
|
138
|
+ return old_completed and new_completed
|
|
139
|
+
|
135
|
140
|
|
136
|
141
|
class UnifiedDiff(object):
|
137
|
142
|
|
|
@@ -162,14 +167,14 @@ class UnifiedDiff(object):
|
162
|
167
|
old_addr = (int(a[0][1:]), int(a[1]))
|
163
|
168
|
else:
|
164
|
169
|
# @@ -1 +1,2 @@
|
165
|
|
- old_addr = (int(a[0][1:]), 0)
|
|
170
|
+ old_addr = (int(a[0][1:]), 1)
|
166
|
171
|
|
167
|
172
|
b = hunk_meta.split()[2].split(',') # +3 6
|
168
|
173
|
if len(b) > 1:
|
169
|
174
|
new_addr = (int(b[0][1:]), int(b[1]))
|
170
|
175
|
else:
|
171
|
176
|
# @@ -0,0 +1 @@
|
172
|
|
- new_addr = (int(b[0][1:]), 0)
|
|
177
|
+ new_addr = (int(b[0][1:]), 1)
|
173
|
178
|
|
174
|
179
|
return (old_addr, new_addr)
|
175
|
180
|
|
|
@@ -321,15 +326,24 @@ class DiffParser(object):
|
321
|
326
|
line = decode(line)
|
322
|
327
|
|
323
|
328
|
if diff.is_old_path(line):
|
324
|
|
- # FIXME: '--- ' breaks here, better to probe next line
|
325
|
|
- if diff._old_path and diff._new_path and diff._hunks:
|
326
|
|
- # See a new diff, yield previous diff if exists
|
327
|
|
- yield diff
|
328
|
|
- diff = UnifiedDiff(headers, line, None, [])
|
329
|
|
- headers = []
|
|
329
|
+ # This is a new diff when current hunk is not yet genreated or
|
|
330
|
+ # is completed. We yield previous diff if exists and construct
|
|
331
|
+ # a new one for this case. Otherwise it's acutally an 'old'
|
|
332
|
+ # line starts with '--- '.
|
|
333
|
+ #
|
|
334
|
+ if (not diff._hunks or diff._hunks[-1].is_completed()):
|
|
335
|
+ if diff._old_path and diff._new_path and diff._hunks:
|
|
336
|
+ yield diff
|
|
337
|
+ diff = UnifiedDiff(headers, line, None, [])
|
|
338
|
+ headers = []
|
|
339
|
+ else:
|
|
340
|
+ diff._hunks[-1].append(diff.parse_hunk_line(line))
|
330
|
341
|
|
331
|
342
|
elif diff.is_new_path(line) and diff._old_path:
|
332
|
|
- diff._new_path = line
|
|
343
|
+ if not diff._new_path:
|
|
344
|
+ diff._new_path = line
|
|
345
|
+ else:
|
|
346
|
+ diff._hunks[-1].append(diff.parse_hunk_line(line))
|
333
|
347
|
|
334
|
348
|
elif diff.is_hunk_meta(line):
|
335
|
349
|
hunk_meta = line
|