Show More
@@ -171,7 +171,7 b' class DiffProcessor(object):' | |||
|
171 | 171 | |
|
172 | 172 | def _extract_rev(self, line1, line2): |
|
173 | 173 | """ |
|
174 | Extract the filename and revision hint from a line. | |
|
174 | Extract the operation (A/M/D), filename and revision hint from a line. | |
|
175 | 175 | """ |
|
176 | 176 | |
|
177 | 177 | try: |
@@ -189,11 +189,15 b' class DiffProcessor(object):' | |||
|
189 | 189 | filename = (old_filename |
|
190 | 190 | if old_filename != '/dev/null' else new_filename) |
|
191 | 191 | |
|
192 | return filename, new_rev, old_rev | |
|
192 | operation = 'D' if new_filename == '/dev/null' else None | |
|
193 | if not operation: | |
|
194 | operation = 'M' if old_filename != '/dev/null' else 'A' | |
|
195 | ||
|
196 | return operation, filename, new_rev, old_rev | |
|
193 | 197 | except (ValueError, IndexError): |
|
194 | 198 | pass |
|
195 | 199 | |
|
196 | return None, None, None | |
|
200 | return None, None, None, None | |
|
197 | 201 | |
|
198 | 202 | def _parse_gitdiff(self, diffiterator): |
|
199 | 203 | def line_decoder(l): |
@@ -288,6 +292,7 b' class DiffProcessor(object):' | |||
|
288 | 292 | line = lineiter.next() |
|
289 | 293 | # skip first context |
|
290 | 294 | skipfirst = True |
|
295 | ||
|
291 | 296 | while 1: |
|
292 | 297 | # continue until we found the old file |
|
293 | 298 | if not line.startswith('--- '): |
@@ -295,17 +300,21 b' class DiffProcessor(object):' | |||
|
295 | 300 | continue |
|
296 | 301 | |
|
297 | 302 | chunks = [] |
|
298 | filename, old_rev, new_rev = \ | |
|
303 | stats = [0, 0] | |
|
304 | operation, filename, old_rev, new_rev = \ | |
|
299 | 305 | self._extract_rev(line, lineiter.next()) |
|
300 | 306 | files.append({ |
|
301 | 307 | 'filename': filename, |
|
302 | 308 | 'old_revision': old_rev, |
|
303 | 309 | 'new_revision': new_rev, |
|
304 | 'chunks': chunks | |
|
310 | 'chunks': chunks, | |
|
311 | 'operation': operation, | |
|
312 | 'stats': stats, | |
|
305 | 313 | }) |
|
306 | 314 | |
|
307 | 315 | line = lineiter.next() |
|
308 | 316 | while line: |
|
317 | ||
|
309 | 318 | match = self._chunk_re.match(line) |
|
310 | 319 | if not match: |
|
311 | 320 | break |
@@ -346,9 +355,11 b' class DiffProcessor(object):' | |||
|
346 | 355 | elif command == '+': |
|
347 | 356 | affects_new = True |
|
348 | 357 | action = 'add' |
|
358 | stats[0] += 1 | |
|
349 | 359 | elif command == '-': |
|
350 | 360 | affects_old = True |
|
351 | 361 | action = 'del' |
|
362 | stats[1] += 1 | |
|
352 | 363 | else: |
|
353 | 364 | affects_old = affects_new = True |
|
354 | 365 | action = 'unmod' |
@@ -362,7 +373,6 b' class DiffProcessor(object):' | |||
|
362 | 373 | 'line': line |
|
363 | 374 | }) |
|
364 | 375 | line = lineiter.next() |
|
365 | ||
|
366 | 376 | except StopIteration: |
|
367 | 377 | pass |
|
368 | 378 | |
@@ -370,7 +380,6 b' class DiffProcessor(object):' | |||
|
370 | 380 | for _ in files: |
|
371 | 381 | for chunk in chunks: |
|
372 | 382 | lineiter = iter(chunk) |
|
373 | #first = True | |
|
374 | 383 | try: |
|
375 | 384 | while 1: |
|
376 | 385 | line = lineiter.next() |
@@ -382,7 +391,6 b' class DiffProcessor(object):' | |||
|
382 | 391 | self.differ(line, nextline) |
|
383 | 392 | except StopIteration: |
|
384 | 393 | pass |
|
385 | ||
|
386 | 394 | return files |
|
387 | 395 | |
|
388 | 396 | def prepare(self): |
@@ -424,7 +432,7 b' class DiffProcessor(object):' | |||
|
424 | 432 | |
|
425 | 433 | def as_html(self, table_class='code-difftable', line_class='line', |
|
426 | 434 | new_lineno_class='lineno old', old_lineno_class='lineno new', |
|
427 | code_class='code', enable_comments=False): | |
|
435 | code_class='code', enable_comments=False, diff_lines=None): | |
|
428 | 436 | """ |
|
429 | 437 | Return udiff as html table with customized css classes |
|
430 | 438 | """ |
@@ -440,7 +448,8 b' class DiffProcessor(object):' | |||
|
440 | 448 | } |
|
441 | 449 | else: |
|
442 | 450 | return label |
|
443 |
diff_lines |
|
|
451 | if diff_lines is None: | |
|
452 | diff_lines = self.prepare() | |
|
444 | 453 | _html_empty = True |
|
445 | 454 | _html = [] |
|
446 | 455 | _html.append('''<table class="%(table_class)s">\n''' % { |
General Comments 0
You need to be logged in to leave comments.
Login now