* teach git diff -v/--invert-match?
@ 2008-08-22 14:51 Brian Ericson
2008-08-22 19:39 ` Jeff King
0 siblings, 1 reply; 7+ messages in thread
From: Brian Ericson @ 2008-08-22 14:51 UTC (permalink / raw)
To: git
I'm wondering what it would take to teach git diff to invert the -S
string (like git grep).
I'm finding git diff -S<string> [--pickaxe-regex] to be really useful,
but find I have cases where I want to ignore differences. For example,
I might not care if the only changes to a Java file, for example, are
related to import statements. I'd like to be able to do something like
"git diff -S'^import' --pickaxe-regex -v". I'll admit I can get by with
something like "git diff -S'^[^i]' --pickaxe-regex", but am pining for
-v/--invert-match.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: teach git diff -v/--invert-match?
2008-08-22 14:51 teach git diff -v/--invert-match? Brian Ericson
@ 2008-08-22 19:39 ` Jeff King
2008-08-22 21:29 ` Brian Ericson
2008-08-25 9:41 ` Paolo Bonzini
0 siblings, 2 replies; 7+ messages in thread
From: Jeff King @ 2008-08-22 19:39 UTC (permalink / raw)
To: Brian Ericson; +Cc: git
On Fri, Aug 22, 2008 at 09:51:16AM -0500, Brian Ericson wrote:
> I'm wondering what it would take to teach git diff to invert the -S
> string (like git grep).
I think you would have to figure out the desired semantics first.
> I'm finding git diff -S<string> [--pickaxe-regex] to be really useful,
> but find I have cases where I want to ignore differences. For example, I
> might not care if the only changes to a Java file, for example, are
> related to import statements. I'd like to be able to do something like
> "git diff -S'^import' --pickaxe-regex -v". I'll admit I can get by with
> something like "git diff -S'^[^i]' --pickaxe-regex", but am pining for
> -v/--invert-match.
I would have thought "-v" meant "match any changes which do not have
this pattern". But you want "match any changes that have any line which
does not have this pattern."
IOW, mine would not match any changes which used an import statement,
whereas yours would not match any changes which are _only_ import
statements.
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: teach git diff -v/--invert-match?
2008-08-22 19:39 ` Jeff King
@ 2008-08-22 21:29 ` Brian Ericson
2008-08-22 21:42 ` Jeff King
2008-08-25 9:41 ` Paolo Bonzini
1 sibling, 1 reply; 7+ messages in thread
From: Brian Ericson @ 2008-08-22 21:29 UTC (permalink / raw)
To: Jeff King; +Cc: git
I was just working on a reply to my own email as I realized it was only
dumb-luck that
converted 1200 noisy changes into a couple of dozen. "-S" matches only
the string
itself, not the line the string resides on. So, -Sxyz will match if
"xyz" itself was
added or deleted in the diff (if "xyz" is on a line that's changed but
did not itself change,
it won't match). Funny that I actually knew this -- I use it to look for
System.out.println additions among other things.
Interestingly, if I wanted to know if an import changed (on top of
knowing if imports were
added or deleted), eg:
-import foo;
+import bar;
I couldn't tell you how to do it. The string "import" didn't change.
I'd've guessed that
"-S'import.*;' --pickaxe-regex" would have been sufficient, but that
doesn't work.
Jeff King wrote:
> On Fri, Aug 22, 2008 at 09:51:16AM -0500, Brian Ericson wrote:
>
>
>> I'm wondering what it would take to teach git diff to invert the -S
>> string (like git grep).
>>
>
> I think you would have to figure out the desired semantics first.
>
I think mostly what I want is a happy marriage between git diff & git
grep so that if the
changed lines matched (or didn't match) the file would show up (or
not). I'd like to grep
added and removed lines (the diff itself) for a pattern and either
include or exclude the file
based on matches.
>
>> I'm finding git diff -S<string> [--pickaxe-regex] to be really useful,
>> but find I have cases where I want to ignore differences. For example, I
>> might not care if the only changes to a Java file, for example, are
>> related to import statements. I'd like to be able to do something like
>> "git diff -S'^import' --pickaxe-regex -v". I'll admit I can get by with
>> something like "git diff -S'^[^i]' --pickaxe-regex", but am pining for
>> -v/--invert-match.
>>
>
> I would have thought "-v" meant "match any changes which do not have
> this pattern". But you want "match any changes that have any line which
> does not have this pattern."
>
Right. Good summary! It's probably not accurate to use "-S" for my
interpretation unless
--pickaxe-regex behaved more as I outlined above. It's probably a
subtle enough difference
> IOW, mine would not match any changes which used an import statement,
> whereas yours would not match any changes which are _only_ import
> statements.
>
The current behavior seems to work well to answer questions like "has
somebody added
a System.out.println", I'd like it to be able to ignore or consider
files based on line changes
that contain a string where the string itself did not change.
> -Peff
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>
>
>
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: teach git diff -v/--invert-match?
2008-08-22 21:29 ` Brian Ericson
@ 2008-08-22 21:42 ` Jeff King
2008-08-22 21:44 ` Junio C Hamano
0 siblings, 1 reply; 7+ messages in thread
From: Jeff King @ 2008-08-22 21:42 UTC (permalink / raw)
To: Brian Ericson; +Cc: git
On Fri, Aug 22, 2008 at 04:29:31PM -0500, Brian Ericson wrote:
> I was just working on a reply to my own email as I realized it was
> only dumb-luck that converted 1200 noisy changes into a couple of
> dozen. "-S" matches only the string itself, not the line the string
> resides on. So, -Sxyz will match if "xyz" itself was added or
> deleted in the diff (if "xyz" is on a line that's changed but did not
> itself change, it won't match). Funny that I actually knew this -- I
> use it to look for System.out.println additions among other things.
Yes (though I couldn't have told you that without experimenting -- I
always assumed it checked whole lines).
> Interestingly, if I wanted to know if an import changed (on top of
> knowing if imports were added or deleted), eg: -import foo; +import
> bar;
That is a bit harder, and AFAIK not possible with -S. You could always
post process the log output. E.g.,:
git log -p | perl -ne '
BEGIN { $/ = "commit " }
chomp; print if /^\+import /
'
which lets you get quite fancy with the matching.
> The current behavior seems to work well to answer questions like "has
> somebody added a System.out.println",
The usual question (for me, anyway) is "when did X get introduced?" when
looking for a token.
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: teach git diff -v/--invert-match?
2008-08-22 21:42 ` Jeff King
@ 2008-08-22 21:44 ` Junio C Hamano
0 siblings, 0 replies; 7+ messages in thread
From: Junio C Hamano @ 2008-08-22 21:44 UTC (permalink / raw)
To: Jeff King; +Cc: Brian Ericson, git
Jeff King <peff@peff.net> writes:
> On Fri, Aug 22, 2008 at 04:29:31PM -0500, Brian Ericson wrote:
>
>> I was just working on a reply to my own email as I realized it was
>> only dumb-luck that converted 1200 noisy changes into a couple of
>> dozen. "-S" matches only the string itself, not the line the string
>> resides on. So, -Sxyz will match if "xyz" itself was added or
>> deleted in the diff (if "xyz" is on a line that's changed but did not
>> itself change, it won't match). Funny that I actually knew this -- I
>> use it to look for System.out.println additions among other things.
>
> Yes (though I couldn't have told you that without experimenting -- I
> always assumed it checked whole lines).
The -Sstring counts the number of 'string' in preimage and postimage and
skips the commit if they are the same. Nothing more.
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: teach git diff -v/--invert-match?
2008-08-22 19:39 ` Jeff King
2008-08-22 21:29 ` Brian Ericson
@ 2008-08-25 9:41 ` Paolo Bonzini
2008-08-27 0:38 ` Jeff King
1 sibling, 1 reply; 7+ messages in thread
From: Paolo Bonzini @ 2008-08-25 9:41 UTC (permalink / raw)
To: Jeff King; +Cc: Brian Ericson, git
> I would have thought "-v" meant "match any changes which do not have
> this pattern". But you want "match any changes that have any line which
> does not have this pattern."
Yours could be "-L/--without-match" (in grep, -L/--files-without-match
only prints the names of files containing no match).
Paolo
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: teach git diff -v/--invert-match?
2008-08-25 9:41 ` Paolo Bonzini
@ 2008-08-27 0:38 ` Jeff King
0 siblings, 0 replies; 7+ messages in thread
From: Jeff King @ 2008-08-27 0:38 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: Brian Ericson, git
On Mon, Aug 25, 2008 at 11:41:37AM +0200, Paolo Bonzini wrote:
> > I would have thought "-v" meant "match any changes which do not have
> > this pattern". But you want "match any changes that have any line which
> > does not have this pattern."
>
> Yours could be "-L/--without-match" (in grep, -L/--files-without-match
> only prints the names of files containing no match).
Ah, yes, that would be better. I think we decided that Brian's original
problem didn't really work with -S, and I don't actually need this
behavior enough to implement it. But your suggestion is a good one if
somebody cares to do so.
-Peff
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2008-08-27 0:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-22 14:51 teach git diff -v/--invert-match? Brian Ericson
2008-08-22 19:39 ` Jeff King
2008-08-22 21:29 ` Brian Ericson
2008-08-22 21:42 ` Jeff King
2008-08-22 21:44 ` Junio C Hamano
2008-08-25 9:41 ` Paolo Bonzini
2008-08-27 0:38 ` Jeff King
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).