[PATCH] grep: fix exit status if external_grep() returns error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sun, Sep 06, 2009 at 03:58:15PM -0700, Junio C Hamano wrote:

> Your patch is queued in 'pu', but it seems to break the exit status in a
> strange way with my limited test.
[...]
> The command should not give different exit status depending on the
> destination of standard output stream.

I could also reproduce this in master using

	:~/git/t$ git grep --no-color not-going-to-match .; echo $?

The problem is a small bug in grep_cache(), which is triggered here because
external_grep() cannot deal with relative paths (not sure why that's the
case though). Fix below.

Clemens
--o<--

If external_grep() is called and returns an error, grep_cache() mistakenly
reported a hit, even if there were none. The bug can be triggered by
calling "git grep --no-color" from a subdirectory.

Signed-off-by: Clemens Buchacher <drizzd@xxxxxx>
---
 builtin-grep.c |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index ad0e0a5..b577738 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -500,9 +500,9 @@ static int grep_cache(struct grep_opt *opt, const char **paths, int cached,
 	 * be a lot more optimized
 	 */
 	if (!cached && external_grep_allowed) {
-		hit = external_grep(opt, paths, cached);
-		if (hit >= 0)
-			return hit;
+		int ret = external_grep(opt, paths, cached);
+		if (ret >= 0)
+			return ret;
 	}
 #endif
 
-- 
1.6.4.2.266.gbaa17

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]