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>
This commit is contained in:
parent
fdc99cbbdc
commit
ae9ee41de8
28
config.c
28
config.c
@ -451,6 +451,9 @@ static int matches(const char* key, const char* value)
|
|||||||
|
|
||||||
static int store_aux(const char* key, const char* value)
|
static int store_aux(const char* key, const char* value)
|
||||||
{
|
{
|
||||||
|
const char *ep;
|
||||||
|
size_t section_len;
|
||||||
|
|
||||||
switch (store.state) {
|
switch (store.state) {
|
||||||
case KEY_SEEN:
|
case KEY_SEEN:
|
||||||
if (matches(key, value)) {
|
if (matches(key, value)) {
|
||||||
@ -468,12 +471,29 @@ static int store_aux(const char* key, const char* value)
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case SECTION_SEEN:
|
case SECTION_SEEN:
|
||||||
if (strncmp(key, store.key, store.baselen+1)) {
|
/*
|
||||||
|
* What we are looking for is in store.key (both
|
||||||
|
* section and var), and its section part is baselen
|
||||||
|
* long. We found key (again, both section and var).
|
||||||
|
* We would want to know if this key is in the same
|
||||||
|
* section as what we are looking for. We already
|
||||||
|
* know we are in the same section as what should
|
||||||
|
* hold store.key.
|
||||||
|
*/
|
||||||
|
ep = strrchr(key, '.');
|
||||||
|
section_len = ep - key;
|
||||||
|
|
||||||
|
if ((section_len != store.baselen) ||
|
||||||
|
memcmp(key, store.key, section_len+1)) {
|
||||||
store.state = SECTION_END_SEEN;
|
store.state = SECTION_END_SEEN;
|
||||||
break;
|
break;
|
||||||
} else
|
}
|
||||||
/* do not increment matches: this is no match */
|
|
||||||
store.offset[store.seen] = ftell(config_file);
|
/*
|
||||||
|
* Do not increment matches: this is no match, but we
|
||||||
|
* just made sure we are in the desired section.
|
||||||
|
*/
|
||||||
|
store.offset[store.seen] = ftell(config_file);
|
||||||
/* fallthru */
|
/* fallthru */
|
||||||
case SECTION_END_SEEN:
|
case SECTION_END_SEEN:
|
||||||
case START:
|
case START:
|
||||||
|
Loading…
Reference in New Issue
Block a user