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

[PATCH 2/2] system_path(): simplify using strip_path_suffix(), and add suffix "git"

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
Feb 18, 2009, 15:11 UTC
Message-ID
<ba10ee3899e1b274c71c91a48a5319d9f18db502.1234969572u.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1234969572u.git.johannes.schindelin@gmx.de>

At least for the author of this patch, the logic in system_path() was too hard to understand. Using the function strip_path_suffix() documents the idea of the code better.

The real change is to add the suffix "git", so that a runtime prefix will be computed correctly even when the executable was called in /git/ as is the case in msysGit (Windows insists to search the current directory before the PATH when looking for an executable).

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 exec_cmd.c |   32 +++-----------------------------
 1 files changed, 3 insertions(+), 29 deletions(-)
diff --git a/exec_cmd.c b/exec_cmd.c
index f234066..f89268b 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -23,35 +23,9 @@ const char *system_path(const char *path)
 	assert(argv0_path);
 	assert(is_absolute_path(argv0_path));
 
-	if (!prefix) {
-		const char *strip[] = {
-			GIT_EXEC_PATH,
-			BINDIR,
-			0
-		};
-		const char **s;
-
-		for (s = strip; *s; s++) {
-			const char *sargv = argv0_path + strlen(argv0_path);
-			const char *ss = *s + strlen(*s);
-			while (argv0_path < sargv && *s < ss
-				&& (*sargv == *ss ||
-				    (is_dir_sep(*sargv) && is_dir_sep(*ss)))) {
-				sargv--;
-				ss--;
-			}
-			if (*s == ss) {
-				struct strbuf d = STRBUF_INIT;
-				/* We also skip the trailing directory separator. */
-				assert(sargv - argv0_path - 1 >= 0);
-				strbuf_add(&d, argv0_path, sargv - argv0_path - 1);
-				prefix = strbuf_detach(&d, NULL);
-				break;
-			}
-		}
-	}
-
-	if (!prefix) {
+	if (!prefix && strip_path_suffix(argv0_path, GIT_EXEC_PATH, &prefix) &&
+			strip_path_suffix(argv0_path, BINDIR, &prefix) &&
+			strip_path_suffix(argv0_path, "git", &prefix)) {
 		prefix = PREFIX;
 		fprintf(stderr, "RUNTIME_PREFIX requested, "
 				"but prefix computation failed.  "
-- 
1.6.1.1.825.g72a9f
Previous: Junio C HamanoNext: Johannes Sixt
Message 16 of 20 in “RUNTIME_PREFIX enhancements”
  1. 0/2 RUNTIME_PREFIX enhancementsJohannes Schindelin, Feb 18, 2009
  2. 1/2 Introduce the function strip_path_suffix()Johannes Schindelin, Feb 18, 2009
  3. Johannes SixtFeb 18, 2009
  4. Johannes SchindelinFeb 18, 2009
  5. Johannes SixtFeb 18, 2009
  6. Johannes SchindelinFeb 18, 2009
  7. 0/2 RUNTIME_PREFIX enhancementsJohannes Schindelin, Feb 19, 2009
  8. 1/2 Introduce the function strip_path_suffix()Johannes Schindelin, Feb 19, 2009
  9. Johannes SchindelinFeb 19, 2009
  10. Johannes SixtFeb 19, 2009
  11. Johannes SchindelinFeb 19, 2009
  12. 2/2 system_path(): simplify using strip_path_suffix(), and add suffix "git"Johannes Schindelin, Feb 19, 2009
  13. Johannes SixtFeb 19, 2009
  14. Johannes SchindelinFeb 19, 2009
  15. Junio C HamanoFeb 20, 2009
  16. 2/2 system_path(): simplify using strip_path_suffix(), and add suffix "git"Johannes Schindelin, Feb 18, 2009
  17. Johannes SixtFeb 18, 2009
  18. Johannes SchindelinFeb 18, 2009
  19. Johannes SixtFeb 18, 2009
  20. Johannes SchindelinFeb 18, 2009

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.