log: make --regexp-ignore-case work with --perl-regexp

Make the --regexp-ignore-case option work with --perl-regexp. This never worked, and there was no test for this. Fix the bug and add a test. When PCRE support was added in commit 63e7e9d8b6 ("git-grep: Learn PCRE", 2011-05-09) compile_pcre_regexp() would only check opt->ignore_case, but when the --perl-regexp option was added in commit 727b6fc3ed ("log --grep: accept --basic-regexp and --perl-regexp", 2012-10-03) the code didn't set the opt->ignore_case. Change the test suite to test for -i and --invert-regexp with basic/extended/perl patterns in addition to fixed, which was the only patternType that was tested for before in combination with those options. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed May 20, 2017 at 21:42 UTC 9e3cbc59d5ec9d1b53c0c2e8c81fa2f3adca5696
2 files changed +56 -5
revision.c
+1
@@ -1991,6 +1991,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1991 } else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {
1992 revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_ERE;
1993 } else if (!strcmp(arg, "--regexp-ignore-case") || !strcmp(arg, "-i")) {
1994 + revs->grep_filter.ignore_case = 1;
1995 revs->grep_filter.regflags |= REG_ICASE;
1996 DIFF_OPT_SET(&revs->diffopt, PICKAXE_IGNORE_CASE);
1997 } else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
t/t4202-log.sh
+55 -5
@@ -231,14 +231,47 @@ second
231 initial
232 EOF
233 test_expect_success 'log --invert-grep --grep' '
234 - git log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual &&
235 - test_cmp expect actual
234 + # Fixed
235 + git -c grep.patternType=fixed log --pretty="tformat:%s" --invert-grep --grep=th --grep=Sec >actual &&
236 + test_cmp expect actual &&
237 +
238 + # POSIX basic
239 + git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
240 + test_cmp expect actual &&
241 +
242 + # POSIX extended
243 + git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
244 + test_cmp expect actual &&
245 +
246 + # PCRE
247 + if test_have_prereq PCRE
248 + then
249 + git -c grep.patternType=perl log --pretty="tformat:%s" --invert-grep --grep=t[h] --grep=S[e]c >actual &&
250 + test_cmp expect actual
251 + fi
252 '
253
254 test_expect_success 'log --invert-grep --grep -i' '
255 echo initial >expect &&
240 - git log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual &&
241 - test_cmp expect actual
256 +
257 + # Fixed
258 + git -c grep.patternType=fixed log --pretty="tformat:%s" --invert-grep -i --grep=th --grep=Sec >actual &&
259 + test_cmp expect actual &&
260 +
261 + # POSIX basic
262 + git -c grep.patternType=basic log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
263 + test_cmp expect actual &&
264 +
265 + # POSIX extended
266 + git -c grep.patternType=extended log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
267 + test_cmp expect actual &&
268 +
269 + # PCRE
270 + if test_have_prereq PCRE
271 + then
272 + git -c grep.patternType=perl log --pretty="tformat:%s" --invert-grep -i --grep=t[h] --grep=S[e]c >actual &&
273 + test_cmp expect actual
274 + fi
275 '
276
277 test_expect_success 'log --grep option parsing' '
@@ -256,8 +289,25 @@ test_expect_success 'log -i --grep' '
289
290 test_expect_success 'log --grep -i' '
291 echo Second >expect &&
292 +
293 + # Fixed
294 git log -1 --pretty="tformat:%s" --grep=sec -i >actual &&
260 - test_cmp expect actual
295 + test_cmp expect actual &&
296 +
297 + # POSIX basic
298 + git -c grep.patternType=basic log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
299 + test_cmp expect actual &&
300 +
301 + # POSIX extended
302 + git -c grep.patternType=extended log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
303 + test_cmp expect actual &&
304 +
305 + # PCRE
306 + if test_have_prereq PCRE
307 + then
308 + git -c grep.patternType=perl log -1 --pretty="tformat:%s" --grep=s[e]c -i >actual &&
309 + test_cmp expect actual
310 + fi
311 '
312
313 test_expect_success 'log -F -E --grep=<ere> uses ere' '