Skip to content

Commit 90b2bb7

Browse files
derrickstoleegitster
authored andcommitted
midx: extract bitmap write setup
The write_midx_bitmap() method is a long method that does a lot of steps. It requires the write_midx_context struct for use in prepare_midx_packing_data() and find_commits_for_midx_bitmap(), but after that only needs the pack_order array. This is a messy, but completely non-functional refactoring. The code is only being moved around to reduce visibility of the write_midx_context during the longest part of computing reachability bitmaps. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5766524 commit 90b2bb7

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

midx.c

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1053,40 +1053,35 @@ static struct commit **find_commits_for_midx_bitmap(uint32_t *indexed_commits_nr
10531053
return cb.commits;
10541054
}
10551055

1056-
static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
1057-
struct write_midx_context *ctx,
1056+
static int write_midx_bitmap(const char *midx_name,
1057+
const unsigned char *midx_hash,
1058+
struct packing_data *pdata,
1059+
struct commit **commits,
1060+
uint32_t commits_nr,
1061+
uint32_t *pack_order,
10581062
const char *refs_snapshot,
10591063
unsigned flags)
10601064
{
1061-
struct packing_data pdata;
1062-
struct pack_idx_entry **index;
1063-
struct commit **commits = NULL;
1064-
uint32_t i, commits_nr;
1065+
int ret, i;
10651066
uint16_t options = 0;
1066-
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name, hash_to_hex(midx_hash));
1067-
int ret;
1068-
1069-
if (!ctx->entries_nr)
1070-
BUG("cannot write a bitmap without any objects");
1067+
struct pack_idx_entry **index;
1068+
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
1069+
hash_to_hex(midx_hash));
10711070

10721071
if (flags & MIDX_WRITE_BITMAP_HASH_CACHE)
10731072
options |= BITMAP_OPT_HASH_CACHE;
10741073

1075-
prepare_midx_packing_data(&pdata, ctx);
1076-
1077-
commits = find_commits_for_midx_bitmap(&commits_nr, refs_snapshot, ctx);
1078-
10791074
/*
10801075
* Build the MIDX-order index based on pdata.objects (which is already
10811076
* in MIDX order; c.f., 'midx_pack_order_cmp()' for the definition of
10821077
* this order).
10831078
*/
1084-
ALLOC_ARRAY(index, pdata.nr_objects);
1085-
for (i = 0; i < pdata.nr_objects; i++)
1086-
index[i] = &pdata.objects[i].idx;
1079+
ALLOC_ARRAY(index, pdata->nr_objects);
1080+
for (i = 0; i < pdata->nr_objects; i++)
1081+
index[i] = &pdata->objects[i].idx;
10871082

10881083
bitmap_writer_show_progress(flags & MIDX_PROGRESS);
1089-
bitmap_writer_build_type_index(&pdata, index, pdata.nr_objects);
1084+
bitmap_writer_build_type_index(pdata, index, pdata->nr_objects);
10901085

10911086
/*
10921087
* bitmap_writer_finish expects objects in lex order, but pack_order
@@ -1101,16 +1096,16 @@ static int write_midx_bitmap(char *midx_name, unsigned char *midx_hash,
11011096
* happens between bitmap_writer_build_type_index() and
11021097
* bitmap_writer_finish().
11031098
*/
1104-
for (i = 0; i < pdata.nr_objects; i++)
1105-
index[ctx->pack_order[i]] = &pdata.objects[i].idx;
1099+
for (i = 0; i < pdata->nr_objects; i++)
1100+
index[pack_order[i]] = &pdata->objects[i].idx;
11061101

11071102
bitmap_writer_select_commits(commits, commits_nr, -1);
1108-
ret = bitmap_writer_build(&pdata);
1103+
ret = bitmap_writer_build(pdata);
11091104
if (ret < 0)
11101105
goto cleanup;
11111106

11121107
bitmap_writer_set_checksum(midx_hash);
1113-
bitmap_writer_finish(index, pdata.nr_objects, bitmap_name, options);
1108+
bitmap_writer_finish(index, pdata->nr_objects, bitmap_name, options);
11141109

11151110
cleanup:
11161111
free(index);
@@ -1443,8 +1438,21 @@ static int write_midx_internal(const char *object_dir,
14431438
if (flags & MIDX_WRITE_REV_INDEX &&
14441439
git_env_bool("GIT_TEST_MIDX_WRITE_REV", 0))
14451440
write_midx_reverse_index(midx_name.buf, midx_hash, &ctx);
1441+
14461442
if (flags & MIDX_WRITE_BITMAP) {
1447-
if (write_midx_bitmap(midx_name.buf, midx_hash, &ctx,
1443+
struct packing_data pdata;
1444+
struct commit **commits;
1445+
uint32_t commits_nr;
1446+
1447+
if (!ctx.entries_nr)
1448+
BUG("cannot write a bitmap without any objects");
1449+
1450+
prepare_midx_packing_data(&pdata, &ctx);
1451+
1452+
commits = find_commits_for_midx_bitmap(&commits_nr, refs_snapshot, &ctx);
1453+
1454+
if (write_midx_bitmap(midx_name.buf, midx_hash, &pdata,
1455+
commits, commits_nr, ctx.pack_order,
14481456
refs_snapshot, flags) < 0) {
14491457
error(_("could not write multi-pack bitmap"));
14501458
result = 1;

0 commit comments

Comments
 (0)