From: Jeff King Date: Thu, 10 Jul 2014 04:07:32 +0000 (-0400) Subject: tag: use skip_prefix instead of magic numbers X-Git-Tag: v2.1.0-rc0~32^2 X-Git-Url: https://git.lorimer.id.au/gitweb.git/diff_plain/ce856044681331d19b867426726db7edd12f1713?ds=sidebyside 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/tag.c b/builtin/tag.c index c6e8a71127..1101c19596 100644 --- a/builtin/tag.c +++ b/builtin/tag.c @@ -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;