# HG changeset patch # User Daniel Dourvaris # Date 2016-10-25 14:24:56 # Node ID ab6082d0576338d2ca43be5ead4f4dfea168b149 # Parent 113b91d4311409ba12e24fd1d30bd552572c6d23 ux: make 'no newline at end of file' message more pronounced in diffs diff --git a/rhodecode/lib/codeblocks.py b/rhodecode/lib/codeblocks.py --- a/rhodecode/lib/codeblocks.py +++ b/rhodecode/lib/codeblocks.py @@ -493,9 +493,9 @@ class DiffSet(object): after.append(line) elif line['action'] == 'del': before.append(line) - elif line['action'] == 'context-old': + elif line['action'] == 'old-no-nl': before.append(line) - elif line['action'] == 'context-new': + elif line['action'] == 'new-no-nl': after.append(line) result.lines.extend( @@ -527,25 +527,31 @@ class DiffSet(object): modified = AttributeDict() if before: - before_tokens = self.get_line_tokens( - line_text=before['line'], line_number=before['old_lineno'], - file=source_file) + if before['action'] == 'old-no-nl': + before_tokens = [('nonl', before['line'])] + else: + before_tokens = self.get_line_tokens( + line_text=before['line'], line_number=before['old_lineno'], + file=source_file) original.lineno = before['old_lineno'] original.content = before['line'] original.action = self.action_to_op(before['action']) if after: - after_tokens = self.get_line_tokens( - line_text=after['line'], line_number=after['new_lineno'], - file=target_file) + if after['action'] == 'new-no-nl': + after_tokens = [('nonl', after['line'])] + else: + after_tokens = self.get_line_tokens( + line_text=after['line'], line_number=after['new_lineno'], + file=target_file) modified.lineno = after['new_lineno'] modified.content = after['line'] modified.action = self.action_to_op(after['action']) - # diff the lines if before_tokens and after_tokens: - o_tokens, m_tokens, similarity = tokens_diff(before_tokens, after_tokens) + o_tokens, m_tokens, similarity = tokens_diff( + before_tokens, after_tokens) original.content = render_tokenstream(o_tokens) modified.content = render_tokenstream(m_tokens) elif before_tokens: @@ -594,8 +600,8 @@ class DiffSet(object): 'add': '+', 'del': '-', 'unmod': ' ', - 'context-old': ' ', - 'context-new': ' ', + 'old-no-nl': ' ', + 'new-no-nl': ' ', }.get(action, action) def as_unified(self, lines): diff --git a/rhodecode/lib/diffs.py b/rhodecode/lib/diffs.py --- a/rhodecode/lib/diffs.py +++ b/rhodecode/lib/diffs.py @@ -180,8 +180,8 @@ class Action(object): UNMODIFIED = 'unmod' CONTEXT = 'context' - CONTEXT_OLD = 'context-old' - CONTEXT_NEW = 'context-new' + OLD_NO_NL = 'old-no-nl' + NEW_NO_NL = 'new-no-nl' class DiffProcessor(object): @@ -846,9 +846,9 @@ class DiffProcessor(object): # we need to append to lines, since this is not # counted in the line specs of diff if affects_old: - action = Action.CONTEXT_OLD + action = Action.OLD_NO_NL elif affects_new: - action = Action.CONTEXT_NEW + action = Action.NEW_NO_NL else: raise Exception('invalid context for no newline')