summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 8385abf)
raw | patch | inline | side by side (parent: 8385abf)
author | Johannes Sixt <johannes.sixt@telecom.at> | |
Sat, 8 Dec 2007 19:57:25 +0000 (20:57 +0100) | ||
committer | Johannes Sixt <johannes.sixt@telecom.at> | |
Mon, 23 Jun 2008 11:34:55 +0000 (13:34 +0200) |
Before we can successfully parse a builtin command from the program name
we must strip off unneeded parts, that is, the file extension.
Furthermore, we must take Windows style path names into account when we
parse the program name.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
we must strip off unneeded parts, that is, the file extension.
Furthermore, we must take Windows style path names into account when we
parse the program name.
Signed-off-by: Johannes Sixt <johannes.sixt@telecom.at>
Makefile | patch | blob | history | |
git-compat-util.h | patch | blob | history | |
git.c | patch | blob | history |
diff --git a/Makefile b/Makefile
index a7dafa7586d951fdce97ccd661c4387943230051..9c5aae03bb6b7aab381cb3e551b176d25f48cf52 100644 (file)
--- a/Makefile
+++ b/Makefile
NO_POSIX_ONLY_PROGRAMS = YesPlease
COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat
COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
+ COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
COMPAT_OBJS += compat/mingw.o compat/fnmatch.o compat/regex.o
EXTLIBS += -lws2_32
X = .exe
diff --git a/git-compat-util.h b/git-compat-util.h
index ab762c79eedb6ba9f539f6679f0d1231d9206f3f..a9a85be89d69c91afcde3530325494dffbdf48b1 100644 (file)
--- a/git-compat-util.h
+++ b/git-compat-util.h
#define PATH_SEP ':'
#endif
+#ifndef STRIP_EXTENSION
+#define STRIP_EXTENSION ""
+#endif
+
#ifndef has_dos_drive_prefix
#define has_dos_drive_prefix(path) 0
#endif
index 59f0fcc1f2278d3234a7e4a306db56c7cfcde9a2..871b93ca7e5eb9e919f0d55e169f8864df5e8a6d 100644 (file)
--- a/git.c
+++ b/git.c
{ "pack-refs", cmd_pack_refs, RUN_SETUP },
};
int i;
+ static const char ext[] = STRIP_EXTENSION;
+
+ if (sizeof(ext) > 1) {
+ i = strlen(argv[0]) - strlen(ext);
+ if (i > 0 && !strcmp(argv[0] + i, ext)) {
+ char *argv0 = strdup(argv[0]);
+ argv[0] = cmd = argv0;
+ argv0[i] = '\0';
+ }
+ }
/* Turn "git cmd --help" into "git help cmd" */
if (argc > 1 && !strcmp(argv[1], "--help")) {
int main(int argc, const char **argv)
{
- const char *cmd = argv[0] ? argv[0] : "git-help";
- char *slash = strrchr(cmd, '/');
+ const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
+ char *slash = (char *)cmd + strlen(cmd);
const char *cmd_path = NULL;
int done_alias = 0;
* name, and the dirname as the default exec_path
* if we don't have anything better.
*/
- if (slash) {
+ do
+ --slash;
+ while (cmd <= slash && !is_dir_sep(*slash));
+ if (cmd <= slash) {
*slash++ = 0;
cmd_path = cmd;
cmd = slash;