Patchwork D3918: grep: add config knob to enable/disable the default wdir search

login
register
mail settings
Submitter phabricator
Date July 11, 2018, 6:12 p.m.
Message ID <3216c95b99af41d184ab9e75715f93f2@localhost.localdomain>
Download mbox | patch
Permalink /patch/32790/
State Not Applicable
Headers show

Comments

phabricator - July 11, 2018, 6:12 p.m.
This revision was automatically updated to reflect the committed changes.
Closed by commit rHG5e4027db52f4: grep: add config knob to enable/disable the default wdir search (authored by yuja, committed by ).

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST UPDATE
  https://phab.mercurial-scm.org/D3918?vs=9535&id=9548

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

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

CHANGE DETAILS




To: yuja, #hg-reviewers, pulkit
Cc: 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
@@ -424,12 +424,25 @@ 
   $ hg grep --all-files -r. mod
   um:1:unmod
 
+commands.all-files can be negated by --no-all-files
+
+  $ hg grep --config commands.grep.all-files=True mod
+  new:2147483647:modified
+  um:2147483647:unmod
+  $ hg grep --config commands.grep.all-files=True --no-all-files mod
+  um:0:unmod
+
 --diff --all-files makes no sense since --diff is the option to grep history
 
   $ hg grep --diff --all-files um
   abort: --diff and --all-files are mutually exclusive
   [255]
 
+but --diff should precede the commands.grep.all-files option
+
+  $ hg grep --config commands.grep.all-files=True --diff mod
+  um:0:+:unmod
+
   $ cd ..
 
 Fix_Wdir(): test that passing wdir() t -r flag does greps on the
diff --git a/mercurial/configitems.py b/mercurial/configitems.py
--- a/mercurial/configitems.py
+++ b/mercurial/configitems.py
@@ -187,6 +187,9 @@ 
 coreconfigitem('color', 'pagermode',
     default=dynamicdefault,
 )
+coreconfigitem('commands', 'grep.all-files',
+    default=True,
+)
 coreconfigitem('commands', 'show.aliasprefix',
     default=list,
 )
diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -2501,7 +2501,7 @@ 
     ('n', 'line-number', None, _('print matching line numbers')),
     ('r', 'rev', [],
      _('only search files changed within revision range'), _('REV')),
-    ('', 'all-files', False,
+    ('', 'all-files', None,
      _('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)')),
@@ -2535,6 +2535,10 @@ 
     diff = opts.get('all') or opts.get('diff')
     if diff and opts.get('all_files'):
         raise error.Abort(_('--diff and --all-files are mutually exclusive'))
+    # TODO: remove "not opts.get('rev')" if --all-files -rMULTIREV gets working
+    if opts.get('all_files') is None and not opts.get('rev') and not diff:
+        # experimental config: commands.grep.all-files
+        opts['all_files'] = ui.configbool('commands', 'grep.all-files')
     if opts.get('all_files') and not opts.get('rev'):
         opts['rev'] = ['wdir()']
 
@@ -2550,10 +2554,6 @@ 
     if opts.get('print0'):
         sep = eol = '\0'
 
-    if not opts.get('rev') and not diff:
-        opts['rev'] = ["wdir()"]
-        opts['all_files'] = True
-
     getfile = util.lrucachefunc(repo.file)
 
     def matchlines(body):