grep: fix --follow with no --diff nor --rev to not fall back to plain grep
authorYuya Nishihara <yuya@tcha.org>
Thu, 10 Sep 2020 13:30:34 +0900
changeset 45478 07c424a13811
parent 45477 20dd2a259b0f
child 45479 3dc848d5ec77
grep: fix --follow with no --diff nor --rev to not fall back to plain grep Before, "grep --follow" would only print matches in the working directory. Since --follow is the option to specify the search space, it should disable the plain (i.e. wdir) grep.
mercurial/commands.py
tests/test-grep.t
--- a/mercurial/commands.py	Fri Sep 11 12:39:45 2020 +0900
+++ b/mercurial/commands.py	Thu Sep 10 13:30:34 2020 +0900
@@ -3357,7 +3357,11 @@
         raise error.Abort(_(b'--diff and --all-files are mutually exclusive'))
     if opts.get(b'all_files') is None and not diff:
         opts[b'all_files'] = True
-    plaingrep = opts.get(b'all_files') and not opts.get(b'rev')
+    plaingrep = (
+        opts.get(b'all_files')
+        and not opts.get(b'rev')
+        and not opts.get(b'follow')
+    )
     all_files = opts.get(b'all_files')
     if plaingrep:
         opts[b'rev'] = [b'wdir()']
--- a/tests/test-grep.t	Fri Sep 11 12:39:45 2020 +0900
+++ b/tests/test-grep.t	Thu Sep 10 13:30:34 2020 +0900
@@ -904,27 +904,44 @@
   add0-rm2:0:+:data0
   add0-rm4:0:+:data0
 
- BROKEN: should not fall back to plain grep
   $ hg grep -f data
-  add0:data0
-  add0-cp1:data0
-  add0-cp1-cp3:data0
-  add0-cp1-mod1:data0
-  add0-cp1-mod1:data1
-  add0-cp1-mod1-cp3-mod3:data0
-  add0-cp1-mod1-cp3-mod3:data1
-  add0-cp1-mod1-cp3-mod3:data3
-  add0-cp4:data0
-  add0-cp4-mod4:data0
-  add0-cp4-mod4:data4
-  add0-mod1:data0
-  add0-mod1:data1
-  add0-mod2:data0
-  add0-mod3:data0
-  add0-mod3:data3
-  add0-mod4:data0
-  add0-mod4:data4
-  add0-rm2:data0
+  add0:3:data0
+  add0-cp1:3:data0
+  add0-cp1-cp3:3:data0
+  add0-cp1-mod1:3:data0
+  add0-cp1-mod1:3:data1
+  add0-cp1-mod1-cp3-mod3:3:data0
+  add0-cp1-mod1-cp3-mod3:3:data1
+  add0-cp1-mod1-cp3-mod3:3:data3
+  add0-mod1:3:data0
+  add0-mod1:3:data1
+  add0-mod2:3:data0
+  add0-mod3:3:data0
+  add0-mod3:3:data3
+  add0-mod4:3:data0
+  add0-rm2:3:data0
+  add0-rm4:3:data0
+  add0:1:data0
+  add0-cp1:1:data0
+  add0-cp1-mod1:1:data0
+  add0-cp1-mod1:1:data1
+  add0-cp1-mod1-rm3:1:data0
+  add0-cp1-mod1-rm3:1:data1
+  add0-mod1:1:data0
+  add0-mod1:1:data1
+  add0-mod2:1:data0
+  add0-mod3:1:data0
+  add0-mod4:1:data0
+  add0-rm2:1:data0
+  add0-rm4:1:data0
+  add0:0:data0
+  add0-mod1:0:data0
+  add0-mod2:0:data0
+  add0-mod3:0:data0
+  add0-mod4:0:data0
+  add0-rm1:0:data0
+  add0-rm2:0:data0
+  add0-rm4:0:data0
 
 follow revision history from specified revision:
 
@@ -1030,10 +1047,13 @@
   add0-mod3:3:+:data3
   add0-mod3:0:+:data0
 
- BROKEN: should not fall back to plain grep
+ BROKEN: should not include the revision 2
   $ hg grep -f data add0-mod3
-  add0-mod3:data0
-  add0-mod3:data3
+  add0-mod3:3:data0
+  add0-mod3:3:data3
+  add0-mod3:2:data0
+  add0-mod3:1:data0
+  add0-mod3:0:data0
 
 follow file history from wdir parent, modified in wdir:
 
@@ -1043,10 +1063,12 @@
   $ hg grep --diff -f data add0-mod4
   add0-mod4:0:+:data0
 
- BROKEN: should not fall back to plain grep
+ BROKEN: should not include the revision 2
   $ hg grep -f data add0-mod4
-  add0-mod4:data0
-  add0-mod4:data4
+  add0-mod4:3:data0
+  add0-mod4:2:data0
+  add0-mod4:1:data0
+  add0-mod4:0:data0
 
 follow file history from wdir parent, copied but unmodified:
 
@@ -1058,9 +1080,9 @@
   $ hg grep --diff -f data add0-cp1-cp3
   add0:0:+:data0
 
- BROKEN: should not fall back to plain grep
+ BROKEN: should follow history across renames
   $ hg grep -f data add0-cp1-cp3
-  add0-cp1-cp3:data0
+  add0-cp1-cp3:3:data0
 
 follow file history from wdir parent, copied and modified:
 
@@ -1074,11 +1096,11 @@
   add0-cp1-mod1:1:+:data1
   add0:0:+:data0
 
- BROKEN: should not fall back to plain grep
+ BROKEN: should follow history across renames
   $ hg grep -f data add0-cp1-mod1-cp3-mod3
-  add0-cp1-mod1-cp3-mod3:data0
-  add0-cp1-mod1-cp3-mod3:data1
-  add0-cp1-mod1-cp3-mod3:data3
+  add0-cp1-mod1-cp3-mod3:3:data0
+  add0-cp1-mod1-cp3-mod3:3:data1
+  add0-cp1-mod1-cp3-mod3:3:data3
 
 follow file history from wdir parent, copied in wdir:
 
@@ -1090,9 +1112,9 @@
   abort: cannot follow file not in parent revision: "add0-cp4"
   [255]
 
- BROKEN: should not fall back to plain grep
+ BROKEN: maybe better to abort
   $ hg grep -f data add0-cp4
-  add0-cp4:data0
+  [1]
 
 follow file history from wdir parent, removed:
 
@@ -1104,9 +1126,10 @@
   abort: cannot follow file not in parent revision: "add0-cp1-mod1-rm3"
   [255]
 
- BROKEN: should not fall back to plain grep
+ BROKEN: maybe better to abort
   $ hg grep -f data add0-cp1-mod1-rm3
-  [1]
+  add0-cp1-mod1-rm3:1:data0
+  add0-cp1-mod1-rm3:1:data1
 
 follow file history from wdir parent (explicit), removed:
 
@@ -1132,9 +1155,12 @@
   $ hg grep --diff -f data add0-rm4
   add0-rm4:0:+:data0
 
- BROKEN: should not fall back to plain grep
+ BROKEN: should not include the revision 2, and maybe better to abort
   $ hg grep -f data add0-rm4
-  [1]
+  add0-rm4:3:data0
+  add0-rm4:2:data0
+  add0-rm4:1:data0
+  add0-rm4:0:data0
 
 follow file history from wdir parent (explicit), removed in wdir:
 
@@ -1162,12 +1188,18 @@
   add0:0:+:data0
   add0-mod3:0:+:data0
 
- BROKEN: should not fall back to plain grep
+ BROKEN: should not include the revision 2
+ BROKEN: should follow history across renames
   $ hg grep -f data add0-mod3 add0-cp1-mod1
-  add0-cp1-mod1:data0
-  add0-cp1-mod1:data1
-  add0-mod3:data0
-  add0-mod3:data3
+  add0-cp1-mod1:3:data0
+  add0-cp1-mod1:3:data1
+  add0-mod3:3:data0
+  add0-mod3:3:data3
+  add0-mod3:2:data0
+  add0-cp1-mod1:1:data0
+  add0-cp1-mod1:1:data1
+  add0-mod3:1:data0
+  add0-mod3:0:data0
 
 follow file history from specified revision, modified: