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:05 pm

On Sun, 7 May 2006, Pavel Roskin wrote:

That wouldn't help. The thing is designed to not only need no quoting 
(except for the _value_), it also is designed to have both section and key 
names ignore case. So you really aren't supposed to put things like branch 
names (which are potentially case-sensitive, depending on filesystem) in 
either.

And we depend on that (and I think it's important - users normally should 
_not_ care about capitalization)

So you'd need to literally create a different syntax if you want unquoted 
section naming.


Here's a possible syntax/patch. I actually think the quoting makes more 
sense in the section name, since you'll usually want several keys under 
each branch, so it makes sense to make the _branch_ be the section.

It basically makes it a special case if you have the section name be 
marked with quotes, like

	["XyZZy"]

and in that case it turns the _real_ section name into the string 
"branch.XyZZy", where the important part is that it does this without 
changing case or limiting the character set (but it will _not_ allow a 
newline) in any way.

So you could have something like

	["Origin"]
		URL = ...
		fetch = master

and it would just turn it into

	branch.Origin.url = ...
	branch.Origin.fetch = master

etc.

No, I'm not sure this is the best possible syntax. It's just a suggestion. 
And it's certainly simple enough.

The downside is that if you start using config files like this, you 
literally can't go back to older git versions. They'll refuse to touch 
such a config file (rather than just ignoring the new entries) and will 
exit with nasty messages. That might be unacceptable.

Instead of quoting with double-quotes, it might be ok to use some 
alternate syntax line "[:$branchname:]" which looks visually reasonable, 
and has the potential advantage that ':' is already an invalid character 
in a branch name, so you don't actually even need any quoting logic at all 
at that point.

I think the

	["branch"]
		...

syntax looks reasonably readable and clean.

		Linus

----
diff --git a/config.c b/config.c
index 41066e4..802e326 100644
--- a/config.c
+++ b/config.c
@@ -134,9 +134,44 @@ 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();
-
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)