diff options
author | Junio C Hamano <gitster@pobox.com> | 2016-02-26 13:37:13 -0800 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-02-26 13:37:13 -0800 |
commit | dede29612a723a7da9f489fecbdf02500a018430 (patch) | |
tree | e09b30d6a8ec19c8d8ff4e92b8f7246fc6b7d1ec | |
parent | 7943cba1ded6c5e295d06f9de6664999db5a09a8 (diff) | |
parent | 63ca1c099c36e61b0e9cd7fa0b912c0b9d89b628 (diff) | |
download | git-dede29612a723a7da9f489fecbdf02500a018430.tar.gz git-dede29612a723a7da9f489fecbdf02500a018430.tar.xz |
Merge branch 'ak/git-strip-extension-from-dashed-command'
Code simplification.
* ak/git-strip-extension-from-dashed-command:
git.c: simplify stripping extension of a file in handle_builtin()
-rw-r--r-- | git-compat-util.h | 4 | ||||
-rw-r--r-- | git.c | 26 |
2 files changed, 15 insertions, 15 deletions
diff --git a/git-compat-util.h b/git-compat-util.h index 693a336ff..2acef3f11 100644 --- a/git-compat-util.h +++ b/git-compat-util.h @@ -325,10 +325,6 @@ extern char *gitdirname(char *); #define _PATH_DEFPATH "/usr/local/bin:/usr/bin:/bin" #endif -#ifndef STRIP_EXTENSION -#define STRIP_EXTENSION "" -#endif - #ifndef has_dos_drive_prefix static inline int git_has_dos_drive_prefix(const char *path) { @@ -513,21 +513,25 @@ int is_builtin(const char *s) return !!get_builtin(s); } +#ifdef STRIP_EXTENSION +static void strip_extension(const char **argv) +{ + size_t len; + + if (strip_suffix(argv[0], STRIP_EXTENSION, &len)) + argv[0] = xmemdupz(argv[0], len); +} +#else +#define strip_extension(cmd) +#endif + static void handle_builtin(int argc, const char **argv) { - const char *cmd = argv[0]; - int i; - static const char ext[] = STRIP_EXTENSION; + const char *cmd; struct cmd_struct *builtin; - if (sizeof(ext) > 1) { - i = strlen(argv[0]) - strlen(ext); - if (i > 0 && !strcmp(argv[0] + i, ext)) { - char *argv0 = xstrdup(argv[0]); - argv[0] = cmd = argv0; - argv0[i] = '\0'; - } - } + strip_extension(argv); + cmd = argv[0]; /* Turn "git cmd --help" into "git help cmd" */ if (argc > 1 && !strcmp(argv[1], "--help")) { |