Subject: Re: feature request: excluding files/paths from "git grep"

From: Jeff King <[email-masked]>
Date: Wed, 25 Feb 2015 13:51:28 -0500

On Wed, Feb 25, 2015 at 10:33:53AM -0800, Junio C Hamano wrote:

> Jeff King <[email-masked]> writes:
> 
> > If it's an attribute of the file, and not the request, maybe
> > gitattributes would be a better fit. You can already do this with:
> >
> >   *.foo -diff
> >
> > in your .gitattributes file, though that _also_ marks the files as "not
> > for diffing", which may not be desired. There's not a separate "grep"
> > attribute, but I do not think it would be unreasonable to add one.
> 
> I have a vague recollection of having a discussion that started with
> something like this:
> 
>     "diff" is named as if it is only for "diff" for historical
>     reasons, but it is about "do we want to treat its raw contents
>     as text?"

Yes, I think we had this discussion, and agreed that is a reasonable
definition...

> I do not recall its conclusion, but it it were "Yes, that is what it
> means", then it might be reasonable to:
> 
>  - have "git grep" ignore paths marked with -diff by default
>    (perhaps "-a" option to disable, just like GNU)

...which led to 41b59bf (grep: respect diff attributes for binary-ness,
2012-02-02)...

>  - have "git grep" pay attention to diff.textconv and search in the
>    result of textconv filter.

..and 335ec3b (grep: allow to use textconv filters, 2013-05-10).

So I think _if_ using "diff" attributes is enough for this purpose, then
there is no code to be written. But if somebody wants to draw a
distinction between the uses (I want to diff "foo" files, but never see
them in grep) then we could introduce a "grep" attribute (with the
fallback being the value of the "diff" attribute for that path).

-Peff