Mercurial > public > src > rhodecode
changeset 2669:5fe0f744bec0 beta
fixed issue #492 missing `\ No newline at end of file` test at the end of new chunk
in html diff
author | Marcin Kuzminski <marcin@python-works.com> |
---|---|
date | Fri, 06 Jul 2012 20:29:36 +0200 |
parents | d097d4bb0437 |
children | 29e999f26998 |
files | rhodecode/lib/diffs.py |
diffstat | 1 files changed, 18 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/rhodecode/lib/diffs.py Fri Jul 06 20:05:31 2012 +0200 +++ b/rhodecode/lib/diffs.py Fri Jul 06 20:29:36 2012 +0200 @@ -134,6 +134,7 @@ can be used to render it in a HTML template. """ _chunk_re = re.compile(r'@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@(.*)') + _newline_marker = '\\ No newline at end of file\n' def __init__(self, diff, differ='diff', format='gitdiff'): """ @@ -345,11 +346,17 @@ }) line = lineiter.next() + while old_line < old_end or new_line < new_end: if line: - command, line = line[0], line[1:] + command = line[0] + if command in ['+', '-', ' ']: + #only modify the line if it's actually a diff + # thing + line = line[1:] else: command = ' ' + affects_old = affects_new = False # ignore those if we don't expect them @@ -367,15 +374,7 @@ affects_old = affects_new = True action = 'unmod' - if line.find('No newline at end of file') != -1: - lines.append({ - 'old_lineno': '...', - 'new_lineno': '...', - 'action': 'context', - 'line': line - }) - - else: + if line != self._newline_marker: old_line += affects_old new_line += affects_new lines.append({ @@ -386,6 +385,15 @@ }) line = lineiter.next() + if line == self._newline_marker: + # we need to append to lines, since this is not + # counted in the line specs of diff + lines.append({ + 'old_lineno': '...', + 'new_lineno': '...', + 'action': 'context', + 'line': line + }) except StopIteration: pass