Page MenuHomePhabricator

[RFC] grep: add config option to grep PWD by default
Needs RevisionPublic

Authored by pulkit on Oct 22 2019, 12:06 PM.


Group Reviewers

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.

Diff Detail

rHG Mercurial
Lint Skipped
Unit Tests Skipped

Event Timeline

pulkit created this revision.Oct 22 2019, 12:06 PM
JordiGH added a subscriber: JordiGH.EditedOct 22 2019, 12:10 PM

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
  5. there's already a way to change this default: alias.grep = grep -I .
jeffpc added a subscriber: jeffpc.Oct 22 2019, 12:24 PM

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.

Huh, this behavior of git grep surprises me, but not _that_ much.

We do already print PWD-relative paths if tweakdefaults is active, right?

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

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.

baymax requested changes to this revision.Jan 24 2020, 12:31 PM

There seems to have been no activities on this Diff for the past 3 Months.

By policy, we are automatically moving it out of the need-review state.

Please, move it back to need-review without hesitation if this diff should still be discussed.


This revision now requires changes to proceed.Jan 24 2020, 12:31 PM