Mercurial > public > mercurial-scm > hg
comparison mercurial/cmdutil.py @ 38342:b8f45fc27370
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
author | Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com> |
---|---|
date | Wed, 13 Jun 2018 16:22:54 +0530 |
parents | 50f5fc232c16 |
children | 89db59e5cf3e |
comparison
equal
deleted
inserted
replaced
38341:50f5fc232c16 | 38342:b8f45fc27370 |
---|---|
1879 | 1879 |
1880 This function returns an iterator yielding contexts. Before | 1880 This function returns an iterator yielding contexts. Before |
1881 yielding each context, the iterator will first call the prepare | 1881 yielding each context, the iterator will first call the prepare |
1882 function on each context in the window in forward order.''' | 1882 function on each context in the window in forward order.''' |
1883 | 1883 |
1884 allfiles = opts.get('allfiles') | |
1884 follow = opts.get('follow') or opts.get('follow_first') | 1885 follow = opts.get('follow') or opts.get('follow_first') |
1885 revs = _walkrevs(repo, opts) | 1886 revs = _walkrevs(repo, opts) |
1886 if not revs: | 1887 if not revs: |
1887 return [] | 1888 return [] |
1889 if allfiles and len(revs) > 1: | |
1890 raise error.Abort(_("multiple revisions not supported with --allfiles")) | |
1888 wanted = set() | 1891 wanted = set() |
1889 slowpath = match.anypats() or (not match.always() and opts.get('removed')) | 1892 slowpath = match.anypats() or (not match.always() and opts.get('removed')) |
1890 fncache = {} | 1893 fncache = {} |
1891 change = repo.__getitem__ | 1894 change = repo.__getitem__ |
1892 | 1895 |
1988 for rev in sorted(nrevs): | 1991 for rev in sorted(nrevs): |
1989 fns = fncache.get(rev) | 1992 fns = fncache.get(rev) |
1990 ctx = change(rev) | 1993 ctx = change(rev) |
1991 if not fns: | 1994 if not fns: |
1992 def fns_generator(): | 1995 def fns_generator(): |
1993 for f in ctx.files(): | 1996 if allfiles: |
1997 fiter = iter(ctx) | |
1998 else: | |
1999 fiter = ctx.files() | |
2000 for f in fiter: | |
1994 if match(f): | 2001 if match(f): |
1995 yield f | 2002 yield f |
1996 fns = fns_generator() | 2003 fns = fns_generator() |
1997 prepare(ctx, fns) | 2004 prepare(ctx, fns) |
1998 for rev in nrevs: | 2005 for rev in nrevs: |