git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Junio C Hamano <gitster@pobox.com>
Date
Mar 1, 2015, 23:22 UTC
Message-ID
<xmqqr3t8fgm4.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20150301130142.GA24782@tsaunders-iceball.corp.tor1.mozilla.com>
Trevor Saunders <tbsaunde@tbsaunde.org> writes:
Show 8 quoted lines
>> ...  For these "per-invocation" differences, attributes
>> to declare permenent/inherent nature of the contents is much less
>> suited than per-invocation inclusion/exclusion mechanism based on
>> pathspecs, I would think.
>
> I think that makes some amount of sense, however typing stuff like
> --exclude=ChangeLog all the time is not terribly easy on the hands.
> Would it make sense to instead add a config variable grep.exclude?

I do not think it makes much more sense for at least three reasons. for one thing, It still goes against "per-invocation" nature of what is being done. Your "for this invocation I do not want ChangeLog" does not have to be limited to 'grep'. And also "I end up having to give these pathspecs all the time" is not limited to negative ones.

We have magic pathspecs, like "This pattern is used to match the string case-insensitively", "This pattern specifies that the path should *not* match it", etc. How about adding a new feature that lets you say "This is a short hand to giving these pathspecs" and call that "pathspec macro"?

If you get tired to keep having to type
    $ git log -- Documentation/ ':!Documentation/technical/'

every time you want to check the end-user facing documentation pages, you could for example say (I am using a made-up 'macro' pathspec magic that is introduced by ':*' followed by a <macro name>):

    $ git log -- ':*userdoc'

and the same macro specification could be used for all the other things that take pathspecs (grep, add, diff, etc.).

You could then have something like this to define your own "nolog" macro:

    [pathspecMacro]
        nolog = ':!ChangeLog' ':!ChangeLog.*'

to shorten your invocation of "grep" by appending it when you want to exclude some files, i.e.

    $ git grep -e pattern -- \*.c ':*nolog'

and the same pathspec macro can be used in other places, not just "grep". Wouldn't it make more sense?

Previous: Trevor SaundersNext: Trevor Saunders
Message 16 of 21 in “feature request: excluding files/paths from "git grep"”
  1. Noel GrandinFeb 25, 2015
  2. Duy NguyenFeb 25, 2015
  3. Jeff KingFeb 25, 2015
  4. Junio C HamanoFeb 25, 2015
  5. Jeff KingFeb 25, 2015
  6. Junio C HamanoFeb 25, 2015
  7. Jeff KingFeb 25, 2015
  8. Michael J GruberFeb 26, 2015
  9. Duy NguyenFeb 26, 2015
  10. Junio C HamanoFeb 26, 2015
  11. Michael J GruberFeb 27, 2015
  12. Junio C HamanoFeb 27, 2015
  13. Trevor SaundersFeb 27, 2015
  14. Junio C HamanoMar 1, 2015
  15. Trevor SaundersMar 1, 2015
  16. Junio C HamanoMar 1, 2015
  17. Trevor SaundersMar 2, 2015
  18. Noel GrandinMar 4, 2015
  19. Junio C HamanoMar 4, 2015
  20. Jeff KingMar 5, 2015
  21. Junio C HamanoMar 5, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.