Skip to content

Commit d799242

Browse files
matheustavaresgitster
authored andcommitted
submodule-config: add skip_if_read option to repo_read_gitmodules()
Currently, submodule-config.c doesn't have an externally accessible function to read gitmodules only if it wasn't already read. But this exact behavior is internally implemented by gitmodules_read_check(), to perform a lazy load. Let's merge this function with repo_read_gitmodules() adding a 'skip_if_read' which allows both internal and external callers to access this functionality. This simplifies a little the code. The added option will also be used in the following patch. Signed-off-by: Matheus Tavares <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1d1729c commit d799242

File tree

4 files changed

+10
-16
lines changed

4 files changed

+10
-16
lines changed

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static int grep_submodule(struct grep_opt *opt,
420420
return 0;
421421
}
422422

423-
repo_read_gitmodules(&subrepo);
423+
repo_read_gitmodules(&subrepo, 0);
424424

425425
/*
426426
* NEEDSWORK: This adds the submodule's object directory to the list of

submodule-config.c

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -674,10 +674,13 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
674674
return parse_config(var, value, &parameter);
675675
}
676676

677-
void repo_read_gitmodules(struct repository *repo)
677+
void repo_read_gitmodules(struct repository *repo, int skip_if_read)
678678
{
679679
submodule_cache_check_init(repo);
680680

681+
if (repo->submodule_cache->gitmodules_read && skip_if_read)
682+
return;
683+
681684
if (repo_read_index(repo) < 0)
682685
return;
683686

@@ -703,28 +706,19 @@ void gitmodules_config_oid(const struct object_id *commit_oid)
703706
the_repository->submodule_cache->gitmodules_read = 1;
704707
}
705708

706-
static void gitmodules_read_check(struct repository *repo)
707-
{
708-
submodule_cache_check_init(repo);
709-
710-
/* read the repo's .gitmodules file if it hasn't been already */
711-
if (!repo->submodule_cache->gitmodules_read)
712-
repo_read_gitmodules(repo);
713-
}
714-
715709
const struct submodule *submodule_from_name(struct repository *r,
716710
const struct object_id *treeish_name,
717711
const char *name)
718712
{
719-
gitmodules_read_check(r);
713+
repo_read_gitmodules(r, 1);
720714
return config_from(r->submodule_cache, treeish_name, name, lookup_name);
721715
}
722716

723717
const struct submodule *submodule_from_path(struct repository *r,
724718
const struct object_id *treeish_name,
725719
const char *path)
726720
{
727-
gitmodules_read_check(r);
721+
repo_read_gitmodules(r, 1);
728722
return config_from(r->submodule_cache, treeish_name, path, lookup_path);
729723
}
730724

submodule-config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ int option_fetch_parse_recurse_submodules(const struct option *opt,
6161
const char *arg, int unset);
6262
int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
6363
int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
64-
void repo_read_gitmodules(struct repository *repo);
64+
void repo_read_gitmodules(struct repository *repo, int skip_if_read);
6565
void gitmodules_config_oid(const struct object_id *commit_oid);
6666

6767
/**

unpack-trees.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,11 @@ static void load_gitmodules_file(struct index_state *index,
291291
if (pos >= 0) {
292292
struct cache_entry *ce = index->cache[pos];
293293
if (!state && ce->ce_flags & CE_WT_REMOVE) {
294-
repo_read_gitmodules(the_repository);
294+
repo_read_gitmodules(the_repository, 0);
295295
} else if (state && (ce->ce_flags & CE_UPDATE)) {
296296
submodule_free(the_repository);
297297
checkout_entry(ce, state, NULL, NULL);
298-
repo_read_gitmodules(the_repository);
298+
repo_read_gitmodules(the_repository, 0);
299299
}
300300
}
301301
}

0 commit comments

Comments
 (0)