Skip to content

Commit 627d934

Browse files
bmwillgitster
authored andcommitted
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>
1 parent 69aba53 commit 627d934

File tree

4 files changed

+16
-18
lines changed

4 files changed

+16
-18
lines changed

builtin/grep.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Copyright (c) 2006 Junio C Hamano
55
*/
66
#include "cache.h"
7+
#include "repository.h"
78
#include "config.h"
89
#include "blob.h"
910
#include "tree.h"
@@ -643,7 +644,7 @@ static int grep_submodule_launch(struct grep_opt *opt,
643644
static int grep_submodule(struct grep_opt *opt, const struct object_id *oid,
644645
const char *filename, const char *path)
645646
{
646-
if (!is_submodule_initialized(path))
647+
if (!is_submodule_active(the_repository, path))
647648
return 0;
648649
if (!is_submodule_populated_gently(path, NULL)) {
649650
/*

builtin/submodule--helper.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "builtin.h"
2+
#include "repository.h"
23
#include "cache.h"
34
#include "config.h"
45
#include "parse-options.h"
@@ -280,7 +281,7 @@ static void module_list_active(struct module_list *list)
280281
for (i = 0; i < list->nr; i++) {
281282
const struct cache_entry *ce = list->entries[i];
282283

283-
if (!is_submodule_initialized(ce->name))
284+
if (!is_submodule_active(the_repository, ce->name))
284285
continue;
285286

286287
ALLOC_GROW(active_modules.entries,
@@ -362,7 +363,7 @@ static void init_submodule(const char *path, const char *prefix, int quiet)
362363
*
363364
* Set active flag for the submodule being initialized
364365
*/
365-
if (!is_submodule_initialized(path)) {
366+
if (!is_submodule_active(the_repository, path)) {
366367
strbuf_reset(&sb);
367368
strbuf_addf(&sb, "submodule.%s.active", sub->name);
368369
git_config_set_gently(sb.buf, "true");
@@ -817,7 +818,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
817818
}
818819

819820
/* Check if the submodule has been initialized. */
820-
if (!is_submodule_initialized(ce->name)) {
821+
if (!is_submodule_active(the_repository, ce->name)) {
821822
next_submodule_warn_missing(suc, out, displaypath);
822823
goto cleanup;
823824
}
@@ -1193,7 +1194,7 @@ static int is_active(int argc, const char **argv, const char *prefix)
11931194

11941195
gitmodules_config();
11951196

1196-
return !is_submodule_initialized(argv[1]);
1197+
return !is_submodule_active(the_repository, argv[1]);
11971198
}
11981199

11991200
#define SUPPORT_SUPER_PREFIX (1<<0)

submodule.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -283,36 +283,32 @@ void gitmodules_config_sha1(const unsigned char *commit_sha1)
283283
}
284284

285285
/*
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-
*
292286
* Determine if a submodule has been initialized at a given 'path'
293287
*/
294-
int is_submodule_initialized(const char *path)
288+
int is_submodule_active(struct repository *repo, const char *path)
295289
{
296290
int ret = 0;
297291
char *key = NULL;
298292
char *value = NULL;
299293
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);
301297

302298
/* early return if there isn't a path->module mapping */
303299
if (!module)
304300
return 0;
305301

306302
/* submodule.<name>.active is set */
307303
key = xstrfmt("submodule.%s.active", module->name);
308-
if (!git_config_get_bool(key, &ret)) {
304+
if (!repo_config_get_bool(repo, key, &ret)) {
309305
free(key);
310306
return ret;
311307
}
312308
free(key);
313309

314310
/* submodule.active is set */
315-
sl = git_config_get_value_multi("submodule.active");
311+
sl = repo_config_get_value_multi(repo, "submodule.active");
316312
if (sl) {
317313
struct pathspec ps;
318314
struct argv_array args = ARGV_ARRAY_INIT;
@@ -332,7 +328,7 @@ int is_submodule_initialized(const char *path)
332328

333329
/* fallback to checking if the URL is set */
334330
key = xstrfmt("submodule.%s.url", module->name);
335-
ret = !git_config_get_string(key, &value);
331+
ret = !repo_config_get_string(repo, key, &value);
336332

337333
free(value);
338334
free(key);
@@ -1532,7 +1528,7 @@ int submodule_move_head(const char *path,
15321528
const struct submodule *sub;
15331529
int *error_code_ptr, error_code;
15341530

1535-
if (!is_submodule_initialized(path))
1531+
if (!is_submodule_active(the_repository, path))
15361532
return 0;
15371533

15381534
if (flags & SUBMODULE_MOVE_HEAD_FORCE)

submodule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ void load_submodule_cache(void);
4949
extern void gitmodules_config(void);
5050
extern void repo_read_gitmodules(struct repository *repo);
5151
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);
5353
/*
5454
* Determine if a submodule has been populated at a given 'path' by checking if
5555
* the <path>/.git resolves to a valid git repository.

0 commit comments

Comments
 (0)