[PATCH 02 of 13] grep: make use of output labeling
Brodie Rao
dackze at gmail.com
Fri Apr 2 15:33:15 CDT 2010
# HG changeset patch
# User Brodie Rao <brodie at bitheap.org>
# Date 1270239723 18000
# Node ID 635d601e8f21e870b46b1e028c026ef1df46a988
# Parent 32b213b9b22ce922246a5d029c96b090771b98b0
grep: make use of output labeling
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -1353,6 +1353,7 @@ def grep(ui, repo, pattern, *pats, **opt
iter = [('', l) for l in states]
for change, l in iter:
cols = [fn, str(rev)]
+ before, match, after = None, None, None
if opts.get('line_number'):
cols.append(str(l.linenum))
if opts.get('all'):
@@ -1367,8 +1368,15 @@ def grep(ui, repo, pattern, *pats, **opt
continue
filerevmatches[c] = 1
else:
- cols.append(l.line)
- ui.write(sep.join(cols), eol)
+ before = l.line[:l.colstart]
+ match = l.line[l.colstart:l.colend]
+ after = l.line[l.colend:]
+ ui.write(sep.join(cols))
+ if before is not None:
+ ui.write(sep + before)
+ ui.write(match, label='grep.match')
+ ui.write(after)
+ ui.write(eol)
found = True
return found
More information about the Mercurial-devel
mailing list