diff options
author | Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz> | 2024-03-23 14:18:08 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2024-03-25 19:40:53 +0100 |
commit | 0d527842b7633091158450d4dcda3ceb3547a636 (patch) | |
tree | 70bdfe14d7749a003b8a717aec430839f0dfd11b /grep.c | |
parent | Git 2.44 (diff) | |
download | git-0d527842b7633091158450d4dcda3ceb3547a636.tar.xz git-0d527842b7633091158450d4dcda3ceb3547a636.zip |
grep: improve errors for unmatched ( and )
Imagine you want to grep for (. Easy:
$ git grep '('
fatal: unmatched parenthesis
uhoh. This is plainly wrong. Unless you know specifically that
(a) git grep has expression groups and '(' ... ')' are used for them.
(b) you can use -e '(' to explicitly say '(' is what you are looking
for, not the beginning of a group.
Similarly,
$ git grep ')'
fatal: incomplete pattern expression: )
is somehow worse. ")" is a complete regular expression pattern.
Of course, the error wants to say "group" here.
In this case it is also not "incomplete", it is unmatched.
Make them say
$ ./git grep '('
fatal: unmatched ( for expression group
$ ./git grep ')'
fatal: incomplete pattern expression group: )
which are clearer in indicating that it is not the expression that
is wrong (since no pattern had been parsed at all), but rather that
it is been misconstrued as a grouping operator.
Link: https://bugs.debian.org/1051205
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'grep.c')
-rw-r--r-- | grep.c | 4 |
1 files changed, 2 insertions, 2 deletions
@@ -621,7 +621,7 @@ static struct grep_expr *compile_pattern_atom(struct grep_pat **list) *list = p->next; x = compile_pattern_or(list); if (!*list || (*list)->token != GREP_CLOSE_PAREN) - die("unmatched parenthesis"); + die("unmatched ( for expression group"); *list = (*list)->next; return x; default: @@ -792,7 +792,7 @@ void compile_grep_patterns(struct grep_opt *opt) if (p) opt->pattern_expression = compile_pattern_expr(&p); if (p) - die("incomplete pattern expression: %s", p->pattern); + die("incomplete pattern expression group: %s", p->pattern); if (opt->no_body_match && opt->pattern_expression) opt->pattern_expression = grep_not_expr(opt->pattern_expression); |