Mercurial > hg-stable
changeset 15201:2c4fdee4d1a8
diff: enhance highlighting with color (issue3034)
Now the highlighter knows whether it is in the header of the patch or not.
author | Kirill Elagin <kirelagin@gmail.com> |
---|---|
date | Wed, 05 Oct 2011 09:20:38 +0300 |
parents | 797bf1dc1ff8 |
children | 0150741caace |
files | mercurial/patch.py |
diffstat | 1 files changed, 22 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/patch.py Fri Oct 07 15:36:50 2011 -0500 +++ b/mercurial/patch.py Wed Oct 05 09:20:38 2011 +0300 @@ -1619,27 +1619,36 @@ def difflabel(func, *args, **kw): '''yields 2-tuples of (output, label) based on the output of func()''' - prefixes = [('diff', 'diff.diffline'), - ('copy', 'diff.extended'), - ('rename', 'diff.extended'), - ('old', 'diff.extended'), - ('new', 'diff.extended'), - ('deleted', 'diff.extended'), - ('---', 'diff.file_a'), - ('+++', 'diff.file_b'), - ('@@', 'diff.hunk'), - ('-', 'diff.deleted'), - ('+', 'diff.inserted')] - + headprefixes = [('diff', 'diff.diffline'), + ('copy', 'diff.extended'), + ('rename', 'diff.extended'), + ('old', 'diff.extended'), + ('new', 'diff.extended'), + ('deleted', 'diff.extended'), + ('---', 'diff.file_a'), + ('+++', 'diff.file_b')] + textprefixes = [('@', 'diff.hunk'), + ('-', 'diff.deleted'), + ('+', 'diff.inserted')] + head = False for chunk in func(*args, **kw): lines = chunk.split('\n') for i, line in enumerate(lines): if i != 0: yield ('\n', '') + if head: + if line.startswith('@'): + head = False + else: + if line and not line[0] in ' +-@': + head = True stripline = line - if line and line[0] in '+-': + if not head and line and line[0] in '+-': # highlight trailing whitespace, but only in changed lines stripline = line.rstrip() + prefixes = textprefixes + if head: + prefixes = headprefixes for prefix, label in prefixes: if stripline.startswith(prefix): yield (stripline, label)