Skip to content

Commit 0b6a950

Browse files
committed
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]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent df35f33 commit 0b6a950

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
@@ -453,6 +453,10 @@ all::
453453
# When using RUNTIME_PREFIX, define HAVE_NS_GET_EXECUTABLE_PATH if your platform
454454
# supports calling _NSGetExecutablePath to retrieve the path of the running
455455
# executable.
456+
#
457+
# When using RUNTIME_PREFIX, define HAVE_WPGMPTR if your platform offers
458+
# the global variable _wpgmptr containing the absolute path of the current
459+
# executable (this is the case on Windows).
456460

457461
GIT-VERSION-FILE: FORCE
458462
@$(SHELL_PATH) ./GIT-VERSION-GEN
@@ -1694,6 +1698,10 @@ ifdef HAVE_NS_GET_EXECUTABLE_PATH
16941698
BASIC_CFLAGS += -DHAVE_NS_GET_EXECUTABLE_PATH
16951699
endif
16961700

1701+
ifdef HAVE_WPGMPTR
1702+
BASIC_CFLAGS += -DHAVE_WPGMPTR
1703+
endif
1704+
16971705
ifeq ($(TCLTK_PATH),)
16981706
NO_TCLTK = NoThanks
16991707
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)