submodule: convert is_submodule_initialized to work on a repository

Convert 'is_submodule_initialized()' to take a repository object and while we're at it, lets rename the function to 'is_submodule_active()' and remove the NEEDSWORK comment. Signed-off-by: Brandon Williams <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Brandon Williams committed Jun 22, 2017 at 11:43 UTC 627d9342fe38598c995578d57cec6cbad1dcbc69
4 files changed +16 -18
builtin/grep.c
+2 -1
@@ -4,6 +4,7 @@
4 * Copyright (c) 2006 Junio C Hamano
5 */
6 #include "cache.h"
7 +#include "repository.h"
8 #include "config.h"
9 #include "blob.h"
10 #include "tree.h"
@@ -643,7 +644,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
644 static int grep_submodule(struct grep_opt *opt, const struct object_id *oid,
645 const char *filename, const char *path)
646 {
646 - if (!is_submodule_initialized(path))
647 + if (!is_submodule_active(the_repository, path))
648 return 0;
649 if (!is_submodule_populated_gently(path, NULL)) {
650 /*
builtin/submodule--helper.c
+5 -4
@@ -1,4 +1,5 @@
1 #include "builtin.h"
2 +#include "repository.h"
3 #include "cache.h"
4 #include "config.h"
5 #include "parse-options.h"
@@ -280,7 +281,7 @@ static void module_list_active(struct module_list *list)
281 for (i = 0; i < list->nr; i++) {
282 const struct cache_entry *ce = list->entries[i];
283
283 - if (!is_submodule_initialized(ce->name))
284 + if (!is_submodule_active(the_repository, ce->name))
285 continue;
286
287 ALLOC_GROW(active_modules.entries,
@@ -362,7 +363,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
363 *
364 * Set active flag for the submodule being initialized
365 */
365 - if (!is_submodule_initialized(path)) {
366 + if (!is_submodule_active(the_repository, path)) {
367 strbuf_reset(&sb);
368 strbuf_addf(&sb, "submodule.%s.active", sub->name);
369 git_config_set_gently(sb.buf, "true");
@@ -817,7 +818,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
818 }
819
820 /* Check if the submodule has been initialized. */
820 - if (!is_submodule_initialized(ce->name)) {
821 + if (!is_submodule_active(the_repository, ce->name)) {
822 next_submodule_warn_missing(suc, out, displaypath);
823 goto cleanup;
824 }
@@ -1193,7 +1194,7 @@ static int is_active(int argc, const char **argv, const char *prefix)
1194
1195 gitmodules_config();
1196
1196 - return !is_submodule_initialized(argv[1]);
1197 + return !is_submodule_active(the_repository, argv[1]);
1198 }
1199
1200 #define SUPPORT_SUPER_PREFIX (1<<0)
submodule.c
+8 -12
@@ -283,21 +283,17 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1)
283 }
284
285 /*
286 - * NEEDSWORK: With the addition of different configuration options to determine
287 - * if a submodule is of interests, the validity of this function's name comes
288 - * into question. Once the dust has settled and more concrete terminology is
289 - * decided upon, come up with a more proper name for this function. One
290 - * potential candidate could be 'is_submodule_active()'.
291 - *
286 * Determine if a submodule has been initialized at a given 'path'
287 */
294 -int is_submodule_initialized(const char *path)
288 +int is_submodule_active(struct repository *repo, const char *path)
289 {
290 int ret = 0;
291 char *key = NULL;
292 char *value = NULL;
293 const struct string_list *sl;
300 - const struct submodule *module = submodule_from_path(null_sha1, path);
294 + const struct submodule *module;
295 +
296 + module = submodule_from_cache(repo, null_sha1, path);
297
298 /* early return if there isn't a path->module mapping */
299 if (!module)
@@ -305,14 +301,14 @@ int is_submodule_initialized(const char *path)
301
302 /* submodule.<name>.active is set */
303 key = xstrfmt("submodule.%s.active", module->name);
308 - if (!git_config_get_bool(key, &ret)) {
304 + if (!repo_config_get_bool(repo, key, &ret)) {
305 free(key);
306 return ret;
307 }
308 free(key);
309
310 /* submodule.active is set */
315 - sl = git_config_get_value_multi("submodule.active");
311 + sl = repo_config_get_value_multi(repo, "submodule.active");
312 if (sl) {
313 struct pathspec ps;
314 struct argv_array args = ARGV_ARRAY_INIT;
@@ -332,7 +328,7 @@ int is_submodule_initialized(const char *path)
328
329 /* fallback to checking if the URL is set */
330 key = xstrfmt("submodule.%s.url", module->name);
335 - ret = !git_config_get_string(key, &value);
331 + ret = !repo_config_get_string(repo, key, &value);
332
333 free(value);
334 free(key);
@@ -1532,7 +1528,7 @@ int submodule_move_head(const char *path,
1528 const struct submodule *sub;
1529 int *error_code_ptr, error_code;
1530
1535 - if (!is_submodule_initialized(path))
1531 + if (!is_submodule_active(the_repository, path))
1532 return 0;
1533
1534 if (flags & SUBMODULE_MOVE_HEAD_FORCE)
submodule.h
+1 -1
@@ -49,7 +49,7 @@ 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_sha1(const unsigned char *commit_sha1);
52 -extern int is_submodule_initialized(const char *path);
52 +extern int is_submodule_active(struct repository *repo, const char *path);
53 /*
54 * Determine if a submodule has been populated at a given 'path' by checking if
55 * the <path>/.git resolves to a valid git repository.