Skip to content

Commit e9b91ea

Browse files
KarthikNayakgitster
authored andcommitted
midx: pass down hash_algo to functions using global variables
The functions `get_split_midx_filename_ext()`, `get_midx_filename()` and `get_midx_filename_ext()` use `hash_to_hex()` which internally uses the `the_hash_algo` global variable. Remove this dependency on global variables by passing down the `hash_algo` through to the functions mentioned and instead calling `hash_to_hex_algop()` along with the obtained `hash_algo`. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 545702e commit e9b91ea

File tree

5 files changed

+37
-29
lines changed

5 files changed

+37
-29
lines changed

midx-write.c

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,10 @@ static int link_midx_to_chain(struct multi_pack_index *m)
991991
for (i = 0; i < ARRAY_SIZE(midx_exts); i++) {
992992
const unsigned char *hash = get_midx_checksum(m);
993993

994-
get_midx_filename_ext(&from, m->object_dir, hash,
995-
midx_exts[i].non_split);
996-
get_split_midx_filename_ext(&to, m->object_dir, hash,
994+
get_midx_filename_ext(m->repo->hash_algo, &from, m->object_dir,
995+
hash, midx_exts[i].non_split);
996+
get_split_midx_filename_ext(m->repo->hash_algo, &to,
997+
m->object_dir, hash,
997998
midx_exts[i].split);
998999

9991000
if (link(from.buf, to.buf) < 0 && errno != ENOENT) {
@@ -1012,9 +1013,8 @@ static int link_midx_to_chain(struct multi_pack_index *m)
10121013
return ret;
10131014
}
10141015

1015-
static void clear_midx_files(const char *object_dir,
1016-
const char **hashes,
1017-
uint32_t hashes_nr,
1016+
static void clear_midx_files(struct repository *r, const char *object_dir,
1017+
const char **hashes, uint32_t hashes_nr,
10181018
unsigned incremental)
10191019
{
10201020
/*
@@ -1039,7 +1039,7 @@ static void clear_midx_files(const char *object_dir,
10391039
}
10401040

10411041
if (incremental)
1042-
get_midx_filename(&buf, object_dir);
1042+
get_midx_filename(r->hash_algo, &buf, object_dir);
10431043
else
10441044
get_midx_chain_filename(&buf, object_dir);
10451045

@@ -1083,7 +1083,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
10831083
"%s/pack/multi-pack-index.d/tmp_midx_XXXXXX",
10841084
object_dir);
10851085
else
1086-
get_midx_filename(&midx_name, object_dir);
1086+
get_midx_filename(r->hash_algo, &midx_name, object_dir);
10871087
if (safe_create_leading_directories(midx_name.buf))
10881088
die_errno(_("unable to create leading directories of %s"),
10891089
midx_name.buf);
@@ -1440,8 +1440,8 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
14401440
if (link_midx_to_chain(ctx.base_midx) < 0)
14411441
return -1;
14421442

1443-
get_split_midx_filename_ext(&final_midx_name, object_dir,
1444-
midx_hash, MIDX_EXT_MIDX);
1443+
get_split_midx_filename_ext(r->hash_algo, &final_midx_name,
1444+
object_dir, midx_hash, MIDX_EXT_MIDX);
14451445

14461446
if (rename_tempfile(&incr, final_midx_name.buf) < 0) {
14471447
error_errno(_("unable to rename new multi-pack-index layer"));
@@ -1474,7 +1474,7 @@ static int write_midx_internal(struct repository *r, const char *object_dir,
14741474
if (commit_lock_file(&lk) < 0)
14751475
die_errno(_("could not write multi-pack-index"));
14761476

1477-
clear_midx_files(object_dir, keep_hashes,
1477+
clear_midx_files(r, object_dir, keep_hashes,
14781478
ctx.num_multi_pack_indexes_before + 1,
14791479
ctx.incremental);
14801480

midx.c

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,19 @@ const unsigned char *get_midx_checksum(struct multi_pack_index *m)
2828
return m->data + m->data_len - m->repo->hash_algo->rawsz;
2929
}
3030

31-
void get_midx_filename(struct strbuf *out, const char *object_dir)
31+
void get_midx_filename(const struct git_hash_algo *hash_algo,
32+
struct strbuf *out, const char *object_dir)
3233
{
33-
get_midx_filename_ext(out, object_dir, NULL, NULL);
34+
get_midx_filename_ext(hash_algo, out, object_dir, NULL, NULL);
3435
}
3536

36-
void get_midx_filename_ext(struct strbuf *out, const char *object_dir,
37+
void get_midx_filename_ext(const struct git_hash_algo *hash_algo,
38+
struct strbuf *out, const char *object_dir,
3739
const unsigned char *hash, const char *ext)
3840
{
3941
strbuf_addf(out, "%s/pack/multi-pack-index", object_dir);
4042
if (ext)
41-
strbuf_addf(out, "-%s.%s", hash_to_hex(hash), ext);
43+
strbuf_addf(out, "-%s.%s", hash_to_hex_algop(hash, hash_algo), ext);
4244
}
4345

4446
static int midx_read_oid_fanout(const unsigned char *chunk_start,
@@ -234,11 +236,13 @@ void get_midx_chain_filename(struct strbuf *buf, const char *object_dir)
234236
strbuf_addstr(buf, "/multi-pack-index-chain");
235237
}
236238

237-
void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,
239+
void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,
240+
struct strbuf *buf, const char *object_dir,
238241
const unsigned char *hash, const char *ext)
239242
{
240243
get_midx_chain_dirname(buf, object_dir);
241-
strbuf_addf(buf, "/multi-pack-index-%s.%s", hash_to_hex(hash), ext);
244+
strbuf_addf(buf, "/multi-pack-index-%s.%s",
245+
hash_to_hex_algop(hash, hash_algo), ext);
242246
}
243247

244248
static int open_multi_pack_index_chain(const struct git_hash_algo *hash_algo,
@@ -326,8 +330,8 @@ static struct multi_pack_index *load_midx_chain_fd_st(struct repository *r,
326330
valid = 0;
327331

328332
strbuf_reset(&buf);
329-
get_split_midx_filename_ext(&buf, object_dir, layer.hash,
330-
MIDX_EXT_MIDX);
333+
get_split_midx_filename_ext(r->hash_algo, &buf, object_dir,
334+
layer.hash, MIDX_EXT_MIDX);
331335
m = load_multi_pack_index_one(r, object_dir, buf.buf, local);
332336

333337
if (m) {
@@ -379,7 +383,7 @@ struct multi_pack_index *load_multi_pack_index(struct repository *r,
379383
struct strbuf midx_name = STRBUF_INIT;
380384
struct multi_pack_index *m;
381385

382-
get_midx_filename(&midx_name, object_dir);
386+
get_midx_filename(r->hash_algo, &midx_name, object_dir);
383387

384388
m = load_multi_pack_index_one(r, object_dir,
385389
midx_name.buf, local);
@@ -822,7 +826,7 @@ void clear_midx_file(struct repository *r)
822826
{
823827
struct strbuf midx = STRBUF_INIT;
824828

825-
get_midx_filename(&midx, r->objects->odb->path);
829+
get_midx_filename(r->hash_algo, &midx, r->objects->odb->path);
826830

827831
if (r->objects && r->objects->multi_pack_index) {
828832
close_midx(r->objects->multi_pack_index);
@@ -891,7 +895,7 @@ int verify_midx_file(struct repository *r, const char *object_dir, unsigned flag
891895
struct stat sb;
892896
struct strbuf filename = STRBUF_INIT;
893897

894-
get_midx_filename(&filename, object_dir);
898+
get_midx_filename(r->hash_algo, &filename, object_dir);
895899

896900
if (!stat(filename.buf, &sb)) {
897901
error(_("multi-pack-index file exists, but failed to parse"));

midx.h

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ struct object_id;
77
struct pack_entry;
88
struct repository;
99
struct bitmapped_pack;
10+
struct git_hash_algo;
1011

1112
#define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
1213
#define MIDX_VERSION 1
@@ -89,12 +90,15 @@ struct multi_pack_index {
8990
#define MIDX_EXT_MIDX "midx"
9091

9192
const unsigned char *get_midx_checksum(struct multi_pack_index *m);
92-
void get_midx_filename(struct strbuf *out, const char *object_dir);
93-
void get_midx_filename_ext(struct strbuf *out, const char *object_dir,
93+
void get_midx_filename(const struct git_hash_algo *hash_algo,
94+
struct strbuf *out, const char *object_dir);
95+
void get_midx_filename_ext(const struct git_hash_algo *hash_algo,
96+
struct strbuf *out, const char *object_dir,
9497
const unsigned char *hash, const char *ext);
9598
void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);
9699
void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);
97-
void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,
100+
void get_split_midx_filename_ext(const struct git_hash_algo *hash_algo,
101+
struct strbuf *buf, const char *object_dir,
98102
const unsigned char *hash, const char *ext);
99103

100104
struct multi_pack_index *load_multi_pack_index(struct repository *r,

pack-bitmap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,8 +375,8 @@ static int load_bitmap_entries_v1(struct bitmap_index *index)
375375
char *midx_bitmap_filename(struct multi_pack_index *midx)
376376
{
377377
struct strbuf buf = STRBUF_INIT;
378-
get_midx_filename_ext(&buf, midx->object_dir, get_midx_checksum(midx),
379-
MIDX_EXT_BITMAP);
378+
get_midx_filename_ext(midx->repo->hash_algo, &buf, midx->object_dir,
379+
get_midx_checksum(midx), MIDX_EXT_BITMAP);
380380

381381
return strbuf_detach(&buf, NULL);
382382
}
@@ -415,7 +415,7 @@ static int open_midx_bitmap_1(struct bitmap_index *bitmap_git,
415415

416416
if (bitmap_git->pack || bitmap_git->midx) {
417417
struct strbuf buf = STRBUF_INIT;
418-
get_midx_filename(&buf, midx->object_dir);
418+
get_midx_filename(midx->repo->hash_algo, &buf, midx->object_dir);
419419
trace2_data_string("bitmap", bitmap_repo(bitmap_git),
420420
"ignoring extra midx bitmap file", buf.buf);
421421
close(fd);

pack-revindex.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ int load_midx_revindex(struct multi_pack_index *m)
383383
trace2_data_string("load_midx_revindex", the_repository,
384384
"source", "rev");
385385

386-
get_midx_filename_ext(&revindex_name, m->object_dir,
386+
get_midx_filename_ext(m->repo->hash_algo, &revindex_name, m->object_dir,
387387
get_midx_checksum(m), MIDX_EXT_REV);
388388

389389
ret = load_revindex_from_disk(revindex_name.buf,

0 commit comments

Comments
 (0)