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

git-config: do not forget seeing "a.b.var" means we are out of "a.var" section.

Earlier code tried to be half-careful and knew the logic that seeing "a.var" after seeing "a.b.var" is a sign of the previous "a.b." section has ended, but forgot it has to handle the other way. Seeing "a.b.var" after seeing "a.var" is a sign that "a." section has ended, so a new "a.var2" variable should be added before the location "a.b.var" appears. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed May 12, 2007 at 21:49 UTC ae9ee41de86cc98adad1a0c70651c55acc3fb699
1 file changed +24 -4
config.c
+24 -4
@@ -451,6 +451,9 @@ static int matches(const char* key, const char* value)
451
452 static int store_aux(const char* key, const char* value)
453 {
454 + const char *ep;
455 + size_t section_len;
456 +
457 switch (store.state) {
458 case KEY_SEEN:
459 if (matches(key, value)) {
@@ -468,12 +471,29 @@ static int store_aux(const char* key, const char* value)
471 }
472 break;
473 case SECTION_SEEN:
471 - if (strncmp(key, store.key, store.baselen+1)) {
474 + /*
475 + * What we are looking for is in store.key (both
476 + * section and var), and its section part is baselen
477 + * long. We found key (again, both section and var).
478 + * We would want to know if this key is in the same
479 + * section as what we are looking for. We already
480 + * know we are in the same section as what should
481 + * hold store.key.
482 + */
483 + ep = strrchr(key, '.');
484 + section_len = ep - key;
485 +
486 + if ((section_len != store.baselen) ||
487 + memcmp(key, store.key, section_len+1)) {
488 store.state = SECTION_END_SEEN;
489 break;
474 - } else
475 - /* do not increment matches: this is no match */
476 - store.offset[store.seen] = ftell(config_file);
490 + }
491 +
492 + /*
493 + * Do not increment matches: this is no match, but we
494 + * just made sure we are in the desired section.
495 + */
496 + store.offset[store.seen] = ftell(config_file);
497 /* fallthru */
498 case SECTION_END_SEEN:
499 case START: