Skip to content

Commit 71a6953

Browse files
ao2gitster
authored andcommitted
submodule-config: add helper function to get 'fetch' config from .gitmodules
Add a helper function to make it clearer that retrieving 'fetch' configuration from the .gitmodules file is a special case supported solely for backward compatibility purposes. This change removes one direct use of 'config_from_gitmodules' in code not strictly related to submodules, in the effort to communicate better that .gitmodules is not to be used as a mechanism to store arbitrary configuration in the repository that any command can retrieve. Signed-off-by: Antonio Ospite <[email protected]> Acked-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ad13637 commit 71a6953

File tree

3 files changed

+31
-14
lines changed

3 files changed

+31
-14
lines changed

builtin/fetch.c

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -93,19 +93,6 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
9393
return git_default_config(k, v, cb);
9494
}
9595

96-
static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
97-
{
98-
if (!strcmp(var, "submodule.fetchjobs")) {
99-
max_children = parse_submodule_fetchjobs(var, value);
100-
return 0;
101-
} else if (!strcmp(var, "fetch.recursesubmodules")) {
102-
recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
103-
return 0;
104-
}
105-
106-
return 0;
107-
}
108-
10996
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
11097
{
11198
/*
@@ -1433,7 +1420,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
14331420
for (i = 1; i < argc; i++)
14341421
strbuf_addf(&default_rla, " %s", argv[i]);
14351422

1436-
config_from_gitmodules(gitmodules_fetch_config, NULL);
1423+
fetch_config_from_gitmodules(&max_children, &recurse_submodules);
14371424
git_config(git_fetch_config, NULL);
14381425

14391426
argc = parse_options(argc, argv, prefix,

submodule-config.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,3 +688,31 @@ void config_from_gitmodules(config_fn_t fn, void *data)
688688
free(file);
689689
}
690690
}
691+
692+
struct fetch_config {
693+
int *max_children;
694+
int *recurse_submodules;
695+
};
696+
697+
static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
698+
{
699+
struct fetch_config *config = cb;
700+
if (!strcmp(var, "submodule.fetchjobs")) {
701+
*(config->max_children) = parse_submodule_fetchjobs(var, value);
702+
return 0;
703+
} else if (!strcmp(var, "fetch.recursesubmodules")) {
704+
*(config->recurse_submodules) = parse_fetch_recurse_submodules_arg(var, value);
705+
return 0;
706+
}
707+
708+
return 0;
709+
}
710+
711+
void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
712+
{
713+
struct fetch_config config = {
714+
.max_children = max_children,
715+
.recurse_submodules = recurse_submodules
716+
};
717+
config_from_gitmodules(gitmodules_fetch_config, &config);
718+
}

submodule-config.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,6 @@ int check_submodule_name(const char *name);
6666
*/
6767
extern void config_from_gitmodules(config_fn_t fn, void *data);
6868

69+
extern void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules);
70+
6971
#endif /* SUBMODULE_CONFIG_H */

0 commit comments

Comments
 (0)