Skip to content

Commit c1be1cb

Browse files
dschogitster
authored andcommitted
exec_cmd: provide a new-style RUNTIME_PREFIX helper for Windows
The RUNTIME_PREFIX feature comes from Git for Windows, but it was enhanced to allow support for other platforms. While changing the original idea, the concept was also improved by not forcing argv[0] to be adjusted. Let's allow the same for Windows by implementing a helper just as for the other platforms. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 226c0dd commit c1be1cb

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -460,6 +460,10 @@ all::
460460
# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
461461
# supports calling _NSGetExecutablePath to retrieve the path of the running
462462
# executable.
463+
#
464+
# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
465+
# the global variable _wpgmptr containing the absolute path of the current
466+
# executable (this is the case on Windows).
463467

464468
GIT-VERSION-FILE: FORCE
465469
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1703,6 +1707,10 @@ ifdef HAVE_NS_GET_EXECUTABLE_PATH
17031707
BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
17041708
endif
17051709

1710+
ifdef HAVE_WPGMPTR
1711+
BASIC_CFLAGS += -DHAVE_WPGMPTR
1712+
endif
1713+
17061714
ifeq ($(TCLTK_PATH),)
17071715
NO_TCLTK = NoThanks
17081716
endif

exec_cmd.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,24 @@ static int git_get_exec_path_darwin(struct strbuf *buf)
144144
}
145145
#endif /* HAVE_NS_GET_EXECUTABLE_PATH */
146146

147+
#ifdef HAVE_WPGMPTR
148+
/*
149+
* Resolves the executable path by using the global variable _wpgmptr.
150+
*
151+
* Returns 0 on success, -1 on failure.
152+
*/
153+
static int git_get_exec_path_wpgmptr(struct strbuf *buf)
154+
{
155+
int len = wcslen(_wpgmptr) * 3 + 1;
156+
strbuf_grow(buf, len);
157+
len = xwcstoutf(buf->buf, _wpgmptr, len);
158+
if (len < 0)
159+
return -1;
160+
buf->len += len;
161+
return 0;
162+
}
163+
#endif /* HAVE_WPGMPTR */
164+
147165
/*
148166
* Resolves the absolute path of the current executable.
149167
*
@@ -178,6 +196,10 @@ static int git_get_exec_path(struct strbuf *buf, const char *argv0)
178196
git_get_exec_path_procfs(buf) &&
179197
#endif /* PROCFS_EXECUTABLE_PATH */
180198

199+
#ifdef HAVE_WPGMPTR
200+
git_get_exec_path_wpgmptr(buf) &&
201+
#endif /* HAVE_WPGMPTR */
202+
181203
git_get_exec_path_from_argv0(buf, argv0)) {
182204
return -1;
183205
}

0 commit comments

Comments
 (0)