Skip to content

Commit 2e197a7

Browse files
avargitster
authored andcommitted
pickaxe: assert that we must have a needle under -G or -S
Assert early in diffcore_pickaxe() that we've got a needle to work with under -G and -S. This code is redundant to the check -G and -S get from parse-options.c's get_arg(), which I'm adding a test for. This check dates back to e1b1611 (diffcore-pickaxe: fix infinite loop on zero-length needle, 2007-01-25) when "git log -S" could send this code into an infinite loop. It was then later refactored in 8fa4b09 (pickaxe: hoist empty needle check, 2012-10-28) into its current form, but it seemingly wasn't noticed that in the meantime a move to the parse-options.c API in dea007f (diff: parse separate options like -S foo, 2010-08-05) had made it redundant. Let's retain some of the paranoia here with a BUG(), but there's no need to be checking this in the pickaxe_match() inner loop. Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 03c1f14 commit 2e197a7

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

diffcore-pickaxe.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,6 @@ static int pickaxe_match(struct diff_filepair *p, struct diff_options *o,
132132
oidset_contains(o->objfind, &p->two->oid));
133133
}
134134

135-
if (!o->pickaxe[0])
136-
return 0;
137-
138135
if (o->flags.allow_textconv) {
139136
textconv_one = get_textconv(o->repo, p->one);
140137
textconv_two = get_textconv(o->repo, p->two);
@@ -230,6 +227,9 @@ void diffcore_pickaxe(struct diff_options *o)
230227
kwset_t kws = NULL;
231228
pickaxe_fn fn;
232229

230+
if (opts & ~DIFF_PICKAXE_KIND_OBJFIND &&
231+
(!needle || !*needle))
232+
BUG("should have needle under -G or -S");
233233
if (opts & (DIFF_PICKAXE_REGEX | DIFF_PICKAXE_KIND_G)) {
234234
int cflags = REG_EXTENDED | REG_NEWLINE;
235235
if (o->pickaxe_opts & DIFF_PICKAXE_IGNORE_CASE)

t/t4209-log-pickaxe.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ test_expect_success setup '
5656
'
5757

5858
test_expect_success 'usage' '
59+
test_expect_code 129 git log -S 2>err &&
60+
test_i18ngrep "switch.*requires a value" err &&
61+
62+
test_expect_code 129 git log -G 2>err &&
63+
test_i18ngrep "switch.*requires a value" err &&
64+
5965
test_expect_code 128 git log -Gregex -Sstring 2>err &&
6066
grep "mutually exclusive" err &&
6167

0 commit comments

Comments
 (0)