submodule-config: move submodule-config functions to submodule-config.c

Migrate the functions used to initialize the submodule-config to submodule-config.c so that the callback routine used in the initialization process can be static and prevent it from being used outside of initializing the submodule-config through the main API. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Aug 3, 2017 at 11:19 UTC 1b796ace7b5566d7cd2ed2ee56d3e5b1f7605272
5 files changed +34 -49
builtin/ls-files.c
+1
@@ -19,6 +19,7 @@
19 #include "pathspec.h"
20 #include "run-command.h"
21 #include "submodule.h"
22 +#include "submodule-config.h"
23
24 static int abbrev;
25 static int show_deleted;
submodule-config.c
+31 -7
@@ -449,9 +449,9 @@ static int parse_config(const char *var, const char *value, void *data)
449 return ret;
450 }
451
452 -int gitmodule_oid_from_commit(const struct object_id *treeish_name,
453 - struct object_id *gitmodules_oid,
454 - struct strbuf *rev)
452 +static int gitmodule_oid_from_commit(const struct object_id *treeish_name,
453 + struct object_id *gitmodules_oid,
454 + struct strbuf *rev)
455 {
456 int ret = 0;
457
@@ -552,9 +552,9 @@ static void submodule_cache_check_init(struct repository *repo)
552 submodule_cache_init(repo->submodule_cache);
553 }
554
555 -int submodule_config_option(struct repository *repo,
556 - const char *var, const char *value)
555 +static int gitmodules_cb(const char *var, const char *value, void *data)
556 {
557 + struct repository *repo = data;
558 struct parse_config_parameter parameter;
559
560 submodule_cache_check_init(repo);
@@ -567,9 +567,33 @@ int submodule_config_option(struct repository *repo,
567 return parse_config(var, value, &parameter);
568 }
569
570 -int parse_submodule_config_option(const char *var, const char *value)
570 +void repo_read_gitmodules(struct repository *repo)
571 {
572 - return submodule_config_option(the_repository, var, value);
572 + if (repo->worktree) {
573 + char *gitmodules;
574 +
575 + if (repo_read_index(repo) < 0)
576 + return;
577 +
578 + gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
579 +
580 + if (!is_gitmodules_unmerged(repo->index))
581 + git_config_from_file(gitmodules_cb, gitmodules, repo);
582 +
583 + free(gitmodules);
584 + }
585 +}
586 +
587 +void gitmodules_config_oid(const struct object_id *commit_oid)
588 +{
589 + struct strbuf rev = STRBUF_INIT;
590 + struct object_id oid;
591 +
592 + if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
593 + git_config_from_blob_oid(gitmodules_cb, rev.buf,
594 + &oid, the_repository);
595 + }
596 + strbuf_release(&rev);
597 }
598
599 const struct submodule *submodule_from_name(const struct object_id *treeish_name,
submodule-config.h
+2 -5
@@ -34,8 +34,8 @@ extern int option_fetch_parse_recurse_submodules(const struct option *opt,
34 const char *arg, int unset);
35 extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
36 extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
37 -extern int submodule_config_option(struct repository *repo,
38 - const char *var, const char *value);
37 +extern void repo_read_gitmodules(struct repository *repo);
38 +extern void gitmodules_config_oid(const struct object_id *commit_oid);
39 extern const struct submodule *submodule_from_name(
40 const struct object_id *commit_or_tree, const char *name);
41 extern const struct submodule *submodule_from_path(
@@ -43,9 +43,6 @@ extern const struct submodule *submodule_from_path(
43 extern const struct submodule *submodule_from_cache(struct repository *repo,
44 const struct object_id *treeish_name,
45 const char *key);
46 -extern int gitmodule_oid_from_commit(const struct object_id *commit_oid,
47 - struct object_id *gitmodules_oid,
48 - struct strbuf *rev);
46 extern void submodule_free(void);
47
48 #endif /* SUBMODULE_CONFIG_H */
submodule.c
-35
@@ -216,46 +216,11 @@ void load_submodule_cache(void)
216 gitmodules_config();
217 }
218
219 -static int gitmodules_cb(const char *var, const char *value, void *data)
220 -{
221 - struct repository *repo = data;
222 - return submodule_config_option(repo, var, value);
223 -}
224 -
225 -void repo_read_gitmodules(struct repository *repo)
226 -{
227 - if (repo->worktree) {
228 - char *gitmodules;
229 -
230 - if (repo_read_index(repo) < 0)
231 - return;
232 -
233 - gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
234 -
235 - if (!is_gitmodules_unmerged(repo->index))
236 - git_config_from_file(gitmodules_cb, gitmodules, repo);
237 -
238 - free(gitmodules);
239 - }
240 -}
241 -
219 void gitmodules_config(void)
220 {
221 repo_read_gitmodules(the_repository);
222 }
223
247 -void gitmodules_config_oid(const struct object_id *commit_oid)
248 -{
249 - struct strbuf rev = STRBUF_INIT;
250 - struct object_id oid;
251 -
252 - if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
253 - git_config_from_blob_oid(gitmodules_cb, rev.buf,
254 - &oid, the_repository);
255 - }
256 - strbuf_release(&rev);
257 -}
258 -
224 /*
225 * Determine if a submodule has been initialized at a given 'path'
226 */
submodule.h
-2
@@ -47,8 +47,6 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
47 const char *arg, int unset);
48 void load_submodule_cache(void);
49 extern void gitmodules_config(void);
50 -extern void repo_read_gitmodules(struct repository *repo);
51 -extern void gitmodules_config_oid(const struct object_id *commit_oid);
50 extern int is_submodule_active(struct repository *repo, const char *path);
51 /*
52 * Determine if a submodule has been populated at a given 'path' by checking if