Patchwork D3728: grep: adds allfiles mode

login
register
mail settings
Submitter phabricator
Date June 17, 2018, 5:51 a.m.
Message ID <0a054b3043433cb0c24442b4d274030b@localhost.localdomain>
Download mbox | patch
Permalink /patch/32209/
State Not Applicable
Headers show

Comments

phabricator - June 17, 2018, 5:51 a.m.
sangeet259 updated this revision to Diff 9121.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3728?vs=9107&id=9121

REVISION DETAIL
  https://phab.mercurial-scm.org/D3728

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/commands.py
  tests/test-grep.t

CHANGE DETAILS




To: sangeet259, #hg-reviewers
Cc: pulkit, yuja, mharbison72, mercurial-devel
Yuya Nishihara - June 17, 2018, 8:30 a.m.
> +    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 +1994,11 @@
>                  ctx = change(rev)
>                  if not fns:
>                      def fns_generator():
> -                        for f in ctx.files():
> +                        if allfiles and len(revs) == 1:

Removed `len(revs) == 1` here and queued, thanks.
phabricator - June 17, 2018, 8:46 a.m.
yuja added a comment.


  > +    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 +1994,11 @@
  > 
  >   ctx = change(rev)
  >   if not fns:
  >       def fns_generator():
  > 
  > - for f in ctx.files(): +                        if allfiles and len(revs) == 1:
  
  Removed `len(revs) == 1` here and queued, thanks.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D3728

To: sangeet259, #hg-reviewers
Cc: pulkit, yuja, mharbison72, mercurial-devel

Patch

diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -368,3 +368,20 @@ 
   binfile.bin:0:+: Binary file matches
 
   $ 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 ..
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2408,6 +2408,8 @@ 
     ('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/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1881,10 +1881,14 @@ 
     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 +1994,11 @@ 
                 ctx = change(rev)
                 if not fns:
                     def fns_generator():
-                        for f in ctx.files():
+                        if allfiles and len(revs) == 1:
+                            fiter = iter(ctx)
+                        else:
+                            fiter = ctx.files()
+                        for f in fiter:
                             if match(f):
                                 yield f
                     fns = fns_generator()