# HG changeset patch # User Marcin Kuzminski # Date 2017-11-19 14:23:38 # Node ID 8531a2ca3448d8b49a32e4c08f2004b993442f3e # Parent 76c34f087f7f1bf06e5cefaaf86fe2867ecb0c78 diffs: fixed problem with rendering no newline at the end of file markers. - fixes #5402 diff --git a/rhodecode/lib/codeblocks.py b/rhodecode/lib/codeblocks.py --- a/rhodecode/lib/codeblocks.py +++ b/rhodecode/lib/codeblocks.py @@ -553,6 +553,23 @@ class DiffSet(object): # line 6: """ lines = [] + + before_newline = AttributeDict() + after_newline = AttributeDict() + if before_lines and before_lines[-1]['action'] == 'old-no-nl': + before_newline_line = before_lines.pop(-1) + before_newline.content = '\n {}'.format( + render_tokenstream( + [(x[0], '', x[1]) + for x in [('nonl', before_newline_line['line'])]])) + + if after_lines and after_lines[-1]['action'] == 'new-no-nl': + after_newline_line = after_lines.pop(-1) + after_newline.content = '\n {}'.format( + render_tokenstream( + [(x[0], '', x[1]) + for x in [('nonl', after_newline_line['line'])]])) + while before_lines or after_lines: before, after = None, None before_tokens, after_tokens = None, None @@ -605,6 +622,13 @@ class DiffSet(object): modified.content = render_tokenstream( [(x[0], '', x[1]) for x in after_tokens]) + if not before_lines and before_newline: + original.content += before_newline.content + before_newline = None + if not after_lines and after_newline: + modified.content += after_newline.content + after_newline = None + lines.append(AttributeDict({ 'original': original, 'modified': modified, diff --git a/rhodecode/lib/diffs.py b/rhodecode/lib/diffs.py --- a/rhodecode/lib/diffs.py +++ b/rhodecode/lib/diffs.py @@ -779,7 +779,7 @@ class DiffProcessor(object): 'action': action, 'line': self._clean_line(line, command) }) - raw_diff.append(line) + raw_diff.append(line) line = diff_iter.next() diff --git a/rhodecode/tests/fixtures/hg_diff_no_newline.diff b/rhodecode/tests/fixtures/hg_diff_no_newline.diff new file mode 100644 --- /dev/null +++ b/rhodecode/tests/fixtures/hg_diff_no_newline.diff @@ -0,0 +1,10 @@ +diff --git a/server.properties b/server.properties +--- a/server.properties ++++ b/server.properties +@@ -1,2 +1,3 @@ +property=value +-anotherProperty=value +\ No newline at end of file ++anotherProperty=value ++newProperty=super_important_value +\ No newline at end of file \ No newline at end of file diff --git a/rhodecode/tests/lib/test_diffs.py b/rhodecode/tests/lib/test_diffs.py --- a/rhodecode/tests/lib/test_diffs.py +++ b/rhodecode/tests/lib/test_diffs.py @@ -226,6 +226,14 @@ DIFF_FIXTURES = [ CHMOD_FILENODE: 'modified file chmod 100755 => 100644'}}), ]), ('hg', + 'hg_diff_no_newline.diff', + [('server.properties', 'M', + {'added': 2, + 'deleted': 1, + 'binary': False, + 'ops': {MOD_FILENODE: 'modified file'}}), + ]), + ('hg', 'hg_diff_mod_file_and_rename.diff', [('README.rst', 'M', {'added': 3,