OSDN Git Service

git: avoid magic number with skip_prefix
authorJeff King <peff@peff.net>
Wed, 18 Jun 2014 19:56:48 +0000 (15:56 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Jun 2014 17:45:19 +0000 (10:45 -0700)
After handling options, any leftover arguments should be
commands. However, we pass through "--help" and "--version",
so that we convert them into "git help" and "git version"
respectively.

This is a straightforward use of skip_prefix to avoid a
magic number, but while we are there, it is worth adding a
comment to explain this otherwise confusing behavior.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git.c

diff --git a/git.c b/git.c
index b2bb09e..1537f00 100644 (file)
--- a/git.c
+++ b/git.c
@@ -588,8 +588,8 @@ int main(int argc, char **av)
        argc--;
        handle_options(&argv, &argc, NULL);
        if (argc > 0) {
-               if (starts_with(argv[0], "--"))
-                       argv[0] += 2;
+               /* translate --help and --version into commands */
+               skip_prefix(argv[0], "--", &argv[0]);
        } else {
                /* The user didn't specify a command; give them help */
                commit_pager_choice();