[PATCH 3 of 9] grep: add --no-filename option to suppress filename column from output
Idan Kamara
idankk86 at gmail.com
Sun Oct 14 20:54:20 UTC 2012
# HG changeset patch
# User Idan Kamara <idankk86 at gmail.com>
# Date 1350073245 -7200
# Node ID 806bab6620c0308b61a4cf9c0e95927650ccb513
# Parent 35568b484500bd199d337b4f2abaa21965a6aa15
grep: add --no-filename option to suppress filename column from output
The short option in GNU grep is -h but we can't use it here since that's
taken by --help.
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2884,6 +2884,7 @@
('l', 'files-with-matches', None,
_('print only filenames and revisions that match')),
('n', 'line-number', None, _('print matching line numbers')),
+ ('', 'no-filename', None, _('suppress filename from output')),
('r', 'rev', [],
_('only search files changed within revision range'), _('REV')),
('u', 'user', None, _('list the author (long with -v)')),
@@ -2987,7 +2988,10 @@
else:
iter = [('', l) for l in states]
for change, l in iter:
- cols = [(fn, 'grep.filename'), (str(rev), 'grep.rev')]
+ cols = []
+ if not opts.get('no_filename'):
+ cols.append((fn, 'grep.filename'))
+ cols.append((str(rev), 'grep.rev'))
before, match, after = None, None, None
if opts.get('line_number'):
diff --git a/tests/test-debugcomplete.t b/tests/test-debugcomplete.t
--- a/tests/test-debugcomplete.t
+++ b/tests/test-debugcomplete.t
@@ -250,7 +250,7 @@
debugwalk: include, exclude
debugwireargs: three, four, five, ssh, remotecmd, insecure
graft: rev, continue, edit, log, currentdate, currentuser, date, user, tool, dry-run
- grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, include, exclude
+ grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, no-filename, rev, user, date, include, exclude
heads: rev, topo, active, closed, style, template
help: extension, command, keyword
identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure
diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -27,6 +27,10 @@
port:4:export
port:4:vaportight
port:4:import/export
+ $ hg grep --no-filename port port
+ 4:export
+ 4:vaportight
+ 4:import/export
simple with color
More information about the Mercurial-devel
mailing list