{"thread":{"id":"38651","subject":"feature request: excluding files/paths from \"git grep\"","startedAt":"2015-02-25T12:23:30Z","lastAt":"2015-03-05T06:03:54Z","messageCount":21,"participants":["Noel Grandin","Duy Nguyen","Jeff King","Junio C Hamano","Michael J Gruber","Trevor Saunders"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"256636","messageId":"54EDBEC2.8090107@peralex.com","threadId":"38651","inReplyTo":null,"subject":"feature request: excluding files/paths from \"git grep\"","fromName":"Noel Grandin","fromEmail":"noel@peralex.com","sentAt":"2015-02-25T12:23:30Z","receivedAt":"2015-02-25T12:23:30Z","isPatch":false,"sender":{"key":"noel@peralex.com","avatar":null},"body":"Hi\n\nIn our repo (LibreOffice) we have various test files which tend to show up on 'grit grep',\nwhich just generate noise because\n(a) they have lots of common keywords that one might search for in them\nand\n(b) they have very little in the way of linebreaks\n\nSo they tend to generate a lot of noise when searching.\n\nWhat would be nice is a per-user/repo config setting that excludes certain files and paths from the 'git grep' search.\n\nDoes this sound reasonable/acceptable?\n\nThanks, Noel Grandin\n\nDisclaimer: http://www.peralex.com/disclaimer.html\n"},{"id":"256639","messageId":"CACsJy8AM=W4f6u_7YpvmfiBwrJjqfJMJoq6CQYfKOh+qD6rF3Q@mail.gmail.com","threadId":"38651","inReplyTo":"54EDBEC2.8090107@peralex.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-02-25T13:46:37Z","receivedAt":"2015-02-25T13:46:37Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Wed, Feb 25, 2015 at 7:23 PM, Noel Grandin <noel@peralex.com> wrote:\n> What would be nice is a per-user/repo config setting that excludes certain\n> files and paths from the 'git grep' search.\n>\n> Does this sound reasonable/acceptable?\n\nThere is no config setting to do that, but since v1.9.5 you can use\n':!' or ':(exclude) to exclude paths, for example\n\ngit grep foo -- '*.c' ':!src/ ':!*foo*.c'\n\nwill exclude .c files in src directory or contains \"foo\". If you use\nsome exclude patterns often, you can write a short script. Perhaps we\ncould support pathspec macros (similar to git-attr macros), stored in\nconfig file. You still need to type, but it'll be a lot shorter.\n-- \nDuy\n"},{"id":"256641","messageId":"20150225143116.GA13567@peff.net","threadId":"38651","inReplyTo":"CACsJy8AM=W4f6u_7YpvmfiBwrJjqfJMJoq6CQYfKOh+qD6rF3Q@mail.gmail.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-25T14:31:16Z","receivedAt":"2015-02-25T14:31:16Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 25, 2015 at 08:46:37PM +0700, Duy Nguyen wrote:\n\n> On Wed, Feb 25, 2015 at 7:23 PM, Noel Grandin <noel@peralex.com> wrote:\n> > What would be nice is a per-user/repo config setting that excludes certain\n> > files and paths from the 'git grep' search.\n> >\n> > Does this sound reasonable/acceptable?\n> \n> There is no config setting to do that, but since v1.9.5 you can use\n> ':!' or ':(exclude) to exclude paths, for example\n> \n> git grep foo -- '*.c' ':!src/ ':!*foo*.c'\n> \n> will exclude .c files in src directory or contains \"foo\". If you use\n> some exclude patterns often, you can write a short script. Perhaps we\n> could support pathspec macros (similar to git-attr macros), stored in\n> config file. You still need to type, but it'll be a lot shorter.\n\nIf it's an attribute of the file, and not the request, maybe\ngitattributes would be a better fit. You can already do this with:\n\n  *.foo -diff\n\nin your .gitattributes file, though that _also_ marks the files as \"not\nfor diffing\", which may not be desired. There's not a separate \"grep\"\nattribute, but I do not think it would be unreasonable to add one.\n\n-Peff\n"},{"id":"256646","messageId":"xmqqk2z5on72.fsf@gitster.dls.corp.google.com","threadId":"38651","inReplyTo":"20150225143116.GA13567@peff.net","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-25T18:33:53Z","receivedAt":"2015-02-25T18:33:53Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> If it's an attribute of the file, and not the request, maybe\n> gitattributes would be a better fit. You can already do this with:\n>\n>   *.foo -diff\n>\n> in your .gitattributes file, though that _also_ marks the files as \"not\n> for diffing\", which may not be desired. There's not a separate \"grep\"\n> attribute, but I do not think it would be unreasonable to add one.\n\nI have a vague recollection of having a discussion that started with\nsomething like this:\n\n    \"diff\" is named as if it is only for \"diff\" for historical\n    reasons, but it is about \"do we want to treat its raw contents\n    as text?\"\n\nI do not recall its conclusion, but it it were \"Yes, that is what it\nmeans\", then it might be reasonable to:\n\n - have \"git grep\" ignore paths marked with -diff by default\n   (perhaps \"-a\" option to disable, just like GNU)\n\n - have \"git grep\" pay attention to diff.textconv and search in the\n   result of textconv filter.\n\n\n \n"},{"id":"256648","messageId":"20150225185128.GA16569@peff.net","threadId":"38651","inReplyTo":"xmqqk2z5on72.fsf@gitster.dls.corp.google.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-25T18:51:28Z","receivedAt":"2015-02-25T18:51:28Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 25, 2015 at 10:33:53AM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > If it's an attribute of the file, and not the request, maybe\n> > gitattributes would be a better fit. You can already do this with:\n> >\n> >   *.foo -diff\n> >\n> > in your .gitattributes file, though that _also_ marks the files as \"not\n> > for diffing\", which may not be desired. There's not a separate \"grep\"\n> > attribute, but I do not think it would be unreasonable to add one.\n> \n> I have a vague recollection of having a discussion that started with\n> something like this:\n> \n>     \"diff\" is named as if it is only for \"diff\" for historical\n>     reasons, but it is about \"do we want to treat its raw contents\n>     as text?\"\n\nYes, I think we had this discussion, and agreed that is a reasonable\ndefinition...\n\n> I do not recall its conclusion, but it it were \"Yes, that is what it\n> means\", then it might be reasonable to:\n> \n>  - have \"git grep\" ignore paths marked with -diff by default\n>    (perhaps \"-a\" option to disable, just like GNU)\n\n...which led to 41b59bf (grep: respect diff attributes for binary-ness,\n2012-02-02)...\n\n>  - have \"git grep\" pay attention to diff.textconv and search in the\n>    result of textconv filter.\n\n..and 335ec3b (grep: allow to use textconv filters, 2013-05-10).\n\nSo I think _if_ using \"diff\" attributes is enough for this purpose, then\nthere is no code to be written. But if somebody wants to draw a\ndistinction between the uses (I want to diff \"foo\" files, but never see\nthem in grep) then we could introduce a \"grep\" attribute (with the\nfallback being the value of the \"diff\" attribute for that path).\n\n-Peff\n"},{"id":"256650","messageId":"xmqqbnkholx9.fsf@gitster.dls.corp.google.com","threadId":"38651","inReplyTo":"20150225185128.GA16569@peff.net","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-25T19:01:22Z","receivedAt":"2015-02-25T19:01:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> So I think _if_ using \"diff\" attributes is enough for this purpose, then\n> there is no code to be written.  But if somebody wants to draw a\n> distinction between the uses (I want to diff \"foo\" files, but never see\n> them in grep) then we could introduce a \"grep\" attribute (with the\n> fallback being the value of the \"diff\" attribute for that path).\n\nThat is all true.\n\nIf we were to have a new 'grep' attribute that can be used to\nexpress 'It is OK to diff two versions of this path, but hits by\ngrep in this path is useless' (and verse versa), the built-in macro\nattribute 'binary' should also be updated with it.  A path being\n'binary' currently means '-diff -merge -text' but it should also\nmean '-grep' in the new world, if we were to go in that direction.\n\nThanks.\n"},{"id":"256652","messageId":"20150225191108.GA17467@peff.net","threadId":"38651","inReplyTo":"xmqqbnkholx9.fsf@gitster.dls.corp.google.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-02-25T19:11:08Z","receivedAt":"2015-02-25T19:11:08Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Feb 25, 2015 at 11:01:22AM -0800, Junio C Hamano wrote:\n\n> Jeff King <peff@peff.net> writes:\n> \n> > So I think _if_ using \"diff\" attributes is enough for this purpose, then\n> > there is no code to be written.  But if somebody wants to draw a\n> > distinction between the uses (I want to diff \"foo\" files, but never see\n> > them in grep) then we could introduce a \"grep\" attribute (with the\n> > fallback being the value of the \"diff\" attribute for that path).\n> \n> That is all true.\n> \n> If we were to have a new 'grep' attribute that can be used to\n> express 'It is OK to diff two versions of this path, but hits by\n> grep in this path is useless' (and verse versa), the built-in macro\n> attribute 'binary' should also be updated with it.  A path being\n> 'binary' currently means '-diff -merge -text' but it should also\n> mean '-grep' in the new world, if we were to go in that direction.\n\nI think it would do so automatically. There is no \"grep\" attribute\ngiven, so we fall back to the \"-diff\" attribute. But I do not mind\nmodifying the macro to be more explicit.\n\nNote also that I am not volunteering to work on this, nor am I convinced\nit's actually worth pursuing. I've yet to see a useful case where you\nwould want text diffs but not greps (or vice versa), and if we can avoid\ncluttering the attribute space, we should. I was mostly pointing it out\nthat it is not logically inconsistent to want such a thing. :)\n\nIf somebody does look into it, I suspect the place to start is modifying\nuserdiff_find_by_path to optionally prefer \"grep\" to \"diff\".\n\n-Peff\n"},{"id":"256679","messageId":"54EF0089.6070605@drmicha.warpmail.net","threadId":"38651","inReplyTo":"20150225191108.GA17467@peff.net","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-02-26T11:16:25Z","receivedAt":"2015-02-26T11:16:25Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Jeff King venit, vidit, dixit 25.02.2015 20:11:\n> On Wed, Feb 25, 2015 at 11:01:22AM -0800, Junio C Hamano wrote:\n> \n>> Jeff King <peff@peff.net> writes:\n>>\n>>> So I think _if_ using \"diff\" attributes is enough for this purpose, then\n>>> there is no code to be written.  But if somebody wants to draw a\n>>> distinction between the uses (I want to diff \"foo\" files, but never see\n>>> them in grep) then we could introduce a \"grep\" attribute (with the\n>>> fallback being the value of the \"diff\" attribute for that path).\n>>\n>> That is all true.\n>>\n>> If we were to have a new 'grep' attribute that can be used to\n>> express 'It is OK to diff two versions of this path, but hits by\n>> grep in this path is useless' (and verse versa), the built-in macro\n>> attribute 'binary' should also be updated with it.  A path being\n>> 'binary' currently means '-diff -merge -text' but it should also\n>> mean '-grep' in the new world, if we were to go in that direction.\n> \n> I think it would do so automatically. There is no \"grep\" attribute\n> given, so we fall back to the \"-diff\" attribute. But I do not mind\n> modifying the macro to be more explicit.\n> \n> Note also that I am not volunteering to work on this, nor am I convinced\n> it's actually worth pursuing. I've yet to see a useful case where you\n> would want text diffs but not greps (or vice versa), and if we can avoid\n> cluttering the attribute space, we should. I was mostly pointing it out\n> that it is not logically inconsistent to want such a thing. :)\n> \n> If somebody does look into it, I suspect the place to start is modifying\n> userdiff_find_by_path to optionally prefer \"grep\" to \"diff\".\n> \n> -Peff\n> \n\nSo, as a summary of the discussion, it seems it's time to switch the\ndefault to --textconv for git grep?\n\nMichael\n"},{"id":"256681","messageId":"CACsJy8Dw5tfQ72kqc-QEfGmbs=ZOePGuXd6+tRtkmApMcdma-A@mail.gmail.com","threadId":"38651","inReplyTo":"54EF0089.6070605@drmicha.warpmail.net","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2015-02-26T11:58:14Z","receivedAt":"2015-02-26T11:58:14Z","isPatch":false,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Thu, Feb 26, 2015 at 6:16 PM, Michael J Gruber\n<git@drmicha.warpmail.net> wrote:\n> So, as a summary of the discussion, it seems it's time to switch the\n> default to --textconv for git grep?\n\nEither that or make it clearer in git-grep.txt about this diff\nattribute. It takes me some time to make the connection after reading\nboth git-grep.txt and gitattributes.txt\n-- \nDuy\n"},{"id":"256707","messageId":"xmqqr3tcl78o.fsf@gitster.dls.corp.google.com","threadId":"38651","inReplyTo":"54EF0089.6070605@drmicha.warpmail.net","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-26T20:59:03Z","receivedAt":"2015-02-26T20:59:03Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> So, as a summary of the discussion, it seems it's time to switch the\n> default to --textconv for git grep?\n\nHmmm, why?\n\nNobody seems to be asking for such a change in this thread.  The\noriginal issue IIRC was that the grep output was unnecessary for\nsome paths and the repository did not mark these paths as such.\nOnce they are marked as \"-diff\", there is no reason why you want to\ntrigger textconv to squelch the hits from grep.\n\nSo that does not sound to me a summary of the discussion at all.\n"},{"id":"256737","messageId":"20150227100441.GA11861@tsaunders-iceball.corp.tor1.mozilla.com","threadId":"38651","inReplyTo":"20150225191108.GA17467@peff.net","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Trevor Saunders","fromEmail":"tbsaunde@tbsaunde.org","sentAt":"2015-02-27T10:04:41Z","receivedAt":"2015-02-27T10:04:41Z","isPatch":false,"sender":{"key":"tbsaunde@tbsaunde.org","avatar":null},"body":"On Wed, Feb 25, 2015 at 02:11:08PM -0500, Jeff King wrote:\n> On Wed, Feb 25, 2015 at 11:01:22AM -0800, Junio C Hamano wrote:\n> \n> > Jeff King <peff@peff.net> writes:\n> > \n> > > So I think _if_ using \"diff\" attributes is enough for this purpose, then\n> > > there is no code to be written.  But if somebody wants to draw a\n> > > distinction between the uses (I want to diff \"foo\" files, but never see\n> > > them in grep) then we could introduce a \"grep\" attribute (with the\n> > > fallback being the value of the \"diff\" attribute for that path).\n> > \n> > That is all true.\n> > \n> > If we were to have a new 'grep' attribute that can be used to\n> > express 'It is OK to diff two versions of this path, but hits by\n> > grep in this path is useless' (and verse versa), the built-in macro\n> > attribute 'binary' should also be updated with it.  A path being\n> > 'binary' currently means '-diff -merge -text' but it should also\n> > mean '-grep' in the new world, if we were to go in that direction.\n> \n> I think it would do so automatically. There is no \"grep\" attribute\n> given, so we fall back to the \"-diff\" attribute. But I do not mind\n> modifying the macro to be more explicit.\n> \n> Note also that I am not volunteering to work on this, nor am I convinced\n> it's actually worth pursuing. I've yet to see a useful case where you\n> would want text diffs but not greps (or vice versa), and if we can avoid\n> cluttering the attribute space, we should. I was mostly pointing it out\n> that it is not logically inconsistent to want such a thing. :)\n\n There have been cases where I wanted grep to always ignore certain\n files, but to still get text diffs for those files.  One case is people\n insist on using ChangeLog files, and another is people who commit\n generated files of one sort or another.\n\n Trev\n\n> \n> If somebody does look into it, I suspect the place to start is modifying\n> userdiff_find_by_path to optionally prefer \"grep\" to \"diff\".\n> \n> -Peff\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"256744","messageId":"54F08989.2050504@drmicha.warpmail.net","threadId":"38651","inReplyTo":"xmqqr3tcl78o.fsf@gitster.dls.corp.google.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Michael J Gruber","fromEmail":"git@drmicha.warpmail.net","sentAt":"2015-02-27T15:13:13Z","receivedAt":"2015-02-27T15:13:13Z","isPatch":false,"sender":{"key":"git@grubix.eu","avatar":"https://avatars.githubusercontent.com/u/233215?v=4"},"body":"Junio C Hamano venit, vidit, dixit 26.02.2015 21:59:\n> Michael J Gruber <git@drmicha.warpmail.net> writes:\n> \n>> So, as a summary of the discussion, it seems it's time to switch the\n>> default to --textconv for git grep?\n> \n> Hmmm, why?\n> \n> Nobody seems to be asking for such a change in this thread.  The\n> original issue IIRC was that the grep output was unnecessary for\n> some paths and the repository did not mark these paths as such.\n> Once they are marked as \"-diff\", there is no reason why you want to\n> trigger textconv to squelch the hits from grep.\n\nOf course not. All that I want, and that I wanted back then, was to have\ndiff and grep behave the same.\n\n> So that does not sound to me a summary of the discussion at all.\n> \n\nWell, your conditional\n\n> I do not recall its conclusion, but it it were \"Yes, that is what it\n> means\", then it might be reasonable to:\n> \n>  - have \"git grep\" ignore paths marked with -diff by default\n>    (perhaps \"-a\" option to disable, just like GNU)\n> \n>  - have \"git grep\" pay attention to diff.textconv and search in the\n>    result of textconv filter.\n\nand Jeff's \"Yes\" on that condition certainly read like that to me: Make\n\"git grep\" react to \"diff\", \"-diff\" attributes in the same way as \"git\ndiff\".\n\nBut I've set up my alias greppp since then and don't care any more, and\nI won't invest anything in this topic any more.\n\nMichael\n"},{"id":"256752","messageId":"xmqq4mq7jh9d.fsf@gitster.dls.corp.google.com","threadId":"38651","inReplyTo":"54F08989.2050504@drmicha.warpmail.net","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-02-27T19:17:50Z","receivedAt":"2015-02-27T19:17:50Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Michael J Gruber <git@drmicha.warpmail.net> writes:\n\n> Junio C Hamano venit, vidit, dixit 26.02.2015 21:59:\n>\n>> So that does not sound to me a summary of the discussion at all.\n>\n> Well, your conditional\n>\n>> I do not recall its conclusion, but it it were \"Yes, that is what it\n>> means\", then it might be reasonable to:\n>> \n>>  - have \"git grep\" ignore paths marked with -diff by default\n>>    (perhaps \"-a\" option to disable, just like GNU)\n>> \n>>  - have \"git grep\" pay attention to diff.textconv and search in the\n>>    result of textconv filter.\n>\n> and Jeff's \"Yes\" on that condition certainly read like that to me: Make\n> \"git grep\" react to \"diff\", \"-diff\" attributes in the same way as \"git\n> diff\".\n\nAh, OK, I missed that flow of thought.\n\nI read the conclusion as \"_if_ using \"diff\" attributes is enough for\nthis purpose, then there is no code to be written ... but 'grep' and\n'diff' may want to be different.\"\n\nOnce we know if they do *not* want to be different, I agree that it\nmay make things more consistent to turn --textconv on for binary\nfiles when running grep.\n"},{"id":"256789","messageId":"xmqqvbilh0wn.fsf@gitster.dls.corp.google.com","threadId":"38651","inReplyTo":"20150227100441.GA11861@tsaunders-iceball.corp.tor1.mozilla.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-01T03:06:16Z","receivedAt":"2015-03-01T03:06:16Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Trevor Saunders <tbsaunde@tbsaunde.org> writes:\n\n>  There have been cases where I wanted grep to always ignore certain\n>  files, but to still get text diffs for those files.  One case is people\n>  insist on using ChangeLog files, and another is people who commit\n>  generated files of one sort or another.\n\nThe attributes are to say \"the contents to be stored in this file is\nof this nature\".  Something inherent to the type of the contents,\nand that is why there is no way to countermand them from the command\nline.\n\nThe \"nature of the content\" may be \"result of comparing two versions\nof them textually will never make sense to humans\", or \"result of\nfinding substrings in them will never make sense to humans\", which\nare what \"-diff\" and hypothetical \"-grep\" mean, respectively.\n\n\"It is inconvenient that I see hits in ChangeLog files when I look\nfor string BUG\" does not make ChangeLog inherently \"result of\nfinding substrings in it never makes sense to humans\"-kind of file\ntype.  Maybe somebody who is playing a role of a coder right now may\nnot look at existing ChangeLog entries, but when that same person\nplays the role of a release manager next day, running grep on older\nChangeLog files may become necessary to find changes related to\nrecent changes.  For these \"per-invocation\" differences, attributes\nto declare permenent/inherent nature of the contents is much less\nsuited than per-invocation inclusion/exclusion mechanism based on\npathspecs, I would think.\n"},{"id":"256802","messageId":"20150301130142.GA24782@tsaunders-iceball.corp.tor1.mozilla.com","threadId":"38651","inReplyTo":"xmqqvbilh0wn.fsf@gitster.dls.corp.google.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Trevor Saunders","fromEmail":"tbsaunde@tbsaunde.org","sentAt":"2015-03-01T13:03:08Z","receivedAt":"2015-03-01T13:03:08Z","isPatch":false,"sender":{"key":"tbsaunde@tbsaunde.org","avatar":null},"body":"On Sat, Feb 28, 2015 at 07:06:16PM -0800, Junio C Hamano wrote:\n> Trevor Saunders <tbsaunde@tbsaunde.org> writes:\n> \n> >  There have been cases where I wanted grep to always ignore certain\n> >  files, but to still get text diffs for those files.  One case is people\n> >  insist on using ChangeLog files, and another is people who commit\n> >  generated files of one sort or another.\n> \n> The attributes are to say \"the contents to be stored in this file is\n> of this nature\".  Something inherent to the type of the contents,\n> and that is why there is no way to countermand them from the command\n> line.\n> \n> The \"nature of the content\" may be \"result of comparing two versions\n> of them textually will never make sense to humans\", or \"result of\n> finding substrings in them will never make sense to humans\", which\n> are what \"-diff\" and hypothetical \"-grep\" mean, respectively.\n> \n> \"It is inconvenient that I see hits in ChangeLog files when I look\n> for string BUG\" does not make ChangeLog inherently \"result of\n> finding substrings in it never makes sense to humans\"-kind of file\n> type.  Maybe somebody who is playing a role of a coder right now may\n> not look at existing ChangeLog entries, but when that same person\n> plays the role of a release manager next day, running grep on older\n> ChangeLog files may become necessary to find changes related to\n> recent changes.  For these \"per-invocation\" differences, attributes\n> to declare permenent/inherent nature of the contents is much less\n> suited than per-invocation inclusion/exclusion mechanism based on\n> pathspecs, I would think.\n\nI think that makes some amount of sense, however typing stuff like\n--exclude=ChangeLog all the time is not terribly easy on the hands.\nWould it make sense to instead add a config variable grep.exclude?\n\nTrev\n\n> \n> \n"},{"id":"256811","messageId":"xmqqr3t8fgm4.fsf@gitster.dls.corp.google.com","threadId":"38651","inReplyTo":"20150301130142.GA24782@tsaunders-iceball.corp.tor1.mozilla.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-01T23:22:11Z","receivedAt":"2015-03-01T23:22:11Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Trevor Saunders <tbsaunde@tbsaunde.org> writes:\n\n>> ...  For these \"per-invocation\" differences, attributes\n>> to declare permenent/inherent nature of the contents is much less\n>> suited than per-invocation inclusion/exclusion mechanism based on\n>> pathspecs, I would think.\n>\n> I think that makes some amount of sense, however typing stuff like\n> --exclude=ChangeLog all the time is not terribly easy on the hands.\n> Would it make sense to instead add a config variable grep.exclude?\n\nI do not think it makes much more sense for at least three reasons.\nfor one thing, It still goes against \"per-invocation\" nature of what\nis being done.  Your \"for this invocation I do not want ChangeLog\"\ndoes not have to be limited to 'grep'.  And also \"I end up having to\ngive these pathspecs all the time\" is not limited to negative ones.\n\nWe have magic pathspecs, like \"This pattern is used to match the\nstring case-insensitively\", \"This pattern specifies that the path\nshould *not* match it\", etc.  How about adding a new feature that\nlets you say \"This is a short hand to giving these pathspecs\" and\ncall that \"pathspec macro\"?\n\nIf you get tired to keep having to type\n\n    $ git log -- Documentation/ ':!Documentation/technical/'\n\nevery time you want to check the end-user facing documentation\npages, you could for example say (I am using a made-up 'macro'\npathspec magic that is introduced by ':*' followed by a <macro\nname>):\n\n    $ git log -- ':*userdoc'\n\nand the same macro specification could be used for all the other\nthings that take pathspecs (grep, add, diff, etc.).\n\nYou could then have something like this to define your own \"nolog\"\nmacro:\n\n    [pathspecMacro]\n        nolog = ':!ChangeLog' ':!ChangeLog.*'\n\nto shorten your invocation of \"grep\" by appending it when you want\nto exclude some files, i.e.\n\n    $ git grep -e pattern -- \\*.c ':*nolog'\n\nand the same pathspec macro can be used in other places, not just\n\"grep\".  Wouldn't it make more sense?\n"},{"id":"256835","messageId":"20150302125017.GA4464@tsaunders-iceball.corp.tor1.mozilla.com","threadId":"38651","inReplyTo":"xmqqr3t8fgm4.fsf@gitster.dls.corp.google.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Trevor Saunders","fromEmail":"tbsaunde@tbsaunde.org","sentAt":"2015-03-02T12:50:17Z","receivedAt":"2015-03-02T12:50:17Z","isPatch":false,"sender":{"key":"tbsaunde@tbsaunde.org","avatar":null},"body":"On Sun, Mar 01, 2015 at 03:22:11PM -0800, Junio C Hamano wrote:\n> Trevor Saunders <tbsaunde@tbsaunde.org> writes:\n> \n> >> ...  For these \"per-invocation\" differences, attributes\n> >> to declare permenent/inherent nature of the contents is much less\n> >> suited than per-invocation inclusion/exclusion mechanism based on\n> >> pathspecs, I would think.\n> >\n> > I think that makes some amount of sense, however typing stuff like\n> > --exclude=ChangeLog all the time is not terribly easy on the hands.\n> > Would it make sense to instead add a config variable grep.exclude?\n> \n> I do not think it makes much more sense for at least three reasons.\n> for one thing, It still goes against \"per-invocation\" nature of what\n> is being done.  Your \"for this invocation I do not want ChangeLog\"\n> does not have to be limited to 'grep'.  And also \"I end up having to\n> give these pathspecs all the time\" is not limited to negative ones.\n\nI think what is somewhat special about grep is that I want to ignore a\nset of paths such a large majority of the time that I really want to\nchange the default.  I could see someone wanting to do the same thing\nfor diff or log maybe, and so adding diff.exclude, but personally I\ndon't have a use for it.\n\n> We have magic pathspecs, like \"This pattern is used to match the\n> string case-insensitively\", \"This pattern specifies that the path\n> should *not* match it\", etc.  How about adding a new feature that\n> lets you say \"This is a short hand to giving these pathspecs\" and\n> call that \"pathspec macro\"?\n> \n> If you get tired to keep having to type\n> \n>     $ git log -- Documentation/ ':!Documentation/technical/'\n> \n> every time you want to check the end-user facing documentation\n> pages, you could for example say (I am using a made-up 'macro'\n> pathspec magic that is introduced by ':*' followed by a <macro\n> name>):\n> \n>     $ git log -- ':*userdoc'\n> \n> and the same macro specification could be used for all the other\n> things that take pathspecs (grep, add, diff, etc.).\n\nI can certainly see use cases for that, say\ngit log -- :!t/ :!foo/tests/ :!bar/testsuite/\nto see what non test changes have happened in a project that doesn't\nhave a standardized name for test directories.\n\n> You could then have something like this to define your own \"nolog\"\n> macro:\n> \n>     [pathspecMacro]\n>         nolog = ':!ChangeLog' ':!ChangeLog.*'\n> \n> to shorten your invocation of \"grep\" by appending it when you want\n> to exclude some files, i.e.\n> \n>     $ git grep -e pattern -- \\*.c ':*nolog'\n> \n> and the same pathspec macro can be used in other places, not just\n> \"grep\".  Wouldn't it make more sense?\n\nI think they solve somewhat different problems, but maybe my problem is\nso specialized I should just have a wrapper around grep that changes\ndefaults.\n\nTrev\n"},{"id":"256995","messageId":"54F6EB96.6080500@peralex.com","threadId":"38651","inReplyTo":"20150302125017.GA4464@tsaunders-iceball.corp.tor1.mozilla.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Noel Grandin","fromEmail":"noel@peralex.com","sentAt":"2015-03-04T11:25:10Z","receivedAt":"2015-03-04T11:25:10Z","isPatch":false,"sender":{"key":"noel@peralex.com","avatar":null},"body":"On 2015-03-02 02:50 PM, Trevor Saunders wrote:\n> I think they solve somewhat different problems, but maybe my problem is so specialized I should just have a wrapper \n> around grep that changes defaults. Trev \n\nI'm with Trevor on this one. While I see the appeal of the generality of a macro solution, this is really just about \nconvenience for me on a per-project basis.\n\nAs in, while working on a specific project, I sometimes just want to exclude, for the time being, a bunch of stuff from \n'git grep'.\n\nMind you, I use 'git grep' a hang of a lot during development, since it is so powerful, so maybe that's just me.\n\nThanks, Noel Grandin\n\n\n\nDisclaimer: http://www.peralex.com/disclaimer.html\n"},{"id":"257016","messageId":"xmqq385k8ot1.fsf@gitster.dls.corp.google.com","threadId":"38651","inReplyTo":"54F6EB96.6080500@peralex.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-04T20:56:10Z","receivedAt":"2015-03-04T20:56:10Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Noel Grandin <noel@peralex.com> writes:\n\n> On 2015-03-02 02:50 PM, Trevor Saunders wrote:\n>> I think they solve somewhat different problems, but maybe my problem\n>> is so specialized I should just have a wrapper around grep that\n>> changes defaults. Trev \n>\n> I'm with Trevor on this one. While I see the appeal of the generality\n> of a macro solution, this is really just about convenience for me on a\n> per-project basis.\n>\n> As in, while working on a specific project, I sometimes just want to\n> exclude, for the time being, a bunch of stuff from 'git grep'.\n\nThe key word here is \"for the time being\", though.  What would you\ndo once you are done with the \"for the time being\" activity?  \"git\nconfig --unset\"?\n\nIf you forget to do so when the \"for the time being\" activity ends,\nand then you try to run 'git grep' and see that you did not get\nexpected hits from hierarchies that you set to exclude earlier, you\neither (1) get misled to a wrong decison based on that false\nnon-hit, or (2) start scratching your head, wasting time trying to\nfigure out why 'git grep' is not hitting, no?\n\nI expect the answer might be \"No, I won't forget; I am very well\norganized and you do not have to worry for me\".  But a feature is an\ninvitation for people other than yourself, so...\n"},{"id":"257053","messageId":"20150305052206.GC3344@peff.net","threadId":"38651","inReplyTo":"xmqq385k8ot1.fsf@gitster.dls.corp.google.com","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-03-05T05:22:06Z","receivedAt":"2015-03-05T05:22:06Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Wed, Mar 04, 2015 at 12:56:10PM -0800, Junio C Hamano wrote:\n\n> > As in, while working on a specific project, I sometimes just want to\n> > exclude, for the time being, a bunch of stuff from 'git grep'.\n> \n> The key word here is \"for the time being\", though.  What would you\n> do once you are done with the \"for the time being\" activity?  \"git\n> config --unset\"?\n\nIMHO this is being too paternalistic. You can already shoot yourself\nin the foot by configuring an alias to grep, running your alias, and\nwondering why it does not produce the results you wanted.\n\nBut I'd also oppose a `grep.pathspecs` config option for a similar\nreason: you can already accomplish the same thing (and more) with an\nalias.\n\n-Peff\n\nPS One annoying thing about aliases is that you cannot re-alias an\n   existing command, and git has already taken all of the good, easy\n   names that we have trained our fingers for. :)\n\n   Of course re-aliasing git-grep is another recipe for head-scratching\n   (and broken scripts), but I am not sure there aren't a host of other\n   ways to do a similar thing (basically any configuration option has\n   the capacity to produce unexpected results if you forget that it is\n   set).\n\n   I dunno. Probably I am a bad person for dredging up that ancient\n   argument again.\n"},{"id":"257055","messageId":"xmqqy4nc3rqt.fsf@gitster.dls.corp.google.com","threadId":"38651","inReplyTo":"20150305052206.GC3344@peff.net","subject":"Re: feature request: excluding files/paths from \"git grep\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-03-05T06:03:54Z","receivedAt":"2015-03-05T06:03:54Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Wed, Mar 04, 2015 at 12:56:10PM -0800, Junio C Hamano wrote:\n>\n>> > As in, while working on a specific project, I sometimes just want to\n>> > exclude, for the time being, a bunch of stuff from 'git grep'.\n>> \n>> The key word here is \"for the time being\", though.  What would you\n>> do once you are done with the \"for the time being\" activity?  \"git\n>> config --unset\"?\n>\n> IMHO this is being too paternalistic. You can already shoot yourself\n> in the foot by configuring an alias to grep, running your alias, and\n> wondering why it does not produce the results you wanted.\n\nYeah, as I said, it is a deliberately paternalistic stance.  But at\nleast when I say \"git mygrep\" using the alias mechanism and get a\nresult that is different from what I expect from \"git grep\", I would\nknow I am doing something different with \"mygrep\" from \"grep\", no?\n\nAnd a great thing about that \"use alias\" approach is that we can\nsidestep the entire \"then what should I do when I have to override\nthe configured thing for one-shot invocation?\" question, as there is\nan obvious simple answer \"don't use that alias but use the\nunderlying command\".\n"}]}