Re: [PATCH] execv_git_cmd(): also try PATH if everything else fails.

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Scott Parish
Date: Sunday, October 21, 2007 - 11:21 am

Earlier, we tried to find the git commands in several possible exec
dirs.  Now, if all of these failed, try to find the git command in
PATH.

This allows you to install the git programs somewhere else than
originally specified when building git, as long as you add that location
to the PATH.

Implementation by Johannes Schindelin

Signed-off-by: Scott R Parish <srp@srparish.net>
---
 exec_cmd.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/exec_cmd.c b/exec_cmd.c
index 9b74ed2..374ffc9 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -36,7 +36,8 @@ int execv_git_cmd(const char **argv)
 	int i;
 	const char *paths[] = { current_exec_path,
 				getenv(EXEC_PATH_ENVIRONMENT),
-				builtin_exec_path };
+				builtin_exec_path,
+				"" };
 
 	for (i = 0; i < ARRAY_SIZE(paths); ++i) {
 		size_t len;
@@ -44,9 +45,12 @@ int execv_git_cmd(const char **argv)
 		const char *exec_dir = paths[i];
 		const char *tmp;
 
-		if (!exec_dir || !*exec_dir) continue;
+		if (!exec_dir) continue;
 
-		if (*exec_dir != '/') {
+		if (!*exec_dir)
+			/* try PATH */
+			*git_command = '\0';
+		else if (*exec_dir != '/') {
 			if (!getcwd(git_command, sizeof(git_command))) {
 				fprintf(stderr, "git: cannot determine "
 					"current directory: %s\n",
@@ -81,7 +85,7 @@ int execv_git_cmd(const char **argv)
 
 		len = strlen(git_command);
 		rc = snprintf(git_command + len, sizeof(git_command) - len,
-			      "/git-%s", argv[0]);
+			      "%sgit-%s", *exec_dir ? "/" : "", argv[0]);
 		if (rc < 0 || rc >= sizeof(git_command) - len) {
 			fprintf(stderr,
 				"git: command name given is too long.\n");
@@ -99,8 +103,8 @@ int execv_git_cmd(const char **argv)
 
 		trace_argv_printf(argv, -1, "trace: exec:");
 
-		/* execve() can only ever return if it fails */
-		execve(git_command, (char **)argv, environ);
+		/* execvp() can only ever return if it fails */
+		execvp(git_command, (char **)argv);
 
 		trace_printf("trace: exec failed: %s\n", strerror(errno));
 
-- 
1.5.3.4.206.g58ba4-dirty


-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [PATCH] When exec'ing sub-commands, fall back on ..., Scott R Parish, (Sat Oct 20, 1:12 am)
Re: [PATCH] When exec'ing sub-commands, fall back on ..., Johannes Schindelin, (Sat Oct 20, 1:25 pm)
Re: [PATCH] Deduce exec_path also from calls to git with a ..., Johannes Schindelin, (Sat Oct 20, 2:31 pm)
[PATCH] execv_git_cmd(): also try PATH if everything else ..., Johannes Schindelin, (Sat Oct 20, 3:00 pm)
Re: [PATCH] execv_git_cmd(): also try PATH if everything e ..., Scott Parish, (Sun Oct 21, 11:21 am)
[PATCH] execv_git_cmd(): also try PATH if everything else ..., Johannes Schindelin, (Sun Oct 21, 2:59 pm)
Re: [PATCH] execv_git_cmd(): also try PATH if everything e ..., Johannes Schindelin, (Sun Oct 21, 3:02 pm)
Re: [PATCH] execv_git_cmd(): also try PATH if everything e ..., Johannes Schindelin, (Mon Oct 22, 3:35 am)
Re: [PATCH] execv_git_cmd(): also try PATH if everything e ..., Johannes Schindelin, (Tue Oct 23, 4:12 am)