Skip to content

Commit ecdc7cb

Browse files
committed
Merge branch 'tb/log-G-binary'
"git log -G<regex>" looked for a hunk in the "git log -p" patch output that contained a string that matches the given pattern. Optimize this code to ignore binary files, which by default will not show any hunk that would match any pattern (unless textconv or the --text option is in effect, that is). * tb/log-G-binary: log -G: ignore binary files
2 parents 932b867 + e0e7cb8 commit ecdc7cb

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

Documentation/diff-options.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ struct), and want to know the history of that block since it first
524524
came into being: use the feature iteratively to feed the interesting
525525
block in the preimage back into `-S`, and keep going until you get the
526526
very first version of the block.
527+
+
528+
Binary files are searched as well.
527529

528530
-G<regex>::
529531
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
543545
-S"regexec\(regexp" --pickaxe-regex` will not (because the number of
544546
occurrences of that string did not change).
545547
+
548+
Unless `--text` is supplied patches of binary files without a textconv
549+
filter will be ignored.
550+
+
546551
See the 'pickaxe' entry in linkgit:gitdiffcore[7] for more
547552
information.
548553

Documentation/gitdiffcore.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,8 @@ textual diff has an added or a deleted line that matches the given
242242
regular expression. This means that it will detect in-file (or what
243243
rename-detection considers the same file) moves, which is noise. The
244244
implementation runs diff twice and greps, and this can be quite
245-
expensive.
245+
expensive. To speed things up binary files without textconv filters
246+
will be ignored.
246247

247248
When `-S` or `-G` are used without `--pickaxe-all`, only filepairs
248249
that match their respective criterion are kept in the output. When

diffcore-pickaxe.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,12 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
154154
if (textconv_one == textconv_two && diff_unmodified_pair(p))
155155
return 0;
156156

157+
if ((o->pickaxe_opts & DIFF_PICKAXE_KIND_G) &&
158+
!o->flags.text &&
159+
((!textconv_one && diff_filespec_is_binary(o->repo, p->one)) ||
160+
(!textconv_two && diff_filespec_is_binary(o->repo, p->two))))
161+
return 0;
162+
157163
mf1.size = fill_textconv(o->repo, textconv_one, p->one, &mf1.ptr);
158164
mf2.size = fill_textconv(o->repo, textconv_two, p->two, &mf2.ptr);
159165

t/t4209-log-pickaxe.sh

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,39 @@ test_expect_success 'log -S --no-textconv (missing textconv tool)' '
106106
rm .gitattributes
107107
'
108108

109+
test_expect_success 'setup log -[GS] binary & --text' '
110+
git checkout --orphan GS-binary-and-text &&
111+
git read-tree --empty &&
112+
printf "a\na\0a\n" >data.bin &&
113+
git add data.bin &&
114+
git commit -m "create binary file" data.bin &&
115+
printf "a\na\0a\n" >>data.bin &&
116+
git commit -m "modify binary file" data.bin &&
117+
git rm data.bin &&
118+
git commit -m "delete binary file" data.bin &&
119+
git log >full-log
120+
'
121+
122+
test_expect_success 'log -G ignores binary files' '
123+
git log -Ga >log &&
124+
test_must_be_empty log
125+
'
126+
127+
test_expect_success 'log -G looks into binary files with -a' '
128+
git log -a -Ga >log &&
129+
test_cmp log full-log
130+
'
131+
132+
test_expect_success 'log -G looks into binary files with textconv filter' '
133+
test_when_finished "rm .gitattributes" &&
134+
echo "* diff=bin" >.gitattributes &&
135+
git -c diff.bin.textconv=cat log -Ga >log &&
136+
test_cmp log full-log
137+
'
138+
139+
test_expect_success 'log -S looks into binary files' '
140+
git log -Sa >log &&
141+
test_cmp log full-log
142+
'
143+
109144
test_done

0 commit comments

Comments
 (0)