Skip to content

Commit 9eb9727

Browse files
committed
Merge branch 'sg/update-ref-stdin-cleanup'
Code cleanup. * sg/update-ref-stdin-cleanup: update-ref --stdin: use skip_prefix()
2 parents 208ee59 + aee9be2 commit 9eb9727

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

builtin/update-ref.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -311,11 +311,12 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
311311

312312
static const char *parse_cmd_option(struct strbuf *input, const char *next)
313313
{
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)
315316
update_flags |= REF_NO_DEREF;
316317
else
317318
die("option unknown: %s", next);
318-
return next + 8;
319+
return rest;
319320
}
320321

321322
static void update_refs_stdin(struct ref_transaction *transaction)
@@ -332,16 +333,16 @@ static void update_refs_stdin(struct ref_transaction *transaction)
332333
die("empty command in input");
333334
else if (isspace(*next))
334335
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);
345346
else
346347
die("unknown command: %s", next);
347348

0 commit comments

Comments
 (0)