@matheusbsbs / matheus-bagliano / commits / d7992421e1
Fork 0

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 <matheus.bernardino@usp.br> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Matheus Tavares committed Jan 15, 2020 at 23:39 UTC d7992421e1a0e3ea5f836d8906e0f8b197fb6c1e
4 files changed +10 -16
builtin/grep.c
+1 -1
@@ -420,7 +420,7 @@ static int grep_submodule(struct grep_opt *opt,
420 return 0;
421 }
422
423 - repo_read_gitmodules(&subrepo);
423 + repo_read_gitmodules(&subrepo, 0);
424
425 /*
426 * NEEDSWORK: This adds the submodule's object directory to the list of
submodule-config.c
+6 -12
@@ -674,10 +674,13 @@ static int gitmodules_cb(const char *var, const char *value, void *data)
674 return parse_config(var, value, &parameter);
675 }
676
677 -void repo_read_gitmodules(struct repository *repo)
677 +void repo_read_gitmodules(struct repository *repo, int skip_if_read)
678 {
679 submodule_cache_check_init(repo);
680
681 + if (repo->submodule_cache->gitmodules_read && skip_if_read)
682 + return;
683 +
684 if (repo_read_index(repo) < 0)
685 return;
686
@@ -703,20 +706,11 @@ void gitmodules_config_oid(const struct object_id *commit_oid)
706 the_repository->submodule_cache->gitmodules_read = 1;
707 }
708
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 -
709 const struct submodule *submodule_from_name(struct repository *r,
710 const struct object_id *treeish_name,
711 const char *name)
712 {
719 - gitmodules_read_check(r);
713 + repo_read_gitmodules(r, 1);
714 return config_from(r->submodule_cache, treeish_name, name, lookup_name);
715 }
716
@@ -724,7 +718,7 @@ const struct submodule *submodule_from_path(struct repository *r,
718 const struct object_id *treeish_name,
719 const char *path)
720 {
727 - gitmodules_read_check(r);
721 + repo_read_gitmodules(r, 1);
722 return config_from(r->submodule_cache, treeish_name, path, lookup_path);
723 }
724
submodule-config.h
+1 -1
@@ -61,7 +61,7 @@ int option_fetch_parse_recurse_submodules(const struct option *opt,
61 const char *arg, int unset);
62 int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
63 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);
65 void gitmodules_config_oid(const struct object_id *commit_oid);
66
67 /**
unpack-trees.c
+2 -2
@@ -291,11 +291,11 @@ static void load_gitmodules_file(struct index_state *index,
291 if (pos >= 0) {
292 struct cache_entry *ce = index->cache[pos];
293 if (!state && ce->ce_flags & CE_WT_REMOVE) {
294 - repo_read_gitmodules(the_repository);
294 + repo_read_gitmodules(the_repository, 0);
295 } else if (state && (ce->ce_flags & CE_UPDATE)) {
296 submodule_free(the_repository);
297 checkout_entry(ce, state, NULL, NULL);
298 - repo_read_gitmodules(the_repository);
298 + repo_read_gitmodules(the_repository, 0);
299 }
300 }
301 }