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

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

From
TSTrevor Saunders <tbsaunde@tbsaunde.org>
Date
Mar 2, 2015, 12:50 UTC
Message-ID
<20150302125017.GA4464@tsaunders-iceball.corp.tor1.mozilla.com>
In-Reply-To
<xmqqr3t8fgm4.fsf@gitster.dls.corp.google.com>
On Sun, Mar 01, 2015 at 03:22:11PM -0800, Junio C Hamano wrote:
Show 16 quoted lines
> Trevor Saunders <tbsaunde@tbsaunde.org> writes:
> 
> >> ...  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.

I think what is somewhat special about grep is that I want to ignore a set of paths such a large majority of the time that I really want to change the default. I could see someone wanting to do the same thing for diff or log maybe, and so adding diff.exclude, but personally I don't have a use for it.

Show 19 quoted lines
> 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.).

I can certainly see use cases for that, say git log -- :!t/ :!foo/tests/ :!bar/testsuite/ to see what non test changes have happened in a project that doesn't have a standardized name for test directories.

Show 13 quoted lines
> 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?

I think they solve somewhat different problems, but maybe my problem is so specialized I should just have a wrapper around grep that changes defaults.

Trev
Previous: Junio C HamanoNext: Noel Grandin
Message 17 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.