log: add -P as a synonym for --perl-regexp

Add a short -P option as a synonym for the longer --perl-regexp, for consistency with the options the corresponding grep invocations accept. This was intentionally omitted in commit 727b6fc3ed ("log --grep: accept --basic-regexp and --perl-regexp", 2012-10-03) for unspecified future use. Make it consistent with "grep" rather than to keep it open for future use, and to avoid the confusion of -P meaning different things for grep & log, as is the case with the -G option. As noted in the aforementioned commit the --basic-regexp option can't have a corresponding -G argument, as the log command already uses that for -G<regex>. 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 25, 2017 at 20:05 UTC 7531a2dd876994479484968d361e18b70b2c764e
3 files changed +14 -1
Documentation/rev-list-options.txt
+1
@@ -91,6 +91,7 @@ endif::git-rev-list[]
91 Consider the limiting patterns to be fixed strings (don't interpret
92 pattern as a regular expression).
93
94 +-P::
95 --perl-regexp::
96 Consider the limiting patterns to be Perl-compatible regular
97 expressions.
revision.c
+1 -1
@@ -1996,7 +1996,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
1996 DIFF_OPT_SET(&revs->diffopt, PICKAXE_IGNORE_CASE);
1997 } else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
1998 revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_FIXED;
1999 - } else if (!strcmp(arg, "--perl-regexp")) {
1999 + } else if (!strcmp(arg, "--perl-regexp") || !strcmp(arg, "-P")) {
2000 revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;
2001 } else if (!strcmp(arg, "--all-match")) {
2002 revs->grep_filter.all_match = 1;
t/t4202-log.sh
+12
@@ -404,8 +404,20 @@ test_expect_success 'log with various grep.patternType configurations & command-
404 --grep="(1|2)" >actual.fixed.short-arg &&
405 git log --pretty=tformat:%s -E \
406 --grep="\|2" >actual.extended.short-arg &&
407 + if test_have_prereq PCRE
408 + then
409 + git log --pretty=tformat:%s -P \
410 + --grep="[\d]\|" >actual.perl.short-arg
411 + else
412 + test_must_fail git log -P \
413 + --grep="[\d]\|"
414 + fi &&
415 test_cmp expect.fixed actual.fixed.short-arg &&
416 test_cmp expect.extended actual.extended.short-arg &&
417 + if test_have_prereq PCRE
418 + then
419 + test_cmp expect.perl actual.perl.short-arg
420 + fi &&
421
422 git log --pretty=tformat:%s --fixed-strings \
423 --grep="(1|2)" >actual.fixed.long-arg &&