Skip to content

Commit 7531a2d

Browse files
avargitster
authored andcommitted
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 727b6fc ("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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9ec726a commit 7531a2d

File tree

3 files changed

+14
-1
lines changed

3 files changed

+14
-1
lines changed

Documentation/rev-list-options.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ endif::git-rev-list[]
9191
Consider the limiting patterns to be fixed strings (don't interpret
9292
pattern as a regular expression).
9393

94+
-P::
9495
--perl-regexp::
9596
Consider the limiting patterns to be Perl-compatible regular
9697
expressions.

revision.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1996,7 +1996,7 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
19961996
DIFF_OPT_SET(&revs->diffopt, PICKAXE_IGNORE_CASE);
19971997
} else if (!strcmp(arg, "--fixed-strings") || !strcmp(arg, "-F")) {
19981998
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")) {
20002000
revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_PCRE;
20012001
} else if (!strcmp(arg, "--all-match")) {
20022002
revs->grep_filter.all_match = 1;

t/t4202-log.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,8 +404,20 @@ test_expect_success 'log with various grep.patternType configurations & command-
404404
--grep="(1|2)" >actual.fixed.short-arg &&
405405
git log --pretty=tformat:%s -E \
406406
--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 &&
407415
test_cmp expect.fixed actual.fixed.short-arg &&
408416
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 &&
409421
410422
git log --pretty=tformat:%s --fixed-strings \
411423
--grep="(1|2)" >actual.fixed.long-arg &&

0 commit comments

Comments
 (0)