Skip to content

Commit 351d77e

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 6ee10d9 commit 351d77e

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_alternate_by_path(struct object_database *odb,
476474
string_list_insert(&odb->submodule_alternate_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_alternate *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->type_name)
682682
strbuf_addstr(oi->type_name, type_name(co->type));
683683
if (oi->contentp)
@@ -765,10 +765,10 @@ static int oid_object_info_convert(struct repository *r,
765765
void *content;
766766
int ret;
767767

768-
if (repo_oid_to_algop(r, input_oid, the_hash_algo, &oid)) {
768+
if (repo_oid_to_algop(r, input_oid, r->hash_algo, &oid)) {
769769
if (do_die)
770770
die(_("missing mapping of %s to %s"),
771-
oid_to_hex(input_oid), the_hash_algo->name);
771+
oid_to_hex(input_oid), r->hash_algo->name);
772772
return -1;
773773
}
774774

@@ -804,8 +804,8 @@ static int oid_object_info_convert(struct repository *r,
804804
if (type == -1)
805805
return -1;
806806
if (type != OBJ_BLOB) {
807-
ret = convert_object_file(the_repository, &outbuf,
808-
the_hash_algo, input_algo,
807+
ret = convert_object_file(r, &outbuf,
808+
r->hash_algo, input_algo,
809809
content, size, type, !do_die);
810810
free(content);
811811
if (ret == -1)
@@ -953,9 +953,9 @@ void *read_object_with_reference(struct repository *r,
953953
}
954954
ref_length = strlen(ref_type);
955955

956-
if (ref_length + the_hash_algo->hexsz > isize ||
956+
if (ref_length + r->hash_algo->hexsz > isize ||
957957
memcmp(buffer, ref_type, ref_length) ||
958-
get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
958+
get_oid_hex_algop((char *) buffer + ref_length, &actual_oid, r->hash_algo)) {
959959
free(buffer);
960960
return NULL;
961961
}

0 commit comments

Comments
 (0)