git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 2/2] submodule: pass repo instead of adding to alternates list

From
Matheus Tavares <matheus.bernardino@usp.br>
Date
Aug 26, 2019, 23:57 UTC
Message-ID
<4619e04ecca575e7eb5f73f555be0bb55d11385e.1566863604.git.matheus.bernardino@usp.br>
In-Reply-To
<cover.1566863604.git.matheus.bernardino@usp.br>

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(-)
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);
-- 
2.22.0
Previous: Duy Nguyen
Message 10 of 10 in “config: make config_with_options() handle any repo”
  1. 0/2 config: make config_with_options() handle any repoMatheus Tavares, Aug 26, 2019
  2. 1/2 config: allow config_with_options() to handle any repoMatheus Tavares, Aug 26, 2019
  3. Duy NguyenAug 27, 2019
  4. Matheus Tavares BernardinoAug 27, 2019
  5. Matheus Tavares BernardinoAug 29, 2019
  6. Duy NguyenAug 29, 2019
  7. Jeff KingAug 29, 2019
  8. Matheus Tavares BernardinoAug 29, 2019
  9. Duy NguyenAug 30, 2019
  10. 2/2 submodule: pass repo instead of adding to alternates listMatheus Tavares, Aug 26, 2019

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.