tag: use skip_prefix instead of magic numbers
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>
Jeff King committed
Jul 10, 2014 at 00:07 UTC
ce856044681331d19b867426726db7edd12f1713
1 file changed
+5
-9
builtin/tag.c
+5
-9
@@ -524,18 +524,14 @@ static int parse_opt_sort(const struct option *opt, const char *arg, int unset)
524
int *sort = opt->value;
525
int flags = 0;
526
527
- if (*arg == '-') {
527
+ if (skip_prefix(arg, "-", &arg))
528
flags |= REVERSE_SORT;
529
- arg++;
530
- }
531
- if (starts_with(arg, "version:")) {
532
- *sort = VERCMP_SORT;
533
- arg += 8;
534
- } else if (starts_with(arg, "v:")) {
529
+
530
+ if (skip_prefix(arg, "version:", &arg) || skip_prefix(arg, "v:", &arg))
531
*sort = VERCMP_SORT;
536
- arg += 2;
537
- } else
532
+ else
533
*sort = STRCMP_SORT;
534
+
535
if (strcmp(arg, "refname"))
536
die(_("unsupported sort specification %s"), arg);
537
*sort |= flags;