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

[PATCH v4 12/17] odb: trivial refactorings to get rid of `the_repository`

From
Patrick Steinhardt <ps@pks.im>
Date
Jun 2, 2025, 10:27 UTC
Message-ID
<20250602-pks-object-store-wo-the-repository-v4-12-e986804a7c62@pks.im>
In-Reply-To
<20250602-pks-object-store-wo-the-repository-v4-0-e986804a7c62@pks.im>

All of the external functions provided by the object database subsystem don't depend on `the_repository` anymore, but some internal functions still do. Refactor those cases by plumbing through the repository that owns the object database.

This change allows us to get rid of the `USE_THE_REPOSITORY_VARIABLE` preprocessor define.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 odb.c | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)
diff --git a/odb.c b/odb.c
index 793903cb046..a13b9ecbbc9 100644
--- a/odb.c
+++ b/odb.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_source_by_path(struct object_database *odb,
 	string_list_insert(&odb->submodule_source_paths, path);
 }
 
-static void fill_alternate_refs_command(struct child_process *cmd,
+static void fill_alternate_refs_command(struct repository *repo,
+					struct child_process *cmd,
 					const char *repo_path)
 {
 	const char *value;
 
-	if (!git_config_get_value("core.alternateRefsCommand", &value)) {
+	if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
 		cmd->use_shell = 1;
 
 		strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
 		strvec_push(&cmd->args, "for-each-ref");
 		strvec_push(&cmd->args, "--format=%(objectname)");
 
-		if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
+		if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
 			strvec_push(&cmd->args, "--");
 			strvec_split(&cmd->args, value);
 		}
@@ -503,7 +502,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
 	cmd->out = -1;
 }
 
-static void read_alternate_refs(const char *path,
+static void read_alternate_refs(struct repository *repo,
+				const char *path,
 				odb_for_each_alternate_ref_fn *cb,
 				void *payload)
 {
@@ -511,7 +511,7 @@ static void read_alternate_refs(const char *path,
 	struct strbuf line = STRBUF_INIT;
 	FILE *fh;
 
-	fill_alternate_refs_command(&cmd, path);
+	fill_alternate_refs_command(repo, &cmd, path);
 
 	if (start_command(&cmd))
 		return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
 		struct object_id oid;
 		const char *p;
 
-		if (parse_oid_hex(line.buf, &oid, &p) || *p) {
+		if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
 			warning(_("invalid line while parsing alternate refs: %s"),
 				line.buf);
 			break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
 		goto out;
 	strbuf_setlen(&path, base_len);
 
-	read_alternate_refs(path.buf, cb->fn, cb->payload);
+	read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
 
 out:
 	strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
 		if (oi->disk_sizep)
 			*(oi->disk_sizep) = 0;
 		if (oi->delta_base_oid)
-			oidclr(oi->delta_base_oid, the_repository->hash_algo);
+			oidclr(oi->delta_base_oid, r->hash_algo);
 		if (oi->contentp)
 			*oi->contentp = xmemdupz(co->buf, co->size);
 		oi->whence = OI_CACHED;
@@ -763,10 +763,10 @@ static int oid_object_info_convert(struct repository *r,
 	void *content;
 	int ret;
 
-	if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
+	if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
 		if (do_die)
 			die(_("missing mapping of %s to %s"),
-			    oid_to_hex(input_oid), the_hash_algo->name);
+			    oid_to_hex(input_oid), r->hash_algo->name);
 		return -1;
 	}
 
@@ -797,8 +797,8 @@ static int oid_object_info_convert(struct repository *r,
 		struct strbuf outbuf = STRBUF_INIT;
 
 		if (type != OBJ_BLOB) {
-			ret = convert_object_file(the_repository, &outbuf,
-						  the_hash_algo, input_algo,
+			ret = convert_object_file(r, &outbuf,
+						  r->hash_algo, input_algo,
 						  content, size, type, !do_die);
 			free(content);
 			if (ret == -1)
@@ -944,9 +944,9 @@ void *read_object_with_reference(struct repository *r,
 		}
 		ref_length = strlen(ref_type);
 
-		if (ref_length + the_hash_algo->hexsz > isize ||
+		if (ref_length + r->hash_algo->hexsz > isize ||
 		    memcmp(buffer, ref_type, ref_length) ||
-		    get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
+		    get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
 			free(buffer);
 			return NULL;
 		}
-- 
2.50.0.rc0.629.g846fc57c9e.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 17 of 23 in “object-store: carve out the object database subsystem”
  1. 00/17 object-store: carve out the object database subsystemPatrick Steinhardt, Jun 2, 2025
  2. 01/17 object-store: rename `raw_object_store` to `object_database`Patrick Steinhardt, Jun 2, 2025
  3. Toon ClaesJun 4, 2025
  4. Patrick SteinhardtJun 4, 2025
  5. 03/17 object-store: rename files to "odb.{c,h}"Patrick Steinhardt, Jun 2, 2025
  6. 02/17 object-store: rename `object_directory` to `odb_source`Patrick Steinhardt, Jun 2, 2025
  7. Toon ClaesJun 4, 2025
  8. Patrick SteinhardtJun 4, 2025
  9. 04/17 odb: introduce parent pointersPatrick Steinhardt, Jun 2, 2025
  10. 05/17 odb: get rid of `the_repository` in `find_odb()`Patrick Steinhardt, Jun 2, 2025
  11. 07/17 odb: get rid of `the_repository` in `odb_mkstemp()`Patrick Steinhardt, Jun 2, 2025
  12. 06/17 odb: get rid of `the_repository` in `assert_oid_type()`Patrick Steinhardt, Jun 2, 2025
  13. 09/17 odb: get rid of `the_repository` in `for_each()` functionsPatrick Steinhardt, Jun 2, 2025
  14. 08/17 odb: get rid of `the_repository` when handling alternatesPatrick Steinhardt, Jun 2, 2025
  15. 11/17 odb: get rid of `the_repository` when handling submodule sourcesPatrick Steinhardt, Jun 2, 2025
  16. 10/17 odb: get rid of `the_repository` when handling the primary sourcePatrick Steinhardt, Jun 2, 2025
  17. 12/17 odb: trivial refactorings to get rid of `the_repository`Patrick Steinhardt, Jun 2, 2025
  18. 13/17 odb: rename `oid_object_info()`Patrick Steinhardt, Jun 2, 2025
  19. 15/17 odb: rename `has_object()`Patrick Steinhardt, Jun 2, 2025
  20. 14/17 odb: rename `repo_read_object_file()`Patrick Steinhardt, Jun 2, 2025
  21. 17/17 odb: rename `read_object_with_reference()`Patrick Steinhardt, Jun 2, 2025
  22. 16/17 odb: rename `pretend_object_file()`Patrick Steinhardt, Jun 2, 2025
  23. Junio C HamanoJun 2, 2025

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.