csum-file: stop depending on the_repository

There are multiple sites in "csum-file.c" where we use the global
`the_repository` variable, either explicitly or implicitly by using
`the_hash_algo`.

Refactor the code to stop using `the_repository` by adapting functions
to receive required data as parameters. Adapt callsites accordingly by
either using `the_repository->hash_algo`, or by using a context-provided
hash algorithm in case the subsystem already got rid of its dependency
on `the_repository`.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-03-10 08:13:20 +01:00
committed by Junio C Hamano
parent e969bc8759
commit 228457c9d9
14 changed files with 56 additions and 39 deletions

View File

@@ -82,7 +82,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
if (opts->flags & WRITE_IDX_VERIFY) {
assert(index_name);
f = hashfd_check(index_name);
f = hashfd_check(the_repository->hash_algo, index_name);
} else {
if (!index_name) {
struct strbuf tmp_file = STRBUF_INIT;
@@ -92,7 +92,7 @@ const char *write_idx_file(const struct git_hash_algo *hash_algo,
unlink(index_name);
fd = xopen(index_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
}
f = hashfd(fd, index_name);
f = hashfd(the_repository->hash_algo, fd, index_name);
}
/* if last object's offset is >= 2^31 we should use index V2 */
@@ -268,7 +268,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
fd = xopen(rev_name, O_CREAT|O_EXCL|O_WRONLY, 0600);
path = xstrdup(rev_name);
}
f = hashfd(fd, path);
f = hashfd(the_repository->hash_algo, fd, path);
} else if (flags & WRITE_REV_VERIFY) {
struct stat statbuf;
if (stat(rev_name, &statbuf)) {
@@ -278,7 +278,7 @@ char *write_rev_file_order(const struct git_hash_algo *hash_algo,
} else
die_errno(_("could not stat: %s"), rev_name);
}
f = hashfd_check(rev_name);
f = hashfd_check(the_repository->hash_algo, rev_name);
path = xstrdup(rev_name);
} else {
return NULL;
@@ -346,7 +346,7 @@ static char *write_mtimes_file(const struct git_hash_algo *hash_algo,
fd = odb_mkstemp(&tmp_file, "pack/tmp_mtimes_XXXXXX");
mtimes_name = strbuf_detach(&tmp_file, NULL);
f = hashfd(fd, mtimes_name);
f = hashfd(the_repository->hash_algo, fd, mtimes_name);
write_mtimes_header(hash_algo, f);
write_mtimes_objects(f, to_pack, objects, nr_objects);
@@ -534,7 +534,7 @@ struct hashfile *create_tmp_packfile(char **pack_tmp_name)
fd = odb_mkstemp(&tmpname, "pack/tmp_pack_XXXXXX");
*pack_tmp_name = strbuf_detach(&tmpname, NULL);
return hashfd(fd, *pack_tmp_name);
return hashfd(the_repository->hash_algo, fd, *pack_tmp_name);
}
static void rename_tmp_packfile(struct strbuf *name_prefix, const char *source,