grep: add "basic", "extended", "fixed", and "perl" to grep.extendedRegexp
PATCH 1/2 grep: add "basic", "extended", "fixed", and "perl" to grep.extendedRegexp
Adds "basic", "extended", "fixed", and "perl" settings to the grep.extendedRegexp configuration option which set "--basic-regexp", "--extended-regexp", "--fixed-strings", and "--perl-regexp" options by default respectively. For the purposes of backwards compatibility, "extended" is equivalent to "true".
--- Documentation/config.txt | 6 ++- Documentation/git-grep.txt | 6 ++- builtin/grep.c | 95 ++++++++++++++++++++++++---------------- grep.h | 8 ++++ t/t7810-grep.sh | 105 +++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 180 insertions(+), 40 deletions(-)
Documentation/config.txt +5 -1
@@ -1211,7 +1211,11 @@ grep.lineNumber:: If set to true, enable '-n' option by default. grep.extendedRegexp:: - If set to true, enable '--extended-regexp' option by default. + Sets the default matching behavior. This option can be set to a + boolean value or one of 'basic', 'extended', 'fixed', or 'perl' + which will enable the '--basic-regexp', '--extended-regexp', + '--fixed-strings' or '--perl-regexp' options accordingly. The value + of 'true' is equivalent to 'extended'. gpg.program:: Use this custom program instead of "gpg" found on $PATH when
Documentation/git-grep.txt +5 -1
@@ -43,7 +43,11 @@ grep.lineNumber:: If set to true, enable '-n' option by default. grep.extendedRegexp:: - If set to true, enable '--extended-regexp' option by default. + Sets the default matching behavior. This option can be set to a + boolean value or one of 'basic', 'extended', 'fixed', or 'perl' + which will enable the '--basic-regexp', '--extended-regexp', + '--fixed-strings' or '--perl-regexp' options accordingly. The value + of 'true' is equivalent to 'extended'. OPTIONS
builtin/grep.c +57 -38
131 lines not on this page · raw message
grep.h +8 -0
@@ -58,6 +58,14 @@ enum grep_expr_node {GREP_NODE_OR }; +enum grep_pattern_type { +GREP_PATTERN_TYPE_UNSPECIFIED =0 , +GREP_PATTERN_TYPE_BRE , +GREP_PATTERN_TYPE_ERE , +GREP_PATTERN_TYPE_FIXED , +GREP_PATTERN_TYPE_PCRE +}; +struct grep_expr {enum grep_expr_node node;unsigned hit;
t/t7810-grep.sh +105 -0
117 lines not on this page · raw message
--
1.7.11.3
PATCH 2/2 grep: rename "grep.extendedRegexp" option to "grep.patternType"
With the addition of the "basic", "extended", "fixed", and "perl" values for the "grep.extendedRegexp" option the name "grep.patternType" better represents the option's functionality. "grep.extendedRegexp" remains available as an alias to "grep.patternType" for the purposes of backwards compatibility.
--- Documentation/config.txt | 5 ++- Documentation/git-grep.txt | 5 ++- builtin/grep.c | 4 ++- t/t7810-grep.sh | 80 ++++++++++++++++++++++++++-------------------- 4 files changed, 56 insertions(+), 38 deletions(-)
Documentation/config.txt +4 -1
@@ -1210,13 +1210,16 @@ gitweb.snapshot:: grep.lineNumber:: If set to true, enable '-n' option by default. -grep.extendedRegexp:: +grep.patternType:: Sets the default matching behavior. This option can be set to a boolean value or one of 'basic', 'extended', 'fixed', or 'perl' which will enable the '--basic-regexp', '--extended-regexp', '--fixed-strings' or '--perl-regexp' options accordingly. The value of 'true' is equivalent to 'extended'. +grep.extendedRegexp:: + Alias for grep.patternType. + gpg.program:: Use this custom program instead of "gpg" found on $PATH when making or verifying a PGP signature. The program must support the
Documentation/git-grep.txt +4 -1
@@ -42,13 +42,16 @@ CONFIGURATION grep.lineNumber:: If set to true, enable '-n' option by default. -grep.extendedRegexp:: +grep.patternType:: Sets the default matching behavior. This option can be set to a boolean value or one of 'basic', 'extended', 'fixed', or 'perl' which will enable the '--basic-regexp', '--extended-regexp', '--fixed-strings' or '--perl-regexp' options accordingly. The value of 'true' is equivalent to 'extended'. +grep.extendedRegexp:: + Alias for grep.patternType. + OPTIONS -------
builtin/grep.c +3 -1
@@ -317,7 +317,9 @@ static int grep_config(const char *var, const char *value, void *cb)if (userdiff_config (var, value) <0 )return -1 ; -if (!strcmp (var,"grep.extendedregexp" )) { +if (!strcmp (var,"grep.patterntype" ) || +/* for backwards compatibility */ + !strcmp (var,"grep.extendedregexp" )) {grep_pattern_type_options (parse_pattern_type_arg (var, value), opt);return 0 ; }
t/t7810-grep.sh +45 -35
172 lines not on this page · raw message
--
1.7.11.3
Re: [PATCH/RFC 2/2] grep: rename "grep.extendedRegexp" option to "grep.patternType"
Quoted 6 lines · J Smith
With the addition of the "basic", "extended", "fixed", and "perl" values for the "grep.extendedRegexp" option the name "grep.patternType" better represents the option's functionality. "grep.extendedRegexp" remains available as an alias to "grep.patternType" for the purposes of backwards compatibility.
---
Sorry for not bringing this up earlier when we discussed grep.patternType, but my preference would be to introduce grep.patternType with these type names (including basic and perl) from the beginning, and then ignore grep.extendedRegexp if grep.patternType is set.
The core part of the change may look something like this...
builtin/grep.c +70 -38
@@ -260,6 +260,57 @@ static int wait_all(void) }#endif +static int parse_pattern_type_arg (const char *opt,const char *arg) +{ +switch (git_config_maybe_bool (opt, arg)) { +case 1 : +return GREP_PATTERN_TYPE_ERE ; +case 0 : +return GREP_PATTERN_TYPE_UNSPECIFIED ; +default : +if (!strcmp (arg,"basic" )) +return GREP_PATTERN_TYPE_BRE ; +else if (!strcmp (arg,"extended" )) +return GREP_PATTERN_TYPE_ERE ; +else if (!strcmp (arg,"fixed" )) +return GREP_PATTERN_TYPE_FIXED ; +else if (!strcmp (arg,"perl" )) +return GREP_PATTERN_TYPE_PCRE ; +die ("bad %s argument: %s" , opt, arg); + } +} + +static void grep_pattern_type_options (const int pattern_type,void *cb) +{ +struct grep_opt *opt = cb; + +switch (pattern_type) { +case GREP_PATTERN_TYPE_BRE : + opt->fixed =0 ; + opt->pcre =0 ; + opt->regflags &= ~REG_EXTENDED ; +break ; + +case GREP_PATTERN_TYPE_ERE : + opt->fixed =0 ; + opt->pcre =0 ; + opt->regflags |=REG_EXTENDED ; +break ; + +case GREP_PATTERN_TYPE_FIXED : + opt->fixed =1 ; + opt->pcre =0 ; + opt->regflags &= ~REG_EXTENDED ; +break ; + +case GREP_PATTERN_TYPE_PCRE : + opt->fixed =0 ; + opt->pcre =1 ; + opt->regflags &= ~REG_EXTENDED ; +break ; + } +} +static int grep_config (const char *var,const char *value,void *cb) {struct grep_opt *opt = cb;
@@ -269,10 +320,18 @@ static int grep_config(const char *var, const char *value, void *cb)return -1 ;if (!strcmp (var,"grep.extendedregexp" )) { -if (git_config_bool (var, value)) - opt->regflags |=REG_EXTENDED ; -else - opt->regflags &= ~REG_EXTENDED ; +if (!opt->pattern_type_used) { +if (git_config_bool (var, value)) + opt->regflags |=REG_EXTENDED ; +else + opt->regflags &= ~REG_EXTENDED ; + } +return 0 ; + } + +if (!strcmp (var,"grep.patterntype" )) { +grep_pattern_type_options (parse_pattern_type_arg (var, value), opt); + opt->pattern_type_used =1 ;return 0 ; }
@@ -669,14 +728,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)int i;int dummy;int use_index =1 ; -enum { - pattern_type_unspecified =0 , - pattern_type_bre, - pattern_type_ere, - pattern_type_fixed, - pattern_type_pcre, - }; -int pattern_type = pattern_type_unspecified; +int pattern_type =GREP_PATTERN_TYPE_UNSPECIFIED ;struct option options[] = { OPT_BOOLEAN(0, "cached", &cached,
@@ -705,16 +757,16 @@ int cmd_grep(int argc, const char **argv, const char *prefix)OPT_GROUP ("" ),OPT_SET_INT ('E' ,"extended-regexp" , &pattern_type,"use extended POSIX regular expressions" , - pattern_type_ere), +GREP_PATTERN_TYPE_ERE ),OPT_SET_INT ('G' ,"basic-regexp" , &pattern_type,"use basic POSIX regular expressions (default)" , - pattern_type_bre), +GREP_PATTERN_TYPE_BRE ),OPT_SET_INT ('F' ,"fixed-strings" , &pattern_type,"interpret patterns as fixed strings" , - pattern_type_fixed), +GREP_PATTERN_TYPE_FIXED ),OPT_SET_INT ('P' ,"perl-regexp" , &pattern_type,"use Perl-compatible regular expressions" , - pattern_type_pcre), +GREP_PATTERN_TYPE_PCRE ),OPT_GROUP ("" ),OPT_BOOLEAN ('n' ,"line-number" , &opt.linenum,"show line numbers" ), OPT_NEGBIT('h', NULL, &opt.pathname, "don't show filenames", 1),
@@ -824,28 +876,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)PARSE_OPT_KEEP_DASHDASH |PARSE_OPT_STOP_AT_NON_OPTION | PARSE_OPT_NO_INTERNAL_HELP); -switch (pattern_type) { -case pattern_type_fixed: - opt.fixed =1 ; - opt.pcre =0 ; -break ; -case pattern_type_bre: - opt.fixed =0 ; - opt.pcre =0 ; - opt.regflags &= ~REG_EXTENDED ; -break ; -case pattern_type_ere: - opt.fixed =0 ; - opt.pcre =0 ; - opt.regflags |=REG_EXTENDED ; -break ; -case pattern_type_pcre: - opt.fixed =0 ; - opt.pcre =1 ; -break ; -default : -break ;/* nothing */ - } + +grep_pattern_type_options (pattern_type, &opt);if (use_index && !startup_info->have_repository)/* die the same way as if we did it at the beginning */
Re: [PATCH/RFC 2/2] grep: rename "grep.extendedRegexp" option to "grep.patternType"
Quoted 9 lines · Junio C Hamano
Quoted 6 lines · J Smith
With the addition of the "basic", "extended", "fixed", and "perl" values for the "grep.extendedRegexp" option the name "grep.patternType" better represents the option's functionality. "grep.extendedRegexp" remains available as an alias to "grep.patternType" for the purposes of backwards compatibility.
---
Quoted 6 lines
Sorry for not bringing this up earlier when we discussed grep.patternType, but my preference would be to introduce grep.patternType with these type names (including basic and perl) from the beginning, and then ignore grep.extendedRegexp if grep.patternType is set.
The core part of the change may look something like this...
Ah, I see. Yeah, that's not a problem. I'll make the appropriate changes tomorrow and post a new patch.