Skip to content

Commit

Permalink
tag: use skip_prefix instead of magic numbers
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Jul 10, 2014
1 parent 67a31f6 commit ce85604
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions builtin/tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit ce85604

Please sign in to comment.