# HG changeset patch # User Sangeet Kumar Mishra # Date 2018-06-13 10:52:54 # Node ID b8f45fc27370dc7df283c47f71927c10462197fb # Parent 50f5fc232c161ba1e38067411afd96af1e0e9296 grep: adds allfiles mode Adds an allfiles flag that lets you grep on all files in the revision and not just the one that were modified in that changeset. This would work on a single revision and get all the files that were there in that revision. So it's like grepping on a previous state. Using this with wdir() :: `hg grep -r "wdir()" --allfiles` is what the default behavior is desired for grep. Support for multiple revisions to be added later. Differential Revision: https://phab.mercurial-scm.org/D3728 diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py --- a/mercurial/cmdutil.py +++ b/mercurial/cmdutil.py @@ -1881,10 +1881,13 @@ def walkchangerevs(repo, match, opts, pr yielding each context, the iterator will first call the prepare function on each context in the window in forward order.''' + allfiles = opts.get('allfiles') follow = opts.get('follow') or opts.get('follow_first') revs = _walkrevs(repo, opts) if not revs: return [] + if allfiles and len(revs) > 1: + raise error.Abort(_("multiple revisions not supported with --allfiles")) wanted = set() slowpath = match.anypats() or (not match.always() and opts.get('removed')) fncache = {} @@ -1990,7 +1993,11 @@ def walkchangerevs(repo, match, opts, pr ctx = change(rev) if not fns: def fns_generator(): - for f in ctx.files(): + if allfiles: + fiter = iter(ctx) + else: + fiter = ctx.files() + for f in fiter: if match(f): yield f fns = fns_generator() diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -2403,6 +2403,8 @@ def _stopgraft(ui, repo, graftstate): ('n', 'line-number', None, _('print matching line numbers')), ('r', 'rev', [], _('only search files changed within revision range'), _('REV')), + ('', 'allfiles', False, + _('include all files in the changeset while grepping (EXPERIMENTAL)')), ('u', 'user', None, _('list the author (long with -v)')), ('d', 'date', None, _('list the date (short with -q)')), ] + formatteropts + walkopts, diff --git a/tests/test-completion.t b/tests/test-completion.t --- a/tests/test-completion.t +++ b/tests/test-completion.t @@ -313,7 +313,7 @@ Show all commands + options debugwireproto: localssh, peer, noreadstderr, nologhandshake, ssh, remotecmd, insecure files: rev, print0, include, exclude, template, subrepos graft: rev, continue, stop, edit, log, force, currentdate, currentuser, date, user, tool, dry-run - grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, user, date, template, include, exclude + grep: print0, all, text, follow, ignore-case, files-with-matches, line-number, rev, allfiles, user, date, template, include, exclude heads: rev, topo, active, closed, style, template help: extension, command, keyword, system identify: rev, num, id, branch, tags, bookmarks, ssh, remotecmd, insecure, template diff --git a/tests/test-grep.t b/tests/test-grep.t --- a/tests/test-grep.t +++ b/tests/test-grep.t @@ -372,6 +372,23 @@ revisions printed, just their order. $ cd .. +Test for showing working of allfiles flag + + $ hg init sng + $ cd sng + $ echo "unmod" >> um + $ hg ci -A -m "adds unmod to um" + adding um + $ echo "something else" >> new + $ hg ci -A -m "second commit" + adding new + $ hg grep -r "." "unmod" + [1] + $ hg grep -r "." "unmod" --allfiles + um:1:unmod + + $ cd .. + Fix_Wdir(): test that passing wdir() t -r flag does greps on the files modified in the working directory