D3976: grep: add MULTIREV support to --all-files flag

sangeet259 (Sangeet Kumar Mishra) phabricator at mercurial-scm.org
Wed Jul 25 07:44:24 UTC 2018


sangeet259 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REPOSITORY
  rHG Mercurial

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

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

CHANGE DETAILS

diff --git a/tests/test-grep.t b/tests/test-grep.t
--- a/tests/test-grep.t
+++ b/tests/test-grep.t
@@ -491,3 +491,12 @@
   ]
 
   $ cd ..
+
+test -rMULTIREV with --all-files
+
+  $ cd sng
+  $ hg rm um
+  $ hg commit -m "deletes um"
+  $ hg grep -r "0:2" "unmod" --all-files
+  um:0:unmod
+  $ cd ..
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1983,6 +1983,11 @@
 
         it = iter(revs)
         stopiteration = False
+
+        # the files dictionary stores all the files that have been looked at
+        # in the allfiles mode
+        files ={}
+        
         for windowsize in increasingwindows():
             nrevs = []
             for i in xrange(windowsize):
@@ -1998,12 +2003,15 @@
                 if not fns:
                     def fns_generator():
                         if allfiles:
-                            fiter = iter(ctx)
+                            for f in ctx:
+                                if match(f):
+                                    if f not in files:
+                                        files[f] = ctx
+                                        yield f
                         else:
-                            fiter = ctx.files()
-                        for f in fiter:
-                            if match(f):
-                                yield f
+                            for f in ctx.files():
+                                if match(f):
+                                    yield f
                     fns = fns_generator()
                 prepare(ctx, fns)
             for rev in nrevs:



To: sangeet259, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list