Skip to contentSkip to conversation

Teach log -G to ignore binary files

PATCH Superseded Thomas Braun 5 participants 30 messages Nov 21, 2018 – Dec 28, 2018 Documentation

lore
Share & tools
lore
#2 lore raw

PATCH 2/2 log -S: Add test which searches in binary files

In reply to Thomas Braun

The -S <regex> option of log looks for differences that changes the number of occurrences of the specified string (i.e. addition/deletion) in a file.

Add a test to ensure that we keep looking into binary files with -S as changing that would break backwards compatibility in unexpected ways.

---
 t/t4209-log-pickaxe.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
t/t4209-log-pickaxe.sh +11 -0
index 42cc8afd8b..d430f6f2f9 100755
@@ -128,4 +128,15 @@ test_expect_success 'log -G looks into binary files with textconv filter' '
 	test_cmp actual expected
 '
 
+test_expect_success 'log -S looks into binary files' '
+	rm -rf .git &&
+	git init &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -S a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done
Signature · 1 line
2.19.0.271.gfe8321ec05.dirty
#1 lore raw

PATCH 1/2 log -G: Ignore binary files

In reply to Thomas Braun

The -G <regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

The concept of differences only makes sense for text files, therefore we need to ignore binary files when searching with -G <regex> as well.

---
 Documentation/gitdiffcore.txt |  2 +-
 diffcore-pickaxe.c            |  5 +++++
 t/t4209-log-pickaxe.sh        | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
Documentation/gitdiffcore.txt +1 -1
index c0a60f3158..059ddd3431 100644
@@ -242,7 +242,7 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  Binary files without textconv filter are ignored.
 
 When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
 that match their respective criterion are kept in the output.  When
diffcore-pickaxe.c +5 -0
index 69fc55ea1e..8c2558b07d 100644
@@ -144,6 +144,11 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 		textconv_two = get_textconv(o->repo->index, p->two);
 	}
 
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;
+
 	/*
 	 * If we have an unmodified pair, we know that the count will be the
 	 * same and don't even have to load the blobs. Unless textconv is in
t/t4209-log-pickaxe.sh +22 -0
index 844df760f7..42cc8afd8b 100755
@@ -106,4 +106,26 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'log -G ignores binary files' '
+	rm -rf .git &&
+	git init &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -G a >result &&
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	rm -rf .git &&
+	git init &&
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -G a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done
Signature · 1 line
2.19.0.271.gfe8321ec05.dirty
#0 lore raw

cover Teach log -G to ignore binary files

Based on the previous discussion in [1] I've prepared patches which teach log -G to ignore binary files. log -S keeps its behaviour but got a test to ensure that.

Feedback welcome!

[1]: https://public-inbox.org/git/[email protected]/

Thomas Braun (2):
log -G: Ignore binary files
log -S: Add test which searches in binary files

 Documentation/gitdiffcore.txt |  2 +-
 diffcore-pickaxe.c            |  5 +++++
 t/t4209-log-pickaxe.sh        | 21 +++++++++++++++++++++
 3 files changed, 27 insertions(+), 1 deletion(-)
Signature · 1 line
2.19.0.271.gfe8321ec05.dirty
#18 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Thomas Braun
Quoted 6 lines · Thomas Braun

The -G <regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

The concept of differences only makes sense for text files, therefore we need to ignore binary files when searching with -G <regex> as well.

Quoted 6 lines
---
 Documentation/gitdiffcore.txt |  2 +-
 diffcore-pickaxe.c            |  5 +++++
 t/t4209-log-pickaxe.sh        | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

OK.

Documentation/gitdiffcore.txt textual diff has an added or a deleted line that matches the given · line 245

Quoted 10 lines
Documentation/gitdiffcore.txt +1 -1
index c0a60f3158..059ddd3431 100644
@@ -242,7 +242,7 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  Binary files without textconv filter are ignored.

OK.

Quoted 6 lines
diffcore-pickaxe.c +0 -0
index 69fc55ea1e..8c2558b07d 100644
@@ -144,6 +144,11 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 		textconv_two = get_textconv(o->repo->index, p->two);

diffcore-pickaxe.c static int pickaxe_match(struct diff_filepair *p, struct diff_options *o, · line 154

Quoted 10 lines
diffcore-pickaxe.c +5 -0
 	}
 
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;
+
 	/*
 	 * If we have an unmodified pair, we know that the count will be the
 	 * same and don't even have to load the blobs. Unless textconv is in

Shouldn't this new test come after the existing optimization, which allows us to leave without loading the blob contents (which is needed once you call diff_filespec_is_binary())?

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 111

Quoted 11 lines
t/t4209-log-pickaxe.sh +3 -0
index 844df760f7..42cc8afd8b 100755
@@ -106,4 +106,26 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'log -G ignores binary files' '
+	rm -rf .git &&
+	git init &&

Please never never ever do the above two unless you are writing a test that checks low-level repository details.

If you want a clean history that has specific lineage of commits without getting affected by commits that have been made by the previous test pieces, it is OK to "checkout --orphan" to create an empty history to work with.

Quoted 20 lines
t/t4209-log-pickaxe.sh +19 -0
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -G a >result &&
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	rm -rf .git &&
+	git init &&
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -G a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done
#13 lore raw

Re: [PATCH v1 2/2] log -S: Add test which searches in binary files

In reply to Thomas Braun
Quoted 3 lines · Thomas Braun

The -S <regex> option of log looks for differences that changes the number of occurrences of the specified string (i.e. addition/deletion) in a file.

s/-S <regex>/-S<block of text>/ and
s/the specified string/the specified block of text/ would make it more in line with how Documentation/gitdiffcore.txt explains it. The original discussion from early 2017 also explains with a pointer why the primary mode of -S is not <regex> but is <block of text>.

t/t4209-log-pickaxe.sh test_expect_success 'log -G looks into binary files with textconv filter' ' · line 133

Quoted 11 lines
t/t4209-log-pickaxe.sh +3 -0
index 42cc8afd8b..d430f6f2f9 100755
@@ -128,4 +128,15 @@ test_expect_success 'log -G looks into binary files with textconv filter' '
 	test_cmp actual expected
 '
 
+test_expect_success 'log -S looks into binary files' '
+	rm -rf .git &&
+	git init &&

Same comment as the one for 1/2 applies here.

t/t4209-log-pickaxe.sh test_expect_success 'log -G looks into binary files with textconv filter' ' · line 142

Quoted 9 lines
t/t4209-log-pickaxe.sh +8 -0
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -S a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

Other than these, I think both patches look sensible. Thanks for resurrecting the old topic and reigniting it.

#15 lore raw

Re: [PATCH v1 2/2] log -S: Add test which searches in binary files

In reply to Thomas Braun
Quoted 22 lines · Thomas Braun

The -S <regex> option of log looks for differences that changes the number of occurrences of the specified string (i.e. addition/deletion) in a file.

Add a test to ensure that we keep looking into binary files with -S as changing that would break backwards compatibility in unexpected ways.

---
 t/t4209-log-pickaxe.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
t/t4209-log-pickaxe.sh +2 -0
index 42cc8afd8b..d430f6f2f9 100755
@@ -128,4 +128,15 @@ test_expect_success 'log -G looks into binary files with textconv filter' '
 	test_cmp actual expected
 '
 
+test_expect_success 'log -S looks into binary files' '
+	rm -rf .git &&

t/t4209-log-pickaxe.sh test_expect_success 'log -G looks into binary files with textconv filter' ' · line 142

Quoted 10 lines
t/t4209-log-pickaxe.sh +9 -0
+	git init &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -S a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

This should just be part of 1/2 since the behavior is changed there & the commit message should describe both cases.

#20 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Thomas Braun
Quoted 1 line
Quoted 47 lines · Thomas Braun

The -G <regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

The concept of differences only makes sense for text files, therefore we need to ignore binary files when searching with -G <regex> as well.

---
 Documentation/gitdiffcore.txt |  2 +-
 diffcore-pickaxe.c            |  5 +++++
 t/t4209-log-pickaxe.sh        | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)
Documentation/gitdiffcore.txt +1 -1
index c0a60f3158..059ddd3431 100644
@@ -242,7 +242,7 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  Binary files without textconv filter are ignored.
 
 When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
 that match their respective criterion are kept in the output.  When
diffcore-pickaxe.c +5 -0
index 69fc55ea1e..8c2558b07d 100644
@@ -144,6 +144,11 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 		textconv_two = get_textconv(o->repo->index, p->two);
 	}
 
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;
+
 	/*
 	 * If we have an unmodified pair, we know that the count will be the
 	 * same and don't even have to load the blobs. Unless textconv is in
t/t4209-log-pickaxe.sh +0 -0
index 844df760f7..42cc8afd8b 100755

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 115

Quoted 10 lines
t/t4209-log-pickaxe.sh +7 -0
@@ -106,4 +106,26 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'log -G ignores binary files' '
+	rm -rf .git &&
+	git init &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -G a >result &&

Would be less confusing as "-Ga" since that's the invocation we document, even though I see (but wasn't aware that...) "-G a" works too.

Quoted 6 lines
t/t4209-log-pickaxe.sh +6 -0
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	rm -rf .git &&
+	git init &&

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 131

Quoted 10 lines
t/t4209-log-pickaxe.sh +9 -0
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -G a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

This patch seems like the wrong direction to me. In particular the assertion that "the concept of differences only makes sense for text files". That's just not true. This patch breaks this:

    (
        rm -rf /tmp/g-test &&
        git init /tmp/g-test &&
        cd /tmp/g-test &&
        for i in {1..10}; do
            echo "Always matching thensome 5" >file &&
            printf "a thensome %d binary \0" $i >>file &&
            git add file &&
            git commit -m"Bump $i"
        done &&
        git log -Gthensome.*5
    )

Right now this will emit 3/10 patches, and the right ones! I.e. "Bump [156]". The 1st one because it introduces the "Always matching thensome 5". Then 5/6 because the add/remove the string "a thensome 5 binary", respectively. Which matches /thensome.*5/.

I.e. in the first one we do a regex match against the content here because we don't have both sides:
https://github.com/git/git/blob/v2.19.2/diffcore-pickaxe.c#L48-L53

And then for the later ones where we have both sides we end up in diffgrep_consume():
https://github.com/git/git/blob/v2.19.2/diffcore-pickaxe.c#L27-L36

I think there may be a real issue here to address, which might be some combination of:

a) Even though the diffcore can do a binary diff internally, this is not what it exposes with "-p", we just say "Binary files differ".

I don't know how to emit the raw version we'll end up passing to diffgrep_consume() in this case. Is it just --binary without the encoding? I don't know...

b) Your test case shows that you're matching a string at a \0 boundary. Is this perhaps something you ran into? I.e. that we don't have some -F version of -G so we can't supply regexes that match past a \0? I had some related work on grep for this that hasn't been carried over to the diffcore:

git log --grep='grep:.*\\0' --author=Ævar

c) Is this binary diff we end up matching against just bad in some cases? I haven't dug but that wouldn't surprise me, i.e. that it's trying to be line-based so we'll overmatch in many cases.

So maybe this is something that should be passed down as a flag? See a recent discussion at
https://public-inbox.org/git/[email protected]/ for how that could be done.

Also if we don't have some tests already that were failing with this patch we really should have those as "let's test the current behavior first". Unfortunately tests in this area are really lacking, see e.g. my:

    git log --author=Junio --min-parents=2 --grep=ab/.*grep

For some series of patches to grep where to get one patch in I needed to often lead with 5-10 test patches to convince reviewers that I knew what I was changing, and also to be comfortable that I'd covered all the edge cases we currently supported, but weren't testing for.

#24 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Thomas Braun

diffcore-pickaxe.c static int pickaxe_match(struct diff_filepair *p, struct diff_options *o, · line 150

Quoted 12 lines · Thomas Braun
diffcore-pickaxe.c +4 -0
index 69fc55ea1e..8c2558b07d 100644
@@ -144,6 +144,11 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 		textconv_two = get_textconv(o->repo->index, p->two);
 	}
 
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;

If the user passes "-a" to treat binary files as text, we should probably skip the binary check. I think we'd need to check "o->flags.text" here.

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 119

Quoted 9 lines
t/t4209-log-pickaxe.sh +2 -0
index 844df760f7..42cc8afd8b 100755
@@ -106,4 +106,26 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
[...]
+test_expect_success 'log -G ignores binary files' '
[...]
+test_expect_success 'log -G looks into binary files with textconv filter' '

And likewise add a test here similar to the textconv one.

-Peff

#21 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Ævar Arnfjörð Bjarmason
Quoted 9 lines · Ævar Arnfjörð Bjarmason
Quoted 9 lines
t/t4209-log-pickaxe.sh +9 -0
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	rm -rf .git &&
+	git init &&
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -G a >actual &&
+	git log >expected &&
Quoted 8 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 131

Quoted 4 lines
t/t4209-log-pickaxe.sh +3 -0
+	test_cmp actual expected
+'
+
 test_done

This patch seems like the wrong direction to me. In particular the assertion that "the concept of differences only makes sense for text files". That's just not true. This patch breaks this:

But "-G" is defined as "look for differences whose patch text contains added/removed lines that match <regex>". We don't have patch text here, let alone added/removed lines.

For binary files, "-Sfoo" is better defined. I think we _could_ define "search for <pattern> in the added/removed bytes of a binary file". But I don't think that's what the current code does (it really does a line diff on a binary file, which is likely to put tons of unchanged crap into the "added and removed" lines, because the line divisions aren't meaningful in the first place).

Quoted 13 lines
    (
        rm -rf /tmp/g-test &&
        git init /tmp/g-test &&
        cd /tmp/g-test &&
        for i in {1..10}; do
            echo "Always matching thensome 5" >file &&
            printf "a thensome %d binary \0" $i >>file &&
            git add file &&
            git commit -m"Bump $i"
        done &&
        git log -Gthensome.*5
    )
Quoted 4 lines

Right now this will emit 3/10 patches, and the right ones! I.e. "Bump [156]". The 1st one because it introduces the "Always matching thensome 5". Then 5/6 because the add/remove the string "a thensome 5 binary", respectively. Which matches /thensome.*5/.

Right, this will sometimes do the right thing. But it will also often do the wrong thing. It's also very expensive (we specifically avoid feeding large binary files to xdiff, but I think "-G" will happily do so -- I didn't double check, though).

-Peff

#16 lore raw

Re: [PATCH v1 2/2] log -S: Add test which searches in binary files

In reply to Ævar Arnfjörð Bjarmason
Quoted 9 lines · Ævar Arnfjörð Bjarmason
Quoted 4 lines · Thomas Braun

The -S <regex> option of log looks for differences that changes the number of occurrences of the specified string (i.e. addition/deletion) in a file.

...
This should just be part of 1/2 since the behavior is changed there & the commit message should describe both cases.

Sensible suggestion. Thanks.

#25 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Jeff King
Quoted 8 lines · Jeff King

diffcore-pickaxe.c static int pickaxe_match(struct diff_filepair *p, struct diff_options *o, · line 150

Quoted 4 lines
diffcore-pickaxe.c +4 -0
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;

If the user passes "-a" to treat binary files as text, we should probably skip the binary check. I think we'd need to check "o->flags.text" here.

Yeah, I forgot about that option. It would give an escape hatch that has a sane explanation.

#27 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Thomas Braun
Quoted 6 lines · Thomas Braun

The -G <regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

The concept of differences only makes sense for text files, therefore we need to ignore binary files when searching with -G <regex> as well.

What about partial text/partial binary files?

I recall using text searching tools (not necessarily git machinery, my memory is fuzzy) to check for strings in pdf files, which are usually marked binary in context of git, such that we do not see their diffs in log -p.

But I would expect a search with -G or -S to still work... until I find the exception in the docs, only to wonder if there is a switch to turn off this optimisation for this corner case.

Stefan

#28 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

Quoted 10 lines · Stefan Beller
Quoted 6 lines · Thomas Braun

The -G <regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

The concept of differences only makes sense for text files, therefore we need to ignore binary files when searching with -G <regex> as well.

What about partial text/partial binary files?

Good point. You'd use "-a" (or "--text") to tell the diff machinery to treat the contents as text, and the new logic must pay attention to that command line option.

#19 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Junio C Hamano
Quoted 41 lines

Junio C Hamano <[email protected]> hat am 22. November 2018 um 02:29 geschrieben:

Quoted 6 lines · Thomas Braun

The -G <regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

The concept of differences only makes sense for text files, therefore we need to ignore binary files when searching with -G <regex> as well.

Quoted 6 lines
---
 Documentation/gitdiffcore.txt |  2 +-
 diffcore-pickaxe.c            |  5 +++++
 t/t4209-log-pickaxe.sh        | 22 ++++++++++++++++++++++
 3 files changed, 28 insertions(+), 1 deletion(-)

OK.

Documentation/gitdiffcore.txt textual diff has an added or a deleted line that matches the given · line 245

Quoted 10 lines
Documentation/gitdiffcore.txt +1 -1
index c0a60f3158..059ddd3431 100644
@@ -242,7 +242,7 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  Binary files without textconv filter are ignored.

OK.

Quoted 8 lines
diffcore-pickaxe.c +0 -0
index 69fc55ea1e..8c2558b07d 100644
@@ -144,6 +144,11 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 		textconv_two = get_textconv(o->repo->index, p->two);
 	}
 
Quoted 12 lines

diffcore-pickaxe.c static int pickaxe_match(struct diff_filepair *p, struct diff_options *o, · line 154

Quoted 8 lines
diffcore-pickaxe.c +5 -0
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;
+
 	/*
 	 * If we have an unmodified pair, we know that the count will be the
 	 * same and don't even have to load the blobs. Unless textconv is in

Shouldn't this new test come after the existing optimization, which allows us to leave without loading the blob contents (which is needed once you call diff_filespec_is_binary())?

Yes, good point.

Quoted 15 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 111

Quoted 11 lines
t/t4209-log-pickaxe.sh +3 -0
index 844df760f7..42cc8afd8b 100755
@@ -106,4 +106,26 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'log -G ignores binary files' '
+	rm -rf .git &&
+	git init &&

Please never never ever do the above two unless you are writing a test that checks low-level repository details.

Quoted 4 lines

If you want a clean history that has specific lineage of commits without getting affected by commits that have been made by the previous test pieces, it is OK to "checkout --orphan" to create an empty history to work with.

Thanks for the hint. I thought I had seen a less intrusive way for getting an empty history. Changed.

Quoted 21 lines
Quoted 20 lines
t/t4209-log-pickaxe.sh +19 -0
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -G a >result &&
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	rm -rf .git &&
+	git init &&
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -G a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done
#14 lore raw

Re: [PATCH v1 2/2] log -S: Add test which searches in binary files

In reply to Junio C Hamano
Quoted 9 lines

Junio C Hamano <[email protected]> hat am 22. November 2018 um 02:34 geschrieben:

Quoted 3 lines · Thomas Braun

The -S <regex> option of log looks for differences that changes the number of occurrences of the specified string (i.e. addition/deletion) in a file.

Quoted 5 lines

s/-S <regex>/-S<block of text>/ and
s/the specified string/the specified block of text/ would make it more in line with how Documentation/gitdiffcore.txt explains it. The original discussion from early 2017 also explains with a pointer why the primary mode of -S is not <regex> but is <block of text>.

Thanks for the pointer. I've updated the commit message.

Quoted 8 lines
Quoted 8 lines
t/t4209-log-pickaxe.sh +0 -0
index 42cc8afd8b..d430f6f2f9 100755
@@ -128,4 +128,15 @@ test_expect_success 'log -G looks into binary files with textconv filter' '
 	test_cmp actual expected
 '
 
Quoted 5 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -G looks into binary files with textconv filter' ' · line 133

Quoted 3 lines
t/t4209-log-pickaxe.sh +3 -0
+test_expect_success 'log -S looks into binary files' '
+	rm -rf .git &&
+	git init &&

Same comment as the one for 1/2 applies here.

Fixed as well.

Quoted 13 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -G looks into binary files with textconv filter' ' · line 142

Quoted 9 lines
t/t4209-log-pickaxe.sh +8 -0
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -S a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

Other than these, I think both patches look sensible. Thanks for resurrecting the old topic and reigniting it.

#17 lore raw

Re: [PATCH v1 2/2] log -S: Add test which searches in binary files

In reply to Ævar Arnfjörð Bjarmason
Quoted 26 lines

Ævar Arnfjörð Bjarmason <[email protected]> hat am 22. November 2018 um 10:14 geschrieben:

Quoted 20 lines · Thomas Braun

The -S <regex> option of log looks for differences that changes the number of occurrences of the specified string (i.e. addition/deletion) in a file.

Add a test to ensure that we keep looking into binary files with -S as changing that would break backwards compatibility in unexpected ways.

---
 t/t4209-log-pickaxe.sh | 11 +++++++++++
 1 file changed, 11 insertions(+)
t/t4209-log-pickaxe.sh +0 -0
index 42cc8afd8b..d430f6f2f9 100755
@@ -128,4 +128,15 @@ test_expect_success 'log -G looks into binary files with textconv filter' '
 	test_cmp actual expected
 '
 
Quoted 15 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -G looks into binary files with textconv filter' ' · line 142

Quoted 12 lines
t/t4209-log-pickaxe.sh +11 -0
+test_expect_success 'log -S looks into binary files' '
+	rm -rf .git &&
+	git init &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -S a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

This should just be part of 1/2 since the behavior is changed there & the commit message should describe both cases.

My reasoning was that this is a separate test which does not fit in with the other part. But I'm happy in folding both into one patch. Done.

#22 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Ævar Arnfjörð Bjarmason
Quoted 1 line

Ævar Arnfjörð Bjarmason <[email protected]> hat am 22. November 2018 um 11:16 geschrieben:

[...]

Quoted 11 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 115

Quoted 8 lines
t/t4209-log-pickaxe.sh +7 -0
+test_expect_success 'log -G ignores binary files' '
+	rm -rf .git &&
+	git init &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -G a >result &&

Would be less confusing as "-Ga" since that's the invocation we document, even though I see (but wasn't aware that...) "-G a" works too.

Done.

Quoted 34 lines
Quoted 6 lines
t/t4209-log-pickaxe.sh +6 -0
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	rm -rf .git &&
+	git init &&

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 131

Quoted 10 lines
t/t4209-log-pickaxe.sh +9 -0
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -G a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

This patch seems like the wrong direction to me. In particular the assertion that "the concept of differences only makes sense for text files". That's just not true. This patch breaks this:

    (
        rm -rf /tmp/g-test &&
        git init /tmp/g-test &&
        cd /tmp/g-test &&
        for i in {1..10}; do
            echo "Always matching thensome 5" >file &&
            printf "a thensome %d binary \0" $i >>file &&
            git add file &&
            git commit -m"Bump $i"
        done &&
        git log -Gthensome.*5
    )
Quoted 4 lines

Right now this will emit 3/10 patches, and the right ones! I.e. "Bump [156]". The 1st one because it introduces the "Always matching thensome 5". Then 5/6 because the add/remove the string "a thensome 5 binary", respectively. Which matches /thensome.*5/.

log -p does not show you the patch text in your example because it is treated as binary. And currently "log -G" has a different opinion into what it looks and what it ignores. My patch tries to bring both more in line.

Quoted 26 lines

I.e. in the first one we do a regex match against the content here because we don't have both sides:
https://github.com/git/git/blob/v2.19.2/diffcore-pickaxe.c#L48-L53

And then for the later ones where we have both sides we end up in diffgrep_consume():
https://github.com/git/git/blob/v2.19.2/diffcore-pickaxe.c#L27-L36

I think there may be a real issue here to address, which might be some combination of:

a) Even though the diffcore can do a binary diff internally, this is not what it exposes with "-p", we just say "Binary files differ".

I don't know how to emit the raw version we'll end up passing to diffgrep_consume() in this case. Is it just --binary without the encoding? I don't know...

b) Your test case shows that you're matching a string at a \0 boundary. Is this perhaps something you ran into? I.e. that we don't have some -F version of -G so we can't supply regexes that match past a \0? I had some related work on grep for this that hasn't been carried over to the diffcore:

git log --grep='grep:.*\\0' --author=Ævar

Quoted 8 lines

c) Is this binary diff we end up matching against just bad in some cases? I haven't dug but that wouldn't surprise me, i.e. that it's trying to be line-based so we'll overmatch in many cases.

So maybe this is something that should be passed down as a flag? See a recent discussion at
https://public-inbox.org/git/[email protected]/ for how that could be done.

It is not about the \0 boundary. v2 of the patches will clarify that. My main motiviation is to speed up "log -G" as that takes a considerable amount of time when it wades through MBs of binary files which change often. And in multiple places I can already treat binary files differently (e.g. turn off delta compression, skip trying to diff them, no EOL normalization). And for me making log -G ignore what git thinks are binary files is making the line clearer between what should be treated as binary and what as text.

Quoted 11 lines

Also if we don't have some tests already that were failing with this patch we really should have those as "let's test the current behavior first". Unfortunately tests in this area are really lacking, see e.g. my:

    git log --author=Junio --min-parents=2 --grep=ab/.*grep

For some series of patches to grep where to get one patch in I needed to often lead with 5-10 test patches to convince reviewers that I knew what I was changing, and also to be comfortable that I'd covered all the edge cases we currently supported, but weren't testing for.

I'm happy to add more test cases to convince everyone involved :)

#26 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Jeff King
Quoted 13 lines

Jeff King <[email protected]> hat am 22. November 2018 um 17:20 geschrieben:

Quoted 8 lines · Thomas Braun
diffcore-pickaxe.c +0 -0
index 69fc55ea1e..8c2558b07d 100644
@@ -144,6 +144,11 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 		textconv_two = get_textconv(o->repo->index, p->two);
 	}
 
Quoted 8 lines

diffcore-pickaxe.c static int pickaxe_match(struct diff_filepair *p, struct diff_options *o, · line 150

Quoted 4 lines
diffcore-pickaxe.c +4 -0
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;

If the user passes "-a" to treat binary files as text, we should probably skip the binary check. I think we'd need to check "o->flags.text" here.

Good point. I missed that flag. Added.

Quoted 11 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 119

Quoted 9 lines
t/t4209-log-pickaxe.sh +2 -0
index 844df760f7..42cc8afd8b 100755
@@ -106,4 +106,26 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
[...]
+test_expect_success 'log -G ignores binary files' '
[...]
+test_expect_success 'log -G looks into binary files with textconv filter' '

And likewise add a test here similar to the textconv one.

Added as well.

#29 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Junio C Hamano
Quoted 12 lines

Junio C Hamano <[email protected]> hat am 27. November 2018 um 01:51 geschrieben:

Quoted 6 lines · Stefan Beller
Quoted 4 lines · Thomas Braun

The -G <regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

The concept of differences only makes sense for text files, therefore we need to ignore binary files when searching with -G <regex> as well.

What about partial text/partial binary files?

Good point. You'd use "-a" (or "--text") to tell the diff machinery to treat the contents as text, and the new logic must pay attention to that command line option.

Yes exactly. Either use -a for the occasional use or a textconv filter for permanent use.

Coming from the opposite side: I usually mark svg files as binary as the textual diff is well, let's say uninspiring.

#23 lore raw

Re: [PATCH v1 1/2] log -G: Ignore binary files

In reply to Ævar Arnfjörð Bjarmason
Quoted 1 line

Ævar Arnfjörð Bjarmason <[email protected]> hat am 22. November 2018 um 11:16 geschrieben:

[...]

Quoted 11 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 115

Quoted 8 lines
t/t4209-log-pickaxe.sh +7 -0
+test_expect_success 'log -G ignores binary files' '
+	rm -rf .git &&
+	git init &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -G a >result &&

Would be less confusing as "-Ga" since that's the invocation we document, even though I see (but wasn't aware that...) "-G a" works too.

Done.

Quoted 34 lines
Quoted 6 lines
t/t4209-log-pickaxe.sh +6 -0
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	rm -rf .git &&
+	git init &&

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 131

Quoted 10 lines
t/t4209-log-pickaxe.sh +9 -0
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0b" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -G a >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

This patch seems like the wrong direction to me. In particular the assertion that "the concept of differences only makes sense for text files". That's just not true. This patch breaks this:

    (
        rm -rf /tmp/g-test &&
        git init /tmp/g-test &&
        cd /tmp/g-test &&
        for i in {1..10}; do
            echo "Always matching thensome 5" >file &&
            printf "a thensome %d binary \0" $i >>file &&
            git add file &&
            git commit -m"Bump $i"
        done &&
        git log -Gthensome.*5
    )
Quoted 4 lines

Right now this will emit 3/10 patches, and the right ones! I.e. "Bump [156]". The 1st one because it introduces the "Always matching thensome 5". Then 5/6 because the add/remove the string "a thensome 5 binary", respectively. Which matches /thensome.*5/.

log -p does not show you the patch text in your example because it is treated as binary. And currently "log -G" has a different opinion into what it looks and what it ignores. My patch tries to bring both more in line.

Quoted 26 lines

I.e. in the first one we do a regex match against the content here because we don't have both sides:
https://github.com/git/git/blob/v2.19.2/diffcore-pickaxe.c#L48-L53

And then for the later ones where we have both sides we end up in diffgrep_consume():
https://github.com/git/git/blob/v2.19.2/diffcore-pickaxe.c#L27-L36

I think there may be a real issue here to address, which might be some combination of:

a) Even though the diffcore can do a binary diff internally, this is not what it exposes with "-p", we just say "Binary files differ".

I don't know how to emit the raw version we'll end up passing to diffgrep_consume() in this case. Is it just --binary without the encoding? I don't know...

b) Your test case shows that you're matching a string at a \0 boundary. Is this perhaps something you ran into? I.e. that we don't have some -F version of -G so we can't supply regexes that match past a \0? I had some related work on grep for this that hasn't been carried over to the diffcore:

git log --grep='grep:.*\\0' --author=Ævar

Quoted 8 lines

c) Is this binary diff we end up matching against just bad in some cases? I haven't dug but that wouldn't surprise me, i.e. that it's trying to be line-based so we'll overmatch in many cases.

So maybe this is something that should be passed down as a flag? See a recent discussion at
https://public-inbox.org/git/[email protected]/ for how that could be done.

It is not about the \0 boundary. v2 of the patches will clarify that. My main motiviation is to speed up "log -G" as that takes a considerable amount of time when it wades through MBs of binary files which change often. And in multiple places I can already treat binary files differently (e.g. turn off delta compression, skip trying to diff them, no EOL normalization). And for me making log -G ignore what git thinks are binary files is making the line clearer between what should be treated as binary and what as text.

Quoted 11 lines

Also if we don't have some tests already that were failing with this patch we really should have those as "let's test the current behavior first". Unfortunately tests in this area are really lacking, see e.g. my:

    git log --author=Junio --min-parents=2 --grep=ab/.*grep

For some series of patches to grep where to get one patch in I needed to often lead with 5-10 test patches to convince reviewers that I knew what I was changing, and also to be comfortable that I'd covered all the edge cases we currently supported, but weren't testing for.

I'm happy to add more test cases to convince everyone involved :)

#4 lore raw

PATCH v2 1/1 log -G: Ignore binary files

In reply to Thomas Braun

The -G<regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

As the concept of patch text only makes sense for text files, we need to ignore binary files when searching with -G <regex> as well.

The -S<block of text> option of log looks for differences that changes the number of occurrences of the specified block of text (i.e. addition/deletion) in a file. As we want to keep the current behaviour, add a test to ensure it.

---

Changes since v1:
- Merged both patches into one
- Adapted commit messages
- Added missing support for -a flag with tests
- Placed new code into correct location to be able to reuse an existing optimization
- Uses help-suggested -Ga writing without spaces
- Uses orphan branches instead of cannonball cleanup with rm -rf
- Changed search text to make it clear that it is not about the \0 boundary

 Documentation/gitdiffcore.txt |  2 +-
 diffcore-pickaxe.c            |  6 ++++++
 t/t4209-log-pickaxe.sh        | 40 +++++++++++++++++++++++++++++++++++
 3 files changed, 47 insertions(+), 1 deletion(-)
Documentation/gitdiffcore.txt +1 -1
index c0a60f3158..059ddd3431 100644
@@ -242,7 +242,7 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  Binary files without textconv filter are ignored.
 
 When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
 that match their respective criterion are kept in the output.  When
diffcore-pickaxe.c +6 -0
index 69fc55ea1e..4cea086f80 100644
@@ -154,6 +154,12 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 	if (textconv_one == textconv_two && diff_unmodified_pair(p))
 		return 0;
 
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    !o->flags.text &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;
+
 	mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
 	mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
 
t/t4209-log-pickaxe.sh +40 -0
index 844df760f7..5c3e2a16b2 100755
@@ -106,4 +106,44 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'log -G ignores binary files' '
+	git checkout --orphan orphan1 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Ga >result &&
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with -a' '
+	git checkout --orphan orphan2 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -a -Ga >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	git checkout --orphan orphan3 &&
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -Ga >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
+test_expect_success 'log -S looks into binary files' '
+	git checkout --orphan orphan4 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Sa >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done
Signature · 1 line
2.19.0.271.gfe8321ec05.dirty
#5 lore raw

Re: [PATCH v2] log -G: Ignore binary files

On Wed, Nov 28 2018, Thomas Braun wrote:

Looks much better this time around.

Quoted 16 lines

The -G<regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

As the concept of patch text only makes sense for text files, we need to ignore binary files when searching with -G <regex> as well.

The -S<block of text> option of log looks for differences that changes the number of occurrences of the specified block of text (i.e. addition/deletion) in a file. As we want to keep the current behaviour, add a test to ensure it.
[...]

Documentation/gitdiffcore.txt +0 -0
index c0a60f3158..059ddd3431 100644

Documentation/gitdiffcore.txt textual diff has an added or a deleted line that matches the given · line 245

Quoted 5 lines
Documentation/gitdiffcore.txt +1 -1
@@ -242,7 +242,7 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  Binary files without textconv filter are ignored.

Now that we support --text that should be documented. I tried to come up with something on top:

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 0378cd574e..42ae65fb57 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -524,6 +524,10 @@ struct), and want to know the history of that block since it first
came into being: use the feature iteratively to feed the interesting block in the preimage back into -S, and keep going until you get the very first version of the block.
++
+Unlike -G the -S option will always search through binary files +without a textconv filter. [[TODO: Don't we want to support --no-text +then as an optimization?]].

-G<regex>::
Look for differences whose patch text contains added/removed
@@ -545,6 +549,15 @@ occurrences of that string did not change).
+
See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more information.
++
+Unless --text is supplied binary files without a textconv filter +will be ignored. This was not the case before Git version 2.21.. ++
+With --text, instead of patch lines we <some example similar to the +above diff showing what we actually do for binary files. [[TODO: How +does that work?. Could just link to the "diffcore-pickaxe: For +Detecting Addition/Deletion of Specified String" section in +gitdiffcore(7) which could explain it]]

--find-object=<object-id>::
Look for differences that change the number of occurrences of
diff --git a/Documentation/gitdiffcore.txt b/Documentation/gitdiffcore.txt index c0a60f3158..26880b4149 100644
--- a/Documentation/gitdiffcore.txt
+++ b/Documentation/gitdiffcore.txt
@@ -251,6 +251,10 @@ criterion in a changeset, the entire changeset is kept. This behavior
is designed to make reviewing changes in the context of the whole
changeset easier.

+Both -S' and -G' will ignore binary files without a textconv filter +by default, this can be overriden with --text. With --text the +binary patch we look through is generated as [[TODO: ???]]. +
diffcore-order: For Sorting the Output Based on Filenames
---------------------------------------------------------

But as you can see given the TODO comments I don't know how this works exactly. I *could* dig, but that's my main outstanding problem with this patch, the commit message / docs aren't being updated to reflect the new behavior.

I.e. let's leave the docs in some state where the reader can as unambiguously know what to expect with -G and these binary diffs we've been implicitly supporting as with the textual diffs. Ideally with some examples of how to generate them (re my question about the base85 output in v1).

Part of that's obviously behavior we've had all along, but it's much more convincing to say:

We are changing X which we've done for ages, it works exactly like this, and here's a switch to get it back.

Instead of:

X doesn't make sense, let's turn it off.

Also the diffcore docs already say stuff about how slow/fast things are, and in a side-thread you said:

My main motiviation is to speed up "log -G" as that takes a considerable amount of time when it wades through MBs of binary files which change often.

Makes sense, but then let's say something about that in that section of the docs.

Quoted 35 lines
Documentation/gitdiffcore.txt +0 -0
 When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
 that match their respective criterion are kept in the output.  When
diffcore-pickaxe.c +6 -0
index 69fc55ea1e..4cea086f80 100644
@@ -154,6 +154,12 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 	if (textconv_one == textconv_two && diff_unmodified_pair(p))
 		return 0;
 
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    !o->flags.text &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;
+
 	mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
 	mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
 
t/t4209-log-pickaxe.sh +8 -0
index 844df760f7..5c3e2a16b2 100755
@@ -106,4 +106,44 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'log -G ignores binary files' '
+	git checkout --orphan orphan1 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Ga >result &&
+	test_must_be_empty result
+'

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 126

Quoted 10 lines
t/t4209-log-pickaxe.sh +10 -0
+
+test_expect_success 'log -G looks into binary files with -a' '
+	git checkout --orphan orphan2 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -a -Ga >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'

A large part of the question(s) I have above & future readers would presumably have would be answered by these tests using more realistic test data. I.e. also with \n in there to see whether -G is also line-based in this binary case.

Quoted 12 lines
t/t4209-log-pickaxe.sh +12 -0
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	git checkout --orphan orphan3 &&
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -Ga >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
+test_expect_success 'log -S looks into binary files' '

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 148

Quoted 10 lines
t/t4209-log-pickaxe.sh +9 -0
+	git checkout --orphan orphan4 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Sa >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

These tests have way to much repeated boilerplate for no reason. This could just be (as-is, without the better test data suggested above):

t/t4209-log-pickaxe.sh +30 -0
index 844df760f7..23ed6cc4b1 100755
@@ -106,4 +106,34 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'setup log -[GS] binary & --text' '
+	git checkout --orphan GS-binary-and-text &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log >full-log
+'
+
+test_expect_success 'log -G ignores binary files' '
+	git log -Ga >result &&
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with -a' '
+	git log -a -Ga >actual &&
+	test_cmp actual full-log
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	echo "* diff=bin" >.gitattributes &&
+	git -c diff.bin.textconv=cat log -Ga >actual &&
+	test_cmp actual full-log
+'
+
+test_expect_success 'log -S looks into binary files' '
+	>.gitattributes &&
+	git log -Sa >actual &&
+	test_cmp actual full-log
+'
+
 test_done
#7 lore raw

Re: [PATCH v2] log -G: Ignore binary files

In reply to Thomas Braun
Quoted 1 line · Thomas Braun

Subject: Re: [PATCH v2] log -G: Ignore binary files

s/Ig/ig/; (will locally munge--this alone is no reason to reroll).

The code changes looked sensible.

Quoted 6 lines
t/t4209-log-pickaxe.sh +0 -0
index 844df760f7..5c3e2a16b2 100755
@@ -106,4 +106,44 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 116

Quoted 10 lines
t/t4209-log-pickaxe.sh +8 -0
 '
 
+test_expect_success 'log -G ignores binary files' '
+	git checkout --orphan orphan1 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Ga >result &&
+	test_must_be_empty result
+'

As this is the first mention of data.bin, this is adding a new file data.bin that has two 'a' but is a binary file. And that is the only commit in the history leading to orphan1.

The fact that "log -Ga" won't find any means it missed the creation event, because the blob is binary. Good.

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 122

Quoted 5 lines
t/t4209-log-pickaxe.sh +5 -0
+test_expect_success 'log -G looks into binary files with -a' '
+	git checkout --orphan orphan2 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&

This starts from the state left by the previous test piece, i.e. we have a binary data.bin file with two 'a' in it. We pretend to modify and add, but these two steps are no-op if the previous succeeded, but even if the previous step failed, we get what we want in the data.bin file. And then we make an initial commit the same way.

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 123

Quoted 2 lines
t/t4209-log-pickaxe.sh +2 -0
+	git log -a -Ga >actual &&
+	git log >expected &&

And we ran the same test but this time with "-a" to tell Git that binary-ness should not matter. It will find the sole commit. Good.

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 130

Quoted 6 lines
t/t4209-log-pickaxe.sh +6 -0
+	test_cmp actual expected
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	git checkout --orphan orphan3 &&
+	echo "* diff=bin" > .gitattributes &&

s/> />/; (will locally munge--this alone is no reason to reroll).

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 134

Quoted 4 lines
t/t4209-log-pickaxe.sh +4 -0
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -Ga >actual &&

This exposes a slight iffy-ness in the design. The textconv filter used here does not strip the "binary-ness" from the payload, but it is enough to tell the machinery that -G should look into the difference. Is that really desirable, though?

IOW, if this weren't the initial commit (which is handled by the codepath to special-case creation and deletion in diff_grep() function), would "log -Ga" show it without "-a"? Should it?

I think this test piece (and probably the previous ones for "-a" vs "no -a" without textconv, as well) should be using a history with three commits, where

- the root commit introduces "a\0a" to data.bin (creation event)

- the second commit adds another instance of "a\0a" to data.bin (forces comparison)

- the third commit removes data.bin (deletion event)

and make sure that the three are treated identically. If "log -Ga" finds one (with the combination of other conditions like use of textconv or -a option), it should find all three, and vice versa.

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 147

Quoted 13 lines
t/t4209-log-pickaxe.sh +13 -0
+	git log >expected &&
+	test_cmp actual expected
+'
+
+test_expect_success 'log -S looks into binary files' '
+	git checkout --orphan orphan4 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Sa >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'

Likewise. This would also benefit from a three-commit history.

Perhaps you can create such a history at the beginning of these additions as another "setup -G/-S binary test" step and test different variations in subsequent tests without the setup?

Quoted 1 line
t/t4209-log-pickaxe.sh +0 -0
 test_done
#8 lore raw

Re: [PATCH v2] log -G: Ignore binary files

Quoted 13 lines · Junio C Hamano

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 116

Quoted 8 lines
t/t4209-log-pickaxe.sh +8 -0
+test_expect_success 'log -G ignores binary files' '
+	git checkout --orphan orphan1 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Ga >result &&
+	test_must_be_empty result
+'

As this is the first mention of data.bin, this is adding a new file data.bin that has two 'a' but is a binary file. And that is the only commit in the history leading to orphan1.

Quoted 2 lines

The fact that "log -Ga" won't find any means it missed the creation event, because the blob is binary. Good.

By the way, this root commit records another file whose path is "file" and has "Picked<LF>" in it. If the file had 'a' in it, it would have been included in "git log" output, but that is too subtle a point to be noticed by the readers who are only reading this patch without seeing what has been done to the index before this test piece.

If you are going to restructure these tests to create a three-commit history in a single expect_success that is inspected with various "log -Ga" invocations in subsequent tests, it is worth removing that other file (or rather, starting with "read-tree --empty" immediately after checking out the orphan branch, to clarify to the readers that there is nothing but what you add in the set-up step in the index) to make the test more robust.

#6 lore raw

Re: [PATCH v2] log -G: Ignore binary files

In reply to Ævar Arnfjörð Bjarmason
Quoted 7 lines

Ævar Arnfjörð Bjarmason <[email protected]> hat am 28. November 2018 um 13:54 geschrieben:

On Wed, Nov 28 2018, Thomas Braun wrote:

Looks much better this time around.

Thanks.

Quoted 71 lines
Quoted 16 lines

The -G<regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

As the concept of patch text only makes sense for text files, we need to ignore binary files when searching with -G <regex> as well.

The -S<block of text> option of log looks for differences that changes the number of occurrences of the specified block of text (i.e. addition/deletion) in a file. As we want to keep the current behaviour, add a test to ensure it.
[...]

Documentation/gitdiffcore.txt +0 -0
index c0a60f3158..059ddd3431 100644

Documentation/gitdiffcore.txt textual diff has an added or a deleted line that matches the given · line 245

Quoted 5 lines
Documentation/gitdiffcore.txt +1 -1
@@ -242,7 +242,7 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  Binary files without textconv filter are ignored.

Now that we support --text that should be documented. I tried to come up with something on top:

diff --git a/Documentation/diff-options.txt b/Documentation/diff-options.txt index 0378cd574e..42ae65fb57 100644
--- a/Documentation/diff-options.txt
+++ b/Documentation/diff-options.txt
@@ -524,6 +524,10 @@ struct), and want to know the history of that block since it first
came into being: use the feature iteratively to feed the interesting block in the preimage back into -S, and keep going until you get the very first version of the block.
++
+Unlike -G the -S option will always search through binary files +without a textconv filter. [[TODO: Don't we want to support --no-text +then as an optimization?]].

-G<regex>::
Look for differences whose patch text contains added/removed
@@ -545,6 +549,15 @@ occurrences of that string did not change).
+
See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more information.
++
+Unless --text is supplied binary files without a textconv filter +will be ignored. This was not the case before Git version 2.21.. ++
+With --text, instead of patch lines we <some example similar to the +above diff showing what we actually do for binary files. [[TODO: How +does that work?. Could just link to the "diffcore-pickaxe: For +Detecting Addition/Deletion of Specified String" section in +gitdiffcore(7) which could explain it]]

--find-object=<object-id>::
Look for differences that change the number of occurrences of
diff --git a/Documentation/gitdiffcore.txt b/Documentation/gitdiffcore.txt index c0a60f3158..26880b4149 100644
--- a/Documentation/gitdiffcore.txt
+++ b/Documentation/gitdiffcore.txt
@@ -251,6 +251,10 @@ criterion in a changeset, the entire changeset is kept. This behavior
is designed to make reviewing changes in the context of the whole
changeset easier.

+Both -S' and -G' will ignore binary files without a textconv filter +by default, this can be overriden with --text. With --text the +binary patch we look through is generated as [[TODO: ???]]. +
diffcore-order: For Sorting the Output Based on Filenames
---------------------------------------------------------

Quoted 4 lines

But as you can see given the TODO comments I don't know how this works exactly. I *could* dig, but that's my main outstanding problem with this patch, the commit message / docs aren't being updated to reflect the new behavior.

v3 will have some more documentation which took inspiration by your sketches here. I've not included a reference to the git version 2.21 in which that patch will hopefully land as that seems to be not common in the documentation.

I see tweaking the behaviour of -S outside of this patch series.

Quoted 19 lines

I.e. let's leave the docs in some state where the reader can as unambiguously know what to expect with -G and these binary diffs we've been implicitly supporting as with the textual diffs. Ideally with some examples of how to generate them (re my question about the base85 output in v1).

Part of that's obviously behavior we've had all along, but it's much more convincing to say:

We are changing X which we've done for ages, it works exactly like this, and here's a switch to get it back.

Instead of:

X doesn't make sense, let's turn it off.

Also the diffcore docs already say stuff about how slow/fast things are, and in a side-thread you said:

Quoted 6 lines

My main motiviation is to speed up "log -G" as that takes a considerable amount of time when it wades through MBs of binary files which change often.

Makes sense, but then let's say something about that in that section of the docs.

Done.

Quoted 65 lines
Quoted 35 lines
Documentation/gitdiffcore.txt +0 -0
 When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
 that match their respective criterion are kept in the output.  When
diffcore-pickaxe.c +6 -0
index 69fc55ea1e..4cea086f80 100644
@@ -154,6 +154,12 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 	if (textconv_one == textconv_two && diff_unmodified_pair(p))
 		return 0;
 
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    !o->flags.text &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;
+
 	mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
 	mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
 
t/t4209-log-pickaxe.sh +8 -0
index 844df760f7..5c3e2a16b2 100755
@@ -106,4 +106,44 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'log -G ignores binary files' '
+	git checkout --orphan orphan1 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Ga >result &&
+	test_must_be_empty result
+'

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 126

Quoted 10 lines
t/t4209-log-pickaxe.sh +10 -0
+
+test_expect_success 'log -G looks into binary files with -a' '
+	git checkout --orphan orphan2 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -a -Ga >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'

A large part of the question(s) I have above & future readers would presumably have would be answered by these tests using more realistic test data. I.e. also with \n in there to see whether -G is also line-based in this binary case.

Quoted 14 lines
t/t4209-log-pickaxe.sh +14 -0
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	git checkout --orphan orphan3 &&
+	echo "* diff=bin" > .gitattributes &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -Ga >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
+test_expect_success 'log -S looks into binary files' '
+	git checkout --orphan orphan4 &&
+	printf "a\0a" >data.bin &&
Quoted 8 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 139

Quoted 8 lines
t/t4209-log-pickaxe.sh +7 -0
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Sa >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'
+
 test_done

Done.

Quoted 32 lines

These tests have way to much repeated boilerplate for no reason. This could just be (as-is, without the better test data suggested above):

t/t4209-log-pickaxe.sh +21 -0
index 844df760f7..23ed6cc4b1 100755
@@ -106,4 +106,34 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'setup log -[GS] binary & --text' '
+	git checkout --orphan GS-binary-and-text &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log >full-log
+'
+
+test_expect_success 'log -G ignores binary files' '
+	git log -Ga >result &&
+	test_must_be_empty result
+'
+
+test_expect_success 'log -G looks into binary files with -a' '
+	git log -a -Ga >actual &&
+	test_cmp actual full-log
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	echo "* diff=bin" >.gitattributes &&
+	git -c diff.bin.textconv=cat log -Ga >actual &&

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 139

Quoted 10 lines
t/t4209-log-pickaxe.sh +9 -0
+	test_cmp actual full-log
+'
+
+test_expect_success 'log -S looks into binary files' '
+	>.gitattributes &&
+	git log -Sa >actual &&
+	test_cmp actual full-log
+'
+
 test_done

Thanks for pointer. This is resolved in v3 as well. I'm not used to test cases which depend on each other but your are totally right.

Thanks for the review.

#10 lore raw

Re: [PATCH v2] log -G: Ignore binary files

In reply to Junio C Hamano
Quoted 8 lines

Junio C Hamano <[email protected]> hat am 29. November 2018 um 08:10 geschrieben:

Quoted 1 line · Thomas Braun

Subject: Re: [PATCH v2] log -G: Ignore binary files

s/Ig/ig/; (will locally munge--this alone is no reason to reroll).

Done.

Quoted 1 line

The code changes looked sensible.

Thanks.

Quoted 43 lines
Quoted 6 lines
t/t4209-log-pickaxe.sh +0 -0
index 844df760f7..5c3e2a16b2 100755
@@ -106,4 +106,44 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 116

Quoted 10 lines
t/t4209-log-pickaxe.sh +8 -0
 '
 
+test_expect_success 'log -G ignores binary files' '
+	git checkout --orphan orphan1 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Ga >result &&
+	test_must_be_empty result
+'

As this is the first mention of data.bin, this is adding a new file data.bin that has two 'a' but is a binary file. And that is the only commit in the history leading to orphan1.

The fact that "log -Ga" won't find any means it missed the creation event, because the blob is binary. Good.

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 122

Quoted 5 lines
t/t4209-log-pickaxe.sh +5 -0
+test_expect_success 'log -G looks into binary files with -a' '
+	git checkout --orphan orphan2 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&

This starts from the state left by the previous test piece, i.e. we have a binary data.bin file with two 'a' in it. We pretend to modify and add, but these two steps are no-op if the previous succeeded, but even if the previous step failed, we get what we want in the data.bin file. And then we make an initial commit the same way.

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 123

Quoted 2 lines
t/t4209-log-pickaxe.sh +2 -0
+	git log -a -Ga >actual &&
+	git log >expected &&

And we ran the same test but this time with "-a" to tell Git that binary-ness should not matter. It will find the sole commit. Good.

Quoted 8 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 130

Quoted 6 lines
t/t4209-log-pickaxe.sh +6 -0
+	test_cmp actual expected
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	git checkout --orphan orphan3 &&
+	echo "* diff=bin" > .gitattributes &&

s/> />/; (will locally munge--this alone is no reason to reroll).

Done.

Quoted 10 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 134

Quoted 4 lines
t/t4209-log-pickaxe.sh +4 -0
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git -c diff.bin.textconv=cat log -Ga >actual &&

This exposes a slight iffy-ness in the design. The textconv filter used here does not strip the "binary-ness" from the payload, but it is enough to tell the machinery that -G should look into the difference. Is that really desirable, though?

Quoted 3 lines

IOW, if this weren't the initial commit (which is handled by the codepath to special-case creation and deletion in diff_grep() function), would "log -Ga" show it without "-a"? Should it?

Yes "log -Ga" will find all three commits (creation, modification, deletion) which are present in v3 without "-a" and cat as textconv filter.

I can make that more explicit with a textconv filter which removes the binary-ness

git -c diff.bin.textconv="sed -e \"s/\x00//g\"" log -Ga >log &&

(diff.bin.textconv="cat -v" works here as well but seems non-portable)

Now we could also search for "aa" as the NUL separating them is gone but that could be getting too clever or?

Quoted 6 lines

I think this test piece (and probably the previous ones for "-a" vs "no -a" without textconv, as well) should be using a history with three commits, where

- the root commit introduces "a\0a" to data.bin (creation event)

Quoted 8 lines

- the second commit adds another instance of "a\0a" to data.bin (forces comparison)

- the third commit removes data.bin (deletion event)

and make sure that the three are treated identically. If "log -Ga" finds one (with the combination of other conditions like use of textconv or -a option), it should find all three, and vice versa.

Good point. I've added that.

Quoted 16 lines

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 147

Quoted 13 lines
t/t4209-log-pickaxe.sh +13 -0
+	git log >expected &&
+	test_cmp actual expected
+'
+
+test_expect_success 'log -S looks into binary files' '
+	git checkout --orphan orphan4 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Sa >actual &&
+	git log >expected &&
+	test_cmp actual expected
+'

Likewise. This would also benefit from a three-commit history.

Quoted 3 lines

Perhaps you can create such a history at the beginning of these additions as another "setup -G/-S binary test" step and test different variations in subsequent tests without the setup?

Done.

#9 lore raw

Re: [PATCH v2] log -G: Ignore binary files

In reply to Junio C Hamano
Quoted 28 lines

Junio C Hamano <[email protected]> hat am 29. November 2018 um 08:22 geschrieben:

Quoted 13 lines · Junio C Hamano

t/t4209-log-pickaxe.sh test_expect_success 'log -S --no-textconv (missing textconv tool)' ' · line 116

Quoted 8 lines
t/t4209-log-pickaxe.sh +8 -0
+test_expect_success 'log -G ignores binary files' '
+	git checkout --orphan orphan1 &&
+	printf "a\0a" >data.bin &&
+	git add data.bin &&
+	git commit -m "message" &&
+	git log -Ga >result &&
+	test_must_be_empty result
+'

As this is the first mention of data.bin, this is adding a new file data.bin that has two 'a' but is a binary file. And that is the only commit in the history leading to orphan1.

Quoted 2 lines

The fact that "log -Ga" won't find any means it missed the creation event, because the blob is binary. Good.

By the way, this root commit records another file whose path is "file" and has "Picked<LF>" in it. If the file had 'a' in it, it would have been included in "git log" output, but that is too subtle a point to be noticed by the readers who are only reading this patch without seeing what has been done to the index before this test piece.

Quoted 7 lines

If you are going to restructure these tests to create a three-commit history in a single expect_success that is inspected with various "log -Ga" invocations in subsequent tests, it is worth removing that other file (or rather, starting with "read-tree --empty" immediately after checking out the orphan branch, to clarify to the readers that there is nothing but what you add in the set-up step in the index) to make the test more robust.

Thanks for the explanation. First I though that "checkout --orphan" already takes care of everything but "read-tree --empty" is the way to go.

Done.

#11 lore raw

PATCH v3 1/1 log -G: ignore binary files

In reply to Thomas Braun

The -G<regex> option of log looks for the differences whose patch text contains added/removed lines that match regex.

Currently -G looks also into patches of binary files (which according to [1]) is binary as well.

This has a couple of issues:

- It makes the pickaxe search slow. In a proprietary repository of the author with only ~5500 commits and a total .git size of ~300MB searching takes ~13 seconds

    $time git log -Gwave > /dev/null

    real    0m13,241s
    user    0m12,596s
    sys     0m0,644s

whereas when we ignore binary files with this patch it takes ~4s

    $time ~/devel/git/git log -Gwave > /dev/null

    real    0m3,713s
    user    0m3,608s
    sys     0m0,105s

which is a speedup of more than fourfold.

- The internally used algorithm for generating patch text is based on xdiff and its states in [1]

Quoted 3 lines

The output format of the binary patch file is proprietary (and binary) and it is basically a collection of copy and insert commands [..]

which means that the current format could change once the internal algorithm is changed as the format is not standardized. In addition the git binary patch format used for preparing patches for git apply is *different* from the xdiff format as can be seen by comparing

git log -p -a

    commit 6e95bf4bafccf14650d02ab57f3affe669be10cf
    Author: A U Thor <[email protected]>
    Date:   Thu Apr 7 15:14:13 2005 -0700

        modify binary file

    diff --git a/data.bin b/data.bin
    index f414c84..edfeb6f 100644
    --- a/data.bin
    +++ b/data.bin
    @@ -1,2 +1,4 @@
     a
     a^@a
    +a
    +a^@a
  with git log --binary
    commit 6e95bf4bafccf14650d02ab57f3affe669be10cf
    Author: A U Thor <[email protected]>
    Date:   Thu Apr 7 15:14:13 2005 -0700

        modify binary file

    diff --git a/data.bin b/data.bin
    index f414c84bd3aa25fa07836bb1fb73db784635e24b..edfeb6f501[..]
    GIT binary patch
    literal 12
    QcmYe~N@Pgn0zx1O01)N^ZvX%Q

    literal 6
    NcmYe~N@Pgn0ssWg0XP5v

which seems unexpected.

To resolve these issues this patch makes -G<regex> ignore binary files by default. Textconv filters are supported and also -a/--text for getting the old and broken behaviour back.

The -S<block of text> option of log looks for differences that changes the number of occurrences of the specified block of text (i.e. addition/deletion) in a file. As we want to keep the current behaviour, add a test to ensure it stays that way.

[1]: http://www.xmailserver.org/xdiff.html

---

Changes since v2:
- Introduce a setup step for the new tests
- Really start with a clean history in the tests
- Added more complex commit history for the tests
- Use test_when_finished for cleanup instead of doing nothing
- Enhanced commit message to motivate the change better
- Added some more documentation

 Documentation/diff-options.txt |  5 +++++
 Documentation/gitdiffcore.txt  |  3 ++-
 diffcore-pickaxe.c             |  6 ++++++
 t/t4209-log-pickaxe.sh         | 35 ++++++++++++++++++++++++++++++++++
 4 files changed, 48 insertions(+), 1 deletion(-)
Documentation/diff-options.txt +5 -0
index 0378cd574e..b94d332f71 100644
@@ -524,6 +524,8 @@ struct), and want to know the history of that block since it first
 came into being: use the feature iteratively to feed the interesting
 block in the preimage back into `-S`, and keep going until you get the
 very first version of the block.
++
+Binary files are searched as well.
 
 -G<regex>::
 	Look for differences whose patch text contains added/removed
@@ -543,6 +545,9 @@ While `git log -G"regexec\(regexp"` will show this commit, `git log
 -S"regexec\(regexp" --pickaxe-regex` will not (because the number of
 occurrences of that string did not change).
 +
+Unless `--text` is supplied patches of binary files without a textconv
+filter will be ignored.
++
 See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
 information.
 
Documentation/gitdiffcore.txt +2 -1
index c0a60f3158..c970d9fe43 100644
@@ -242,7 +242,8 @@ textual diff has an added or a deleted line that matches the given
 regular expression.  This means that it will detect in-file (or what
 rename-detection considers the same file) moves, which is noise.  The
 implementation runs diff twice and greps, and this can be quite
-expensive.
+expensive.  To speed things up binary files without textconv filters
+will be ignored.
 
 When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
 that match their respective criterion are kept in the output.  When
diffcore-pickaxe.c +6 -0
index 69fc55ea1e..4cea086f80 100644
@@ -154,6 +154,12 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
 	if (textconv_one == textconv_two && diff_unmodified_pair(p))
 		return 0;
 
+	if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
+	    !o->flags.text &&
+	    ((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
+	     (!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
+		return 0;
+
 	mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
 	mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
 
t/t4209-log-pickaxe.sh +35 -0
index 844df760f7..5d06f5f45e 100755
@@ -106,4 +106,39 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
 	rm .gitattributes
 '
 
+test_expect_success 'setup log -[GS] binary & --text' '
+	git checkout --orphan GS-binary-and-text &&
+	git read-tree --empty &&
+	printf "a\na\0a\n" >data.bin &&
+	git add data.bin &&
+	git commit -m "create binary file" data.bin &&
+	printf "a\na\0a\n" >>data.bin &&
+	git commit -m "modify binary file" data.bin &&
+	git rm data.bin &&
+	git commit -m "delete binary file" data.bin &&
+	git log >full-log
+'
+
+test_expect_success 'log -G ignores binary files' '
+	git log -Ga >log &&
+	test_must_be_empty log
+'
+
+test_expect_success 'log -G looks into binary files with -a' '
+	git log -a -Ga >log &&
+	test_cmp log full-log
+'
+
+test_expect_success 'log -G looks into binary files with textconv filter' '
+	test_when_finished "rm .gitattributes" &&
+	echo "* diff=bin" >.gitattributes &&
+	git -c diff.bin.textconv=cat log -Ga >log &&
+	test_cmp log full-log
+'
+
+test_expect_success 'log -S looks into binary files' '
+	git log -Sa >log &&
+	test_cmp log full-log
+'
+
 test_done
Signature · 1 line
2.19.0.271.gfe8321ec05.dirty
#12 lore raw

Re: [PATCH v3] log -G: ignore binary files

Quoted 11 lines · Thomas Braun

- The internally used algorithm for generating patch text is based on xdiff and its states in [1]

Quoted 3 lines

The output format of the binary patch file is proprietary (and binary) and it is basically a collection of copy and insert commands [..]

which means that the current format could change once the internal algorithm is changed as the format is not standardized. In addition the git binary patch format used for preparing patches for git apply is *different* from the xdiff format as can be seen by comparing

This particular argument sounds like a red herring. After all, when the --text option is given

Quoted 18 lines

git log -p -a

    commit 6e95bf4bafccf14650d02ab57f3affe669be10cf
    Author: A U Thor <[email protected]>
    Date:   Thu Apr 7 15:14:13 2005 -0700

        modify binary file

    diff --git a/data.bin b/data.bin
    index f414c84..edfeb6f 100644
    --- a/data.bin
    +++ b/data.bin
    @@ -1,2 +1,4 @@
     a
     a^@a
    +a
    +a^@a

we will see 'a' in the output no matter how xdiff internally works; there is no way to express the above change textually without showing "+a" somewhere in the patch output.

The rest of the log message looks good, and ...

Quoted 7 lines

Changes since v2:
- Introduce a setup step for the new tests
- Really start with a clean history in the tests
- Added more complex commit history for the tests
- Use test_when_finished for cleanup instead of doing nothing
- Enhanced commit message to motivate the change better
- Added some more documentation

... the tests are certainly a lot easier to follow.

Thanks.