use skip_prefix to avoid repeating strings
It's a common idiom to match a prefix and then skip past it
with strlen, like:
if (starts_with(foo, "bar"))
foo += strlen("bar");
This avoids magic numbers, but means we have to repeat the
string (and there is no compiler check that we didn't make a
typo in one of the strings).
We can use skip_prefix to handle this case without repeating
ourselves.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
ae021d8791
commit
95b567c7c3
@ -776,8 +776,8 @@ static int switch_branches(const struct checkout_opts *opts,
|
||||
if (!(flag & REF_ISSYMREF))
|
||||
old.path = NULL;
|
||||
|
||||
if (old.path && starts_with(old.path, "refs/heads/"))
|
||||
old.name = old.path + strlen("refs/heads/");
|
||||
if (old.path)
|
||||
skip_prefix(old.path, "refs/heads/", &old.name);
|
||||
|
||||
if (!new->name) {
|
||||
new->name = "HEAD";
|
||||
|
||||
Reference in New Issue
Block a user