Skip to content

Commit 15c9649

Browse files
avargitster
authored andcommitted
grep/log: remove hidden --debug and --grep-debug options
Remove the hidden "grep --debug" and "log --grep-debug" options added in 17bf35a (grep: teach --debug option to dump the parse tree, 2012-09-13). At the time these options seem to have been intended to go along with a documentation discussion and to help the author of relevant tests to perform ad-hoc debugging on them[1]. Reasons to want this gone: 1. They were never documented, and the only (rather trivial) use of them in our own codebase for testing is something I removed back in e01b4da (grep: change non-ASCII -i test to stop using --debug, 2017-05-20). 2. Googling around doesn't show any in-the-wild uses I could dig up, and on the Git ML the only mentions after the original discussion seem to have been when they came up in unrelated diff contexts, or that test commit of mine. 3. An exception to that is c581e4a (grep: under --debug, show whether PCRE JIT is enabled, 2019-08-18) where we added the ability to dump out when PCREv2 has the JIT in effect. The combination of that and my earlier b65abca (grep: use PCRE v2 for optimized fixed-string search, 2019-07-01) means Git prints this out in its most common in-the-wild configuration: $ git log --grep-debug --grep=foo --grep=bar --grep=baz --all-match pcre2_jit_on=1 pcre2_jit_on=1 pcre2_jit_on=1 [all-match] (or pattern_body<body>foo (or pattern_body<body>bar pattern_body<body>baz ) ) $ git grep --debug \( -e foo --and -e bar \) --or -e baz pcre2_jit_on=1 pcre2_jit_on=1 pcre2_jit_on=1 (or (and patternfoo patternbar ) patternbaz ) I.e. for each pattern we're considering for the and/or/--all-match etc. debugging we'll now diligently spew out another identical line saying whether the PCREv2 JIT is on or not. I think that nobody's complained about that rather glaringly obviously bad output says something about how much this is used, i.e. it's not. The need for this debugging aid for the composed grep/log patterns seems to have passed, and the desire to dump the JIT config seems to have been another one-off around the time we had JIT-related issues on the PCREv2 codepath. That the original author of this debugging facility seemingly hasn't noticed the bad output since then[2] is probably some indicator. 1. https://lore.kernel.org/git/[email protected]/ 2. https://lore.kernel.org/git/[email protected]/ Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 71ca53e commit 15c9649

File tree

4 files changed

+2
-107
lines changed

4 files changed

+2
-107
lines changed

builtin/grep.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,6 @@ static void start_threads(struct grep_opt *opt)
216216
int err;
217217
struct grep_opt *o = grep_opt_dup(opt);
218218
o->output = strbuf_out;
219-
if (i)
220-
o->debug = 0;
221219
compile_grep_patterns(o);
222220
err = pthread_create(&threads[i], NULL, run, o);
223221

@@ -936,9 +934,6 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
936934
N_("indicate hit with exit status without output")),
937935
OPT_BOOL(0, "all-match", &opt.all_match,
938936
N_("show only matches from files that match all patterns")),
939-
OPT_SET_INT_F(0, "debug", &opt.debug,
940-
N_("show parse tree for grep expression"),
941-
1, PARSE_OPT_HIDDEN),
942937
OPT_GROUP(""),
943938
{ OPTION_STRING, 'O', "open-files-in-pager", &show_in_pager,
944939
N_("pager"), N_("show matching files in the pager"),

grep.c

Lines changed: 2 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,6 @@ static void compile_pcre1_regexp(struct grep_pat *p, const struct grep_opt *opt)
400400

401401
#if defined(PCRE_CONFIG_JIT) && !defined(NO_LIBPCRE1_JIT)
402402
pcre_config(PCRE_CONFIG_JIT, &p->pcre1_jit_on);
403-
if (opt->debug)
404-
fprintf(stderr, "pcre1_jit_on=%d\n", p->pcre1_jit_on);
405403

406404
if (p->pcre1_jit_on)
407405
study_options = PCRE_STUDY_JIT_COMPILE;
@@ -508,8 +506,6 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
508506
}
509507

510508
pcre2_config(PCRE2_CONFIG_JIT, &p->pcre2_jit_on);
511-
if (opt->debug)
512-
fprintf(stderr, "pcre2_jit_on=%d\n", p->pcre2_jit_on);
513509
if (p->pcre2_jit_on) {
514510
jitret = pcre2_jit_compile(p->pcre2_pattern, PCRE2_JIT_COMPLETE);
515511
if (jitret)
@@ -535,9 +531,6 @@ static void compile_pcre2_pattern(struct grep_pat *p, const struct grep_opt *opt
535531
BUG("pcre2_pattern_info() failed: %d", patinforet);
536532
if (jitsizearg == 0) {
537533
p->pcre2_jit_on = 0;
538-
if (opt->debug)
539-
fprintf(stderr, "pcre2_jit_on=%d: (*NO_JIT) in regex\n",
540-
p->pcre2_jit_on);
541534
return;
542535
}
543536
}
@@ -616,8 +609,6 @@ static void compile_fixed_regexp(struct grep_pat *p, struct grep_opt *opt)
616609
if (opt->ignore_case)
617610
regflags |= REG_ICASE;
618611
err = regcomp(&p->regexp, sb.buf, regflags);
619-
if (opt->debug)
620-
fprintf(stderr, "fixed %s\n", sb.buf);
621612
strbuf_release(&sb);
622613
if (err) {
623614
char errbuf[1024];
@@ -812,87 +803,6 @@ static struct grep_expr *compile_pattern_expr(struct grep_pat **list)
812803
return compile_pattern_or(list);
813804
}
814805

815-
static void indent(int in)
816-
{
817-
while (in-- > 0)
818-
fputc(' ', stderr);
819-
}
820-
821-
static void dump_grep_pat(struct grep_pat *p)
822-
{
823-
switch (p->token) {
824-
case GREP_AND: fprintf(stderr, "*and*"); break;
825-
case GREP_OPEN_PAREN: fprintf(stderr, "*(*"); break;
826-
case GREP_CLOSE_PAREN: fprintf(stderr, "*)*"); break;
827-
case GREP_NOT: fprintf(stderr, "*not*"); break;
828-
case GREP_OR: fprintf(stderr, "*or*"); break;
829-
830-
case GREP_PATTERN: fprintf(stderr, "pattern"); break;
831-
case GREP_PATTERN_HEAD: fprintf(stderr, "pattern_head"); break;
832-
case GREP_PATTERN_BODY: fprintf(stderr, "pattern_body"); break;
833-
}
834-
835-
switch (p->token) {
836-
default: break;
837-
case GREP_PATTERN_HEAD:
838-
fprintf(stderr, "<head %d>", p->field); break;
839-
case GREP_PATTERN_BODY:
840-
fprintf(stderr, "<body>"); break;
841-
}
842-
switch (p->token) {
843-
default: break;
844-
case GREP_PATTERN_HEAD:
845-
case GREP_PATTERN_BODY:
846-
case GREP_PATTERN:
847-
fprintf(stderr, "%.*s", (int)p->patternlen, p->pattern);
848-
break;
849-
}
850-
fputc('\n', stderr);
851-
}
852-
853-
static void dump_grep_expression_1(struct grep_expr *x, int in)
854-
{
855-
indent(in);
856-
switch (x->node) {
857-
case GREP_NODE_TRUE:
858-
fprintf(stderr, "true\n");
859-
break;
860-
case GREP_NODE_ATOM:
861-
dump_grep_pat(x->u.atom);
862-
break;
863-
case GREP_NODE_NOT:
864-
fprintf(stderr, "(not\n");
865-
dump_grep_expression_1(x->u.unary, in+1);
866-
indent(in);
867-
fprintf(stderr, ")\n");
868-
break;
869-
case GREP_NODE_AND:
870-
fprintf(stderr, "(and\n");
871-
dump_grep_expression_1(x->u.binary.left, in+1);
872-
dump_grep_expression_1(x->u.binary.right, in+1);
873-
indent(in);
874-
fprintf(stderr, ")\n");
875-
break;
876-
case GREP_NODE_OR:
877-
fprintf(stderr, "(or\n");
878-
dump_grep_expression_1(x->u.binary.left, in+1);
879-
dump_grep_expression_1(x->u.binary.right, in+1);
880-
indent(in);
881-
fprintf(stderr, ")\n");
882-
break;
883-
}
884-
}
885-
886-
static void dump_grep_expression(struct grep_opt *opt)
887-
{
888-
struct grep_expr *x = opt->pattern_expression;
889-
890-
if (opt->all_match)
891-
fprintf(stderr, "[all-match]\n");
892-
dump_grep_expression_1(x, 0);
893-
fflush(NULL);
894-
}
895-
896806
static struct grep_expr *grep_true_expr(void)
897807
{
898808
struct grep_expr *z = xcalloc(1, sizeof(*z));
@@ -973,7 +883,7 @@ static struct grep_expr *grep_splice_or(struct grep_expr *x, struct grep_expr *y
973883
return z;
974884
}
975885

976-
static void compile_grep_patterns_real(struct grep_opt *opt)
886+
void compile_grep_patterns(struct grep_opt *opt)
977887
{
978888
struct grep_pat *p;
979889
struct grep_expr *header_expr = prep_header_patterns(opt);
@@ -993,7 +903,7 @@ static void compile_grep_patterns_real(struct grep_opt *opt)
993903

994904
if (opt->all_match || header_expr)
995905
opt->extended = 1;
996-
else if (!opt->extended && !opt->debug)
906+
else if (!opt->extended)
997907
return;
998908

999909
p = opt->pattern_list;
@@ -1016,13 +926,6 @@ static void compile_grep_patterns_real(struct grep_opt *opt)
1016926
opt->all_match = 1;
1017927
}
1018928

1019-
void compile_grep_patterns(struct grep_opt *opt)
1020-
{
1021-
compile_grep_patterns_real(opt);
1022-
if (opt->debug)
1023-
dump_grep_expression(opt);
1024-
}
1025-
1026929
static void free_pattern_expr(struct grep_expr *x)
1027930
{
1028931
switch (x->node) {

grep.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,6 @@ struct grep_opt {
136136
int word_regexp;
137137
int fixed;
138138
int all_match;
139-
int debug;
140139
#define GREP_BINARY_DEFAULT 0
141140
#define GREP_BINARY_NOMATCH 1
142141
#define GREP_BINARY_TEXT 2

revision.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2489,8 +2489,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg
24892489
} else if ((argcount = parse_long_opt("grep", argv, &optarg))) {
24902490
add_message_grep(revs, optarg);
24912491
return argcount;
2492-
} else if (!strcmp(arg, "--grep-debug")) {
2493-
revs->grep_filter.debug = 1;
24942492
} else if (!strcmp(arg, "--basic-regexp")) {
24952493
revs->grep_filter.pattern_type_option = GREP_PATTERN_TYPE_BRE;
24962494
} else if (!strcmp(arg, "--extended-regexp") || !strcmp(arg, "-E")) {

0 commit comments

Comments
 (0)