summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Sixt <johannes.sixt@telecom.at>2007-12-08 19:57:25 (GMT)
committerJohannes Sixt <johannes.sixt@telecom.at>2008-06-23 11:34:55 (GMT)
commit23326d14edbd16469453f6c3ecdd98ab90e6efb7 (patch)
tree0c2c562c5338e53dd9c05defe26016c3165b0a1c
parent8385abfda533819be9fbec436230ccd7be4bcda8 (diff)
downloadgit-23326d14edbd16469453f6c3ecdd98ab90e6efb7.zip
git-23326d14edbd16469453f6c3ecdd98ab90e6efb7.tar.gz
git-23326d14edbd16469453f6c3ecdd98ab90e6efb7.tar.bz2
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>
-rw-r--r--Makefile1
-rw-r--r--git-compat-util.h4
-rw-r--r--git.c19
3 files changed, 21 insertions, 3 deletions
diff --git a/Makefile b/Makefile
index a7dafa7..9c5aae0 100644
--- a/Makefile
+++ b/Makefile
@@ -735,6 +735,7 @@ ifneq (,$(findstring MINGW,$(uname_S)))
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 ab762c7..a9a85be 100644
--- a/git-compat-util.h
+++ b/git-compat-util.h
@@ -114,6 +114,10 @@
#define PATH_SEP ':'
#endif
+#ifndef STRIP_EXTENSION
+#define STRIP_EXTENSION ""
+#endif
+
#ifndef has_dos_drive_prefix
#define has_dos_drive_prefix(path) 0
#endif
diff --git a/git.c b/git.c
index 59f0fcc..871b93c 100644
--- a/git.c
+++ b/git.c
@@ -369,6 +369,16 @@ static void handle_internal_command(int argc, const char **argv)
{ "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")) {
@@ -386,8 +396,8 @@ static void handle_internal_command(int argc, const char **argv)
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;
@@ -396,7 +406,10 @@ int main(int argc, const char **argv)
* 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;