diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -18,6 +18,7 @@ from node import hex, short import base85, mdiff, scmutil, util, diffhelpers, copies, encoding, error gitre = re.compile('diff --git a/(.*) b/(.*)') +tabsplitter = re.compile(r'(\t+|[^\t]+)') class PatchError(Exception): pass @@ -1673,15 +1674,26 @@ def difflabel(func, *args, **kw): if line and line[0] not in ' +-@\\': head = True stripline = line + diffline = False if not head and line and line[0] in '+-': - # highlight trailing whitespace, but only in changed lines + # highlight tabs and trailing whitespace, but only in + # changed lines stripline = line.rstrip() + diffline = True + prefixes = textprefixes if head: prefixes = headprefixes for prefix, label in prefixes: if stripline.startswith(prefix): - yield (stripline, label) + if diffline: + for token in tabsplitter.findall(stripline): + if '\t' == token[0]: + yield (token, 'diff.tab') + else: + yield (token, label) + else: + yield (stripline, label) break else: yield (line, '') diff --git a/tests/test-diff-color.t b/tests/test-diff-color.t --- a/tests/test-diff-color.t +++ b/tests/test-diff-color.t @@ -159,4 +159,44 @@ issue3712: test colorization of subrepo b \x1b[0;32m+bb\x1b[0m (esc) +test tabs + + $ cat >> a < one tab + > two tabs + > end tab + > mid tab + > all tabs + > EOF + $ hg diff --nodates --color=always + \x1b[0;1mdiff --git a/a b/a\x1b[0m (esc) + \x1b[0;31;1m--- a/a\x1b[0m (esc) + \x1b[0;32;1m+++ b/a\x1b[0m (esc) + \x1b[0;35m@@ -7,3 +7,9 @@\x1b[0m (esc) + a + c + c + \x1b[0;32m+aa\x1b[0m (esc) + \x1b[0;32m+\x1b[0m \x1b[0;32mone tab\x1b[0m (esc) + \x1b[0;32m+\x1b[0m \x1b[0;32mtwo tabs\x1b[0m (esc) + \x1b[0;32m+end tab\x1b[0m\x1b[0;1;41m \x1b[0m (esc) + \x1b[0;32m+mid\x1b[0m \x1b[0;32mtab\x1b[0m (esc) + \x1b[0;32m+\x1b[0m \x1b[0;32mall\x1b[0m \x1b[0;32mtabs\x1b[0m\x1b[0;1;41m \x1b[0m (esc) + $ echo "[color]" >> $HGRCPATH + $ echo "diff.tab = bold magenta" >> $HGRCPATH + $ hg diff --nodates --color=always + \x1b[0;1mdiff --git a/a b/a\x1b[0m (esc) + \x1b[0;31;1m--- a/a\x1b[0m (esc) + \x1b[0;32;1m+++ b/a\x1b[0m (esc) + \x1b[0;35m@@ -7,3 +7,9 @@\x1b[0m (esc) + a + c + c + \x1b[0;32m+aa\x1b[0m (esc) + \x1b[0;32m+\x1b[0m\x1b[0;1;35m \x1b[0m\x1b[0;32mone tab\x1b[0m (esc) + \x1b[0;32m+\x1b[0m\x1b[0;1;35m \x1b[0m\x1b[0;32mtwo tabs\x1b[0m (esc) + \x1b[0;32m+end tab\x1b[0m\x1b[0;1;41m \x1b[0m (esc) + \x1b[0;32m+mid\x1b[0m\x1b[0;1;35m \x1b[0m\x1b[0;32mtab\x1b[0m (esc) + \x1b[0;32m+\x1b[0m\x1b[0;1;35m \x1b[0m\x1b[0;32mall\x1b[0m\x1b[0;1;35m \x1b[0m\x1b[0;32mtabs\x1b[0m\x1b[0;1;41m \x1b[0m (esc) + $ cd ..