Skip to content

Commit 963792e

Browse files
committed
Merge branch 'jk/parse-config-key-cleanup'
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
2 parents 3406129 + ad8c7cd commit 963792e

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

cache.h

+4-1
Original file line numberDiff line numberDiff line change
@@ -1863,8 +1863,11 @@ extern int git_config_include(const char *name, const char *value, void *data);
18631863
*
18641864
* (i.e., what gets handed to a config_fn_t). The caller provides the section;
18651865
* we return -1 if it does not match, 0 otherwise. The subsection and key
1866-
* out-parameters are filled by the function (and subsection is NULL if it is
1866+
* out-parameters are filled by the function (and *subsection is NULL if it is
18671867
* missing).
1868+
*
1869+
* If the subsection pointer-to-pointer passed in is NULL, returns 0 only if
1870+
* there is no subsection at all.
18681871
*/
18691872
extern int parse_config_key(const char *var,
18701873
const char *section,

config.c

+9-6
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

+3-4
Original file line numberDiff line numberDiff line change
@@ -1035,11 +1035,10 @@ static struct string_list *hide_refs;
10351035

10361036
int parse_hide_refs_config(const char *var, const char *value, const char *section)
10371037
{
1038-
const char *subsection, *key;
1039-
int subsection_len;
1038+
const char *key;
10401039
if (!strcmp("transfer.hiderefs", var) ||
1041-
(!parse_config_key(var, section, &subsection, &subsection_len, &key)
1042-
&& !subsection && !strcmp(key, "hiderefs"))) {
1040+
(!parse_config_key(var, section, NULL, NULL, &key) &&
1041+
!strcmp(key, "hiderefs"))) {
10431042
char *ref;
10441043
int len;
10451044

0 commit comments

Comments
 (0)