diffs: fixed problem with rendering no newline at the end of file markers.

- fixes #5402
This commit is contained in:
Marcin Kuzminski 2017-11-19 15:23:38 +01:00
parent 12acb7f2a5
commit eeed33bcfe
4 changed files with 43 additions and 1 deletions

View file

@ -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,

View file

@ -846,7 +846,7 @@ class DiffProcessor(object):
'action': action,
'line': self._clean_line(line, command)
})
raw_diff.append(line)
raw_diff.append(line)
line = diff_iter.next()

View file

@ -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

View file

@ -242,6 +242,14 @@ DIFF_FIXTURES = [
RENAMED_FILENODE: 'file renamed from README.rst to README',
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',