From 5390590f6d72ffb80da74ed4cbc8648400ea3481 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 4 Jul 2006 02:31:50 -0700 Subject: [PATCH 1/3] git-grep: fix parsing of pathspec separator '--' We used to misparse git grep -e foo -- '*.sh' Signed-off-by: Junio C Hamano --- builtin-grep.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin-grep.c b/builtin-grep.c index 2e7986cec..a8bec72f8 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -817,8 +817,12 @@ int cmd_grep(int argc, const char **argv, char **envp) } usage(builtin_grep_usage); } - if (!strcmp("--", arg)) + if (!strcmp("--", arg)) { + /* later processing wants to have this at argv[1] */ + argv--; + argc++; break; + } if (*arg == '-') usage(builtin_grep_usage); From fcfe34b5ace3e75d37c462712c7103e39cdb1fbc Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 4 Jul 2006 02:43:40 -0700 Subject: [PATCH 2/3] git-grep: fix exit code when we use external grep. Upon hit, we should exit with status 0. Signed-off-by: Junio C Hamano --- builtin-grep.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/builtin-grep.c b/builtin-grep.c index a8bec72f8..bc53546dc 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -446,7 +446,7 @@ static int exec_grep(int argc, const char **argv) static int external_grep(struct grep_opt *opt, const char **paths, int cached) { - int i, nr, argc, hit, len; + int i, nr, argc, hit, len, status; const char *argv[MAXARGS+1]; char randarg[ARGBUF]; char *argptr = randarg; @@ -536,12 +536,17 @@ static int external_grep(struct grep_opt *opt, const char **paths, int cached) argv[argc++] = name; if (argc < MAXARGS) continue; - hit += exec_grep(argc, argv); + status = exec_grep(argc, argv); + if (0 < status) + hit = 1; argc = nr; } - if (argc > nr) - hit += exec_grep(argc, argv); - return 0; + if (argc > nr) { + status = exec_grep(argc, argv); + if (0 < status) + hit = 1; + } + return hit; } static int grep_cache(struct grep_opt *opt, const char **paths, int cached) From 088b084bbbb7c076a85db941ad60edce582017b4 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Tue, 4 Jul 2006 02:44:48 -0700 Subject: [PATCH 3/3] git-grep: use a bit more specific error messages. Signed-off-by: Junio C Hamano --- builtin-grep.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/builtin-grep.c b/builtin-grep.c index bc53546dc..6973c6670 100644 --- a/builtin-grep.c +++ b/builtin-grep.c @@ -657,6 +657,13 @@ static int grep_object(struct grep_opt *opt, const char **paths, static const char builtin_grep_usage[] = "git-grep