packfile: pass down repository to odb_pack_name

The function `odb_pack_name` currently relies on the global variable
`the_repository`. To eliminate global variable usage in `packfile.c`, we
should progressively shift the dependency on the_repository to higher
layers.

Signed-off-by: Karthik Nayak <karthik.188@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Karthik Nayak
2024-12-03 15:43:58 +01:00
committed by Junio C Hamano
parent 4f9e6bd492
commit 873b00597b
6 changed files with 14 additions and 14 deletions

View File

@ -806,7 +806,7 @@ static char *keep_pack(const char *curr_index_name)
struct strbuf name = STRBUF_INIT; struct strbuf name = STRBUF_INIT;
int keep_fd; int keep_fd;
odb_pack_name(&name, pack_data->hash, "keep"); odb_pack_name(pack_data->repo, &name, pack_data->hash, "keep");
keep_fd = odb_pack_keep(name.buf); keep_fd = odb_pack_keep(name.buf);
if (keep_fd < 0) if (keep_fd < 0)
die_errno("cannot create keep file"); die_errno("cannot create keep file");
@ -814,11 +814,11 @@ static char *keep_pack(const char *curr_index_name)
if (close(keep_fd)) if (close(keep_fd))
die_errno("failed to write keep file"); die_errno("failed to write keep file");
odb_pack_name(&name, pack_data->hash, "pack"); odb_pack_name(pack_data->repo, &name, pack_data->hash, "pack");
if (finalize_object_file(pack_data->pack_name, name.buf)) if (finalize_object_file(pack_data->pack_name, name.buf))
die("cannot store pack file"); die("cannot store pack file");
odb_pack_name(&name, pack_data->hash, "idx"); odb_pack_name(pack_data->repo, &name, pack_data->hash, "idx");
if (finalize_object_file(curr_index_name, name.buf)) if (finalize_object_file(curr_index_name, name.buf))
die("cannot store index file"); die("cannot store index file");
free((void *)curr_index_name); free((void *)curr_index_name);
@ -832,7 +832,7 @@ static void unkeep_all_packs(void)
for (k = 0; k < pack_id; k++) { for (k = 0; k < pack_id; k++) {
struct packed_git *p = all_packs[k]; struct packed_git *p = all_packs[k];
odb_pack_name(&name, p->hash, "keep"); odb_pack_name(p->repo, &name, p->hash, "keep");
unlink_or_warn(name.buf); unlink_or_warn(name.buf);
} }
strbuf_release(&name); strbuf_release(&name);

View File

@ -1479,7 +1479,7 @@ static void write_special_file(const char *suffix, const char *msg,
if (pack_name) if (pack_name)
filename = derive_filename(pack_name, "pack", suffix, &name_buf); filename = derive_filename(pack_name, "pack", suffix, &name_buf);
else else
filename = odb_pack_name(&name_buf, hash, suffix); filename = odb_pack_name(the_repository, &name_buf, hash, suffix);
fd = odb_pack_keep(filename); fd = odb_pack_keep(filename);
if (fd < 0) { if (fd < 0) {
@ -1507,7 +1507,7 @@ static void rename_tmp_packfile(const char **final_name,
{ {
if (!*final_name || strcmp(*final_name, curr_name)) { if (!*final_name || strcmp(*final_name, curr_name)) {
if (!*final_name) if (!*final_name)
*final_name = odb_pack_name(name, hash, ext); *final_name = odb_pack_name(the_repository, name, hash, ext);
if (finalize_object_file(curr_name, *final_name)) if (finalize_object_file(curr_name, *final_name))
die(_("unable to rename temporary '*.%s' file to '%s'"), die(_("unable to rename temporary '*.%s' file to '%s'"),
ext, *final_name); ext, *final_name);

View File

@ -690,7 +690,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
pl = red = pack_list_difference(local_packs, min); pl = red = pack_list_difference(local_packs, min);
while (pl) { while (pl) {
printf("%s\n%s\n", printf("%s\n%s\n",
odb_pack_name(&idx_name, pl->pack->hash, "idx"), odb_pack_name(pl->pack->repo, &idx_name, pl->pack->hash, "idx"),
pl->pack->pack_name); pl->pack->pack_name);
pl = pl->next; pl = pl->next;
} }

2
http.c
View File

@ -2581,7 +2581,7 @@ struct http_pack_request *new_direct_http_pack_request(
preq->url = url; preq->url = url;
odb_pack_name(&preq->tmpfile, packed_git_hash, "pack"); odb_pack_name(the_repository, &preq->tmpfile, packed_git_hash, "pack");
strbuf_addstr(&preq->tmpfile, ".temp"); strbuf_addstr(&preq->tmpfile, ".temp");
preq->packfile = fopen(preq->tmpfile.buf, "a"); preq->packfile = fopen(preq->tmpfile.buf, "a");
if (!preq->packfile) { if (!preq->packfile) {

View File

@ -25,13 +25,12 @@
#include "pack-revindex.h" #include "pack-revindex.h"
#include "promisor-remote.h" #include "promisor-remote.h"
char *odb_pack_name(struct strbuf *buf, char *odb_pack_name(struct repository *r, struct strbuf *buf,
const unsigned char *hash, const unsigned char *hash, const char *ext)
const char *ext)
{ {
strbuf_reset(buf); strbuf_reset(buf);
strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(the_repository), strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(r),
hash_to_hex(hash), ext); hash_to_hex_algop(hash, r->hash_algo), ext);
return buf->buf; return buf->buf;
} }

View File

@ -29,7 +29,8 @@ struct pack_entry {
* *
* Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx" * Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx"
*/ */
char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext); char *odb_pack_name(struct repository *r, struct strbuf *buf,
const unsigned char *hash, const char *ext);
/* /*
* Return the basename of the packfile, omitting any containing directory * Return the basename of the packfile, omitting any containing directory