diff mercurial/commands.py @ 38631:9ef10437bb88

grep: change default behaviour to search working directory files (BC) With this patch, grep searches on the working directory by default and looks for all files tracked by the working directory and greps on them. ### OLD BEHAVIOUR $ hg init a $ cd a $ echo "some text">>file1 $ hg add file1 $ hg commit -m "adds file1" $ hg mv file1 file2 $ hg grep "some" `file2:1:some text` `file1:0:some text` This behaviour is undesirable since file1 is not in the current history and was renamed as file2, so the second result was redundant and confusing. ### NEW BEHAVIOUR $ hg init a $ cd a $ echo "some text">>file1 $ hg add file1 $ hg commit -m "adds file1" $ hg mv file1 file2 $ hg grep "some" `file2:2147483647:some text` Differential Revision: https://phab.mercurial-scm.org/D3826
author Sangeet Kumar Mishra <mail2sangeetmishra@gmail.com>
date Fri, 06 Jul 2018 00:39:21 +0530
parents afef1e362d65
children ffd08ec22955
line wrap: on
line diff
--- a/mercurial/commands.py	Tue Jul 10 13:18:34 2018 +0200
+++ b/mercurial/commands.py	Fri Jul 06 00:39:21 2018 +0530
@@ -2515,11 +2515,12 @@
     Search revision history for a regular expression in the specified
     files or the entire project.
 
-    By default, grep prints the most recent revision number for each
-    file in which it finds a match. To get it to print every revision
-    that contains a change in match status ("-" for a match that becomes
-    a non-match, or "+" for a non-match that becomes a match), use the
-    --diff flag.
+    By default, grep searches the expression on the working directory.
+    To search history and show the most recent revision number for each
+    file in which it finds a match, use :hg:`grep -r tip:0`.
+    To get it to print every revision that contains a change in match status
+    ("-" for a match that becomes a non-match, or "+" for a non-match that
+    becomes a match), use the --diff flag.
 
     PATTERN can be any Python (roughly Perl-compatible) regular
     expression.
@@ -2544,6 +2545,10 @@
     if opts.get('print0'):
         sep = eol = '\0'
 
+    if not opts.get('rev') and not diff:
+        opts['rev'] = ["wdir()"]
+        opts['allfiles'] = True
+
     getfile = util.lrucachefunc(repo.file)
 
     def matchlines(body):