Re: Implementing branch attributes in git config
- From
Linus Torvalds <torvalds@osdl.org>
- Date
- May 8, 2006, 00:18 UTC
- Message-ID
- <Pine.LNX.4.64.0605071713410.3718@g5.osdl.org>
- In-Reply-To
- <Pine.LNX.4.64.0605071629080.3718@g5.osdl.org>
On Sun, 7 May 2006, Linus Torvalds wrote:
> > And it's certainly simple enough.
Well, simple enough to be buggy.
Show 10 quoted lines
> 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();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(); } }