Skip to content

Commit c772d1b

Browse files
committed
Merge branch 'jk/parse-config-key-cleanup' into maint
The "parse_config_key()" API function has been cleaned up. * jk/parse-config-key-cleanup: parse_hide_refs_config: tell parse_config_key we don't want a subsection parse_config_key: allow matching single-level config parse_config_key: use skip_prefix instead of starts_with refs: parse_hide_refs_config to use parse_config_key
2 parents 8f9aeb0 + ad8c7cd commit c772d1b

3 files changed

Lines changed: 16 additions & 10 deletions

File tree

cache.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1816,8 +1816,11 @@ extern int git_config_include(const char *name, const char *value, void *data);
18161816
*
18171817
* (i.e., what gets handed to a config_fn_t). The caller provides the section;
18181818
* we return -1 if it does not match, 0 otherwise. The subsection and key
1819-
* out-parameters are filled by the function (and subsection is NULL if it is
1819+
* out-parameters are filled by the function (and *subsection is NULL if it is
18201820
* missing).
1821+
*
1822+
* If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
1823+
* there is no subsection at all.
18211824
*/
18221825
extern int parse_config_key(const char *var,
18231826
const char *section,

config.c

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2540,11 +2540,10 @@ int parse_config_key(const char *var,
25402540
const char **subsection, int *subsection_len,
25412541
const char **key)
25422542
{
2543-
int section_len = strlen(section);
25442543
const char *dot;
25452544

25462545
/* Does it start with "section." ? */
2547-
if (!starts_with(var, section) || var[section_len] != '.')
2546+
if (!skip_prefix(var, section, &var) || *var != '.')
25482547
return -1;
25492548

25502549
/*
@@ -2556,12 +2555,16 @@ int parse_config_key(const char *var,
25562555
*key = dot + 1;
25572556

25582557
/* Did we have a subsection at all? */
2559-
if (dot == var + section_len) {
2560-
*subsection = NULL;
2561-
*subsection_len = 0;
2558+
if (dot == var) {
2559+
if (subsection) {
2560+
*subsection = NULL;
2561+
*subsection_len = 0;
2562+
}
25622563
}
25632564
else {
2564-
*subsection = var + section_len + 1;
2565+
if (!subsection)
2566+
return -1;
2567+
*subsection = var + 1;
25652568
*subsection_len = dot - *subsection;
25662569
}
25672570

refs.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,10 +1034,10 @@ static struct string_list *hide_refs;
10341034

10351035
int parse_hide_refs_config(const char *var, const char *value, const char *section)
10361036
{
1037+
const char *key;
10371038
if (!strcmp("transfer.hiderefs", var) ||
1038-
/* NEEDSWORK: use parse_config_key() once both are merged */
1039-
(starts_with(var, section) && var[strlen(section)] == '.' &&
1040-
!strcmp(var + strlen(section), ".hiderefs"))) {
1039+
(!parse_config_key(var, section, NULL, NULL, &key) &&
1040+
!strcmp(key, "hiderefs"))) {
10411041
char *ref;
10421042
int len;
10431043

0 commit comments

Comments
 (0)