summaryrefslogtreecommitdiff
path: root/builtin/update-ref.c
diff options
context:
space:
mode:
authorSZEDER Gábor <szeder.dev@gmail.com>2018-06-03 14:36:51 (GMT)
committerJunio C Hamano <gitster@pobox.com>2018-06-04 03:26:01 (GMT)
commitaee9be2ebe370029f6289870fbd1714dccce2adf (patch)
treedf21482111842a165495174f6f71018bebbd8d12 /builtin/update-ref.c
parenta42a58d7b62cc1d6301440e81a83feed9d7c118c (diff)
downloadgit-aee9be2ebe370029f6289870fbd1714dccce2adf.zip
git-aee9be2ebe370029f6289870fbd1714dccce2adf.tar.gz
git-aee9be2ebe370029f6289870fbd1714dccce2adf.tar.bz2
update-ref --stdin: use skip_prefix()
Use skip_prefix() instead of starts_with() and strcmp() when parsing 'git update-ref's stdin to avoid a couple of magic numbers. Signed-off-by: SZEDER Gábor <szeder.dev@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/update-ref.c')
-rw-r--r--builtin/update-ref.c25
1 files changed, 13 insertions, 12 deletions
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 4b4714b..4fa3c0a 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -311,11 +311,12 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
static const char *parse_cmd_option(struct strbuf *input, const char *next)
{
- if (!strncmp(next, "no-deref", 8) && next[8] == line_termination)
+ const char *rest;
+ if (skip_prefix(next, "no-deref", &rest) && *rest == line_termination)
update_flags |= REF_NO_DEREF;
else
die("option unknown: %s", next);
- return next + 8;
+ return rest;
}
static void update_refs_stdin(struct ref_transaction *transaction)
@@ -332,16 +333,16 @@ static void update_refs_stdin(struct ref_transaction *transaction)
die("empty command in input");
else if (isspace(*next))
die("whitespace before command: %s", next);
- else if (starts_with(next, "update "))
- next = parse_cmd_update(transaction, &input, next + 7);
- else if (starts_with(next, "create "))
- next = parse_cmd_create(transaction, &input, next + 7);
- else if (starts_with(next, "delete "))
- next = parse_cmd_delete(transaction, &input, next + 7);
- else if (starts_with(next, "verify "))
- next = parse_cmd_verify(transaction, &input, next + 7);
- else if (starts_with(next, "option "))
- next = parse_cmd_option(&input, next + 7);
+ else if (skip_prefix(next, "update ", &next))
+ next = parse_cmd_update(transaction, &input, next);
+ else if (skip_prefix(next, "create ", &next))
+ next = parse_cmd_create(transaction, &input, next);
+ else if (skip_prefix(next, "delete ", &next))
+ next = parse_cmd_delete(transaction, &input, next);
+ else if (skip_prefix(next, "verify ", &next))
+ next = parse_cmd_verify(transaction, &input, next);
+ else if (skip_prefix(next, "option ", &next))
+ next = parse_cmd_option(&input, next);
else
die("unknown command: %s", next);