@matheusbsbs / matheus-bagliano / commits / 23326d14ed
Fork 0

Windows: Strip ".exe" from the program name.

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>

Johannes Sixt committed Dec 8, 2007 at 20:57 UTC 23326d14edbd16469453f6c3ecdd98ab90e6efb7
3 files changed +21 -3
Makefile
+1
@@ -735,6 +735,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
735 NO_POSIX_ONLY_PROGRAMS = YesPlease
736 COMPAT_CFLAGS += -D__USE_MINGW_ACCESS -DNOGDI -Icompat
737 COMPAT_CFLAGS += -DSNPRINTF_SIZE_CORR=1
738 + COMPAT_CFLAGS += -DSTRIP_EXTENSION=\".exe\"
739 COMPAT_OBJS += compat/mingw.o compat/fnmatch.o compat/regex.o
740 EXTLIBS += -lws2_32
741 X = .exe
git-compat-util.h
+4
@@ -114,6 +114,10 @@
114 #define PATH_SEP ':'
115 #endif
116
117 +#ifndef STRIP_EXTENSION
118 +#define STRIP_EXTENSION ""
119 +#endif
120 +
121 #ifndef has_dos_drive_prefix
122 #define has_dos_drive_prefix(path) 0
123 #endif
git.c
+16 -3
@@ -369,6 +369,16 @@ static void handle_internal_command(int argc, const char **argv)
369 { "pack-refs", cmd_pack_refs, RUN_SETUP },
370 };
371 int i;
372 + static const char ext[] = STRIP_EXTENSION;
373 +
374 + if (sizeof(ext) > 1) {
375 + i = strlen(argv[0]) - strlen(ext);
376 + if (i > 0 && !strcmp(argv[0] + i, ext)) {
377 + char *argv0 = strdup(argv[0]);
378 + argv[0] = cmd = argv0;
379 + argv0[i] = '\0';
380 + }
381 + }
382
383 /* Turn "git cmd --help" into "git help cmd" */
384 if (argc > 1 && !strcmp(argv[1], "--help")) {
@@ -386,8 +396,8 @@ static void handle_internal_command(int argc, const char **argv)
396
397 int main(int argc, const char **argv)
398 {
389 - const char *cmd = argv[0] ? argv[0] : "git-help";
390 - char *slash = strrchr(cmd, '/');
399 + const char *cmd = argv[0] && *argv[0] ? argv[0] : "git-help";
400 + char *slash = (char *)cmd + strlen(cmd);
401 const char *cmd_path = NULL;
402 int done_alias = 0;
403
@@ -396,7 +406,10 @@ int main(int argc, const char **argv)
406 * name, and the dirname as the default exec_path
407 * if we don't have anything better.
408 */
399 - if (slash) {
409 + do
410 + --slash;
411 + while (cmd <= slash && !is_dir_sep(*slash));
412 + if (cmd <= slash) {
413 *slash++ = 0;
414 cmd_path = cmd;
415 cmd = slash;