{"thread":{"id":"31158","subject":"[PATCH/RFC 1/2] grep: add \"basic\", \"extended\", \"fixed\", and \"perl\" to grep.extendedRegexp","startedAt":"2012-07-31T22:53:28Z","lastAt":"2012-08-01T03:38:43Z","messageCount":4,"participants":["J Smith","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"196270","messageId":"1343775209-56505-1-git-send-email-dark.panda@gmail.com","threadId":"31158","inReplyTo":null,"subject":"[PATCH/RFC 1/2] grep: add \"basic\", \"extended\", \"fixed\", and \"perl\" to grep.extendedRegexp","fromName":"J Smith","fromEmail":"dark.panda@gmail.com","sentAt":"2012-07-31T22:53:28Z","receivedAt":"2012-07-31T22:53:28Z","isPatch":true,"sender":{"key":"dark.panda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/84783?v=4"},"body":"Adds \"basic\", \"extended\", \"fixed\", and \"perl\" settings to the\ngrep.extendedRegexp configuration option which set \"--basic-regexp\",\n\"--extended-regexp\", \"--fixed-strings\", and \"--perl-regexp\" options by\ndefault respectively. For the purposes of backwards compatibility,\n\"extended\" is equivalent to \"true\".\n---\n Documentation/config.txt   |   6 ++-\n Documentation/git-grep.txt |   6 ++-\n builtin/grep.c             |  95 ++++++++++++++++++++++++----------------\n grep.h                     |   8 ++++\n t/t7810-grep.sh            | 105 +++++++++++++++++++++++++++++++++++++++++++++\n 5 files changed, 180 insertions(+), 40 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex a95e5a4..67d9f24 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1211,7 +1211,11 @@ grep.lineNumber::\n \tIf set to true, enable '-n' option by default.\n\n grep.extendedRegexp::\n-\tIf set to true, enable '--extended-regexp' option by default.\n+\tSets the default matching behavior. This option can be set to a\n+\tboolean value or one of 'basic', 'extended', 'fixed', or 'perl'\n+\twhich will enable the '--basic-regexp', '--extended-regexp',\n+\t'--fixed-strings' or '--perl-regexp' options accordingly. The value\n+\tof 'true' is equivalent to 'extended'.\n\n gpg.program::\n \tUse this custom program instead of \"gpg\" found on $PATH when\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 3bec036..100328f 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -43,7 +43,11 @@ grep.lineNumber::\n \tIf set to true, enable '-n' option by default.\n\n grep.extendedRegexp::\n-\tIf set to true, enable '--extended-regexp' option by default.\n+\tSets the default matching behavior. This option can be set to a\n+\tboolean value or one of 'basic', 'extended', 'fixed', or 'perl'\n+\twhich will enable the '--basic-regexp', '--extended-regexp',\n+\t'--fixed-strings' or '--perl-regexp' options accordingly. The value\n+\tof 'true' is equivalent to 'extended'.\n\n\n OPTIONS\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 29adb0a..249fc7d 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -260,6 +260,55 @@ static int wait_all(void)\n }\n #endif\n\n+static int parse_pattern_type_arg(const char *opt, const char *arg)\n+{\n+\tswitch (git_config_maybe_bool(opt, arg)) {\n+\tcase 1:\n+\t\treturn GREP_PATTERN_TYPE_ERE;\n+\tcase 0:\n+\t\treturn GREP_PATTERN_TYPE_UNSPECIFIED;\n+\tdefault:\n+\t\tif (!strcmp(arg, \"basic\"))\n+\t\t\treturn GREP_PATTERN_TYPE_BRE;\n+\t\telse if (!strcmp(arg, \"extended\"))\n+\t\t\treturn GREP_PATTERN_TYPE_ERE;\n+\t\telse if (!strcmp(arg, \"fixed\"))\n+\t\t\treturn GREP_PATTERN_TYPE_FIXED;\n+\t\telse if (!strcmp(arg, \"perl\"))\n+\t\t\treturn GREP_PATTERN_TYPE_PCRE;\n+\t\tdie(\"bad %s argument: %s\", opt, arg);\n+\t}\n+}\n+\n+static void grep_pattern_type_options(const int pattern_type, void *cb)\n+{\n+\tstruct grep_opt *opt = cb;\n+\n+\tswitch (pattern_type) {\n+\t\tcase GREP_PATTERN_TYPE_BRE:\n+\t\t\topt->fixed = 0;\n+\t\t\topt->pcre = 0;\n+\t\t\topt->regflags &= ~REG_EXTENDED;\n+\t\t\tbreak;\n+\n+\t\tcase GREP_PATTERN_TYPE_ERE:\n+\t\t\topt->fixed = 0;\n+\t\t\topt->pcre = 0;\n+\t\t\topt->regflags |= REG_EXTENDED;\n+\t\t\tbreak;\n+\n+\t\tcase GREP_PATTERN_TYPE_FIXED:\n+\t\t\topt->fixed = 1;\n+\t\t\topt->pcre = 0;\n+\t\t\tbreak;\n+\n+\t\tcase GREP_PATTERN_TYPE_PCRE:\n+\t\t\topt->fixed = 0;\n+\t\t\topt->pcre = 1;\n+\t\t\tbreak;\n+\t}\n+}\n+\n static int grep_config(const char *var, const char *value, void *cb)\n {\n \tstruct grep_opt *opt = cb;\n@@ -269,10 +318,7 @@ static int grep_config(const char *var, const char *value, void *cb)\n \t\treturn -1;\n\n \tif (!strcmp(var, \"grep.extendedregexp\")) {\n-\t\tif (git_config_bool(var, value))\n-\t\t\topt->regflags |= REG_EXTENDED;\n-\t\telse\n-\t\t\topt->regflags &= ~REG_EXTENDED;\n+\t\tgrep_pattern_type_options(parse_pattern_type_arg(var, value), opt);\n \t\treturn 0;\n \t}\n\n@@ -669,14 +715,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \tint i;\n \tint dummy;\n \tint use_index = 1;\n-\tenum {\n-\t\tpattern_type_unspecified = 0,\n-\t\tpattern_type_bre,\n-\t\tpattern_type_ere,\n-\t\tpattern_type_fixed,\n-\t\tpattern_type_pcre,\n-\t};\n-\tint pattern_type = pattern_type_unspecified;\n+\tint pattern_type = GREP_PATTERN_TYPE_UNSPECIFIED;\n\n \tstruct option options[] = {\n \t\tOPT_BOOLEAN(0, \"cached\", &cached,\n@@ -705,16 +744,16 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_SET_INT('E', \"extended-regexp\", &pattern_type,\n \t\t\t    \"use extended POSIX regular expressions\",\n-\t\t\t    pattern_type_ere),\n+\t\t\t    GREP_PATTERN_TYPE_ERE),\n \t\tOPT_SET_INT('G', \"basic-regexp\", &pattern_type,\n \t\t\t    \"use basic POSIX regular expressions (default)\",\n-\t\t\t    pattern_type_bre),\n+\t\t\t    GREP_PATTERN_TYPE_BRE),\n \t\tOPT_SET_INT('F', \"fixed-strings\", &pattern_type,\n \t\t\t    \"interpret patterns as fixed strings\",\n-\t\t\t    pattern_type_fixed),\n+\t\t\t    GREP_PATTERN_TYPE_FIXED),\n \t\tOPT_SET_INT('P', \"perl-regexp\", &pattern_type,\n \t\t\t    \"use Perl-compatible regular expressions\",\n-\t\t\t    pattern_type_pcre),\n+\t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOLEAN('n', \"line-number\", &opt.linenum, \"show line numbers\"),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, \"don't show filenames\", 1),\n@@ -824,28 +863,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t     PARSE_OPT_KEEP_DASHDASH |\n \t\t\t     PARSE_OPT_STOP_AT_NON_OPTION |\n \t\t\t     PARSE_OPT_NO_INTERNAL_HELP);\n-\tswitch (pattern_type) {\n-\tcase pattern_type_fixed:\n-\t\topt.fixed = 1;\n-\t\topt.pcre = 0;\n-\t\tbreak;\n-\tcase pattern_type_bre:\n-\t\topt.fixed = 0;\n-\t\topt.pcre = 0;\n-\t\topt.regflags &= ~REG_EXTENDED;\n-\t\tbreak;\n-\tcase pattern_type_ere:\n-\t\topt.fixed = 0;\n-\t\topt.pcre = 0;\n-\t\topt.regflags |= REG_EXTENDED;\n-\t\tbreak;\n-\tcase pattern_type_pcre:\n-\t\topt.fixed = 0;\n-\t\topt.pcre = 1;\n-\t\tbreak;\n-\tdefault:\n-\t\tbreak; /* nothing */\n-\t}\n+\n+\tgrep_pattern_type_options(pattern_type, &opt);\n\n \tif (use_index && !startup_info->have_repository)\n \t\t/* die the same way as if we did it at the beginning */\ndiff --git a/grep.h b/grep.h\nindex ed7de6b..eb844a0 100644\n--- a/grep.h\n+++ b/grep.h\n@@ -58,6 +58,14 @@ enum grep_expr_node {\n \tGREP_NODE_OR\n };\n\n+enum grep_pattern_type {\n+\tGREP_PATTERN_TYPE_UNSPECIFIED = 0,\n+\tGREP_PATTERN_TYPE_BRE,\n+\tGREP_PATTERN_TYPE_ERE,\n+\tGREP_PATTERN_TYPE_FIXED,\n+\tGREP_PATTERN_TYPE_PCRE\n+};\n+\n struct grep_expr {\n \tenum grep_expr_node node;\n \tunsigned hit;\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex 523d041..c21cd61 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -250,6 +250,36 @@ do\n \t\tgit -c grep.extendedRegexp=true grep \"a+b*c\" ab >actual &&\n \t\ttest_cmp expected actual\n \t'\n+\n+\ttest_expect_success \"grep $L with grep.extendedRegexp=extended\" '\n+\t\techo \"ab:abc\" >expected &&\n+\t\tgit -c grep.extendedregexp=extended grep \"a+b*c\" ab >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep $L with grep.extendedRegexp=fixed\" '\n+\t\techo \"ab:abc\" >expected &&\n+\t\tgit -c grep.extendedregexp=fixed grep \"ab\" ab >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep $L with a valid regexp and grep.extendedRegexp=fixed \" '\n+\t\ttest_must_fail git -c grep.extendedregexp=fixed grep \"a*\" ab\n+\t'\n+\n+\ttest_expect_success \"grep $L with grep.extendedRegexp=basic\" '\n+\t\t{\n+\t\t\techo \"ab:a+b*c\"\n+\t\t\techo \"ab:a+bc\"\n+\t\t\techo \"ab:abc\"\n+\t\t} >expected &&\n+\t\tgit -c grep.extendedregexp=basic grep \"a*\" ab >actual &&\n+\t\ttest_cmp expected actual\n+\t'\n+\n+\ttest_expect_success \"grep $L with a valid regexp and grep.extendedRegexp=basic \" '\n+\t\ttest_must_fail git -c grep.extendedregexp=basic grep \"a?\" ab\n+\t'\n done\n\n cat >expected <<EOF\n@@ -731,6 +761,81 @@ test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '\n \ttest_cmp expected actual\n '\n\n+test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=basic' '\n+\tgit -c grep.extendedregexp=basic \\\n+\t\tgrep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=extended' '\n+\tgit -c grep.extendedregexp=extended \\\n+\t\tgrep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=fixed' '\n+\tgit -c grep.extendedregexp=fixed \\\n+\t\tgrep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success LIBPCRE 'grep pattern with grep.extendedRegexp=perl' '\n+\tgit -c grep.extendedregexp=perl \\\n+\t\tgrep \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'grep -E pattern with grep.extendedRegexp=perl' '\n+\ttest_must_fail git -c grep.extendedregexp=perl \\\n+\t\tgrep -E \"\\p{Ps}.*?\\p{Pe}\" hello.c\n+'\n+\n+test_expect_success 'grep -G pattern with grep.extendedRegexp=perl' '\n+\ttest_must_fail git -c grep.extendedregexp=perl \\\n+\t\tgrep -G \"\\p{Ps}.*?\\p{Pe}\" hello.c\n+'\n+\n+test_expect_success 'grep pattern with grep.extendedRegexp=fixed' '\n+\t>empty &&\n+\ttest_must_fail git -c grep.extendedregexp=fixed \\\n+\t\tgrep \".*\" ab >actual &&\n+\ttest_cmp empty actual\n+'\n+\n+test_expect_success 'grep -E pattern with grep.extendedRegexp=basic' '\n+\t{\n+\t\techo \"ab:a+b*c\"\n+\t\techo \"ab:a+bc\"\n+\t\techo \"ab:abc\"\n+\t} >expected &&\n+\tgit -c grep.extendedregexp=basic \\\n+\t\tgrep -E \".?\" ab >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'grep -E pattern with grep.extendedRegexp=fixed' '\n+\t{\n+\t\techo \"ab:a+b*c\"\n+\t\techo \"ab:a+bc\"\n+\t\techo \"ab:abc\"\n+\t} >expected &&\n+\tgit -c grep.extendedregexp=fixed \\\n+\t\tgrep -E \".?\" ab >actual &&\n+\ttest_cmp expected actual\n+'\n+\n+test_expect_success 'grep -G pattern with grep.extendedRegexp=fixed' '\n+\t>empty &&\n+\ttest_must_fail git -c grep.extendedregexp=fixed \\\n+\t\tgrep -G \".?\" ab >actual &&\n+\ttest_cmp empty actual\n+'\n+\n+test_expect_success 'grep with grep.extendedRegexp=nonsense properly dies' '\n+\ttest_must_fail git -c grep.extendedregexp=nonsense \\\n+\t\tgrep \"\\p{Ps}.*?\\p{Pe}\" hello.c\n+'\n+\n test_expect_success LIBPCRE 'grep -P -v pattern' '\n \t{\n \t\techo \"ab:a+b*c\"\n--\n1.7.11.3\n"},{"id":"196271","messageId":"1343775209-56505-2-git-send-email-dark.panda@gmail.com","threadId":"31158","inReplyTo":"1343775209-56505-1-git-send-email-dark.panda@gmail.com","subject":"[PATCH/RFC 2/2] grep: rename \"grep.extendedRegexp\" option to \"grep.patternType\"","fromName":"J Smith","fromEmail":"dark.panda@gmail.com","sentAt":"2012-07-31T22:53:29Z","receivedAt":"2012-07-31T22:53:29Z","isPatch":true,"sender":{"key":"dark.panda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/84783?v=4"},"body":"With the addition of the \"basic\", \"extended\", \"fixed\", and \"perl\"\nvalues for the \"grep.extendedRegexp\" option the name \"grep.patternType\"\nbetter represents the option's functionality. \"grep.extendedRegexp\"\nremains available as an alias to \"grep.patternType\" for the purposes of\nbackwards compatibility.\n---\n Documentation/config.txt   |  5 ++-\n Documentation/git-grep.txt |  5 ++-\n builtin/grep.c             |  4 ++-\n t/t7810-grep.sh            | 80 ++++++++++++++++++++++++++--------------------\n 4 files changed, 56 insertions(+), 38 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 67d9f24..9644bba 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1210,13 +1210,16 @@ gitweb.snapshot::\n grep.lineNumber::\n \tIf set to true, enable '-n' option by default.\n\n-grep.extendedRegexp::\n+grep.patternType::\n \tSets the default matching behavior. This option can be set to a\n \tboolean value or one of 'basic', 'extended', 'fixed', or 'perl'\n \twhich will enable the '--basic-regexp', '--extended-regexp',\n \t'--fixed-strings' or '--perl-regexp' options accordingly. The value\n \tof 'true' is equivalent to 'extended'.\n\n+grep.extendedRegexp::\n+\tAlias for grep.patternType.\n+\n gpg.program::\n \tUse this custom program instead of \"gpg\" found on $PATH when\n \tmaking or verifying a PGP signature. The program must support the\ndiff --git a/Documentation/git-grep.txt b/Documentation/git-grep.txt\nindex 100328f..d51cc19 100644\n--- a/Documentation/git-grep.txt\n+++ b/Documentation/git-grep.txt\n@@ -42,13 +42,16 @@ CONFIGURATION\n grep.lineNumber::\n \tIf set to true, enable '-n' option by default.\n\n-grep.extendedRegexp::\n+grep.patternType::\n \tSets the default matching behavior. This option can be set to a\n \tboolean value or one of 'basic', 'extended', 'fixed', or 'perl'\n \twhich will enable the '--basic-regexp', '--extended-regexp',\n \t'--fixed-strings' or '--perl-regexp' options accordingly. The value\n \tof 'true' is equivalent to 'extended'.\n\n+grep.extendedRegexp::\n+\tAlias for grep.patternType.\n+\n\n OPTIONS\n -------\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 249fc7d..a8c1c32 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -317,7 +317,9 @@ static int grep_config(const char *var, const char *value, void *cb)\n \tif (userdiff_config(var, value) < 0)\n \t\treturn -1;\n\n-\tif (!strcmp(var, \"grep.extendedregexp\")) {\n+\tif (!strcmp(var, \"grep.patterntype\") ||\n+\t\t\t/* for backwards compatibility */\n+\t\t\t!strcmp(var, \"grep.extendedregexp\")) {\n \t\tgrep_pattern_type_options(parse_pattern_type_arg(var, value), opt);\n \t\treturn 0;\n \t}\ndiff --git a/t/t7810-grep.sh b/t/t7810-grep.sh\nindex c21cd61..6bfe368 100755\n--- a/t/t7810-grep.sh\n+++ b/t/t7810-grep.sh\n@@ -239,32 +239,32 @@ do\n \t\tgit grep --max-depth 0 -n -e vvv $H -- t . >actual &&\n \t\ttest_cmp expected actual\n \t'\n-\ttest_expect_success \"grep $L with grep.extendedRegexp=false\" '\n+\ttest_expect_success \"grep $L with grep.patternType=false\" '\n \t\techo \"ab:a+bc\" >expected &&\n-\t\tgit -c grep.extendedRegexp=false grep \"a+b*c\" ab >actual &&\n+\t\tgit -c grep.patterntype=false grep \"a+b*c\" ab >actual &&\n \t\ttest_cmp expected actual\n \t'\n\n-\ttest_expect_success \"grep $L with grep.extendedRegexp=true\" '\n+\ttest_expect_success \"grep $L with grep.patternType=true\" '\n \t\techo \"ab:abc\" >expected &&\n-\t\tgit -c grep.extendedRegexp=true grep \"a+b*c\" ab >actual &&\n+\t\tgit -c grep.patterntype=true grep \"a+b*c\" ab >actual &&\n \t\ttest_cmp expected actual\n \t'\n\n-\ttest_expect_success \"grep $L with grep.extendedRegexp=extended\" '\n+\ttest_expect_success \"grep $L with grep.patternType=extended\" '\n \t\techo \"ab:abc\" >expected &&\n-\t\tgit -c grep.extendedregexp=extended grep \"a+b*c\" ab >actual &&\n+\t\tgit -c grep.patterntype=extended grep \"a+b*c\" ab >actual &&\n \t\ttest_cmp expected actual\n \t'\n\n-\ttest_expect_success \"grep $L with grep.extendedRegexp=fixed\" '\n+\ttest_expect_success \"grep $L with grep.patternType=fixed\" '\n \t\techo \"ab:abc\" >expected &&\n-\t\tgit -c grep.extendedregexp=fixed grep \"ab\" ab >actual &&\n+\t\tgit -c grep.patterntype=fixed grep \"ab\" ab >actual &&\n \t\ttest_cmp expected actual\n \t'\n\n-\ttest_expect_success \"grep $L with a valid regexp and grep.extendedRegexp=fixed \" '\n-\t\ttest_must_fail git -c grep.extendedregexp=fixed grep \"a*\" ab\n+\ttest_expect_success \"grep $L with a valid regexp and grep.patternType=fixed \" '\n+\t\ttest_must_fail git -c grep.patterntype=fixed grep \"a*\" ab\n \t'\n\n \ttest_expect_success \"grep $L with grep.extendedRegexp=basic\" '\n@@ -748,91 +748,91 @@ test_expect_success LIBPCRE 'grep -P pattern' '\n \ttest_cmp expected actual\n '\n\n-test_expect_success 'grep pattern with grep.extendedRegexp=true' '\n+test_expect_success 'grep pattern with grep.patternType=true' '\n \t>empty &&\n-\ttest_must_fail git -c grep.extendedregexp=true \\\n+\ttest_must_fail git -c grep.patterntype=true \\\n \t\tgrep \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp empty actual\n '\n\n-test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=true' '\n-\tgit -c grep.extendedregexp=true \\\n+test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=true' '\n+\tgit -c grep.patterntype=true \\\n \t\tgrep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n\n-test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=basic' '\n-\tgit -c grep.extendedregexp=basic \\\n+test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=basic' '\n+\tgit -c grep.patterntype=basic \\\n \t\tgrep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n\n-test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=extended' '\n+test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=extended' '\n \tgit -c grep.extendedregexp=extended \\\n \t\tgrep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n\n-test_expect_success LIBPCRE 'grep -P pattern with grep.extendedRegexp=fixed' '\n-\tgit -c grep.extendedregexp=fixed \\\n+test_expect_success LIBPCRE 'grep -P pattern with grep.patternType=fixed' '\n+\tgit -c grep.patterntype=fixed \\\n \t\tgrep -P \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n\n-test_expect_success LIBPCRE 'grep pattern with grep.extendedRegexp=perl' '\n-\tgit -c grep.extendedregexp=perl \\\n+test_expect_success LIBPCRE 'grep pattern with grep.patternType=perl' '\n+\tgit -c grep.patterntype=perl \\\n \t\tgrep \"\\p{Ps}.*?\\p{Pe}\" hello.c >actual &&\n \ttest_cmp expected actual\n '\n\n-test_expect_success 'grep -E pattern with grep.extendedRegexp=perl' '\n-\ttest_must_fail git -c grep.extendedregexp=perl \\\n+test_expect_success 'grep -E pattern with grep.patternType=perl' '\n+\ttest_must_fail git -c grep.patterntype=perl \\\n \t\tgrep -E \"\\p{Ps}.*?\\p{Pe}\" hello.c\n '\n\n-test_expect_success 'grep -G pattern with grep.extendedRegexp=perl' '\n-\ttest_must_fail git -c grep.extendedregexp=perl \\\n+test_expect_success 'grep -G pattern with grep.patternType=perl' '\n+\ttest_must_fail git -c grep.patterntype=perl \\\n \t\tgrep -G \"\\p{Ps}.*?\\p{Pe}\" hello.c\n '\n\n-test_expect_success 'grep pattern with grep.extendedRegexp=fixed' '\n+test_expect_success 'grep pattern with grep.patternType=fixed' '\n \t>empty &&\n-\ttest_must_fail git -c grep.extendedregexp=fixed \\\n+\ttest_must_fail git -c grep.patterntype=fixed \\\n \t\tgrep \".*\" ab >actual &&\n \ttest_cmp empty actual\n '\n\n-test_expect_success 'grep -E pattern with grep.extendedRegexp=basic' '\n+test_expect_success 'grep -E pattern with grep.patternType=basic' '\n \t{\n \t\techo \"ab:a+b*c\"\n \t\techo \"ab:a+bc\"\n \t\techo \"ab:abc\"\n \t} >expected &&\n-\tgit -c grep.extendedregexp=basic \\\n+\tgit -c grep.patterntype=basic \\\n \t\tgrep -E \".?\" ab >actual &&\n \ttest_cmp expected actual\n '\n\n-test_expect_success 'grep -E pattern with grep.extendedRegexp=fixed' '\n+test_expect_success 'grep -E pattern with grep.patternType=fixed' '\n \t{\n \t\techo \"ab:a+b*c\"\n \t\techo \"ab:a+bc\"\n \t\techo \"ab:abc\"\n \t} >expected &&\n-\tgit -c grep.extendedregexp=fixed \\\n+\tgit -c grep.patterntype=fixed \\\n \t\tgrep -E \".?\" ab >actual &&\n \ttest_cmp expected actual\n '\n\n-test_expect_success 'grep -G pattern with grep.extendedRegexp=fixed' '\n+test_expect_success 'grep -G pattern with grep.patternType=fixed' '\n \t>empty &&\n-\ttest_must_fail git -c grep.extendedregexp=fixed \\\n+\ttest_must_fail git -c grep.patterntype=fixed \\\n \t\tgrep -G \".?\" ab >actual &&\n \ttest_cmp empty actual\n '\n\n-test_expect_success 'grep with grep.extendedRegexp=nonsense properly dies' '\n-\ttest_must_fail git -c grep.extendedregexp=nonsense \\\n+test_expect_success 'grep with grep.patternType=nonsense properly dies' '\n+\ttest_must_fail git -c grep.patterntype=nonsense \\\n \t\tgrep \"\\p{Ps}.*?\\p{Pe}\" hello.c\n '\n\n@@ -1015,4 +1015,14 @@ test_expect_success LIBPCRE 'grep -P \"^ \"' '\n \ttest_cmp expected actual\n '\n\n+test_expect_success \"grep with grep.extendedRegexp=true for backwards compatibility\" '\n+\t{\n+\t\techo \"ab:a+b*c\"\n+\t\techo \"ab:a+bc\"\n+\t\techo \"ab:abc\"\n+\t} >expected &&\n+\tgit -c grep.extendedregexp=true grep \"a?\" ab >actual &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\n--\n1.7.11.3\n"},{"id":"196274","messageId":"7vpq7bh5wx.fsf@alter.siamese.dyndns.org","threadId":"31158","inReplyTo":"1343775209-56505-2-git-send-email-dark.panda@gmail.com","subject":"Re: [PATCH/RFC 2/2] grep: rename \"grep.extendedRegexp\" option to \"grep.patternType\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2012-07-31T23:22:54Z","receivedAt":"2012-07-31T23:22:54Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"J Smith <dark.panda@gmail.com> writes:\n\n> With the addition of the \"basic\", \"extended\", \"fixed\", and \"perl\"\n> values for the \"grep.extendedRegexp\" option the name \"grep.patternType\"\n> better represents the option's functionality. \"grep.extendedRegexp\"\n> remains available as an alias to \"grep.patternType\" for the purposes of\n> backwards compatibility.\n> ---\n\nSorry for not bringing this up earlier when we discussed grep.patternType,\nbut my preference would be to introduce grep.patternType with these\ntype names (including basic and perl) from the beginning, and then\nignore grep.extendedRegexp if grep.patternType is set.\n\nThe core part of the change may look something like this...\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 29adb0a..260a7db 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -260,6 +260,57 @@ static int wait_all(void)\n }\n #endif\n \n+static int parse_pattern_type_arg(const char *opt, const char *arg)\n+{\n+\tswitch (git_config_maybe_bool(opt, arg)) {\n+\tcase 1:\n+\t\treturn GREP_PATTERN_TYPE_ERE;\n+\tcase 0:\n+\t\treturn GREP_PATTERN_TYPE_UNSPECIFIED;\n+\tdefault:\n+\t\tif (!strcmp(arg, \"basic\"))\n+\t\t\treturn GREP_PATTERN_TYPE_BRE;\n+\t\telse if (!strcmp(arg, \"extended\"))\n+\t\t\treturn GREP_PATTERN_TYPE_ERE;\n+\t\telse if (!strcmp(arg, \"fixed\"))\n+\t\t\treturn GREP_PATTERN_TYPE_FIXED;\n+\t\telse if (!strcmp(arg, \"perl\"))\n+\t\t\treturn GREP_PATTERN_TYPE_PCRE;\n+\t\tdie(\"bad %s argument: %s\", opt, arg);\n+\t}\n+}\n+\n+static void grep_pattern_type_options(const int pattern_type, void *cb)\n+{\n+\tstruct grep_opt *opt = cb;\n+\n+\tswitch (pattern_type) {\n+\tcase GREP_PATTERN_TYPE_BRE:\n+\t\topt->fixed = 0;\n+\t\topt->pcre = 0;\n+\t\topt->regflags &= ~REG_EXTENDED;\n+\t\tbreak;\n+\n+\tcase GREP_PATTERN_TYPE_ERE:\n+\t\topt->fixed = 0;\n+\t\topt->pcre = 0;\n+\t\topt->regflags |= REG_EXTENDED;\n+\t\tbreak;\n+\n+\tcase GREP_PATTERN_TYPE_FIXED:\n+\t\topt->fixed = 1;\n+\t\topt->pcre = 0;\n+\t\topt->regflags &= ~REG_EXTENDED;\n+\t\tbreak;\n+\n+\tcase GREP_PATTERN_TYPE_PCRE:\n+\t\topt->fixed = 0;\n+\t\topt->pcre = 1;\n+\t\topt->regflags &= ~REG_EXTENDED;\n+\t\tbreak;\n+\t}\n+}\n+\n static int grep_config(const char *var, const char *value, void *cb)\n {\n \tstruct grep_opt *opt = cb;\n@@ -269,10 +320,18 @@ static int grep_config(const char *var, const char *value, void *cb)\n \t\treturn -1;\n \n \tif (!strcmp(var, \"grep.extendedregexp\")) {\n-\t\tif (git_config_bool(var, value))\n-\t\t\topt->regflags |= REG_EXTENDED;\n-\t\telse\n-\t\t\topt->regflags &= ~REG_EXTENDED;\n+\t\tif (!opt->pattern_type_used) {\n+\t\t\tif (git_config_bool(var, value))\n+\t\t\t\topt->regflags |= REG_EXTENDED;\n+\t\t\telse\n+\t\t\t\topt->regflags &= ~REG_EXTENDED;\n+\t\t}\n+\t\treturn 0;\n+\t}\n+\n+\tif (!strcmp(var, \"grep.patterntype\")) {\n+\t\tgrep_pattern_type_options(parse_pattern_type_arg(var, value), opt);\n+\t\topt->pattern_type_used = 1;\n \t\treturn 0;\n \t}\n \n@@ -669,14 +728,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \tint i;\n \tint dummy;\n \tint use_index = 1;\n-\tenum {\n-\t\tpattern_type_unspecified = 0,\n-\t\tpattern_type_bre,\n-\t\tpattern_type_ere,\n-\t\tpattern_type_fixed,\n-\t\tpattern_type_pcre,\n-\t};\n-\tint pattern_type = pattern_type_unspecified;\n+\tint pattern_type = GREP_PATTERN_TYPE_UNSPECIFIED;\n \n \tstruct option options[] = {\n \t\tOPT_BOOLEAN(0, \"cached\", &cached,\n@@ -705,16 +757,16 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_SET_INT('E', \"extended-regexp\", &pattern_type,\n \t\t\t    \"use extended POSIX regular expressions\",\n-\t\t\t    pattern_type_ere),\n+\t\t\t    GREP_PATTERN_TYPE_ERE),\n \t\tOPT_SET_INT('G', \"basic-regexp\", &pattern_type,\n \t\t\t    \"use basic POSIX regular expressions (default)\",\n-\t\t\t    pattern_type_bre),\n+\t\t\t    GREP_PATTERN_TYPE_BRE),\n \t\tOPT_SET_INT('F', \"fixed-strings\", &pattern_type,\n \t\t\t    \"interpret patterns as fixed strings\",\n-\t\t\t    pattern_type_fixed),\n+\t\t\t    GREP_PATTERN_TYPE_FIXED),\n \t\tOPT_SET_INT('P', \"perl-regexp\", &pattern_type,\n \t\t\t    \"use Perl-compatible regular expressions\",\n-\t\t\t    pattern_type_pcre),\n+\t\t\t    GREP_PATTERN_TYPE_PCRE),\n \t\tOPT_GROUP(\"\"),\n \t\tOPT_BOOLEAN('n', \"line-number\", &opt.linenum, \"show line numbers\"),\n \t\tOPT_NEGBIT('h', NULL, &opt.pathname, \"don't show filenames\", 1),\n@@ -824,28 +876,8 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t\t\t     PARSE_OPT_KEEP_DASHDASH |\n \t\t\t     PARSE_OPT_STOP_AT_NON_OPTION |\n \t\t\t     PARSE_OPT_NO_INTERNAL_HELP);\n-\tswitch (pattern_type) {\n-\tcase pattern_type_fixed:\n-\t\topt.fixed = 1;\n-\t\topt.pcre = 0;\n-\t\tbreak;\n-\tcase pattern_type_bre:\n-\t\topt.fixed = 0;\n-\t\topt.pcre = 0;\n-\t\topt.regflags &= ~REG_EXTENDED;\n-\t\tbreak;\n-\tcase pattern_type_ere:\n-\t\topt.fixed = 0;\n-\t\topt.pcre = 0;\n-\t\topt.regflags |= REG_EXTENDED;\n-\t\tbreak;\n-\tcase pattern_type_pcre:\n-\t\topt.fixed = 0;\n-\t\topt.pcre = 1;\n-\t\tbreak;\n-\tdefault:\n-\t\tbreak; /* nothing */\n-\t}\n+\n+\tgrep_pattern_type_options(pattern_type, &opt);\n \n \tif (use_index && !startup_info->have_repository)\n \t\t/* die the same way as if we did it at the beginning */\n"},{"id":"196281","messageId":"3D9678D0-DD72-4538-81E8-7568A2A3211D@gmail.com","threadId":"31158","inReplyTo":"7vpq7bh5wx.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH/RFC 2/2] grep: rename \"grep.extendedRegexp\" option to \"grep.patternType\"","fromName":"J Smith","fromEmail":"dark.panda@gmail.com","sentAt":"2012-08-01T03:38:43Z","receivedAt":"2012-08-01T03:38:43Z","isPatch":true,"sender":{"key":"dark.panda@gmail.com","avatar":"https://avatars.githubusercontent.com/u/84783?v=4"},"body":"\nOn 2012-07-31, at 7:22 PM, Junio C Hamano <gitster@pobox.com> wrote:\n\n> J Smith <dark.panda@gmail.com> writes:\n> \n>> With the addition of the \"basic\", \"extended\", \"fixed\", and \"perl\"\n>> values for the \"grep.extendedRegexp\" option the name \"grep.patternType\"\n>> better represents the option's functionality. \"grep.extendedRegexp\"\n>> remains available as an alias to \"grep.patternType\" for the purposes of\n>> backwards compatibility.\n>> ---\n> \n> Sorry for not bringing this up earlier when we discussed grep.patternType,\n> but my preference would be to introduce grep.patternType with these\n> type names (including basic and perl) from the beginning, and then\n> ignore grep.extendedRegexp if grep.patternType is set.\n> \n> The core part of the change may look something like this...\n\nAh, I see. Yeah, that's not a problem. I'll make the appropriate changes tomorrow and post a new patch. "}]}