tag: use skip_prefix instead of magic numbers
authorJeff King <peff@peff.net>
Thu, 10 Jul 2014 04:07:32 +0000 (00:07 -0400)
committerJunio C Hamano <gitster@pobox.com>
Thu, 10 Jul 2014 17:56:50 +0000 (10:56 -0700)
We can make the parsing of the --sort parameter a bit more
readable by having skip_prefix keep our pointer up to date.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/tag.c
index c6e8a7112700c03b2615f9c99c9858884128ab25..1101c19596c549e50b2e2b6c640a5e318cefb802 100644 (file)
@@ -524,18 +524,14 @@ static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
        int *sort = opt->value;
        int flags = 0;
 
-       if (*arg == '-') {
+       if (skip_prefix(arg, "-", &arg))
                flags |= REVERSE_SORT;
-               arg++;
-       }
-       if (starts_with(arg, "version:")) {
-               *sort = VERCMP_SORT;
-               arg += 8;
-       } else if (starts_with(arg, "v:")) {
+
+       if (skip_prefix(arg, "version:", &arg) || skip_prefix(arg, "v:", &arg))
                *sort = VERCMP_SORT;
-               arg += 2;
-       } else
+       else
                *sort = STRCMP_SORT;
+
        if (strcmp(arg, "refname"))
                die(_("unsupported sort specification %s"), arg);
        *sort |= flags;