summaryrefslogtreecommitdiff
path: root/git.c
diff options
context:
space:
mode:
authorAlexander Kuleshov <kuleshovmail@gmail.com>2016-02-22 13:18:29 +0600
committerJunio C Hamano <gitster@pobox.com>2016-02-21 23:52:43 -0800
commit63ca1c099c36e61b0e9cd7fa0b912c0b9d89b628 (patch)
tree266daafe353b62f988436638e69fdeea41824862 /git.c
parentbe08dee9738eaaa0423885ed189c2b6ad8368cf0 (diff)
downloadgit-63ca1c099c36e61b0e9cd7fa0b912c0b9d89b628.tar.gz
git.c: simplify stripping extension of a file in handle_builtin()ak/git-strip-extension-from-dashed-command
The handle_builtin() starts from stripping of command extension if STRIP_EXTENSION is enabled. Actually STRIP_EXTENSION does not used anywhere else. This patch introduces strip_extension() helper to strip STRIP_EXTENSION extension from argv[0] with the strip_suffix() instead of manually stripping. Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com> Helped-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git.c')
-rw-r--r--git.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/git.c b/git.c
index 5feba410ca..a9dc2e8b49 100644
--- a/git.c
+++ b/git.c
@@ -505,21 +505,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")) {