Skip to content

Commit 3687a4b

Browse files
KarthikNayakgitster
authored andcommitted
midx-write: pass down repository to static functions
In 'midx-write.c' there are a lot of static functions which use global variables `the_repository` or `the_hash_algo`. In a follow up commit, the repository variable will be added to `write_midx_context`, which some of the functions can use. But for functions which do not have access to this struct, pass down the required information from non-static functions `write_midx_file` and `write_midx_file_only`. This requires that the function `hash_to_hex` is also replaced with `hash_to_hex_algop` since the former internally accesses the `the_hash_algo` global variable. This ensures that the usage of global variables is limited to these non-static functions, which will be cleaned up in a follow up commit. Signed-off-by: Karthik Nayak <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aaafb67 commit 3687a4b

File tree

1 file changed

+31
-26
lines changed

1 file changed

+31
-26
lines changed

midx-write.c

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -35,13 +35,13 @@ extern void clear_incremental_midx_files_ext(const char *object_dir,
3535
extern int cmp_idx_or_pack_name(const char *idx_or_pack_name,
3636
const char *idx_name);
3737

38-
static size_t write_midx_header(struct hashfile *f,
39-
unsigned char num_chunks,
38+
static size_t write_midx_header(const struct git_hash_algo *hash_algo,
39+
struct hashfile *f, unsigned char num_chunks,
4040
uint32_t num_packs)
4141
{
4242
hashwrite_be32(f, MIDX_SIGNATURE);
4343
hashwrite_u8(f, MIDX_VERSION);
44-
hashwrite_u8(f, oid_version(the_hash_algo));
44+
hashwrite_u8(f, oid_version(hash_algo));
4545
hashwrite_u8(f, num_chunks);
4646
hashwrite_u8(f, 0); /* unused */
4747
hashwrite_be32(f, num_packs);
@@ -702,7 +702,7 @@ static int add_ref_to_pending(const char *refname, const char *referent UNUSED,
702702
return 0;
703703
}
704704

705-
if (!peel_iterated_oid(the_repository, oid, &peeled))
705+
if (!peel_iterated_oid(revs->repo, oid, &peeled))
706706
oid = &peeled;
707707

708708
object = parse_object_or_die(oid, refname);
@@ -827,7 +827,7 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
827827
return cb.commits;
828828
}
829829

830-
static int write_midx_bitmap(const char *midx_name,
830+
static int write_midx_bitmap(struct repository *r, const char *midx_name,
831831
const unsigned char *midx_hash,
832832
struct packing_data *pdata,
833833
struct commit **commits,
@@ -840,9 +840,9 @@ static int write_midx_bitmap(const char *midx_name,
840840
struct bitmap_writer writer;
841841
struct pack_idx_entry **index;
842842
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
843-
hash_to_hex(midx_hash));
843+
hash_to_hex_algop(midx_hash, r->hash_algo));
844844

845-
trace2_region_enter("midx", "write_midx_bitmap", the_repository);
845+
trace2_region_enter("midx", "write_midx_bitmap", r);
846846

847847
if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
848848
options |= BITMAP_OPT_HASH_CACHE;
@@ -859,7 +859,7 @@ static int write_midx_bitmap(const char *midx_name,
859859
for (i = 0; i < pdata->nr_objects; i++)
860860
index[i] = &pdata->objects[i].idx;
861861

862-
bitmap_writer_init(&writer, the_repository, pdata);
862+
bitmap_writer_init(&writer, r, pdata);
863863
bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);
864864
bitmap_writer_build_type_index(&writer, index);
865865

@@ -892,7 +892,7 @@ static int write_midx_bitmap(const char *midx_name,
892892
free(bitmap_name);
893893
bitmap_writer_free(&writer);
894894

895-
trace2_region_leave("midx", "write_midx_bitmap", the_repository);
895+
trace2_region_leave("midx", "write_midx_bitmap", r);
896896

897897
return ret;
898898
}
@@ -1049,7 +1049,7 @@ static void clear_midx_files(const char *object_dir,
10491049
strbuf_release(&buf);
10501050
}
10511051

1052-
static int write_midx_internal(const char *object_dir,
1052+
static int write_midx_internal(struct repository *r, const char *object_dir,
10531053
struct string_list *packs_to_include,
10541054
struct string_list *packs_to_drop,
10551055
const char *preferred_pack_name,
@@ -1070,7 +1070,8 @@ static int write_midx_internal(const char *object_dir,
10701070
const char **keep_hashes = NULL;
10711071
struct chunkfile *cf;
10721072

1073-
trace2_region_enter("midx", "write_midx_internal", the_repository);
1073+
trace2_region_enter("midx", "write_midx_internal", r);
1074+
10741075

10751076
ctx.incremental = !!(flags & MIDX_WRITE_INCREMENTAL);
10761077
if (ctx.incremental && (flags & MIDX_WRITE_BITMAP))
@@ -1087,8 +1088,7 @@ static int write_midx_internal(const char *object_dir,
10871088
midx_name.buf);
10881089

10891090
if (!packs_to_include || ctx.incremental) {
1090-
struct multi_pack_index *m = lookup_multi_pack_index(the_repository,
1091-
object_dir);
1091+
struct multi_pack_index *m = lookup_multi_pack_index(r, object_dir);
10921092
if (m && !midx_checksum_valid(m)) {
10931093
warning(_("ignoring existing multi-pack-index; checksum mismatch"));
10941094
m = NULL;
@@ -1351,7 +1351,7 @@ static int write_midx_internal(const char *object_dir,
13511351
add_chunk(cf, MIDX_CHUNKID_OIDFANOUT, MIDX_CHUNK_FANOUT_SIZE,
13521352
write_midx_oid_fanout);
13531353
add_chunk(cf, MIDX_CHUNKID_OIDLOOKUP,
1354-
st_mult(ctx.entries_nr, the_hash_algo->rawsz),
1354+
st_mult(ctx.entries_nr, r->hash_algo->rawsz),
13551355
write_midx_oid_lookup);
13561356
add_chunk(cf, MIDX_CHUNKID_OBJECTOFFSETS,
13571357
st_mult(ctx.entries_nr, MIDX_CHUNK_OFFSET_WIDTH),
@@ -1373,7 +1373,8 @@ static int write_midx_internal(const char *object_dir,
13731373
write_midx_bitmapped_packs);
13741374
}
13751375

1376-
write_midx_header(f, get_num_chunks(cf), ctx.nr - dropped_packs);
1376+
write_midx_header(r->hash_algo, f, get_num_chunks(cf),
1377+
ctx.nr - dropped_packs);
13771378
write_chunkfile(cf, &ctx);
13781379

13791380
finalize_hashfile(f, midx_hash, FSYNC_COMPONENT_PACK_METADATA,
@@ -1405,7 +1406,7 @@ static int write_midx_internal(const char *object_dir,
14051406
FREE_AND_NULL(ctx.entries);
14061407
ctx.entries_nr = 0;
14071408

1408-
if (write_midx_bitmap(midx_name.buf, midx_hash, &pdata,
1409+
if (write_midx_bitmap(r, midx_name.buf, midx_hash, &pdata,
14091410
commits, commits_nr, ctx.pack_order,
14101411
flags) < 0) {
14111412
error(_("could not write multi-pack bitmap"));
@@ -1449,20 +1450,21 @@ static int write_midx_internal(const char *object_dir,
14491450
strbuf_release(&final_midx_name);
14501451

14511452
keep_hashes[ctx.num_multi_pack_indexes_before] =
1452-
xstrdup(hash_to_hex(midx_hash));
1453+
xstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));
14531454

14541455
for (i = 0; i < ctx.num_multi_pack_indexes_before; i++) {
14551456
uint32_t j = ctx.num_multi_pack_indexes_before - i - 1;
14561457

1457-
keep_hashes[j] = xstrdup(hash_to_hex(get_midx_checksum(m)));
1458+
keep_hashes[j] = xstrdup(hash_to_hex_algop(get_midx_checksum(m),
1459+
r->hash_algo));
14581460
m = m->base_midx;
14591461
}
14601462

14611463
for (i = 0; i < ctx.num_multi_pack_indexes_before + 1; i++)
14621464
fprintf(get_lock_file_fp(&lk), "%s\n", keep_hashes[i]);
14631465
} else {
14641466
keep_hashes[ctx.num_multi_pack_indexes_before] =
1465-
xstrdup(hash_to_hex(midx_hash));
1467+
xstrdup(hash_to_hex_algop(midx_hash, r->hash_algo));
14661468
}
14671469

14681470
if (ctx.m || ctx.base_midx)
@@ -1495,7 +1497,7 @@ static int write_midx_internal(const char *object_dir,
14951497
}
14961498
strbuf_release(&midx_name);
14971499

1498-
trace2_region_leave("midx", "write_midx_internal", the_repository);
1500+
trace2_region_leave("midx", "write_midx_internal", r);
14991501

15001502
return result;
15011503
}
@@ -1505,8 +1507,8 @@ int write_midx_file(const char *object_dir,
15051507
const char *refs_snapshot,
15061508
unsigned flags)
15071509
{
1508-
return write_midx_internal(object_dir, NULL, NULL, preferred_pack_name,
1509-
refs_snapshot, flags);
1510+
return write_midx_internal(the_repository, object_dir, NULL, NULL,
1511+
preferred_pack_name, refs_snapshot, flags);
15101512
}
15111513

15121514
int write_midx_file_only(const char *object_dir,
@@ -1515,8 +1517,9 @@ int write_midx_file_only(const char *object_dir,
15151517
const char *refs_snapshot,
15161518
unsigned flags)
15171519
{
1518-
return write_midx_internal(object_dir, packs_to_include, NULL,
1519-
preferred_pack_name, refs_snapshot, flags);
1520+
return write_midx_internal(the_repository, object_dir, packs_to_include,
1521+
NULL, preferred_pack_name, refs_snapshot,
1522+
flags);
15201523
}
15211524

15221525
int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags)
@@ -1572,7 +1575,8 @@ int expire_midx_packs(struct repository *r, const char *object_dir, unsigned fla
15721575
free(count);
15731576

15741577
if (packs_to_drop.nr)
1575-
result = write_midx_internal(object_dir, NULL, &packs_to_drop, NULL, NULL, flags);
1578+
result = write_midx_internal(r, object_dir, NULL,
1579+
&packs_to_drop, NULL, NULL, flags);
15761580

15771581
string_list_clear(&packs_to_drop, 0);
15781582

@@ -1769,7 +1773,8 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size,
17691773
goto cleanup;
17701774
}
17711775

1772-
result = write_midx_internal(object_dir, NULL, NULL, NULL, NULL, flags);
1776+
result = write_midx_internal(r, object_dir, NULL, NULL, NULL, NULL,
1777+
flags);
17731778

17741779
cleanup:
17751780
free(include_pack);

0 commit comments

Comments
 (0)