git/list[1] front-page[2] threads[3] people[4] search[5] about
 

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

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Oct 21, 2007, 21:59 UTC
Message-ID
<Pine.LNX.4.64.0710212256270.25221@racer.site>
In-Reply-To
<20071021023614.GB14735@spearce.org>

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.

Initial implementation by Scott R Parish.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
	On Sat, 20 Oct 2007, Shawn O. Pearce wrote:
	> Johannes Schindelin <Johannes.Schindelin@gmx.de> wrote:
	> > On Sat, 20 Oct 2007, Scott Parish wrote:
	> > 
	> > > Actually, i didn't test it right, execve() were using the 
	> > > files in my cwd. In addition to you patch, you'd need to use 
	> > > execvp() instead of execve().
	> > 
	> > Ah, right.  I missed that one ;-)
	> > 
	> > How about this instead?
	> 
	> Uhhh.  Its the same, isn't it?  Still using execve() which means 
	> we will not look at PATH in the final attempt.
	Sorry.  I forgot to --amend.
 exec_cmd.c |   17 ++++++++++++-----
 1 files changed, 12 insertions(+), 5 deletions(-)
diff --git a/exec_cmd.c b/exec_cmd.c
index 9b74ed2..70b84b0 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");
@@ -100,7 +104,10 @@ 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);
+		if (*exec_dir)
+			execve(git_command, (char **)argv, environ);
+		else
+			execvp(git_command, (char **)argv);
 
 		trace_printf("trace: exec failed: %s\n", strerror(errno));
 
-- 
1.5.3.4.1289.ga1432
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 6 of 17 in “Re: [PATCH] When exec'ing sub-commands, fall back on execvp (thePATH)”
  1. Scott R ParishOct 20, 2007
  2. Johannes SchindelinOct 20, 2007
  3. Scott ParishOct 20, 2007
  4. execv_git_cmd(): also try PATH if everything else fails.Johannes Schindelin, Oct 20, 2007
  5. Shawn O. PearceOct 21, 2007
  6. execv_git_cmd(): also try PATH if everything else fails.Johannes Schindelin, Oct 21, 2007
  7. Shawn O. PearceOct 22, 2007
  8. Johannes SchindelinOct 22, 2007
  9. Shawn O. PearceOct 23, 2007
  10. Johannes SchindelinOct 23, 2007
  11. Scott ParishOct 22, 2007
  12. Andreas EricssonOct 22, 2007
  13. Johannes SixtOct 22, 2007
  14. Andreas EricssonOct 23, 2007
  15. Johannes SixtOct 23, 2007
  16. Scott ParishOct 21, 2007
  17. Johannes SchindelinOct 21, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.