Skip to content

Commit 38c5afa

Browse files
Linus TorvaldsJunio C Hamano
authored andcommitted
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>
1 parent 83877f8 commit 38c5afa

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

config.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,11 @@ static char *parse_value(void)
103103
}
104104
}
105105

106+
static inline int iskeychar(int c)
107+
{
108+
return isalnum(c) || c == '-';
109+
}
110+
106111
static int get_value(config_fn_t fn, char *name, unsigned int len)
107112
{
108113
int c;
@@ -113,7 +118,7 @@ static int get_value(config_fn_t fn, char *name, unsigned int len)
113118
c = get_next_char();
114119
if (c == EOF)
115120
break;
116-
if (!isalnum(c))
121+
if (!iskeychar(c))
117122
break;
118123
name[len++] = tolower(c);
119124
if (len >= MAXNAME)
@@ -181,7 +186,7 @@ static int get_base_var(char *name)
181186
return baselen;
182187
if (isspace(c))
183188
return get_extended_base_var(name, baselen, c);
184-
if (!isalnum(c) && c != '.')
189+
if (!iskeychar(c) && c != '.')
185190
return -1;
186191
if (baselen > MAXNAME / 2)
187192
return -1;
@@ -573,7 +578,7 @@ int git_config_set_multivar(const char* key, const char* value,
573578
dot = 1;
574579
/* Leave the extended basename untouched.. */
575580
if (!dot || i > store.baselen) {
576-
if (!isalnum(c) || (i == store.baselen+1 && !isalpha(c))) {
581+
if (!iskeychar(c) || (i == store.baselen+1 && !isalpha(c))) {
577582
fprintf(stderr, "invalid key: %s\n", key);
578583
free(store.key);
579584
ret = 1;

0 commit comments

Comments
 (0)