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

[PATCH 5/9] Allow the built-in exec path to be relative to the command invocation path

From
Johannes Sixt <johannes.sixt@telecom.at>
Date
Jul 21, 2008, 19:19 UTC
Message-ID
<1216667998-8879-6-git-send-email-johannes.sixt@telecom.at>
In-Reply-To
<1216667998-8879-5-git-send-email-johannes.sixt@telecom.at>

If $(gitexecdir) is relative, it is interpreted relative to the command's invocation path, which usually is $(bindir).

The Makefile rules were written with the assumption that $(gitexecdir) is an absolute path. We introduce a separate variable that names the (absolute) installation directory.

Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
---
 Makefile   |   16 ++++++++++++----
 exec_cmd.c |   38 ++------------------------------------
 2 files changed, 14 insertions(+), 40 deletions(-)
diff --git a/Makefile b/Makefile
index 23f2185..908c1cb 100644
--- a/Makefile
+++ b/Makefile
@@ -1316,10 +1316,18 @@ template_instdir = $(template_dir)
 endif
 export template_instdir
 
+ifeq ($(firstword $(subst /, ,$(gitexecdir))),..)
+gitexec_instdir = $(bindir)/$(gitexecdir)
+else
+gitexec_instdir = $(gitexecdir)
+endif
+gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
+export gitexec_instdir
+
 install: all
 	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
-	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'
-	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
+	$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
+	$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
 	$(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X '$(DESTDIR_SQ)$(bindir_SQ)'
 	$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
 	$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
@@ -1328,10 +1336,10 @@ ifndef NO_TCLTK
 	$(MAKE) -C git-gui install
 endif
 ifneq (,$X)
-	$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), $(RM) '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p';)
+	$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
 endif
 	bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
-	execdir=$$(cd '$(DESTDIR_SQ)$(gitexecdir_SQ)' && pwd) && \
+	execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
 	if test "z$$bindir" != "z$$execdir"; \
 	then \
 		ln -f "$$bindir/git$X" "$$execdir/git$X" || \
diff --git a/exec_cmd.c b/exec_cmd.c
index 45f92eb..c236034 100644
--- a/exec_cmd.c
+++ b/exec_cmd.c
@@ -7,40 +7,6 @@ extern char **environ;
 static const char *argv_exec_path;
 static const char *argv0_path;
 
-static const char *builtin_exec_path(void)
-{
-#ifndef __MINGW32__
-	return GIT_EXEC_PATH;
-#else
-	int len;
-	char *p, *q, *sl;
-	static char *ep;
-	if (ep)
-		return ep;
-
-	len = strlen(_pgmptr);
-	if (len < 2)
-		return ep = ".";
-
-	p = ep = xmalloc(len+1);
-	q = _pgmptr;
-	sl = NULL;
-	/* copy program name, turn '\\' into '/', skip last part */
-	while ((*p = *q)) {
-		if (*q == '\\' || *q == '/') {
-			*p = '/';
-			sl = p;
-		}
-		p++, q++;
-	}
-	if (sl)
-		*sl = '\0';
-	else
-		ep[0] = '.', ep[1] = '\0';
-	return ep;
-#endif
-}
-
 const char *system_path(const char *path)
 {
 	if (!is_absolute_path(path) && argv0_path) {
@@ -75,7 +41,7 @@ const char *git_exec_path(void)
 		return env;
 	}
 
-	return builtin_exec_path();
+	return system_path(GIT_EXEC_PATH);
 }
 
 static void add_path(struct strbuf *out, const char *path)
@@ -99,7 +65,7 @@ void setup_path(void)
 
 	add_path(&new_path, argv_exec_path);
 	add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
-	add_path(&new_path, builtin_exec_path());
+	add_path(&new_path, system_path(GIT_EXEC_PATH));
 	add_path(&new_path, argv0_path);
 
 	if (old_path)
-- 
1.6.0.rc0.18.g6aef2
Previous: Johannes SixtNext: Johannes Sixt
Message 6 of 32 in “Make gitexecdir relative to $(bindir) on Windows”
  1. 0/9 Make gitexecdir relative to $(bindir) on WindowsJohannes Sixt, Jul 21, 2008
  2. 1/9 Makefile: Do not install a copy of 'git' in $(gitexecdir)Johannes Sixt, Jul 21, 2008
  3. 2/9 Makefile: Normalize $(bindir) and $(gitexecdir) before comparingJohannes Sixt, Jul 21, 2008
  4. 3/9 Record the command invocation path earlyJohannes Sixt, Jul 21, 2008
  5. 4/9 Fix relative built-in paths to be relative to the command invocationJohannes Sixt, Jul 21, 2008
  6. 5/9 Allow the built-in exec path to be relative to the command invocation pathJohannes Sixt, Jul 21, 2008
  7. 6/9 Allow add_path() to add non-existent directories to the pathJohannes Sixt, Jul 21, 2008
  8. 7/9 Windows: Make $(gitexecdir) relativeJohannes Sixt, Jul 21, 2008
  9. 8/9 Windows: Make sure argv[0] has a pathJohannes Sixt, Jul 21, 2008
  10. 9/9 Windows: Do not compile git-shellJohannes Sixt, Jul 21, 2008
  11. 10/9 git-gui: git.git now uses $(gitexec_instdir) to point to the exec-pathJohannes Sixt, Jul 21, 2008
  12. Steffen ProhaskaJul 25, 2008
  13. Junio C HamanoJul 23, 2008
  14. 5/9 Allow the built-in exec path to be relative to the command invocation pathJohannes Sixt, Jul 23, 2008
  15. Junio C HamanoJul 24, 2008
  16. Johannes SixtJul 24, 2008
  17. Junio C HamanoJul 25, 2008
  18. Johannes SixtJul 25, 2008
  19. Johannes SixtJul 25, 2008
  20. Junio C HamanoJul 28, 2008
  21. Johannes SchindelinJul 21, 2008
  22. Johannes SixtJul 22, 2008
  23. A Large Angry SCMJul 28, 2008
  24. Junio C HamanoJul 28, 2008
  25. Junio C HamanoJul 28, 2008
  26. A Large Angry SCMJul 28, 2008
  27. A Large Angry SCMJul 28, 2008
  28. A Large Angry SCMJul 28, 2008
  29. Johannes SchindelinJul 21, 2008
  30. Johannes SixtJul 22, 2008
  31. Junio C HamanoJul 23, 2008
  32. Johannes SixtJul 23, 2008

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.