Skip to content

Commit 873b005

Browse files
KarthikNayakgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4f9e6bd commit 873b005

File tree

6 files changed

+14
-14
lines changed

6 files changed

+14
-14
lines changed

builtin/fast-import.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -806,19 +806,19 @@ static char *keep_pack(const char *curr_index_name)
806806
struct strbuf name = STRBUF_INIT;
807807
int keep_fd;
808808

809-
odb_pack_name(&name, pack_data->hash, "keep");
809+
odb_pack_name(pack_data->repo, &name, pack_data->hash, "keep");
810810
keep_fd = odb_pack_keep(name.buf);
811811
if (keep_fd < 0)
812812
die_errno("cannot create keep file");
813813
write_or_die(keep_fd, keep_msg, strlen(keep_msg));
814814
if (close(keep_fd))
815815
die_errno("failed to write keep file");
816816

817-
odb_pack_name(&name, pack_data->hash, "pack");
817+
odb_pack_name(pack_data->repo, &name, pack_data->hash, "pack");
818818
if (finalize_object_file(pack_data->pack_name, name.buf))
819819
die("cannot store pack file");
820820

821-
odb_pack_name(&name, pack_data->hash, "idx");
821+
odb_pack_name(pack_data->repo, &name, pack_data->hash, "idx");
822822
if (finalize_object_file(curr_index_name, name.buf))
823823
die("cannot store index file");
824824
free((void *)curr_index_name);
@@ -832,7 +832,7 @@ static void unkeep_all_packs(void)
832832

833833
for (k = 0; k < pack_id; k++) {
834834
struct packed_git *p = all_packs[k];
835-
odb_pack_name(&name, p->hash, "keep");
835+
odb_pack_name(p->repo, &name, p->hash, "keep");
836836
unlink_or_warn(name.buf);
837837
}
838838
strbuf_release(&name);

builtin/index-pack.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,7 +1479,7 @@ static void write_special_file(const char *suffix, const char *msg,
14791479
if (pack_name)
14801480
filename = derive_filename(pack_name, "pack", suffix, &name_buf);
14811481
else
1482-
filename = odb_pack_name(&name_buf, hash, suffix);
1482+
filename = odb_pack_name(the_repository, &name_buf, hash, suffix);
14831483

14841484
fd = odb_pack_keep(filename);
14851485
if (fd < 0) {
@@ -1507,7 +1507,7 @@ static void rename_tmp_packfile(const char **final_name,
15071507
{
15081508
if (!*final_name || strcmp(*final_name, curr_name)) {
15091509
if (!*final_name)
1510-
*final_name = odb_pack_name(name, hash, ext);
1510+
*final_name = odb_pack_name(the_repository, name, hash, ext);
15111511
if (finalize_object_file(curr_name, *final_name))
15121512
die(_("unable to rename temporary '*.%s' file to '%s'"),
15131513
ext, *final_name);

builtin/pack-redundant.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ int cmd_pack_redundant(int argc, const char **argv, const char *prefix UNUSED, s
690690
pl = red = pack_list_difference(local_packs, min);
691691
while (pl) {
692692
printf("%s\n%s\n",
693-
odb_pack_name(&idx_name, pl->pack->hash, "idx"),
693+
odb_pack_name(pl->pack->repo, &idx_name, pl->pack->hash, "idx"),
694694
pl->pack->pack_name);
695695
pl = pl->next;
696696
}

http.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2581,7 +2581,7 @@ struct http_pack_request *new_direct_http_pack_request(
25812581

25822582
preq->url = url;
25832583

2584-
odb_pack_name(&preq->tmpfile, packed_git_hash, "pack");
2584+
odb_pack_name(the_repository, &preq->tmpfile, packed_git_hash, "pack");
25852585
strbuf_addstr(&preq->tmpfile, ".temp");
25862586
preq->packfile = fopen(preq->tmpfile.buf, "a");
25872587
if (!preq->packfile) {

packfile.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@
2525
#include "pack-revindex.h"
2626
#include "promisor-remote.h"
2727

28-
char *odb_pack_name(struct strbuf *buf,
29-
const unsigned char *hash,
30-
const char *ext)
28+
char *odb_pack_name(struct repository *r, struct strbuf *buf,
29+
const unsigned char *hash, const char *ext)
3130
{
3231
strbuf_reset(buf);
33-
strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(the_repository),
34-
hash_to_hex(hash), ext);
32+
strbuf_addf(buf, "%s/pack/pack-%s.%s", repo_get_object_directory(r),
33+
hash_to_hex_algop(hash, r->hash_algo), ext);
3534
return buf->buf;
3635
}
3736

packfile.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ struct pack_entry {
2929
*
3030
* Example: odb_pack_name(out, sha1, "idx") => ".git/objects/pack/pack-1234..idx"
3131
*/
32-
char *odb_pack_name(struct strbuf *buf, const unsigned char *sha1, const char *ext);
32+
char *odb_pack_name(struct repository *r, struct strbuf *buf,
33+
const unsigned char *hash, const char *ext);
3334

3435
/*
3536
* Return the basename of the packfile, omitting any containing directory

0 commit comments

Comments
 (0)