Skip to content

Commit

Permalink
Merge branch 'tb/pack-bitmap-write-cleanups' into seen
Browse files Browse the repository at this point in the history
* tb/pack-bitmap-write-cleanups:
  pack-bitmap: introduce `bitmap_writer_free()`
  pack-bitmap-write.c: avoid uninitialized 'write_as' field
  pack-bitmap: drop unused `max_bitmaps` parameter
  pack-bitmap: avoid use of static `bitmap_writer`
  pack-bitmap-write.c: move commit_positions into commit_pos fields
  object.h: add flags allocated by pack-bitmap.h
  • Loading branch information
gitster committed May 15, 2024
2 parents 65b9e5f + 85f360f commit b266054
Show file tree
Hide file tree
Showing 5 changed files with 185 additions and 138 deletions.
19 changes: 13 additions & 6 deletions builtin/pack-objects.c
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ static void write_pack_file(void)
if (!pack_to_stdout) {
struct stat st;
struct strbuf tmpname = STRBUF_INIT;
struct bitmap_writer bitmap_writer;
char *idx_tmp_name = NULL;

/*
Expand All @@ -1340,8 +1341,9 @@ static void write_pack_file(void)
hash_to_hex(hash));

if (write_bitmap_index) {
bitmap_writer_set_checksum(hash);
bitmap_writer_build_type_index(
bitmap_writer_init(&bitmap_writer);
bitmap_writer_set_checksum(&bitmap_writer, hash);
bitmap_writer_build_type_index(&bitmap_writer,
&to_pack, written_list, nr_written);
}

Expand All @@ -1359,12 +1361,17 @@ static void write_pack_file(void)
strbuf_addstr(&tmpname, "bitmap");
stop_progress(&progress_state);

bitmap_writer_show_progress(progress);
bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1);
if (bitmap_writer_build(&to_pack) < 0)
bitmap_writer_show_progress(&bitmap_writer,
progress);
bitmap_writer_select_commits(&bitmap_writer,
indexed_commits,
indexed_commits_nr);
if (bitmap_writer_build(&bitmap_writer, &to_pack) < 0)
die(_("failed to write bitmap index"));
bitmap_writer_finish(written_list, nr_written,
bitmap_writer_finish(&bitmap_writer,
written_list, nr_written,
tmpname.buf, write_bitmap_options);
bitmap_writer_free(&bitmap_writer);
write_bitmap_index = 0;
strbuf_setlen(&tmpname, tmpname_len);
}
Expand Down
17 changes: 11 additions & 6 deletions midx-write.c
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ static int write_midx_bitmap(const char *midx_name,
{
int ret, i;
uint16_t options = 0;
struct bitmap_writer writer;
struct pack_idx_entry **index;
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
hash_to_hex(midx_hash));
Expand All @@ -820,8 +821,10 @@ static int write_midx_bitmap(const char *midx_name,
for (i = 0; i < pdata->nr_objects; i++)
index[i] = &pdata->objects[i].idx;

bitmap_writer_show_progress(flags & MIDX_PROGRESS);
bitmap_writer_build_type_index(pdata, index, pdata->nr_objects);
bitmap_writer_init(&writer);
bitmap_writer_show_progress(&writer, flags & MIDX_PROGRESS);
bitmap_writer_build_type_index(&writer, pdata, index,
pdata->nr_objects);

/*
* bitmap_writer_finish expects objects in lex order, but pack_order
Expand All @@ -839,17 +842,19 @@ static int write_midx_bitmap(const char *midx_name,
for (i = 0; i < pdata->nr_objects; i++)
index[pack_order[i]] = &pdata->objects[i].idx;

bitmap_writer_select_commits(commits, commits_nr, -1);
ret = bitmap_writer_build(pdata);
bitmap_writer_select_commits(&writer, commits, commits_nr);
ret = bitmap_writer_build(&writer, pdata);
if (ret < 0)
goto cleanup;

bitmap_writer_set_checksum(midx_hash);
bitmap_writer_finish(index, pdata->nr_objects, bitmap_name, options);
bitmap_writer_set_checksum(&writer, midx_hash);
bitmap_writer_finish(&writer, index, pdata->nr_objects, bitmap_name,
options);

cleanup:
free(index);
free(bitmap_name);
bitmap_writer_free(&writer);

trace2_region_leave("midx", "write_midx_bitmap", the_repository);

Expand Down
1 change: 1 addition & 0 deletions object.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ void object_array_init(struct object_array *array);
* reflog.c: 10--12
* builtin/show-branch.c: 0-------------------------------------------26
* builtin/unpack-objects.c: 2021
* pack-bitmap.h: 22
*/
#define FLAG_BITS 28

Expand Down

0 comments on commit b266054

Please sign in to comment.