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

[PATCH v2 7/8] submodule-config: pass repo upon blob config read

From
JTJonathan Tan <jonathantanmy@google.com>
Date
Aug 13, 2021, 21:05 UTC
Message-ID
<94db10a4e5943d689113693c64633ddffa5508cc.1628888668.git.jonathantanmy@google.com>
In-Reply-To
<cover.1628888668.git.jonathantanmy@google.com>

When reading the config of a submodule, if reading from a blob, read using an explicitly specified repository instead of by adding the submodule's ODB as an alternate and then reading an object from the_repository.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 config.c           | 18 ++++++++++++------
 config.h           |  3 +++
 submodule-config.c |  5 +++--
 3 files changed, 18 insertions(+), 8 deletions(-)
diff --git a/config.c b/config.c
index f33abeab85..a85c12e6cc 100644
--- a/config.c
+++ b/config.c
@@ -1796,6 +1796,7 @@ int git_config_from_mem(config_fn_t fn,
 
 int git_config_from_blob_oid(config_fn_t fn,
 			      const char *name,
+			      struct repository *repo,
 			      const struct object_id *oid,
 			      void *data)
 {
@@ -1804,7 +1805,7 @@ int git_config_from_blob_oid(config_fn_t fn,
 	unsigned long size;
 	int ret;
 
-	buf = read_object_file(oid, &type, &size);
+	buf = repo_read_object_file(repo, oid, &type, &size);
 	if (!buf)
 		return error(_("unable to load config blob object '%s'"), name);
 	if (type != OBJ_BLOB) {
@@ -1820,6 +1821,7 @@ int git_config_from_blob_oid(config_fn_t fn,
 }
 
 static int git_config_from_blob_ref(config_fn_t fn,
+				    struct repository *repo,
 				    const char *name,
 				    void *data)
 {
@@ -1827,7 +1829,7 @@ static int git_config_from_blob_ref(config_fn_t fn,
 
 	if (get_oid(name, &oid) < 0)
 		return error(_("unable to resolve config blob '%s'"), name);
-	return git_config_from_blob_oid(fn, name, &oid, data);
+	return git_config_from_blob_oid(fn, name, repo, &oid, data);
 }
 
 char *git_system_config(void)
@@ -1958,12 +1960,16 @@ int config_with_options(config_fn_t fn, void *data,
 	 * If we have a specific filename, use it. Otherwise, follow the
 	 * regular lookup sequence.
 	 */
-	if (config_source && config_source->use_stdin)
+	if (config_source && config_source->use_stdin) {
 		return git_config_from_stdin(fn, data);
-	else if (config_source && config_source->file)
+	} else if (config_source && config_source->file) {
 		return git_config_from_file(fn, config_source->file, data);
-	else if (config_source && config_source->blob)
-		return git_config_from_blob_ref(fn, config_source->blob, data);
+	} else if (config_source && config_source->blob) {
+		struct repository *repo = config_source->repo ?
+			config_source->repo : the_repository;
+		return git_config_from_blob_ref(fn, repo, config_source->blob,
+						data);
+	}
 
 	return do_git_config_sequence(opts, fn, data);
 }
diff --git a/config.h b/config.h
index a2200f3111..147f5e0490 100644
--- a/config.h
+++ b/config.h
@@ -49,6 +49,8 @@ const char *config_scope_name(enum config_scope scope);
 struct git_config_source {
 	unsigned int use_stdin:1;
 	const char *file;
+	/* The repository if blob is not NULL; leave blank for the_repository */
+	struct repository *repo;
 	const char *blob;
 	enum config_scope scope;
 };
@@ -136,6 +138,7 @@ int git_config_from_mem(config_fn_t fn,
 			const char *buf, size_t len,
 			void *data, const struct config_options *opts);
 int git_config_from_blob_oid(config_fn_t fn, const char *name,
+			     struct repository *repo,
 			     const struct object_id *oid, void *data);
 void git_config_push_parameter(const char *text);
 void git_config_push_env(const char *spec);
diff --git a/submodule-config.c b/submodule-config.c
index 2026120fb3..f95344028b 100644
--- a/submodule-config.c
+++ b/submodule-config.c
@@ -649,9 +649,10 @@ static void config_from_gitmodules(config_fn_t fn, struct repository *repo, void
 			config_source.file = file;
 		} else if (repo_get_oid(repo, GITMODULES_INDEX, &oid) >= 0 ||
 			   repo_get_oid(repo, GITMODULES_HEAD, &oid) >= 0) {
+			config_source.repo = repo;
 			config_source.blob = oidstr = xstrdup(oid_to_hex(&oid));
 			if (repo != the_repository)
-				add_to_alternates_memory(repo->objects->odb->path);
+				add_submodule_odb_by_path(repo->objects->odb->path);
 		} else {
 			goto out;
 		}
@@ -702,7 +703,7 @@ void gitmodules_config_oid(const struct object_id *commit_oid)
 
 	if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
 		git_config_from_blob_oid(gitmodules_cb, rev.buf,
-					 &oid, the_repository);
+					 the_repository, &oid, the_repository);
 	}
 	strbuf_release(&rev);
 
-- 
2.33.0.rc1.237.g0d66db33f3-goog
Previous: Jonathan TanNext: Matheus Tavares Bernardino
Message 47 of 71 in “In grep, no adding submodule ODB as alternates”
  1. 0/7 In grep, no adding submodule ODB as alternatesJonathan Tan, Aug 10, 2021
  2. 4/7 grep: read submodule entry with explicit repoJonathan Tan, Aug 10, 2021
  3. Emily ShafferAug 11, 2021
  4. Jonathan TanAug 13, 2021
  5. 3/7 grep: typesafe versions of grep_source_initJonathan Tan, Aug 10, 2021
  6. Junio C HamanoAug 10, 2021
  7. Emily ShafferAug 11, 2021
  8. Ramsay JonesAug 11, 2021
  9. Jonathan TanAug 13, 2021
  10. Matheus Tavares BernardinoAug 11, 2021
  11. Junio C HamanoAug 12, 2021
  12. Jonathan TanAug 13, 2021
  13. 2/7 grep: use submodule-ODB-as-alternate lazy-additionJonathan Tan, Aug 10, 2021
  14. Emily ShafferAug 11, 2021
  15. Jonathan TanAug 13, 2021
  16. 1/7 submodule: lazily add submodule ODBs as alternatesJonathan Tan, Aug 10, 2021
  17. Junio C HamanoAug 10, 2021
  18. Jonathan TanAug 13, 2021
  19. Emily ShafferAug 11, 2021
  20. Jonathan TanAug 13, 2021
  21. 5/7 grep: allocate subrepos on heapJonathan Tan, Aug 10, 2021
  22. Emily ShafferAug 11, 2021
  23. Jonathan TanAug 13, 2021
  24. 6/7 grep: add repository to OID grep sourcesJonathan Tan, Aug 10, 2021
  25. Emily ShafferAug 11, 2021
  26. Jonathan TanAug 13, 2021
  27. Matheus Tavares BernardinoAug 11, 2021
  28. Jonathan TanAug 13, 2021
  29. 7/7 t7814: show lack of alternate ODB-addingJonathan Tan, Aug 10, 2021
  30. Emily ShafferAug 11, 2021
  31. Matheus Tavares BernardinoAug 11, 2021
  32. Jonathan TanAug 13, 2021
  33. Emily ShafferAug 11, 2021
  34. Josh SteadmonAug 11, 2021
  35. 0/8 In grep, no adding submodule ODB as alternatesJonathan Tan, Aug 13, 2021
  36. 2/8 grep: use submodule-ODB-as-alternate lazy-additionJonathan Tan, Aug 13, 2021
  37. 1/8 submodule: lazily add submodule ODBs as alternatesJonathan Tan, Aug 13, 2021
  38. 3/8 grep: typesafe versions of grep_source_initJonathan Tan, Aug 13, 2021
  39. Matheus Tavares BernardinoAug 16, 2021
  40. 4/8 grep: read submodule entry with explicit repoJonathan Tan, Aug 13, 2021
  41. 5/8 grep: allocate subrepos on heapJonathan Tan, Aug 13, 2021
  42. Junio C HamanoAug 13, 2021
  43. Jonathan TanAug 16, 2021
  44. 6/8 grep: add repository to OID grep sourcesJonathan Tan, Aug 13, 2021
  45. Matheus Tavares BernardinoAug 16, 2021
  46. Jonathan TanAug 16, 2021
  47. 7/8 submodule-config: pass repo upon blob config readJonathan Tan, Aug 13, 2021
  48. Matheus Tavares BernardinoAug 16, 2021
  49. Matheus Tavares BernardinoAug 16, 2021
  50. Jonathan TanAug 16, 2021
  51. Matheus Tavares BernardinoAug 16, 2021
  52. Jonathan TanAug 16, 2021
  53. Jonathan TanAug 16, 2021
  54. 8/8 t7814: show lack of alternate ODB-addingJonathan Tan, Aug 13, 2021
  55. Matheus Tavares BernardinoAug 16, 2021
  56. 0/8 In grep, no adding submodule ODB as alternatesJonathan Tan, Aug 16, 2021
  57. 1/8 submodule: lazily add submodule ODBs as alternatesJonathan Tan, Aug 16, 2021
  58. 2/8 grep: use submodule-ODB-as-alternate lazy-additionJonathan Tan, Aug 16, 2021
  59. 3/8 grep: typesafe versions of grep_source_initJonathan Tan, Aug 16, 2021
  60. 4/8 grep: read submodule entry with explicit repoJonathan Tan, Aug 16, 2021
  61. 5/8 grep: allocate subrepos on heapJonathan Tan, Aug 16, 2021
  62. 6/8 grep: add repository to OID grep sourcesJonathan Tan, Aug 16, 2021
  63. Ævar Arnfjörð BjarmasonSep 27, 2021
  64. Matheus TavaresSep 27, 2021
  65. Ævar Arnfjörð BjarmasonSep 27, 2021
  66. 7/8 submodule-config: pass repo upon blob config readJonathan Tan, Aug 16, 2021
  67. 8/8 t7814: show lack of alternate ODB-addingJonathan Tan, Aug 16, 2021
  68. Matheus Tavares BernardinoAug 17, 2021
  69. Junio C HamanoSep 8, 2021
  70. Matheus Tavares BernardinoSep 8, 2021
  71. Junio C HamanoSep 8, 2021

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.