Allow '-' in config variable names
I need this in order to allow aliases of the same form as "ls-tree", "rev-parse" etc, so that I can use [alias] my-cat=--paginate cat-file -p to add a "git my-cat" command. Signed-off-by: Linus Torvalds <torvalds@osdl.org> Signed-off-by: Junio C Hamano <junkio@cox.net>
This commit is contained in:
parent
83877f8d92
commit
38c5afa87e
11
config.c
11
config.c
@ -103,6 +103,11 @@ static char *parse_value(void)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline int iskeychar(int c)
|
||||||
|
{
|
||||||
|
return isalnum(c) || c == '-';
|
||||||
|
}
|
||||||
|
|
||||||
static int get_value(config_fn_t fn, char *name, unsigned int len)
|
static int get_value(config_fn_t fn, char *name, unsigned int len)
|
||||||
{
|
{
|
||||||
int c;
|
int c;
|
||||||
@ -113,7 +118,7 @@ static int get_value(config_fn_t fn, char *name, unsigned int len)
|
|||||||
c = get_next_char();
|
c = get_next_char();
|
||||||
if (c == EOF)
|
if (c == EOF)
|
||||||
break;
|
break;
|
||||||
if (!isalnum(c))
|
if (!iskeychar(c))
|
||||||
break;
|
break;
|
||||||
name[len++] = tolower(c);
|
name[len++] = tolower(c);
|
||||||
if (len >= MAXNAME)
|
if (len >= MAXNAME)
|
||||||
@ -181,7 +186,7 @@ static int get_base_var(char *name)
|
|||||||
return baselen;
|
return baselen;
|
||||||
if (isspace(c))
|
if (isspace(c))
|
||||||
return get_extended_base_var(name, baselen, c);
|
return get_extended_base_var(name, baselen, c);
|
||||||
if (!isalnum(c) && c != '.')
|
if (!iskeychar(c) && c != '.')
|
||||||
return -1;
|
return -1;
|
||||||
if (baselen > MAXNAME / 2)
|
if (baselen > MAXNAME / 2)
|
||||||
return -1;
|
return -1;
|
||||||
@ -573,7 +578,7 @@ int git_config_set_multivar(const char* key, const char* value,
|
|||||||
dot = 1;
|
dot = 1;
|
||||||
/* Leave the extended basename untouched.. */
|
/* Leave the extended basename untouched.. */
|
||||||
if (!dot || i > store.baselen) {
|
if (!dot || i > store.baselen) {
|
||||||
if (!isalnum(c) || (i == store.baselen+1 && !isalpha(c))) {
|
if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) {
|
||||||
fprintf(stderr, "invalid key: %s\n", key);
|
fprintf(stderr, "invalid key: %s\n", key);
|
||||||
free(store.key);
|
free(store.key);
|
||||||
ret = 1;
|
ret = 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user