@matheusbsbs / matheus-bagliano / commits / b17e659dd4
Fork 0

Allow hierarchical section names

A .git/config like follows becomes valid with this patch: [remote.junio] url = git://git.kernel.org/pub/scm/git/git.git pull = master:junio todo:todo +pu:pu [remote.ibook] url = ibook:git/ pull = master:ibook push = master:quetzal (This patch only does the ini file thing, git-fetch and friends still ignore these values). Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <junkio@cox.net>

Johannes Schindelin committed Nov 20, 2005 at 21:22 UTC b17e659dd4007cb1d3eb5ac32b524c0c5ab59601
2 files changed +29 -9
config.c
+10 -9
@@ -143,7 +143,7 @@ static int get_base_var(char *name)
143 return -1;
144 if (c == ']')
145 return baselen;
146 - if (!isalnum(c))
146 + if (!isalnum(c) && c != '.')
147 return -1;
148 if (baselen > MAXNAME / 2)
149 return -1;
@@ -405,28 +405,29 @@ int git_config_set_multivar(const char* key, const char* value,
405 int fd;
406 char* config_file = strdup(git_path("config"));
407 char* lock_file = strdup(git_path("config.lock"));
408 -
409 - store.multi_replace = multi_replace;
408 + const char* last_dot = strrchr(key, '.');
409
410 /*
411 * Since "key" actually contains the section name and the real
412 * key name separated by a dot, we have to know where the dot is.
413 */
415 - for (store.baselen = 0;
416 - key[store.baselen] != '.' && key[store.baselen];
417 - store.baselen++);
418 - if (!key[store.baselen] || !key[store.baselen+1]) {
414 +
415 + if (last_dot == NULL) {
416 fprintf(stderr, "key does not contain a section: %s\n", key);
417 return 2;
418 }
419 + store.baselen = last_dot - key;
420 +
421 + store.multi_replace = multi_replace;
422
423 /*
424 * Validate the key and while at it, lower case it for matching.
425 */
426 store.key = (char*)malloc(strlen(key)+1);
427 for (i = 0; key[i]; i++)
428 - if (i != store.baselen && (!isalnum(key[i]) ||
429 - (i == store.baselen+1 && !isalpha(key[i])))) {
428 + if (i != store.baselen &&
429 + ((!isalnum(key[i]) && key[i] != '.') ||
430 + (i == store.baselen+1 && !isalpha(key[i])))) {
431 fprintf(stderr, "invalid key: %s\n", key);
432 free(store.key);
433 return 1;
t/t1300-config-set.sh
+19
@@ -248,5 +248,24 @@ test_expect_failure 'invalid key' 'git-config-set inval.2key blabla'
248
249 test_expect_success 'correct key' 'git-config-set 123456.a123 987'
250
251 +test_expect_success 'hierarchical section' \
252 + 'git-config-set 1.2.3.alpha beta'
253 +
254 +cat > expect << EOF
255 +[beta] ; silly comment # another comment
256 +noIndent= sillyValue ; 'nother silly comment
257 +
258 +# empty line
259 + ; comment
260 +[nextSection]
261 + NoNewLine = wow2 for me
262 +[123456]
263 + a123 = 987
264 +[1.2.3]
265 + alpha = beta
266 +EOF
267 +
268 +test_expect_success 'hierarchical section value' 'cmp .git/config expect'
269 +
270 test_done
271