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>

SZEDER Gábor committed Jun 3, 2018 at 16:36 UTC aee9be2ebe370029f6289870fbd1714dccce2adf
1 file changed +13 -12
builtin/update-ref.c
+13 -12
@@ -311,11 +311,12 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
311
312 static const char *parse_cmd_option(struct strbuf *input, const char *next)
313 {
314 - if (!strncmp(next, "no-deref", 8) && next[8] == line_termination)
314 + const char *rest;
315 + if (skip_prefix(next, "no-deref", &rest) && *rest == line_termination)
316 update_flags |= REF_NO_DEREF;
317 else
318 die("option unknown: %s", next);
318 - return next + 8;
319 + return rest;
320 }
321
322 static void update_refs_stdin(struct ref_transaction *transaction)
@@ -332,16 +333,16 @@ static void update_refs_stdin(struct ref_transaction *transaction)
333 die("empty command in input");
334 else if (isspace(*next))
335 die("whitespace before command: %s", next);
335 - else if (starts_with(next, "update "))
336 - next = parse_cmd_update(transaction, &input, next + 7);
337 - else if (starts_with(next, "create "))
338 - next = parse_cmd_create(transaction, &input, next + 7);
339 - else if (starts_with(next, "delete "))
340 - next = parse_cmd_delete(transaction, &input, next + 7);
341 - else if (starts_with(next, "verify "))
342 - next = parse_cmd_verify(transaction, &input, next + 7);
343 - else if (starts_with(next, "option "))
344 - next = parse_cmd_option(&input, next + 7);
336 + else if (skip_prefix(next, "update ", &next))
337 + next = parse_cmd_update(transaction, &input, next);
338 + else if (skip_prefix(next, "create ", &next))
339 + next = parse_cmd_create(transaction, &input, next);
340 + else if (skip_prefix(next, "delete ", &next))
341 + next = parse_cmd_delete(transaction, &input, next);
342 + else if (skip_prefix(next, "verify ", &next))
343 + next = parse_cmd_verify(transaction, &input, next);
344 + else if (skip_prefix(next, "option ", &next))
345 + next = parse_cmd_option(&input, next);
346 else
347 die("unknown command: %s", next);
348