[2/2] submodule: pass repo instead of adding to alternates list
diff mbox series

Message ID 4619e04ecca575e7eb5f73f555be0bb55d11385e.1566863604.git.matheus.bernardino@usp.br
State New
Headers show
Series
  • config: make config_with_options() handle any repo
Related show

Commit Message

Matheus Tavares Bernardino Aug. 26, 2019, 11:57 p.m. UTC
Previously, config_with_options() wouldn't handle arbitrary repositories
besides the_repository. Because of that, when retrieving .gitmodules
from the cache, config_from_gitmodules() first needed to add the object
directories of the given repo to the in-memory alternates list. But we
have repo_config_with_options() now, which takes a repository as
argument. So let's use it and remove the call to
add_to_alternates_memory(). This should bring better performance to
commands using the function (there'll be fewer odb entries to process)
besides saving memory (repos may be free'd right after use whereas
the_repository's alternates list doesn't).

While we are here, let's also adjust the comment on top of
config_from_gitmodules() to be explicit that it also handles the case
where .gitmodules is not present at the working tree.

Signed-off-by: Matheus Tavares <matheus.bernardino@usp.br>
---
 submodule-config.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

Patch
diff mbox series

diff --git a/submodule-config.c b/submodule-config.c
index 1d28b17071..8271aa3834 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -616,7 +616,8 @@  static void submodule_cache_check_init(struct repository *repo)
  * the repository.
  *
  * Runs the provided config function on the '.gitmodules' file found in the
- * working directory.
+ * working directory. If the file is not present, tries to retrieve it from
+ * the staging area or HEAD.
  */
 static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void *data)
 {
@@ -633,13 +634,11 @@  static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 		} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
 			   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
 			config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
-			if (repo != the_repository)
-				add_to_alternates_memory(repo->objects->odb->path);
 		} else {
 			goto out;
 		}
 
-		config_with_options(fn, data, &config_source, &opts);
+		repo_config_with_options(repo, fn, data, &config_source, &opts);
 
 out:
 		free(oidstr);