Re: [PATCH 10/16] add NO_EXTERNAL_GREP build option

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

 



On Thu, Mar 13, 2008 at 08:50:24AM +0100, Johannes Sixt wrote:

> > This might have fallouts for msysgit (i.e., they need to define
> > NO_EXTERNAL_GREP instead of relying on __unix__ not being defined).
> 
> You name it. Would you mind converting exec_grep() to use run_command(),
> too? Or better inline it since it won't do a lot more than run_command()?
> That way we at least won't get a broken git when I merge git.git that has
> this patch.

Junio's fixups should restore the automagic behavior, so you shouldn't
see any problems now, I think. But the run_command cleanup is sensible.

This is on top of what Junio has in pu.

-- >8 --
use run_command for external grep

The behavior should be identical, but there's no good reason
not to use our abstraction library.

Signed-off-by: Jeff King <peff@xxxxxxxx>
---
 builtin-grep.c |   32 ++++----------------------------
 1 files changed, 4 insertions(+), 28 deletions(-)

diff --git a/builtin-grep.c b/builtin-grep.c
index ef29910..44d9bac 100644
--- a/builtin-grep.c
+++ b/builtin-grep.c
@@ -11,6 +11,7 @@
 #include "tree-walk.h"
 #include "builtin.h"
 #include "grep.h"
+#include "run-command.h"
 
 #ifndef NO_EXTERNAL_GREP
 #ifdef __unix__
@@ -162,32 +163,6 @@ static int grep_file(struct grep_opt *opt, const char *filename)
 }
 
 #if !NO_EXTERNAL_GREP
-static int exec_grep(int argc, const char **argv)
-{
-	pid_t pid;
-	int status;
-
-	argv[argc] = NULL;
-	pid = fork();
-	if (pid < 0)
-		return pid;
-	if (!pid) {
-		execvp("grep", (char **) argv);
-		exit(255);
-	}
-	while (waitpid(pid, &status, 0) < 0) {
-		if (errno == EINTR)
-			continue;
-		return -1;
-	}
-	if (WIFEXITED(status)) {
-		if (!WEXITSTATUS(status))
-			return 1;
-		return 0;
-	}
-	return -1;
-}
-
 #define MAXARGS 1000
 #define ARGBUF 4096
 #define push_arg(a) do { \
@@ -253,7 +228,8 @@ static int flush_grep(struct grep_opt *opt,
 		argc -= 2;
 	}
 
-	status = exec_grep(argc, argv);
+	argv[argc] = NULL;
+	status = run_command_v_opt(argv, 0);
 
 	if (kept_0) {
 		/*
@@ -264,7 +240,7 @@ static int flush_grep(struct grep_opt *opt,
 		argv[arg0++] = kept_0;
 		argv[arg0] = argv[argc+1];
 	}
-	return status;
+	return status == 0 ? 1 : -1;
 }
 
 static int external_grep(struct grep_opt *opt, const char **paths, int cached)
-- 
1.5.4.4.553.g83e84.dirty

--
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]

  Powered by Linux