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
5
remote.c
5
remote.c
@ -488,9 +488,8 @@ static void read_config(void)
|
||||
current_branch = NULL;
|
||||
head_ref = resolve_ref_unsafe("HEAD", sha1, 0, &flag);
|
||||
if (head_ref && (flag & REF_ISSYMREF) &&
|
||||
starts_with(head_ref, "refs/heads/")) {
|
||||
current_branch =
|
||||
make_branch(head_ref + strlen("refs/heads/"), 0);
|
||||
skip_prefix(head_ref, "refs/heads/", &head_ref)) {
|
||||
current_branch = make_branch(head_ref, 0);
|
||||
}
|
||||
git_config(handle_config, NULL);
|
||||
if (branch_pushremote_name) {
|
||||
|
Reference in New Issue
Block a user