Patchwork D7146: [RFC] grep: add config option to grep PWD by default

login
register
mail settings
Submitter phabricator
Date Oct. 22, 2019, 4:07 p.m.
Message ID <differential-rev-PHID-DREV-whhddc3rn57hzcattpa7-req@mercurial-scm.org>
Download mbox | patch
Permalink /patch/42530/
State New
Headers show

Comments

phabricator - Oct. 22, 2019, 4:07 p.m.
pulkit created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is motivated by a disscussion on IRC.
  
  TODO: need to add tests, register config option and add docs.
  
  Tests are not ran on this yet.

REPOSITORY
  rHG Mercurial

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

AFFECTED FILES
  mercurial/commands.py

CHANGE DETAILS




To: pulkit, #hg-reviewers
Cc: mercurial-devel
phabricator - Oct. 22, 2019, 4:10 p.m.
JordiGH added a comment.


  I will repeat my position as stated on IRC. I am against this change because,
  
  1. it's inconsistent with shelve, commit, addremove, status, diff and all other operations that by default work on the entire repo
  2. it's difficult to go from this proposed default to grepping the entire repo
  3. it's easy and natural for the user to add this dot themselves
  4. there's no permanent consequence if the user accidentally greps the whole repo; only a little bit of extra output and some CPU wasted

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7146/new/

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

To: pulkit, #hg-reviewers
Cc: JordiGH, mercurial-devel
phabricator - Oct. 22, 2019, 4:24 p.m.
jeffpc added a comment.


  I'm the instigator of the IRC discussion, so I'll summarize my reasoning here as well.
  
  Based on years of working on various sw projects, I've concluded that about 90% of the time I want to grep $PWD and the remaining 10% of the time I want to grep the whole repo.  (It is possible that my usage is very weird, but I'm pretty sure I'm not the only one.)
  
  While I agree that consistency is important, usability is also important.  If the common operation is to grep the $PWD (and that is what happens if you run `grep -R` or `git grep` or many other "grepping" tools), then it should be the default for "hg grep".
  
  I realize that the new "hg grep" behavior hasn't even made it into a release yet, and therefore usage data is essentially non-existent.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7146/new/

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

To: pulkit, #hg-reviewers
Cc: jeffpc, JordiGH, mercurial-devel
phabricator - Oct. 22, 2019, 5:06 p.m.
durin42 added a comment.


  Huh, this behavior of `git grep` surprises me, but not _that_ much.
  
  We do already print PWD-relative paths if `tweakdefaults` is active, right?

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7146/new/

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

To: pulkit, #hg-reviewers
Cc: durin42, jeffpc, JordiGH, mercurial-devel
phabricator - Oct. 22, 2019, 5:06 p.m.
durin42 added a comment.


  (Note that post-5.2 is probably too late to make this tweak, so there's some urgency in this discussion.)

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7146/new/

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

To: pulkit, #hg-reviewers
Cc: durin42, jeffpc, JordiGH, mercurial-devel
phabricator - Oct. 23, 2019, 2:50 a.m.
mharbison72 added a comment.


  I lean towards searching the whole repo by default, for the reasons that Jordi listed, especially consistency with other hg commands.
  
  I almost never `hg grep` from the command line, and typically search in TortoiseHg instead.  But there, I always want it to search everything by default, unless I start passing `-X`.  (I realize a change here doesn't mean it has to change in thg, just relaying my typical usage and expectations.)
  
  I do think a config option to swap the default is reasonable, if for no other reason than $PWD is chosen for the default, and I can still get the behavior I'd expect.

REPOSITORY
  rHG Mercurial

CHANGES SINCE LAST ACTION
  https://phab.mercurial-scm.org/D7146/new/

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

To: pulkit, #hg-reviewers
Cc: mharbison72, durin42, jeffpc, JordiGH, mercurial-devel

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -3396,6 +3396,9 @@ 
 
     getfile = util.lrucachefunc(repo.file)
 
+    if (not pats and ui.configbool("grep", "pwd")):
+        pats = ('.',)
+
     def matchlines(body):
         begin = 0
         linenum = 0