From c26f7d7b268c14f9ee7fa9cbeaad3bc890526d49 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Tue, 28 Jul 2015 23:08:18 +0200 Subject: get_remote_group(): handle remotes with single-character names The code for splitting a whitespace-separated list of values in "remotes." had an off-by-one error that caused it to skip over remotes whose names consist of a single character. Also remove unnecessary braces. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/fetch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 75a55e590b..9f7fe983a9 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -978,10 +978,9 @@ static int get_remote_group(const char *key, const char *value, void *priv) /* split list by white space */ int space = strcspn(value, " \t\n"); while (*value) { - if (space > 1) { + if (space >= 1) string_list_append(g->list, xstrndup(value, space)); - } value += space + (value[space] != '\0'); space = strcspn(value, " \t\n"); } -- cgit v1.2.3 From e286542de0c27e2c53d9a1ec44897dbef5de80dc Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Tue, 28 Jul 2015 23:08:19 +0200 Subject: get_remote_group(): rename local variable "space" to "wordlen" Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/fetch.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 9f7fe983a9..680ba66e53 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -976,13 +976,13 @@ static int get_remote_group(const char *key, const char *value, void *priv) if (starts_with(key, "remotes.") && !strcmp(key + 8, g->name)) { /* split list by white space */ - int space = strcspn(value, " \t\n"); + size_t wordlen = strcspn(value, " \t\n"); while (*value) { - if (space >= 1) + if (wordlen >= 1) string_list_append(g->list, - xstrndup(value, space)); - value += space + (value[space] != '\0'); - space = strcspn(value, " \t\n"); + xstrndup(value, wordlen)); + value += wordlen + (value[wordlen] != '\0'); + wordlen = strcspn(value, " \t\n"); } } -- cgit v1.2.3 From 5f65499fa281748421f2ae65cd794533ada4b4de Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Tue, 28 Jul 2015 23:08:20 +0200 Subject: get_remote_group(): eliminate superfluous call to strcspn() There is no need to call it if value is the empty string. This also eliminates code duplication. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/fetch.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index 680ba66e53..bbc2bb8859 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -976,13 +976,13 @@ static int get_remote_group(const char *key, const char *value, void *priv) if (starts_with(key, "remotes.") && !strcmp(key + 8, g->name)) { /* split list by white space */ - size_t wordlen = strcspn(value, " \t\n"); while (*value) { + size_t wordlen = strcspn(value, " \t\n"); + if (wordlen >= 1) string_list_append(g->list, xstrndup(value, wordlen)); value += wordlen + (value[wordlen] != '\0'); - wordlen = strcspn(value, " \t\n"); } } -- cgit v1.2.3 From bc598c32ae41cd355169ca7b207c2e35d9449232 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Tue, 28 Jul 2015 23:08:21 +0200 Subject: get_remote_group(): use skip_prefix() Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- builtin/fetch.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/builtin/fetch.c b/builtin/fetch.c index bbc2bb8859..262809c787 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -973,8 +973,7 @@ static int get_remote_group(const char *key, const char *value, void *priv) { struct remote_group_data *g = priv; - if (starts_with(key, "remotes.") && - !strcmp(key + 8, g->name)) { + if (skip_prefix(key, "remotes.", &key) && !strcmp(key, g->name)) { /* split list by white space */ while (*value) { size_t wordlen = strcspn(value, " \t\n"); -- cgit v1.2.3