Skip to content

Commit 49fa65a

Browse files
Johannes Sixtgitster
authored andcommitted
Allow the built-in exec path to be relative to the command invocation path
If GIT_EXEC_PATH (the macro that is defined in the Makefile) 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 966c6ed commit 49fa65a

File tree

2 files changed

+26
-42
lines changed

2 files changed

+26
-42
lines changed

Makefile

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,16 @@ ALL_CFLAGS = $(CFLAGS)
170170
ALL_LDFLAGS = $(LDFLAGS)
171171
STRIP ?= strip
172172

173+
# Among the variables below, these:
174+
# gitexecdir
175+
# template_dir
176+
# htmldir
177+
# ETC_GITCONFIG (but not sysconfdir)
178+
# can be specified as a relative path ../some/where/else (which must begin
179+
# with ../); this is interpreted as relative to $(bindir) and "git" at
180+
# runtime figures out where they are based on the path to the executable.
181+
# This can help installing the suite in a relocatable way.
182+
173183
prefix = $(HOME)
174184
bindir = $(prefix)/bin
175185
mandir = $(prefix)/share/man
@@ -205,7 +215,7 @@ GITWEB_FAVICON = git-favicon.png
205215
GITWEB_SITE_HEADER =
206216
GITWEB_SITE_FOOTER =
207217

208-
export prefix bindir gitexecdir sharedir htmldir sysconfdir
218+
export prefix bindir sharedir htmldir sysconfdir
209219

210220
CC = gcc
211221
AR = ar
@@ -1321,22 +1331,30 @@ template_instdir = $(template_dir)
13211331
endif
13221332
export template_instdir
13231333

1334+
ifeq ($(firstword $(subst /, ,$(gitexecdir))),..)
1335+
gitexec_instdir = $(bindir)/$(gitexecdir)
1336+
else
1337+
gitexec_instdir = $(gitexecdir)
1338+
endif
1339+
gitexec_instdir_SQ = $(subst ','\'',$(gitexec_instdir))
1340+
export gitexec_instdir
1341+
13241342
install: all
13251343
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(bindir_SQ)'
1326-
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexecdir_SQ)'
1327-
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexecdir_SQ)'
1344+
$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
1345+
$(INSTALL) $(ALL_PROGRAMS) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)'
13281346
$(INSTALL) git$X git-upload-pack$X git-receive-pack$X git-upload-archive$X '$(DESTDIR_SQ)$(bindir_SQ)'
13291347
$(MAKE) -C templates DESTDIR='$(DESTDIR_SQ)' install
13301348
$(MAKE) -C perl prefix='$(prefix_SQ)' DESTDIR='$(DESTDIR_SQ)' install
13311349
ifndef NO_TCLTK
13321350
$(MAKE) -C gitk-git install
1333-
$(MAKE) -C git-gui install
1351+
$(MAKE) -C git-gui gitexecdir='$(gitexec_instdir_SQ)' install
13341352
endif
13351353
ifneq (,$X)
1336-
$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), $(RM) '$(DESTDIR_SQ)$(gitexecdir_SQ)/$p';)
1354+
$(foreach p,$(patsubst %$X,%,$(filter %$X,$(ALL_PROGRAMS) $(BUILT_INS) git$X)), $(RM) '$(DESTDIR_SQ)$(gitexec_instdir_SQ)/$p';)
13371355
endif
13381356
bindir=$$(cd '$(DESTDIR_SQ)$(bindir_SQ)' && pwd) && \
1339-
execdir=$$(cd '$(DESTDIR_SQ)$(gitexecdir_SQ)' && pwd) && \
1357+
execdir=$$(cd '$(DESTDIR_SQ)$(gitexec_instdir_SQ)' && pwd) && \
13401358
if test "z$$bindir" != "z$$execdir"; \
13411359
then \
13421360
ln -f "$$bindir/git$X" "$$execdir/git$X" || \

exec_cmd.c

Lines changed: 2 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,40 +7,6 @@ extern char **environ;
77
static const char *argv_exec_path;
88
static const char *argv0_path;
99

10-
static const char *builtin_exec_path(void)
11-
{
12-
#ifndef __MINGW32__
13-
return GIT_EXEC_PATH;
14-
#else
15-
int len;
16-
char *p, *q, *sl;
17-
static char *ep;
18-
if (ep)
19-
return ep;
20-
21-
len = strlen(_pgmptr);
22-
if (len < 2)
23-
return ep = ".";
24-
25-
p = ep = xmalloc(len+1);
26-
q = _pgmptr;
27-
sl = NULL;
28-
/* copy program name, turn '\\' into '/', skip last part */
29-
while ((*p = *q)) {
30-
if (*q == '\\' || *q == '/') {
31-
*p = '/';
32-
sl = p;
33-
}
34-
p++, q++;
35-
}
36-
if (sl)
37-
*sl = '\0';
38-
else
39-
ep[0] = '.', ep[1] = '\0';
40-
return ep;
41-
#endif
42-
}
43-
4410
const char *system_path(const char *path)
4511
{
4612
if (!is_absolute_path(path) && argv0_path) {
@@ -75,7 +41,7 @@ const char *git_exec_path(void)
7541
return env;
7642
}
7743

78-
return builtin_exec_path();
44+
return system_path(GIT_EXEC_PATH);
7945
}
8046

8147
static void add_path(struct strbuf *out, const char *path)
@@ -99,7 +65,7 @@ void setup_path(void)
9965

10066
add_path(&new_path, argv_exec_path);
10167
add_path(&new_path, getenv(EXEC_PATH_ENVIRONMENT));
102-
add_path(&new_path, builtin_exec_path());
68+
add_path(&new_path, system_path(GIT_EXEC_PATH));
10369
add_path(&new_path, argv0_path);
10470

10571
if (old_path)

0 commit comments

Comments
 (0)