[PATCH 3 of 3] color: add support for hunk-splitting with record
Steve Losh
steve at stevelosh.com
Tue Jan 5 00:44:54 UTC 2010
# HG changeset patch
# User Steve Losh <steve at stevelosh.com>
# Date 1262652127 18000
# Node ID 7b540f437c44958f203c050ff8f683c073631bec
# Parent 4c11455bab391bee9fc7ae8ad9182b46468923c4
color: add support for hunk-splitting with record
diff --git a/hgext/color.py b/hgext/color.py
--- a/hgext/color.py
+++ b/hgext/color.py
@@ -60,7 +60,7 @@
bookmarks.current = green
'''
-import os, sys
+import os, re, sys
from mercurial import cmdutil, commands, extensions, error
from mercurial.i18n import _
@@ -189,8 +189,14 @@
# highlight trailing whitespace, but only in changed lines
stripline = line.rstrip()
for prefix, style in _diff_prefixes:
- if stripline.startswith(prefix):
- lines[i] = render_effects(stripline, _diff_effects[style])
+ if re.match(prefix, stripline):
+ # check for numbered diff lines from record's hunk-splitting
+ m = re.match(r' *[0-9]+: ', stripline)
+ if m:
+ num_prefix = m.group()
+ lines[i] = num_prefix + render_effects(stripline[len(num_prefix):], _diff_effects[style])
+ else:
+ lines[i] = render_effects(stripline, _diff_effects[style])
break
if line != stripline:
lines[i] += render_effects(
@@ -240,17 +246,17 @@
finally:
ui.write = oldwrite
-_diff_prefixes = [('diff', 'diffline'),
- ('copy', 'extended'),
- ('rename', 'extended'),
- ('old', 'extended'),
- ('new', 'extended'),
- ('deleted', 'extended'),
- ('---', 'file_a'),
- ('+++', 'file_b'),
- ('@', 'hunk'),
- ('-', 'deleted'),
- ('+', 'inserted')]
+_diff_prefixes = [(r'diff', 'diffline'),
+ (r'copy', 'extended'),
+ (r'rename', 'extended'),
+ (r'old', 'extended'),
+ (r'new', 'extended'),
+ (r'deleted', 'extended'),
+ (r'---', 'file_a'),
+ (r'\+\+\+', 'file_b'),
+ (r'@', 'hunk'),
+ (r'( *[0-9]+: )?\-', 'deleted'),
+ (r'( *[0-9]+: )?\+', 'inserted')]
_diff_effects = {'diffline': ['bold'],
'extended': ['cyan', 'bold'],
More information about the Mercurial-devel
mailing list