Mercurial > diff-colorize
comparison diff-colorize.py @ 21:929a488c4960
Prevent lines that are completely different from being completely highlighted as different.
| author | Peter Hosey <hg@boredzo.org> |
|---|---|
| date | Wed, 05 Jan 2011 21:02:24 -0800 |
| parents | b4caea436f4d |
| children | d2bb1603f081 |
comparison
equal
deleted
inserted
replaced
| 20:b4caea436f4d | 21:929a488c4960 |
|---|---|
| 321 | 321 |
| 322 # Buffers to support interleaving old and new lines that were contiguous runs. | 322 # Buffers to support interleaving old and new lines that were contiguous runs. |
| 323 buffer_old = [] # '-' lines | 323 buffer_old = [] # '-' lines |
| 324 buffer_new = [] # '+' lines | 324 buffer_new = [] # '+' lines |
| 325 | 325 |
| 326 from string import whitespace | |
| 327 | |
| 326 def flush_buffers(buffer_old, buffer_new): | 328 def flush_buffers(buffer_old, buffer_new): |
| 327 "Flush the buffers, interleaving the lines and highlighting differences between them." | 329 "Flush the buffers, interleaving the lines and highlighting differences between them." |
| 328 def print_single_line(buffered_line): | 330 def print_single_line(buffered_line): |
| 329 prefix = '-' if buffered_line.startswith('-') else '+' | 331 prefix = '-' if buffered_line.startswith('-') else '+' |
| 330 buffered_line = buffered_line[len(prefix):] | 332 buffered_line = buffered_line[len(prefix):] |
| 347 old_line = last_line_if_old | 349 old_line = last_line_if_old |
| 348 new_line = buffered_line | 350 new_line = buffered_line |
| 349 | 351 |
| 350 old_line_output = [prefixes['-']] | 352 old_line_output = [prefixes['-']] |
| 351 new_line_output = [prefixes['+']] | 353 new_line_output = [prefixes['+']] |
| 352 for node in common_and_distinct_substrings(old_line[1:], new_line[1:]): | 354 |
| 353 if node.differ: | 355 differenced_lines = common_and_distinct_substrings(old_line[1:], new_line[1:]) |
| 356 lines_have_any_non_whitespace_part_in_common = False | |
| 357 for node in differenced_lines: | |
| 358 if not node.differ: | |
| 359 if str(node.a) not in whitespace: | |
| 360 lines_have_any_non_whitespace_part_in_common = True | |
| 361 break | |
| 362 | |
| 363 for node in differenced_lines: | |
| 364 if lines_have_any_non_whitespace_part_in_common and node.differ: | |
| 354 old_line_output.append(BEGIN_REVERSE_FORMAT) | 365 old_line_output.append(BEGIN_REVERSE_FORMAT) |
| 355 old_line_output.append(str(node.a)) | 366 old_line_output.append(str(node.a)) |
| 356 old_line_output.append(END_REVERSE_FORMAT) | 367 old_line_output.append(END_REVERSE_FORMAT) |
| 357 | 368 |
| 358 new_line_output.append(BEGIN_REVERSE_FORMAT) | 369 new_line_output.append(BEGIN_REVERSE_FORMAT) |
