Skip to content

Commit 61b886c

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9991f41 commit 61b886c

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

odb.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#define USE_THE_REPOSITORY_VARIABLE
2-
31
#include "git-compat-util.h"
42
#include "abspath.h"
53
#include "commit-graph.h"
@@ -476,12 +474,13 @@ void odb_add_submodule_source_by_path(struct object_database *odb,
476474
string_list_insert(&odb->submodule_source_paths, path);
477475
}
478476

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,
480479
const char *repo_path)
481480
{
482481
const char *value;
483482

484-
if (!git_config_get_value("core.alternateRefsCommand", &value)) {
483+
if (!repo_config_get_value(repo, "core.alternateRefsCommand", &value)) {
485484
cmd->use_shell = 1;
486485

487486
strvec_push(&cmd->args, value);
@@ -493,7 +492,7 @@ static void fill_alternate_refs_command(struct child_process *cmd,
493492
strvec_push(&cmd->args, "for-each-ref");
494493
strvec_push(&cmd->args, "--format=%(objectname)");
495494

496-
if (!git_config_get_value("core.alternateRefsPrefixes", &value)) {
495+
if (!repo_config_get_value(repo, "core.alternateRefsPrefixes", &value)) {
497496
strvec_push(&cmd->args, "--");
498497
strvec_split(&cmd->args, value);
499498
}
@@ -503,15 +502,16 @@ static void fill_alternate_refs_command(struct child_process *cmd,
503502
cmd->out = -1;
504503
}
505504

506-
static void read_alternate_refs(const char *path,
505+
static void read_alternate_refs(struct repository *repo,
506+
const char *path,
507507
odb_for_each_alternate_ref_fn *cb,
508508
void *payload)
509509
{
510510
struct child_process cmd = CHILD_PROCESS_INIT;
511511
struct strbuf line = STRBUF_INIT;
512512
FILE *fh;
513513

514-
fill_alternate_refs_command(&cmd, path);
514+
fill_alternate_refs_command(repo, &cmd, path);
515515

516516
if (start_command(&cmd))
517517
return;
@@ -521,7 +521,7 @@ static void read_alternate_refs(const char *path,
521521
struct object_id oid;
522522
const char *p;
523523

524-
if (parse_oid_hex(line.buf, &oid, &p) || *p) {
524+
if (parse_oid_hex_algop(line.buf, &oid, &p, repo->hash_algo) || *p) {
525525
warning(_("invalid line while parsing alternate refs: %s"),
526526
line.buf);
527527
break;
@@ -559,7 +559,7 @@ static int refs_from_alternate_cb(struct odb_source *alternate,
559559
goto out;
560560
strbuf_setlen(&path, base_len);
561561

562-
read_alternate_refs(path.buf, cb->fn, cb->payload);
562+
read_alternate_refs(alternate->odb->repo, path.buf, cb->fn, cb->payload);
563563

564564
out:
565565
strbuf_release(&path);
@@ -677,7 +677,7 @@ static int do_oid_object_info_extended(struct repository *r,
677677
if (oi->disk_sizep)
678678
*(oi->disk_sizep) = 0;
679679
if (oi->delta_base_oid)
680-
oidclr(oi->delta_base_oid, the_repository->hash_algo);
680+
oidclr(oi->delta_base_oid, r->hash_algo);
681681
if (oi->contentp)
682682
*oi->contentp = xmemdupz(co->buf, co->size);
683683
oi->whence = OI_CACHED;
@@ -763,10 +763,10 @@ static int oid_object_info_convert(struct repository *r,
763763
void *content;
764764
int ret;
765765

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)) {
767767
if (do_die)
768768
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);
770770
return -1;
771771
}
772772

@@ -797,8 +797,8 @@ static int oid_object_info_convert(struct repository *r,
797797
struct strbuf outbuf = STRBUF_INIT;
798798

799799
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,
802802
content, size, type, !do_die);
803803
free(content);
804804
if (ret == -1)
@@ -944,9 +944,9 @@ void *read_object_with_reference(struct repository *r,
944944
}
945945
ref_length = strlen(ref_type);
946946

947-
if (ref_length + the_hash_algo->hexsz > isize ||
947+
if (ref_length + r->hash_algo->hexsz > isize ||
948948
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)) {
950950
free(buffer);
951951
return NULL;
952952
}

0 commit comments

Comments
 (0)