odb: trivial refactorings to get rid of `the_repository`

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

Patrick Steinhardt committed Jul 1, 2025 at 14:22 UTC 16cf7494962f20d09dcd8ef20af8962600fafca9
1 file changed +16 -16
odb.c
+16 -16
@@ -1,5 +1,3 @@
1 -#define USE_THE_REPOSITORY_VARIABLE
2 -
1 #include "git-compat-util.h"
2 #include "abspath.h"
3 #include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_source_by_path(struct object_database *odb,
474 string_list_insert(&odb->submodule_source_paths, path);
475 }
476
479 -static void fill_alternate_refs_command(struct child_process *cmd,
477 +static void fill_alternate_refs_command(struct repository *repo,
478 + struct child_process *cmd,
479 const char *repo_path)
480 {
481 const char *value;
482
484 - if (!git_config_get_value("core.alternateRefsCommand", &value)) {
483 + if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
484 cmd->use_shell = 1;
485
486 strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
492 strvec_push(&cmd->args, "for-each-ref");
493 strvec_push(&cmd->args, "--format=%(objectname)");
494
496 - if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
495 + if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
496 strvec_push(&cmd->args, "--");
497 strvec_split(&cmd->args, value);
498 }
@@ -503,7 +502,8 @@ static void fill_alternate_refs_command(struct child_process *cmd,
502 cmd->out = -1;
503 }
504
506 -static void read_alternate_refs(const char *path,
505 +static void read_alternate_refs(struct repository *repo,
506 + const char *path,
507 odb_for_each_alternate_ref_fn *cb,
508 void *payload)
509 {
@@ -511,7 +511,7 @@ static void read_alternate_refs(const char *path,
511 struct strbuf line = STRBUF_INIT;
512 FILE *fh;
513
514 - fill_alternate_refs_command(&cmd, path);
514 + fill_alternate_refs_command(repo, &cmd, path);
515
516 if (start_command(&cmd))
517 return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
521 struct object_id oid;
522 const char *p;
523
524 - if (parse_oid_hex(line.buf, &oid, &p) || *p) {
524 + if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
525 warning(_("invalid line while parsing alternate refs: %s"),
526 line.buf);
527 break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
559 goto out;
560 strbuf_setlen(&path, base_len);
561
562 - read_alternate_refs(path.buf, cb->fn, cb->payload);
562 + read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
563
564 out:
565 strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
677 if (oi->disk_sizep)
678 *(oi->disk_sizep) = 0;
679 if (oi->delta_base_oid)
680 - oidclr(oi->delta_base_oid, the_repository->hash_algo);
680 + oidclr(oi->delta_base_oid, r->hash_algo);
681 if (oi->contentp)
682 *oi->contentp = xmemdupz(co->buf, co->size);
683 oi->whence = OI_CACHED;
@@ -763,10 +763,10 @@ static int oid_object_info_convert(struct repository *r,
763 void *content;
764 int ret;
765
766 - if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
766 + if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
767 if (do_die)
768 die(_("missing mapping of %s to %s"),
769 - oid_to_hex(input_oid), the_hash_algo->name);
769 + oid_to_hex(input_oid), r->hash_algo->name);
770 return -1;
771 }
772
@@ -797,8 +797,8 @@ static int oid_object_info_convert(struct repository *r,
797 struct strbuf outbuf = STRBUF_INIT;
798
799 if (type != OBJ_BLOB) {
800 - ret = convert_object_file(the_repository, &outbuf,
801 - the_hash_algo, input_algo,
800 + ret = convert_object_file(r, &outbuf,
801 + r->hash_algo, input_algo,
802 content, size, type, !do_die);
803 free(content);
804 if (ret == -1)
@@ -944,9 +944,9 @@ void *read_object_with_reference(struct repository *r,
944 }
945 ref_length = strlen(ref_type);
946
947 - if (ref_length + the_hash_algo->hexsz > isize ||
947 + if (ref_length + r->hash_algo->hexsz > isize ||
948 memcmp(buffer, ref_type, ref_length) ||
949 - get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
949 + get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
950 free(buffer);
951 return NULL;
952 }