Re: Implementing branch attributes in git config

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
From: Linus Torvalds
Date: Sunday, May 7, 2006 - 5:18 pm

On Sun, 7 May 2006, Linus Torvalds wrote:

Well, simple enough to be buggy.


You also need to move the "int c = get_next_char()" in the for() loop down 
to the end of the loop (removing the "int", of course).

So here's the fixed thing in case people care (and this time I actually 
looked at whether it might even work, not just compile ;)

		Linus
---
diff --git a/config.c b/config.c
index 41066e4..69d451a 100644
--- a/config.c
+++ b/config.c
@@ -134,12 +134,46 @@ static int get_value(config_fn_t fn, cha
 	return fn(name, value);
 }
 
+static int get_branch_name(char *name)
+{
+	int baselen = 7;
+	int quote = 0;
+
+	memcpy(name, "branch.", 7);
+	for (;;) {
+		int c = get_next_char();
+		if (c == EOF)
+			return -1;
+		if (c == '\n')
+			return -1;
+		if (!quote) {
+			if (c == '"')
+				break;
+			if (c == ']')
+				return -1;
+			if (c == '\\') {
+				quote = 1;
+				continue;
+			}
+		}
+		name[baselen++] = c;
+		if (baselen > MAXNAME / 2)
+			return -1;
+	}
+	if (get_next_char() != ']')
+		return -1;
+	return baselen;
+}
+
 static int get_base_var(char *name)
 {
 	int baselen = 0;
+	int c = get_next_char();
+
+	if (c == '"')
+		return get_branch_name(name);
 
 	for (;;) {
-		int c = get_next_char();
 		if (c == EOF)
 			return -1;
 		if (c == ']')
@@ -149,6 +183,7 @@ static int get_base_var(char *name)
 		if (baselen > MAXNAME / 2)
 			return -1;
 		name[baselen++] = tolower(c);
+		c = get_next_char();
 	}
 }
 
-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Implementing branch attributes in git config, Pavel Roskin, (Sun May 7, 2:34 pm)
Re: Implementing branch attributes in git config, Junio C Hamano, (Sun May 7, 3:24 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Sun May 7, 5:05 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Sun May 7, 5:18 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Sun May 7, 5:25 pm)
Re: Implementing branch attributes in git config, Pavel Roskin, (Sun May 7, 5:36 pm)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Sun May 7, 5:43 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Sun May 7, 5:43 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Sun May 7, 5:55 pm)
Re: Implementing branch attributes in git config, Pavel Roskin, (Sun May 7, 6:04 pm)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Sun May 7, 6:05 pm)
Re: Implementing branch attributes in git config, Pavel Roskin, (Sun May 7, 6:21 pm)
Re: Implementing branch attributes in git config, Junio C Hamano, (Sun May 7, 6:27 pm)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Sun May 7, 6:27 pm)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Sun May 7, 6:45 pm)
Re: Implementing branch attributes in git config, Pavel Roskin, (Sun May 7, 6:55 pm)
Re: Implementing branch attributes in git config, Junio C Hamano, (Sun May 7, 7:29 pm)
Re: Implementing branch attributes in git config, Junio C Hamano, (Mon May 8, 2:00 am)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Mon May 8, 5:17 am)
Re: Implementing branch attributes in git config, Pavel Roskin, (Mon May 8, 8:15 am)
Re: Implementing branch attributes in git config, Daniel Barkalow, (Mon May 8, 4:20 pm)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Mon May 8, 4:40 pm)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Mon May 8, 4:44 pm)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Mon May 8, 5:23 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Mon May 8, 5:37 pm)
Re: Implementing branch attributes in git config, Junio C Hamano, (Mon May 8, 5:54 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Mon May 8, 6:05 pm)
Re: Implementing branch attributes in git config, Junio C Hamano, (Mon May 8, 6:18 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Mon May 8, 6:30 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Mon May 8, 6:57 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Mon May 8, 8:08 pm)
Re: Implementing branch attributes in git config, Linus Torvalds, (Mon May 8, 9:11 pm)
Re: Implementing branch attributes in git config, Junio C Hamano, (Mon May 8, 10:31 pm)
Re: Implementing branch attributes in git config, Martin Waitz, (Tue May 9, 4:26 am)
Re: Implementing branch attributes in git config, Johannes Schindelin, (Tue May 9, 4:34 am)