|
@@ -168,6 +168,9 @@ class Diff(object):
|
168
|
168
|
def is_eof(self, line):
|
169
|
169
|
return False
|
170
|
170
|
|
|
171
|
+ def is_only_in_dir(self, line):
|
|
172
|
+ return False
|
|
173
|
+
|
171
|
174
|
def markup_traditional(self):
|
172
|
175
|
"""Returns a generator"""
|
173
|
176
|
for line in self._headers:
|
|
@@ -260,13 +263,18 @@ class Diff(object):
|
260
|
263
|
|
261
|
264
|
return ''.join(out)
|
262
|
265
|
|
263
|
|
- # Setup line width and number width
|
|
266
|
+ # Set up line width
|
264
|
267
|
if width <= 0:
|
265
|
268
|
width = 80
|
266
|
|
- (start, offset) = self._hunks[-1]._old_addr
|
267
|
|
- max1 = start + offset - 1
|
268
|
|
- (start, offset) = self._hunks[-1]._new_addr
|
269
|
|
- max2 = start + offset - 1
|
|
269
|
+
|
|
270
|
+ # Set up number width, note last hunk might be empty
|
|
271
|
+ try:
|
|
272
|
+ (start, offset) = self._hunks[-1]._old_addr
|
|
273
|
+ max1 = start + offset - 1
|
|
274
|
+ (start, offset) = self._hunks[-1]._new_addr
|
|
275
|
+ max2 = start + offset - 1
|
|
276
|
+ except IndexError:
|
|
277
|
+ max1 = max2 = 0
|
270
|
278
|
num_width = max(len(str(max1)), len(str(max2)))
|
271
|
279
|
|
272
|
280
|
# Setup lineno and line format
|
|
@@ -412,6 +420,9 @@ class Udiff(Diff):
|
412
|
420
|
# \ No newline at end of property
|
413
|
421
|
return line.startswith(r'\ No newline at end of')
|
414
|
422
|
|
|
423
|
+ def is_only_in_dir(self, line):
|
|
424
|
+ return line.startswith('Only in ')
|
|
425
|
+
|
415
|
426
|
|
416
|
427
|
class PatchStream(object):
|
417
|
428
|
|
|
@@ -492,7 +503,9 @@ class DiffParser(object):
|
492
|
503
|
line = decode(line)
|
493
|
504
|
|
494
|
505
|
if difflet.is_old_path(line):
|
495
|
|
- # FIXME: '--- ' breaks here, need to probe next 3 lines
|
|
506
|
+ # FIXME: '--- ' breaks here, need to probe next 3 lines,
|
|
507
|
+ # reproducible with github raw patch
|
|
508
|
+ #
|
496
|
509
|
if diff._old_path and diff._new_path and len(diff._hunks) > 0:
|
497
|
510
|
# One diff constructed
|
498
|
511
|
yield diff
|
|
@@ -518,6 +531,16 @@ class DiffParser(object):
|
518
|
531
|
# ignore
|
519
|
532
|
pass
|
520
|
533
|
|
|
534
|
+ elif difflet.is_only_in_dir(line):
|
|
535
|
+ # 'Only in foo: ' is considered a separate diff, so yield
|
|
536
|
+ # current diff, then this line
|
|
537
|
+ #
|
|
538
|
+ if diff._old_path and diff._new_path and len(diff._hunks) > 0:
|
|
539
|
+ # One diff constructed
|
|
540
|
+ yield diff
|
|
541
|
+ yield Diff([line], '', '', [])
|
|
542
|
+ diff = Diff([], None, None, [])
|
|
543
|
+
|
521
|
544
|
else:
|
522
|
545
|
# All other non-recognized lines are considered as headers or
|
523
|
546
|
# hunk headers respectively
|
|
@@ -527,12 +550,14 @@ class DiffParser(object):
|
527
|
550
|
if headers:
|
528
|
551
|
raise RuntimeError('dangling header(s):\n%s' % ''.join(headers))
|
529
|
552
|
|
530
|
|
- # Validate and yield the last patch set
|
531
|
|
- assert diff._old_path is not None
|
532
|
|
- assert diff._new_path is not None
|
533
|
|
- assert len(diff._hunks) > 0
|
534
|
|
- assert len(diff._hunks[-1]._hunk_meta) > 0
|
535
|
|
- yield diff
|
|
553
|
+ # Validate and yield the last patch set if it is not yielded yet
|
|
554
|
+ if diff._old_path:
|
|
555
|
+ assert diff._new_path is not None
|
|
556
|
+ assert len(diff._hunks) > 0
|
|
557
|
+ if diff._hunks:
|
|
558
|
+ assert len(diff._hunks[-1]._hunk_meta) > 0
|
|
559
|
+ assert len(diff._hunks[-1]._hunk_list) > 0
|
|
560
|
+ yield diff
|
536
|
561
|
|
537
|
562
|
|
538
|
563
|
class DiffMarkup(object):
|