Commit 48f8d9f
parse_config_key: allow matching single-level config
The parse_config_key() function was introduced to make it
easier to match "section.subsection.key" variables. It also
handles the simpler "section.key", and the caller is
responsible for distinguishing the two from its
out-parameters.
Most callers who _only_ want "section.key" would just use a
strcmp(var, "section.key"), since there is no parsing
required. However, they may still use parse_config_key() if
their "section" variable isn't a constant (an example of
this is in parse_hide_refs_config).
Using the parse_config_key is a bit clunky, though:
const char *subsection;
int subsection_len;
const char *key;
if (!parse_config_key(var, section, &subsection, &subsection_len, &key) &&
!subsection) {
/* matched! */
}
Instead, let's treat a NULL subsection as an indication that
the caller does not expect one. That lets us write:
const char *key;
if (!parse_config_key(var, section, NULL, NULL, &key)) {
/* matched! */
}
Existing callers should be unaffected, as passing a NULL
subsection would currently segfault.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>1 parent e3394fd commit 48f8d9f
2 files changed
Lines changed: 10 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1790 | 1790 | | |
1791 | 1791 | | |
1792 | 1792 | | |
1793 | | - | |
| 1793 | + | |
1794 | 1794 | | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
1795 | 1798 | | |
1796 | 1799 | | |
1797 | 1800 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2547 | 2547 | | |
2548 | 2548 | | |
2549 | 2549 | | |
2550 | | - | |
2551 | | - | |
| 2550 | + | |
| 2551 | + | |
| 2552 | + | |
| 2553 | + | |
2552 | 2554 | | |
2553 | 2555 | | |
| 2556 | + | |
| 2557 | + | |
2554 | 2558 | | |
2555 | 2559 | | |
2556 | 2560 | | |
| |||
0 commit comments