Skip to content

Commit ae9ee41

Browse files
author
Junio C Hamano
committed
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 <[email protected]>
1 parent fdc99cb commit ae9ee41

File tree

1 file changed

+24
-4
lines changed

1 file changed

+24
-4
lines changed

config.c

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,9 @@ static int matches(const char* key, const char* value)
451451

452452
static int store_aux(const char* key, const char* value)
453453
{
454+
const char *ep;
455+
size_t section_len;
456+
454457
switch (store.state) {
455458
case KEY_SEEN:
456459
if (matches(key, value)) {
@@ -468,12 +471,29 @@ static int store_aux(const char* key, const char* value)
468471
}
469472
break;
470473
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)) {
472488
store.state = SECTION_END_SEEN;
473489
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);
477497
/* fallthru */
478498
case SECTION_END_SEEN:
479499
case START:

0 commit comments

Comments
 (0)