From 17bf35a3c7b46df7131681bcc5bee5f12e1caec4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 13 Sep 2012 14:21:44 -0700 Subject: grep: teach --debug option to dump the parse tree Our "grep" allows complex boolean expressions to be formed to match each individual line with operators like --and, '(', ')' and --not. Introduce the "--debug" option to show the parse tree to help people who want to debug and enhance it. Also "log" learns "--grep-debug" option to do the same. The command line parser to the log family is a lot more limited than the general "git grep" parser, but it has special handling for header matching (e.g. "--author"), and a parse tree is valuable when working on it. Note that "--all-match" is *not* any individual node in the parse tree. It is an instruction to the evaluator to check all the nodes in the top-level backbone have matched and reject a document as non-matching otherwise. Signed-off-by: Junio C Hamano --- builtin/grep.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'builtin') diff --git a/builtin/grep.c b/builtin/grep.c index fe1726f5ef..8aea00c048 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -772,6 +772,9 @@ int cmd_grep(int argc, const char **argv, const char *prefix) "indicate hit with exit status without output"), OPT_BOOLEAN(0, "all-match", &opt.all_match, "show only matches from files that match all patterns"), + { OPTION_SET_INT, 0, "debug", &opt.debug, NULL, + "show parse tree for grep expression", + PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 1 }, OPT_GROUP(""), { OPTION_STRING, 'O', "open-files-in-pager", &show_in_pager, "pager", "show matching files in the pager", -- cgit v1.2.3 From 208f5aa42615671bae1e55de20a58d9ba046d3e8 Mon Sep 17 00:00:00 2001 From: Michael J Gruber Date: Fri, 14 Sep 2012 11:46:35 +0200 Subject: grep: show --debug output only once When threaded grep is in effect, the patterns are duplicated and recompiled for each thread. Avoid "--debug" output during the recompilation so that the output is given once instead of "1+nthreads" times. Signed-off-by: Michael J Gruber Signed-off-by: Junio C Hamano --- builtin/grep.c | 1 + 1 file changed, 1 insertion(+) (limited to 'builtin') diff --git a/builtin/grep.c b/builtin/grep.c index 8aea00c048..a7e8df0d40 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -209,6 +209,7 @@ static void start_threads(struct grep_opt *opt) int err; struct grep_opt *o = grep_opt_dup(opt); o->output = strbuf_out; + o->debug = 0; compile_grep_patterns(o); err = pthread_create(&threads[i], NULL, run, o); -- cgit v1.2.3