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:
Jeff King
2014-06-18 15:48:29 -04:00
committed by Junio C Hamano
parent ae021d8791
commit 95b567c7c3
10 changed files with 44 additions and 54 deletions

View File

@ -100,7 +100,8 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
{
int i, len = strlen(line);
struct origin_data *origin_data;
char *src, *origin;
char *src;
const char *origin;
struct src_data *src_data;
struct string_list_item *item;
int pulling_head = 0;
@ -164,8 +165,7 @@ static int handle_line(char *line, struct merge_parents *merge_parents)
origin = line;
string_list_append(&src_data->tag, origin + 4);
src_data->head_status |= 2;
} else if (starts_with(line, "remote-tracking branch ")) {
origin = line + strlen("remote-tracking branch ");
} else if (skip_prefix(line, "remote-tracking branch ", &origin)) {
string_list_append(&src_data->r_branch, origin);
src_data->head_status |= 2;
} else {