Skip to contentSkip to conversation

Fix handling of remotes with single-character names

PATCH In review Michael Haggerty 2 participants 7 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

cover Fix handling of remotes with single-character names

The parsing of remotes.<groupname> was broken if any of the remotes in the group has a name consisting of a single character.

The first patch fixes the bug; the others are general refactoring to make the function a little bit clearer.

This series is based on maint, which I just noticed is still v2.4.7, but it also rebases cleanly to master. It might make sense to apply only the first patch to maint and the others only to master.

These patches are also available from my GitHub repository [1] as branch "single-character-remotes".

Michael

[1] https://github.com/mhagger/git

Michael Haggerty (4):
get_remote_group(): handle remotes with single-character names get_remote_group(): rename local variable "space" to "wordlen" get_remote_group(): eliminate superfluous call to strcspn() get_remote_group(): use skip_prefix()

 builtin/fetch.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
Signature · 1 line
2.4.6
#1 lore raw

PATCH 1/4 get_remote_group(): handle remotes with single-character names

The code for splitting a whitespace-separated list of values in "remotes.<name>" had an off-by-one error that caused it to skip over remotes whose names consist of a single character.

Also remove unnecessary braces.

---
 builtin/fetch.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
builtin/fetch.c +1 -2
index f951265..98f9048 100644
@@ -980,10 +980,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");
 		}
Signature · 1 line
2.4.6
#2 lore raw

PATCH 2/4 get_remote_group(): rename local variable "space" to "wordlen"

In reply to Michael Haggerty
---
 builtin/fetch.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
builtin/fetch.c +5 -5
index 98f9048..d0d267b 100644
@@ -978,13 +978,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");
 		}
 	}
 
Signature · 1 line
2.4.6
#3 lore raw

PATCH 3/4 get_remote_group(): eliminate superfluous call to strcspn()

In reply to Michael Haggerty

There is no need to call it if value is the empty string. This also eliminates code duplication.

---
 builtin/fetch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
builtin/fetch.c +2 -2
index d0d267b..bd945d0 100644
@@ -978,13 +978,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");
 		}
 	}
 
Signature · 1 line
2.4.6
#4 lore raw

PATCH 4/4 get_remote_group(): use skip_prefix()

In reply to Michael Haggerty
---
 builtin/fetch.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
builtin/fetch.c +1 -2
index bd945d0..76ca100 100644
@@ -975,8 +975,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");
Signature · 1 line
2.4.6
#6 lore raw
Quoted 4 lines · Junio C Hamano

Thanks, queued.

By the way, do you plan to revisit two rather large-ish stalled topics of yours queued on 'pu' any time soon?

I hope to revive the "tempfile" and "numparse" topics earlyish in this release cycle if at all possible.

Michael

Signature · 2 lines
Michael Haggerty
[email protected]