Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2018-07-18 22:20:31 +0300
committerJunio C Hamano <gitster@pobox.com>2018-07-18 22:20:31 +0300
commitb9632c9d95f601c3d557cdbad60c06fcc7d30110 (patch)
treebe604c30d9bfc2ef04d9fd0484dd108326e90519
parentd18602f4123ad61b094aff5b2822774cf020e70e (diff)
parentdb64d1127f5c76b721830ba390176cf0d6e59d74 (diff)
Merge branch 'ao/config-from-gitmodules'
Tighten the API to make it harder to misuse in-tree .gitmodules file, even though it shares the same syntax with configuration files, to read random configuration items from it. * ao/config-from-gitmodules: submodule-config: reuse config_from_gitmodules in repo_read_gitmodules submodule-config: pass repository as argument to config_from_gitmodules submodule-config: make 'config_from_gitmodules' private submodule-config: add helper to get 'update-clone' config from .gitmodules submodule-config: add helper function to get 'fetch' config from .gitmodules config: move config_from_gitmodules to submodule-config.c
-rw-r--r--builtin/fetch.c15
-rw-r--r--builtin/submodule--helper.c8
-rw-r--r--config.c17
-rw-r--r--config.h10
-rw-r--r--submodule-config.c75
-rw-r--r--submodule-config.h12
6 files changed, 80 insertions, 57 deletions
diff --git a/builtin/fetch.c b/builtin/fetch.c
index 83f36d7cde..d9bb72bf49 100644
--- a/builtin/fetch.c
+++ b/builtin/fetch.c
@@ -94,19 +94,6 @@ static int git_fetch_config(const char *k, const char *v, void *cb)
return git_default_config(k, v, cb);
}
-static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
-{
- if (!strcmp(var, "submodule.fetchjobs")) {
- max_children = parse_submodule_fetchjobs(var, value);
- return 0;
- } else if (!strcmp(var, "fetch.recursesubmodules")) {
- recurse_submodules = parse_fetch_recurse_submodules_arg(var, value);
- return 0;
- }
-
- return 0;
-}
-
static int parse_refmap_arg(const struct option *opt, const char *arg, int unset)
{
/*
@@ -1434,7 +1421,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
for (i = 1; i < argc; i++)
strbuf_addf(&default_rla, " %s", argv[i]);
- config_from_gitmodules(gitmodules_fetch_config, NULL);
+ fetch_config_from_gitmodules(&max_children, &recurse_submodules);
git_config(git_fetch_config, NULL);
argc = parse_options(argc, argv, prefix,
diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c
index 216e3daf5c..a3c4564c6c 100644
--- a/builtin/submodule--helper.c
+++ b/builtin/submodule--helper.c
@@ -1708,8 +1708,8 @@ static int update_clone_task_finished(int result,
return 0;
}
-static int gitmodules_update_clone_config(const char *var, const char *value,
- void *cb)
+static int git_update_clone_config(const char *var, const char *value,
+ void *cb)
{
int *max_jobs = cb;
if (!strcmp(var, "submodule.fetchjobs"))
@@ -1759,8 +1759,8 @@ static int update_clone(int argc, const char **argv, const char *prefix)
};
suc.prefix = prefix;
- config_from_gitmodules(gitmodules_update_clone_config, &max_jobs);
- git_config(gitmodules_update_clone_config, &max_jobs);
+ update_clone_config_from_gitmodules(&max_jobs);
+ git_config(git_update_clone_config, &max_jobs);
argc = parse_options(argc, argv, prefix, module_update_clone_options,
git_submodule_helper_usage, 0);
diff --git a/config.c b/config.c
index 139c903f6b..7968ef7566 100644
--- a/config.c
+++ b/config.c
@@ -2173,23 +2173,6 @@ int git_config_get_pathname(const char *key, const char **dest)
return repo_config_get_pathname(the_repository, key, dest);
}
-/*
- * Note: This function exists solely to maintain backward compatibility with
- * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
- * NOT be used anywhere else.
- *
- * Runs the provided config function on the '.gitmodules' file found in the
- * working directory.
- */
-void config_from_gitmodules(config_fn_t fn, void *data)
-{
- if (the_repository->worktree) {
- char *file = repo_worktree_path(the_repository, GITMODULES_FILE);
- git_config_from_file(fn, file, data);
- free(file);
- }
-}
-
int git_config_get_expiry(const char *key, const char **output)
{
int ret = git_config_get_string_const(key, output);
diff --git a/config.h b/config.h
index 626d4654bd..b95bb7649d 100644
--- a/config.h
+++ b/config.h
@@ -215,16 +215,6 @@ extern int repo_config_get_maybe_bool(struct repository *repo,
extern int repo_config_get_pathname(struct repository *repo,
const char *key, const char **dest);
-/*
- * Note: This function exists solely to maintain backward compatibility with
- * 'fetch' and 'update_clone' storing configuration in '.gitmodules' and should
- * NOT be used anywhere else.
- *
- * Runs the provided config function on the '.gitmodules' file found in the
- * working directory.
- */
-extern void config_from_gitmodules(config_fn_t fn, void *data);
-
extern int git_config_get_value(const char *key, const char **value);
extern const struct string_list *git_config_get_value_multi(const char *key);
extern void git_config_clear(void);
diff --git a/submodule-config.c b/submodule-config.c
index ca324a9e37..2a7259ba8b 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -592,6 +592,23 @@ static void submodule_cache_check_init(struct repository *repo)
submodule_cache_init(repo->submodule_cache);
}
+/*
+ * Note: This function is private for a reason, the '.gitmodules' file should
+ * not be used as as a mechanism to retrieve arbitrary configuration stored in
+ * the repository.
+ *
+ * Runs the provided config function on the '.gitmodules' file found in the
+ * working directory.
+ */
+static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void *data)
+{
+ if (repo->worktree) {
+ char *file = repo_worktree_path(repo, GITMODULES_FILE);
+ git_config_from_file(fn, file, data);
+ free(file);
+ }
+}
+
static int gitmodules_cb(const char *var, const char *value, void *data)
{
struct repository *repo = data;
@@ -609,19 +626,11 @@ void repo_read_gitmodules(struct repository *repo)
{
submodule_cache_check_init(repo);
- if (repo->worktree) {
- char *gitmodules;
-
- if (repo_read_index(repo) < 0)
- return;
-
- gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
-
- if (!is_gitmodules_unmerged(repo->index))
- git_config_from_file(gitmodules_cb, gitmodules, repo);
+ if (repo_read_index(repo) < 0)
+ return;
- free(gitmodules);
- }
+ if (!is_gitmodules_unmerged(repo->index))
+ config_from_gitmodules(gitmodules_cb, repo, repo);
repo->submodule_cache->gitmodules_read = 1;
}
@@ -672,3 +681,45 @@ void submodule_free(struct repository *r)
if (r->submodule_cache)
submodule_cache_clear(r->submodule_cache);
}
+
+struct fetch_config {
+ int *max_children;
+ int *recurse_submodules;
+};
+
+static int gitmodules_fetch_config(const char *var, const char *value, void *cb)
+{
+ struct fetch_config *config = cb;
+ if (!strcmp(var, "submodule.fetchjobs")) {
+ *(config->max_children) = parse_submodule_fetchjobs(var, value);
+ return 0;
+ } else if (!strcmp(var, "fetch.recursesubmodules")) {
+ *(config->recurse_submodules) = parse_fetch_recurse_submodules_arg(var, value);
+ return 0;
+ }
+
+ return 0;
+}
+
+void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules)
+{
+ struct fetch_config config = {
+ .max_children = max_children,
+ .recurse_submodules = recurse_submodules
+ };
+ config_from_gitmodules(gitmodules_fetch_config, the_repository, &config);
+}
+
+static int gitmodules_update_clone_config(const char *var, const char *value,
+ void *cb)
+{
+ int *max_jobs = cb;
+ if (!strcmp(var, "submodule.fetchjobs"))
+ *max_jobs = parse_submodule_fetchjobs(var, value);
+ return 0;
+}
+
+void update_clone_config_from_gitmodules(int *max_jobs)
+{
+ config_from_gitmodules(gitmodules_update_clone_config, the_repository, &max_jobs);
+}
diff --git a/submodule-config.h b/submodule-config.h
index ca1f94e2d2..dc7278eea4 100644
--- a/submodule-config.h
+++ b/submodule-config.h
@@ -2,6 +2,7 @@
#define SUBMODULE_CONFIG_CACHE_H
#include "cache.h"
+#include "config.h"
#include "hashmap.h"
#include "submodule.h"
#include "strbuf.h"
@@ -55,4 +56,15 @@ void submodule_free(struct repository *r);
*/
int check_submodule_name(const char *name);
+/*
+ * Note: these helper functions exist solely to maintain backward
+ * compatibility with 'fetch' and 'update_clone' storing configuration in
+ * '.gitmodules'.
+ *
+ * New helpers to retrieve arbitrary configuration from the '.gitmodules' file
+ * should NOT be added.
+ */
+extern void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules);
+extern void update_clone_config_from_gitmodules(int *max_jobs);
+
#endif /* SUBMODULE_CONFIG_H */