{"thread":{"id":"15162","subject":"teach git diff -v/--invert-match?","startedAt":"2008-08-22T14:51:16Z","lastAt":"2008-08-27T00:38:18Z","messageCount":7,"participants":["Brian Ericson","Jeff King","Junio C Hamano","Paolo Bonzini"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"88140","messageId":"48AED264.60600@visi.com","threadId":"15162","inReplyTo":null,"subject":"teach git diff -v/--invert-match?","fromName":"Brian Ericson","fromEmail":"bme@visi.com","sentAt":"2008-08-22T14:51:16Z","receivedAt":"2008-08-22T14:51:16Z","isPatch":false,"sender":{"key":"bme@visi.com","avatar":null},"body":"I'm wondering what it would take to teach git diff to invert the -S \nstring (like git grep).\n\nI'm finding git diff -S<string> [--pickaxe-regex] to be really useful, \nbut find I have cases where I want to ignore differences.  For example, \nI might not care if the only changes to a Java file, for example, are \nrelated to import statements.  I'd like to be able to do something like \n\"git diff -S'^import' --pickaxe-regex -v\".  I'll admit I can get by with \nsomething like \"git diff -S'^[^i]' --pickaxe-regex\", but am pining for \n-v/--invert-match.\n"},{"id":"88181","messageId":"20080822193947.GA31322@coredump.intra.peff.net","threadId":"15162","inReplyTo":"48AED264.60600@visi.com","subject":"Re: teach git diff -v/--invert-match?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-08-22T19:39:47Z","receivedAt":"2008-08-22T19:39:47Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Aug 22, 2008 at 09:51:16AM -0500, Brian Ericson wrote:\n\n> I'm wondering what it would take to teach git diff to invert the -S  \n> string (like git grep).\n\nI think you would have to figure out the desired semantics first.\n\n> I'm finding git diff -S<string> [--pickaxe-regex] to be really useful,  \n> but find I have cases where I want to ignore differences.  For example, I \n> might not care if the only changes to a Java file, for example, are  \n> related to import statements.  I'd like to be able to do something like  \n> \"git diff -S'^import' --pickaxe-regex -v\".  I'll admit I can get by with  \n> something like \"git diff -S'^[^i]' --pickaxe-regex\", but am pining for  \n> -v/--invert-match.\n\nI would have thought \"-v\" meant \"match any changes which do not have\nthis pattern\". But you want \"match any changes that have any line which\ndoes not have this pattern.\"\n\nIOW, mine would not match any changes which used an import statement,\nwhereas yours would not match any changes which are _only_ import\nstatements.\n\n-Peff\n"},{"id":"88207","messageId":"48AF2FBB.2080401@visi.com","threadId":"15162","inReplyTo":"20080822193947.GA31322@coredump.intra.peff.net","subject":"Re: teach git diff -v/--invert-match?","fromName":"Brian Ericson","fromEmail":"bme@visi.com","sentAt":"2008-08-22T21:29:31Z","receivedAt":"2008-08-22T21:29:31Z","isPatch":false,"sender":{"key":"bme@visi.com","avatar":null},"body":"I was just working on a reply to my own email as I realized it was only \ndumb-luck that\nconverted 1200 noisy changes into a couple of dozen.  \"-S\" matches only \nthe string\nitself, not the line the string resides on.  So, -Sxyz will match if \n\"xyz\" itself was\nadded or deleted in the diff (if \"xyz\" is on a line that's changed but \ndid not itself change,\nit won't match).  Funny that I actually knew this -- I use it to look for\nSystem.out.println additions among other things.\n\nInterestingly, if I wanted to know if an import changed (on top of \nknowing if imports were\nadded or deleted), eg:\n-import foo;\n+import bar;\n\nI couldn't tell you how to do it.  The string \"import\" didn't change.  \nI'd've guessed that\n\"-S'import.*;' --pickaxe-regex\" would have been sufficient, but that \ndoesn't work.\n\nJeff King wrote:\n> On Fri, Aug 22, 2008 at 09:51:16AM -0500, Brian Ericson wrote:\n>\n>   \n>> I'm wondering what it would take to teach git diff to invert the -S  \n>> string (like git grep).\n>>     \n>\n> I think you would have to figure out the desired semantics first.\n>   \nI think mostly what I want is a happy marriage between git diff & git \ngrep so that if the\nchanged lines matched (or didn't match) the file would show up (or \nnot).  I'd like to grep\nadded and removed lines (the diff itself) for a pattern and either \ninclude or exclude the file\nbased on matches.\n>   \n>> I'm finding git diff -S<string> [--pickaxe-regex] to be really useful,  \n>> but find I have cases where I want to ignore differences.  For example, I \n>> might not care if the only changes to a Java file, for example, are  \n>> related to import statements.  I'd like to be able to do something like  \n>> \"git diff -S'^import' --pickaxe-regex -v\".  I'll admit I can get by with  \n>> something like \"git diff -S'^[^i]' --pickaxe-regex\", but am pining for  \n>> -v/--invert-match.\n>>     \n>\n> I would have thought \"-v\" meant \"match any changes which do not have\n> this pattern\". But you want \"match any changes that have any line which\n> does not have this pattern.\"\n>   \nRight.  Good summary!  It's probably not accurate to use \"-S\" for my \ninterpretation unless\n--pickaxe-regex behaved more as I outlined above.  It's probably a \nsubtle enough difference\n> IOW, mine would not match any changes which used an import statement,\n> whereas yours would not match any changes which are _only_ import\n> statements.\n>   \nThe current behavior seems to work well to answer questions like \"has \nsomebody added\na System.out.println\", I'd like it to be able to ignore or consider \nfiles based on line changes\nthat contain a string where the string itself did not change.\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>\n>\n>   \n"},{"id":"88210","messageId":"20080822214208.GA4498@coredump.intra.peff.net","threadId":"15162","inReplyTo":"48AF2FBB.2080401@visi.com","subject":"Re: teach git diff -v/--invert-match?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-08-22T21:42:08Z","receivedAt":"2008-08-22T21:42:08Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Aug 22, 2008 at 04:29:31PM -0500, Brian Ericson wrote:\n\n> I was just working on a reply to my own email as I realized it was\n> only  dumb-luck that converted 1200 noisy changes into a couple of\n> dozen.  \"-S\" matches only  the string itself, not the line the string\n> resides on.  So, -Sxyz will match if  \"xyz\" itself was added or\n> deleted in the diff (if \"xyz\" is on a line that's changed but  did not\n> itself change, it won't match).  Funny that I actually knew this -- I\n> use it to look for System.out.println additions among other things.\n\nYes (though I couldn't have told you that without experimenting -- I\nalways assumed it checked whole lines).\n\n> Interestingly, if I wanted to know if an import changed (on top of\n> knowing if imports were added or deleted), eg: -import foo; +import\n> bar;\n\nThat is a bit harder, and AFAIK not possible with -S. You could always\npost process the log output. E.g.,:\n\n  git log -p | perl -ne '\n    BEGIN { $/ = \"commit \" }\n    chomp; print if /^\\+import /\n  '\n\nwhich lets you get quite fancy with the matching.\n\n> The current behavior seems to work well to answer questions like \"has\n> somebody added a System.out.println\",\n\nThe usual question (for me, anyway) is \"when did X get introduced?\" when\nlooking for a token.\n\n-Peff\n"},{"id":"88211","messageId":"7vmyj47mil.fsf@gitster.siamese.dyndns.org","threadId":"15162","inReplyTo":"20080822214208.GA4498@coredump.intra.peff.net","subject":"Re: teach git diff -v/--invert-match?","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2008-08-22T21:44:34Z","receivedAt":"2008-08-22T21:44:34Z","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 Fri, Aug 22, 2008 at 04:29:31PM -0500, Brian Ericson wrote:\n>\n>> I was just working on a reply to my own email as I realized it was\n>> only  dumb-luck that converted 1200 noisy changes into a couple of\n>> dozen.  \"-S\" matches only  the string itself, not the line the string\n>> resides on.  So, -Sxyz will match if  \"xyz\" itself was added or\n>> deleted in the diff (if \"xyz\" is on a line that's changed but  did not\n>> itself change, it won't match).  Funny that I actually knew this -- I\n>> use it to look for System.out.println additions among other things.\n>\n> Yes (though I couldn't have told you that without experimenting -- I\n> always assumed it checked whole lines).\n\nThe -Sstring counts the number of 'string' in preimage and postimage and\nskips the commit if they are the same.  Nothing more.\n"},{"id":"88439","messageId":"48B27E51.2020709@gnu.org","threadId":"15162","inReplyTo":"20080822193947.GA31322@coredump.intra.peff.net","subject":"Re: teach git diff -v/--invert-match?","fromName":"Paolo Bonzini","fromEmail":"bonzini@gnu.org","sentAt":"2008-08-25T09:41:37Z","receivedAt":"2008-08-25T09:41:37Z","isPatch":false,"sender":{"key":"bonzini@gnu.org","avatar":"https://avatars.githubusercontent.com/u/42082?v=4"},"body":"\n> I would have thought \"-v\" meant \"match any changes which do not have\n> this pattern\". But you want \"match any changes that have any line which\n> does not have this pattern.\"\n\nYours could be \"-L/--without-match\" (in grep, -L/--files-without-match\nonly prints the names of files containing no match).\n\nPaolo\n"},{"id":"88675","messageId":"20080827003818.GD7347@coredump.intra.peff.net","threadId":"15162","inReplyTo":"48B27E51.2020709@gnu.org","subject":"Re: teach git diff -v/--invert-match?","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2008-08-27T00:38:18Z","receivedAt":"2008-08-27T00:38:18Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Aug 25, 2008 at 11:41:37AM +0200, Paolo Bonzini wrote:\n\n> > I would have thought \"-v\" meant \"match any changes which do not have\n> > this pattern\". But you want \"match any changes that have any line which\n> > does not have this pattern.\"\n> \n> Yours could be \"-L/--without-match\" (in grep, -L/--files-without-match\n> only prints the names of files containing no match).\n\nAh, yes, that would be better. I think we decided that Brian's original\nproblem didn't really work with -S, and I don't actually need this\nbehavior enough to implement it. But your suggestion is a good one if\nsomebody cares to do so.\n\n-Peff\n"}]}