Merge branch 'tb/pack-bitmap-write-cleanups'
The pack bitmap code saw some clean-up to prepare for a follow-up topic. * 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.hmaint
commit
ee8537ebc9
|
@ -1315,6 +1315,7 @@ static void write_pack_file(void)
|
||||||
if (!pack_to_stdout) {
|
if (!pack_to_stdout) {
|
||||||
struct stat st;
|
struct stat st;
|
||||||
struct strbuf tmpname = STRBUF_INIT;
|
struct strbuf tmpname = STRBUF_INIT;
|
||||||
|
struct bitmap_writer bitmap_writer;
|
||||||
char *idx_tmp_name = NULL;
|
char *idx_tmp_name = NULL;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1340,8 +1341,9 @@ static void write_pack_file(void)
|
||||||
hash_to_hex(hash));
|
hash_to_hex(hash));
|
||||||
|
|
||||||
if (write_bitmap_index) {
|
if (write_bitmap_index) {
|
||||||
bitmap_writer_set_checksum(hash);
|
bitmap_writer_init(&bitmap_writer);
|
||||||
bitmap_writer_build_type_index(
|
bitmap_writer_set_checksum(&bitmap_writer, hash);
|
||||||
|
bitmap_writer_build_type_index(&bitmap_writer,
|
||||||
&to_pack, written_list, nr_written);
|
&to_pack, written_list, nr_written);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1359,12 +1361,17 @@ static void write_pack_file(void)
|
||||||
strbuf_addstr(&tmpname, "bitmap");
|
strbuf_addstr(&tmpname, "bitmap");
|
||||||
stop_progress(&progress_state);
|
stop_progress(&progress_state);
|
||||||
|
|
||||||
bitmap_writer_show_progress(progress);
|
bitmap_writer_show_progress(&bitmap_writer,
|
||||||
bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1);
|
progress);
|
||||||
if (bitmap_writer_build(&to_pack) < 0)
|
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"));
|
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);
|
tmpname.buf, write_bitmap_options);
|
||||||
|
bitmap_writer_free(&bitmap_writer);
|
||||||
write_bitmap_index = 0;
|
write_bitmap_index = 0;
|
||||||
strbuf_setlen(&tmpname, tmpname_len);
|
strbuf_setlen(&tmpname, tmpname_len);
|
||||||
}
|
}
|
||||||
|
|
17
midx-write.c
17
midx-write.c
|
@ -799,6 +799,7 @@ static int write_midx_bitmap(const char *midx_name,
|
||||||
{
|
{
|
||||||
int ret, i;
|
int ret, i;
|
||||||
uint16_t options = 0;
|
uint16_t options = 0;
|
||||||
|
struct bitmap_writer writer;
|
||||||
struct pack_idx_entry **index;
|
struct pack_idx_entry **index;
|
||||||
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
|
char *bitmap_name = xstrfmt("%s-%s.bitmap", midx_name,
|
||||||
hash_to_hex(midx_hash));
|
hash_to_hex(midx_hash));
|
||||||
|
@ -820,8 +821,10 @@ static int write_midx_bitmap(const char *midx_name,
|
||||||
for (i = 0; i < pdata->nr_objects; i++)
|
for (i = 0; i < pdata->nr_objects; i++)
|
||||||
index[i] = &pdata->objects[i].idx;
|
index[i] = &pdata->objects[i].idx;
|
||||||
|
|
||||||
bitmap_writer_show_progress(flags & MIDX_PROGRESS);
|
bitmap_writer_init(&writer);
|
||||||
bitmap_writer_build_type_index(pdata, index, pdata->nr_objects);
|
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
|
* bitmap_writer_finish expects objects in lex order, but pack_order
|
||||||
|
@ -839,17 +842,19 @@ static int write_midx_bitmap(const char *midx_name,
|
||||||
for (i = 0; i < pdata->nr_objects; i++)
|
for (i = 0; i < pdata->nr_objects; i++)
|
||||||
index[pack_order[i]] = &pdata->objects[i].idx;
|
index[pack_order[i]] = &pdata->objects[i].idx;
|
||||||
|
|
||||||
bitmap_writer_select_commits(commits, commits_nr, -1);
|
bitmap_writer_select_commits(&writer, commits, commits_nr);
|
||||||
ret = bitmap_writer_build(pdata);
|
ret = bitmap_writer_build(&writer, pdata);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
bitmap_writer_set_checksum(midx_hash);
|
bitmap_writer_set_checksum(&writer, midx_hash);
|
||||||
bitmap_writer_finish(index, pdata->nr_objects, bitmap_name, options);
|
bitmap_writer_finish(&writer, index, pdata->nr_objects, bitmap_name,
|
||||||
|
options);
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
free(index);
|
free(index);
|
||||||
free(bitmap_name);
|
free(bitmap_name);
|
||||||
|
bitmap_writer_free(&writer);
|
||||||
|
|
||||||
trace2_region_leave("midx", "write_midx_bitmap", the_repository);
|
trace2_region_leave("midx", "write_midx_bitmap", the_repository);
|
||||||
|
|
||||||
|
|
1
object.h
1
object.h
|
@ -81,6 +81,7 @@ void object_array_init(struct object_array *array);
|
||||||
* reflog.c: 10--12
|
* reflog.c: 10--12
|
||||||
* builtin/show-branch.c: 0-------------------------------------------26
|
* builtin/show-branch.c: 0-------------------------------------------26
|
||||||
* builtin/unpack-objects.c: 2021
|
* builtin/unpack-objects.c: 2021
|
||||||
|
* pack-bitmap.h: 22
|
||||||
*/
|
*/
|
||||||
#define FLAG_BITS 28
|
#define FLAG_BITS 28
|
||||||
|
|
||||||
|
|
|
@ -27,43 +27,53 @@ struct bitmapped_commit {
|
||||||
uint32_t commit_pos;
|
uint32_t commit_pos;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct bitmap_writer {
|
void bitmap_writer_init(struct bitmap_writer *writer)
|
||||||
struct ewah_bitmap *commits;
|
|
||||||
struct ewah_bitmap *trees;
|
|
||||||
struct ewah_bitmap *blobs;
|
|
||||||
struct ewah_bitmap *tags;
|
|
||||||
|
|
||||||
kh_oid_map_t *bitmaps;
|
|
||||||
struct packing_data *to_pack;
|
|
||||||
|
|
||||||
struct bitmapped_commit *selected;
|
|
||||||
unsigned int selected_nr, selected_alloc;
|
|
||||||
|
|
||||||
struct progress *progress;
|
|
||||||
int show_progress;
|
|
||||||
unsigned char pack_checksum[GIT_MAX_RAWSZ];
|
|
||||||
};
|
|
||||||
|
|
||||||
static struct bitmap_writer writer;
|
|
||||||
|
|
||||||
void bitmap_writer_show_progress(int show)
|
|
||||||
{
|
{
|
||||||
writer.show_progress = show;
|
memset(writer, 0, sizeof(struct bitmap_writer));
|
||||||
|
}
|
||||||
|
|
||||||
|
void bitmap_writer_free(struct bitmap_writer *writer)
|
||||||
|
{
|
||||||
|
uint32_t i;
|
||||||
|
|
||||||
|
if (!writer)
|
||||||
|
return;
|
||||||
|
|
||||||
|
ewah_free(writer->commits);
|
||||||
|
ewah_free(writer->trees);
|
||||||
|
ewah_free(writer->blobs);
|
||||||
|
ewah_free(writer->tags);
|
||||||
|
|
||||||
|
kh_destroy_oid_map(writer->bitmaps);
|
||||||
|
|
||||||
|
for (i = 0; i < writer->selected_nr; i++) {
|
||||||
|
struct bitmapped_commit *bc = &writer->selected[i];
|
||||||
|
if (bc->write_as != bc->bitmap)
|
||||||
|
ewah_free(bc->write_as);
|
||||||
|
ewah_free(bc->bitmap);
|
||||||
|
}
|
||||||
|
free(writer->selected);
|
||||||
|
}
|
||||||
|
|
||||||
|
void bitmap_writer_show_progress(struct bitmap_writer *writer, int show)
|
||||||
|
{
|
||||||
|
writer->show_progress = show;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Build the initial type index for the packfile or multi-pack-index
|
* Build the initial type index for the packfile or multi-pack-index
|
||||||
*/
|
*/
|
||||||
void bitmap_writer_build_type_index(struct packing_data *to_pack,
|
void bitmap_writer_build_type_index(struct bitmap_writer *writer,
|
||||||
|
struct packing_data *to_pack,
|
||||||
struct pack_idx_entry **index,
|
struct pack_idx_entry **index,
|
||||||
uint32_t index_nr)
|
uint32_t index_nr)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
writer.commits = ewah_new();
|
writer->commits = ewah_new();
|
||||||
writer.trees = ewah_new();
|
writer->trees = ewah_new();
|
||||||
writer.blobs = ewah_new();
|
writer->blobs = ewah_new();
|
||||||
writer.tags = ewah_new();
|
writer->tags = ewah_new();
|
||||||
ALLOC_ARRAY(to_pack->in_pack_pos, to_pack->nr_objects);
|
ALLOC_ARRAY(to_pack->in_pack_pos, to_pack->nr_objects);
|
||||||
|
|
||||||
for (i = 0; i < index_nr; ++i) {
|
for (i = 0; i < index_nr; ++i) {
|
||||||
|
@ -88,19 +98,19 @@ void bitmap_writer_build_type_index(struct packing_data *to_pack,
|
||||||
|
|
||||||
switch (real_type) {
|
switch (real_type) {
|
||||||
case OBJ_COMMIT:
|
case OBJ_COMMIT:
|
||||||
ewah_set(writer.commits, i);
|
ewah_set(writer->commits, i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OBJ_TREE:
|
case OBJ_TREE:
|
||||||
ewah_set(writer.trees, i);
|
ewah_set(writer->trees, i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OBJ_BLOB:
|
case OBJ_BLOB:
|
||||||
ewah_set(writer.blobs, i);
|
ewah_set(writer->blobs, i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OBJ_TAG:
|
case OBJ_TAG:
|
||||||
ewah_set(writer.tags, i);
|
ewah_set(writer->tags, i);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -115,23 +125,26 @@ void bitmap_writer_build_type_index(struct packing_data *to_pack,
|
||||||
* Compute the actual bitmaps
|
* Compute the actual bitmaps
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static inline void push_bitmapped_commit(struct commit *commit)
|
static inline void push_bitmapped_commit(struct bitmap_writer *writer,
|
||||||
|
struct commit *commit)
|
||||||
{
|
{
|
||||||
if (writer.selected_nr >= writer.selected_alloc) {
|
if (writer->selected_nr >= writer->selected_alloc) {
|
||||||
writer.selected_alloc = (writer.selected_alloc + 32) * 2;
|
writer->selected_alloc = (writer->selected_alloc + 32) * 2;
|
||||||
REALLOC_ARRAY(writer.selected, writer.selected_alloc);
|
REALLOC_ARRAY(writer->selected, writer->selected_alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
writer.selected[writer.selected_nr].commit = commit;
|
writer->selected[writer->selected_nr].commit = commit;
|
||||||
writer.selected[writer.selected_nr].bitmap = NULL;
|
writer->selected[writer->selected_nr].bitmap = NULL;
|
||||||
writer.selected[writer.selected_nr].flags = 0;
|
writer->selected[writer->selected_nr].write_as = NULL;
|
||||||
|
writer->selected[writer->selected_nr].flags = 0;
|
||||||
|
|
||||||
writer.selected_nr++;
|
writer->selected_nr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint32_t find_object_pos(const struct object_id *oid, int *found)
|
static uint32_t find_object_pos(struct bitmap_writer *writer,
|
||||||
|
const struct object_id *oid, int *found)
|
||||||
{
|
{
|
||||||
struct object_entry *entry = packlist_find(writer.to_pack, oid);
|
struct object_entry *entry = packlist_find(writer->to_pack, oid);
|
||||||
|
|
||||||
if (!entry) {
|
if (!entry) {
|
||||||
if (found)
|
if (found)
|
||||||
|
@ -143,17 +156,17 @@ static uint32_t find_object_pos(const struct object_id *oid, int *found)
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
*found = 1;
|
*found = 1;
|
||||||
return oe_in_pack_pos(writer.to_pack, entry);
|
return oe_in_pack_pos(writer->to_pack, entry);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void compute_xor_offsets(void)
|
static void compute_xor_offsets(struct bitmap_writer *writer)
|
||||||
{
|
{
|
||||||
static const int MAX_XOR_OFFSET_SEARCH = 10;
|
static const int MAX_XOR_OFFSET_SEARCH = 10;
|
||||||
|
|
||||||
int i, next = 0;
|
int i, next = 0;
|
||||||
|
|
||||||
while (next < writer.selected_nr) {
|
while (next < writer->selected_nr) {
|
||||||
struct bitmapped_commit *stored = &writer.selected[next];
|
struct bitmapped_commit *stored = &writer->selected[next];
|
||||||
|
|
||||||
int best_offset = 0;
|
int best_offset = 0;
|
||||||
struct ewah_bitmap *best_bitmap = stored->bitmap;
|
struct ewah_bitmap *best_bitmap = stored->bitmap;
|
||||||
|
@ -166,7 +179,7 @@ static void compute_xor_offsets(void)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
test_xor = ewah_pool_new();
|
test_xor = ewah_pool_new();
|
||||||
ewah_xor(writer.selected[curr].bitmap, stored->bitmap, test_xor);
|
ewah_xor(writer->selected[curr].bitmap, stored->bitmap, test_xor);
|
||||||
|
|
||||||
if (test_xor->buffer_size < best_bitmap->buffer_size) {
|
if (test_xor->buffer_size < best_bitmap->buffer_size) {
|
||||||
if (best_bitmap != stored->bitmap)
|
if (best_bitmap != stored->bitmap)
|
||||||
|
@ -348,7 +361,8 @@ static void bitmap_builder_clear(struct bitmap_builder *bb)
|
||||||
bb->commits_nr = bb->commits_alloc = 0;
|
bb->commits_nr = bb->commits_alloc = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int fill_bitmap_tree(struct bitmap *bitmap,
|
static int fill_bitmap_tree(struct bitmap_writer *writer,
|
||||||
|
struct bitmap *bitmap,
|
||||||
struct tree *tree)
|
struct tree *tree)
|
||||||
{
|
{
|
||||||
int found;
|
int found;
|
||||||
|
@ -360,7 +374,7 @@ static int fill_bitmap_tree(struct bitmap *bitmap,
|
||||||
* If our bit is already set, then there is nothing to do. Both this
|
* If our bit is already set, then there is nothing to do. Both this
|
||||||
* tree and all of its children will be set.
|
* tree and all of its children will be set.
|
||||||
*/
|
*/
|
||||||
pos = find_object_pos(&tree->object.oid, &found);
|
pos = find_object_pos(writer, &tree->object.oid, &found);
|
||||||
if (!found)
|
if (!found)
|
||||||
return -1;
|
return -1;
|
||||||
if (bitmap_get(bitmap, pos))
|
if (bitmap_get(bitmap, pos))
|
||||||
|
@ -375,12 +389,12 @@ static int fill_bitmap_tree(struct bitmap *bitmap,
|
||||||
while (tree_entry(&desc, &entry)) {
|
while (tree_entry(&desc, &entry)) {
|
||||||
switch (object_type(entry.mode)) {
|
switch (object_type(entry.mode)) {
|
||||||
case OBJ_TREE:
|
case OBJ_TREE:
|
||||||
if (fill_bitmap_tree(bitmap,
|
if (fill_bitmap_tree(writer, bitmap,
|
||||||
lookup_tree(the_repository, &entry.oid)) < 0)
|
lookup_tree(the_repository, &entry.oid)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
break;
|
break;
|
||||||
case OBJ_BLOB:
|
case OBJ_BLOB:
|
||||||
pos = find_object_pos(&entry.oid, &found);
|
pos = find_object_pos(writer, &entry.oid, &found);
|
||||||
if (!found)
|
if (!found)
|
||||||
return -1;
|
return -1;
|
||||||
bitmap_set(bitmap, pos);
|
bitmap_set(bitmap, pos);
|
||||||
|
@ -397,7 +411,8 @@ static int fill_bitmap_tree(struct bitmap *bitmap,
|
||||||
|
|
||||||
static int reused_bitmaps_nr;
|
static int reused_bitmaps_nr;
|
||||||
|
|
||||||
static int fill_bitmap_commit(struct bb_commit *ent,
|
static int fill_bitmap_commit(struct bitmap_writer *writer,
|
||||||
|
struct bb_commit *ent,
|
||||||
struct commit *commit,
|
struct commit *commit,
|
||||||
struct prio_queue *queue,
|
struct prio_queue *queue,
|
||||||
struct prio_queue *tree_queue,
|
struct prio_queue *tree_queue,
|
||||||
|
@ -436,7 +451,7 @@ static int fill_bitmap_commit(struct bb_commit *ent,
|
||||||
* Mark ourselves and queue our tree. The commit
|
* Mark ourselves and queue our tree. The commit
|
||||||
* walk ensures we cover all parents.
|
* walk ensures we cover all parents.
|
||||||
*/
|
*/
|
||||||
pos = find_object_pos(&c->object.oid, &found);
|
pos = find_object_pos(writer, &c->object.oid, &found);
|
||||||
if (!found)
|
if (!found)
|
||||||
return -1;
|
return -1;
|
||||||
bitmap_set(ent->bitmap, pos);
|
bitmap_set(ent->bitmap, pos);
|
||||||
|
@ -444,7 +459,8 @@ static int fill_bitmap_commit(struct bb_commit *ent,
|
||||||
repo_get_commit_tree(the_repository, c));
|
repo_get_commit_tree(the_repository, c));
|
||||||
|
|
||||||
for (p = c->parents; p; p = p->next) {
|
for (p = c->parents; p; p = p->next) {
|
||||||
pos = find_object_pos(&p->item->object.oid, &found);
|
pos = find_object_pos(writer, &p->item->object.oid,
|
||||||
|
&found);
|
||||||
if (!found)
|
if (!found)
|
||||||
return -1;
|
return -1;
|
||||||
if (!bitmap_get(ent->bitmap, pos)) {
|
if (!bitmap_get(ent->bitmap, pos)) {
|
||||||
|
@ -455,29 +471,31 @@ static int fill_bitmap_commit(struct bb_commit *ent,
|
||||||
}
|
}
|
||||||
|
|
||||||
while (tree_queue->nr) {
|
while (tree_queue->nr) {
|
||||||
if (fill_bitmap_tree(ent->bitmap,
|
if (fill_bitmap_tree(writer, ent->bitmap,
|
||||||
prio_queue_get(tree_queue)) < 0)
|
prio_queue_get(tree_queue)) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void store_selected(struct bb_commit *ent, struct commit *commit)
|
static void store_selected(struct bitmap_writer *writer,
|
||||||
|
struct bb_commit *ent, struct commit *commit)
|
||||||
{
|
{
|
||||||
struct bitmapped_commit *stored = &writer.selected[ent->idx];
|
struct bitmapped_commit *stored = &writer->selected[ent->idx];
|
||||||
khiter_t hash_pos;
|
khiter_t hash_pos;
|
||||||
int hash_ret;
|
int hash_ret;
|
||||||
|
|
||||||
stored->bitmap = bitmap_to_ewah(ent->bitmap);
|
stored->bitmap = bitmap_to_ewah(ent->bitmap);
|
||||||
|
|
||||||
hash_pos = kh_put_oid_map(writer.bitmaps, commit->object.oid, &hash_ret);
|
hash_pos = kh_put_oid_map(writer->bitmaps, commit->object.oid, &hash_ret);
|
||||||
if (hash_ret == 0)
|
if (hash_ret == 0)
|
||||||
die("Duplicate entry when writing index: %s",
|
die("Duplicate entry when writing index: %s",
|
||||||
oid_to_hex(&commit->object.oid));
|
oid_to_hex(&commit->object.oid));
|
||||||
kh_value(writer.bitmaps, hash_pos) = stored;
|
kh_value(writer->bitmaps, hash_pos) = stored;
|
||||||
}
|
}
|
||||||
|
|
||||||
int bitmap_writer_build(struct packing_data *to_pack)
|
int bitmap_writer_build(struct bitmap_writer *writer,
|
||||||
|
struct packing_data *to_pack)
|
||||||
{
|
{
|
||||||
struct bitmap_builder bb;
|
struct bitmap_builder bb;
|
||||||
size_t i;
|
size_t i;
|
||||||
|
@ -488,11 +506,12 @@ int bitmap_writer_build(struct packing_data *to_pack)
|
||||||
uint32_t *mapping;
|
uint32_t *mapping;
|
||||||
int closed = 1; /* until proven otherwise */
|
int closed = 1; /* until proven otherwise */
|
||||||
|
|
||||||
writer.bitmaps = kh_init_oid_map();
|
writer->bitmaps = kh_init_oid_map();
|
||||||
writer.to_pack = to_pack;
|
writer->to_pack = to_pack;
|
||||||
|
|
||||||
if (writer.show_progress)
|
if (writer->show_progress)
|
||||||
writer.progress = start_progress("Building bitmaps", writer.selected_nr);
|
writer->progress = start_progress("Building bitmaps",
|
||||||
|
writer->selected_nr);
|
||||||
trace2_region_enter("pack-bitmap-write", "building_bitmaps_total",
|
trace2_region_enter("pack-bitmap-write", "building_bitmaps_total",
|
||||||
the_repository);
|
the_repository);
|
||||||
|
|
||||||
|
@ -502,23 +521,23 @@ int bitmap_writer_build(struct packing_data *to_pack)
|
||||||
else
|
else
|
||||||
mapping = NULL;
|
mapping = NULL;
|
||||||
|
|
||||||
bitmap_builder_init(&bb, &writer, old_bitmap);
|
bitmap_builder_init(&bb, writer, old_bitmap);
|
||||||
for (i = bb.commits_nr; i > 0; i--) {
|
for (i = bb.commits_nr; i > 0; i--) {
|
||||||
struct commit *commit = bb.commits[i-1];
|
struct commit *commit = bb.commits[i-1];
|
||||||
struct bb_commit *ent = bb_data_at(&bb.data, commit);
|
struct bb_commit *ent = bb_data_at(&bb.data, commit);
|
||||||
struct commit *child;
|
struct commit *child;
|
||||||
int reused = 0;
|
int reused = 0;
|
||||||
|
|
||||||
if (fill_bitmap_commit(ent, commit, &queue, &tree_queue,
|
if (fill_bitmap_commit(writer, ent, commit, &queue, &tree_queue,
|
||||||
old_bitmap, mapping) < 0) {
|
old_bitmap, mapping) < 0) {
|
||||||
closed = 0;
|
closed = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ent->selected) {
|
if (ent->selected) {
|
||||||
store_selected(ent, commit);
|
store_selected(writer, ent, commit);
|
||||||
nr_stored++;
|
nr_stored++;
|
||||||
display_progress(writer.progress, nr_stored);
|
display_progress(writer->progress, nr_stored);
|
||||||
}
|
}
|
||||||
|
|
||||||
while ((child = pop_commit(&ent->reverse_edges))) {
|
while ((child = pop_commit(&ent->reverse_edges))) {
|
||||||
|
@ -549,10 +568,10 @@ int bitmap_writer_build(struct packing_data *to_pack)
|
||||||
trace2_data_intmax("pack-bitmap-write", the_repository,
|
trace2_data_intmax("pack-bitmap-write", the_repository,
|
||||||
"building_bitmaps_reused", reused_bitmaps_nr);
|
"building_bitmaps_reused", reused_bitmaps_nr);
|
||||||
|
|
||||||
stop_progress(&writer.progress);
|
stop_progress(&writer->progress);
|
||||||
|
|
||||||
if (closed)
|
if (closed)
|
||||||
compute_xor_offsets();
|
compute_xor_offsets(writer);
|
||||||
return closed ? 0 : -1;
|
return closed ? 0 : -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -590,9 +609,9 @@ static int date_compare(const void *_a, const void *_b)
|
||||||
return (long)b->date - (long)a->date;
|
return (long)b->date - (long)a->date;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitmap_writer_select_commits(struct commit **indexed_commits,
|
void bitmap_writer_select_commits(struct bitmap_writer *writer,
|
||||||
unsigned int indexed_commits_nr,
|
struct commit **indexed_commits,
|
||||||
int max_bitmaps)
|
unsigned int indexed_commits_nr)
|
||||||
{
|
{
|
||||||
unsigned int i = 0, j, next;
|
unsigned int i = 0, j, next;
|
||||||
|
|
||||||
|
@ -600,12 +619,12 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,
|
||||||
|
|
||||||
if (indexed_commits_nr < 100) {
|
if (indexed_commits_nr < 100) {
|
||||||
for (i = 0; i < indexed_commits_nr; ++i)
|
for (i = 0; i < indexed_commits_nr; ++i)
|
||||||
push_bitmapped_commit(indexed_commits[i]);
|
push_bitmapped_commit(writer, indexed_commits[i]);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (writer.show_progress)
|
if (writer->show_progress)
|
||||||
writer.progress = start_progress("Selecting bitmap commits", 0);
|
writer->progress = start_progress("Selecting bitmap commits", 0);
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
struct commit *chosen = NULL;
|
struct commit *chosen = NULL;
|
||||||
|
@ -615,11 +634,6 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,
|
||||||
if (i + next >= indexed_commits_nr)
|
if (i + next >= indexed_commits_nr)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (max_bitmaps > 0 && writer.selected_nr >= max_bitmaps) {
|
|
||||||
writer.selected_nr = max_bitmaps;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (next == 0) {
|
if (next == 0) {
|
||||||
chosen = indexed_commits[i];
|
chosen = indexed_commits[i];
|
||||||
} else {
|
} else {
|
||||||
|
@ -638,13 +652,13 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
push_bitmapped_commit(chosen);
|
push_bitmapped_commit(writer, chosen);
|
||||||
|
|
||||||
i += next + 1;
|
i += next + 1;
|
||||||
display_progress(writer.progress, i);
|
display_progress(writer->progress, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
stop_progress(&writer.progress);
|
stop_progress(&writer->progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -670,19 +684,18 @@ static const struct object_id *oid_access(size_t pos, const void *table)
|
||||||
return &index[pos]->oid;
|
return &index[pos]->oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_selected_commits_v1(struct hashfile *f,
|
static void write_selected_commits_v1(struct bitmap_writer *writer,
|
||||||
uint32_t *commit_positions,
|
struct hashfile *f, off_t *offsets)
|
||||||
off_t *offsets)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < writer.selected_nr; ++i) {
|
for (i = 0; i < writer->selected_nr; ++i) {
|
||||||
struct bitmapped_commit *stored = &writer.selected[i];
|
struct bitmapped_commit *stored = &writer->selected[i];
|
||||||
|
|
||||||
if (offsets)
|
if (offsets)
|
||||||
offsets[i] = hashfile_total(f);
|
offsets[i] = hashfile_total(f);
|
||||||
|
|
||||||
hashwrite_be32(f, commit_positions[i]);
|
hashwrite_be32(f, stored->commit_pos);
|
||||||
hashwrite_u8(f, stored->xor_offset);
|
hashwrite_u8(f, stored->xor_offset);
|
||||||
hashwrite_u8(f, stored->flags);
|
hashwrite_u8(f, stored->flags);
|
||||||
|
|
||||||
|
@ -692,29 +705,28 @@ static void write_selected_commits_v1(struct hashfile *f,
|
||||||
|
|
||||||
static int table_cmp(const void *_va, const void *_vb, void *_data)
|
static int table_cmp(const void *_va, const void *_vb, void *_data)
|
||||||
{
|
{
|
||||||
uint32_t *commit_positions = _data;
|
struct bitmap_writer *writer = _data;
|
||||||
uint32_t a = commit_positions[*(uint32_t *)_va];
|
struct bitmapped_commit *a = &writer->selected[*(uint32_t *)_va];
|
||||||
uint32_t b = commit_positions[*(uint32_t *)_vb];
|
struct bitmapped_commit *b = &writer->selected[*(uint32_t *)_vb];
|
||||||
|
|
||||||
if (a > b)
|
if (a->commit_pos < b->commit_pos)
|
||||||
return 1;
|
|
||||||
else if (a < b)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
else if (a->commit_pos > b->commit_pos)
|
||||||
|
return 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void write_lookup_table(struct hashfile *f,
|
static void write_lookup_table(struct bitmap_writer *writer, struct hashfile *f,
|
||||||
uint32_t *commit_positions,
|
|
||||||
off_t *offsets)
|
off_t *offsets)
|
||||||
{
|
{
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t *table, *table_inv;
|
uint32_t *table, *table_inv;
|
||||||
|
|
||||||
ALLOC_ARRAY(table, writer.selected_nr);
|
ALLOC_ARRAY(table, writer->selected_nr);
|
||||||
ALLOC_ARRAY(table_inv, writer.selected_nr);
|
ALLOC_ARRAY(table_inv, writer->selected_nr);
|
||||||
|
|
||||||
for (i = 0; i < writer.selected_nr; i++)
|
for (i = 0; i < writer->selected_nr; i++)
|
||||||
table[i] = i;
|
table[i] = i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -722,17 +734,17 @@ static void write_lookup_table(struct hashfile *f,
|
||||||
* bitmap corresponds to j'th bitmapped commit (among the selected
|
* bitmap corresponds to j'th bitmapped commit (among the selected
|
||||||
* commits) in lex order of OIDs.
|
* commits) in lex order of OIDs.
|
||||||
*/
|
*/
|
||||||
QSORT_S(table, writer.selected_nr, table_cmp, commit_positions);
|
QSORT_S(table, writer->selected_nr, table_cmp, writer);
|
||||||
|
|
||||||
/* table_inv helps us discover that relationship (i'th bitmap
|
/* table_inv helps us discover that relationship (i'th bitmap
|
||||||
* to j'th commit by j = table_inv[i])
|
* to j'th commit by j = table_inv[i])
|
||||||
*/
|
*/
|
||||||
for (i = 0; i < writer.selected_nr; i++)
|
for (i = 0; i < writer->selected_nr; i++)
|
||||||
table_inv[table[i]] = i;
|
table_inv[table[i]] = i;
|
||||||
|
|
||||||
trace2_region_enter("pack-bitmap-write", "writing_lookup_table", the_repository);
|
trace2_region_enter("pack-bitmap-write", "writing_lookup_table", the_repository);
|
||||||
for (i = 0; i < writer.selected_nr; i++) {
|
for (i = 0; i < writer->selected_nr; i++) {
|
||||||
struct bitmapped_commit *selected = &writer.selected[table[i]];
|
struct bitmapped_commit *selected = &writer->selected[table[i]];
|
||||||
uint32_t xor_offset = selected->xor_offset;
|
uint32_t xor_offset = selected->xor_offset;
|
||||||
uint32_t xor_row;
|
uint32_t xor_row;
|
||||||
|
|
||||||
|
@ -753,7 +765,7 @@ static void write_lookup_table(struct hashfile *f,
|
||||||
xor_row = 0xffffffff;
|
xor_row = 0xffffffff;
|
||||||
}
|
}
|
||||||
|
|
||||||
hashwrite_be32(f, commit_positions[table[i]]);
|
hashwrite_be32(f, writer->selected[table[i]].commit_pos);
|
||||||
hashwrite_be64(f, (uint64_t)offsets[table[i]]);
|
hashwrite_be64(f, (uint64_t)offsets[table[i]]);
|
||||||
hashwrite_be32(f, xor_row);
|
hashwrite_be32(f, xor_row);
|
||||||
}
|
}
|
||||||
|
@ -775,12 +787,14 @@ static void write_hash_cache(struct hashfile *f,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitmap_writer_set_checksum(const unsigned char *sha1)
|
void bitmap_writer_set_checksum(struct bitmap_writer *writer,
|
||||||
|
const unsigned char *sha1)
|
||||||
{
|
{
|
||||||
hashcpy(writer.pack_checksum, sha1);
|
hashcpy(writer->pack_checksum, sha1);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bitmap_writer_finish(struct pack_idx_entry **index,
|
void bitmap_writer_finish(struct bitmap_writer *writer,
|
||||||
|
struct pack_idx_entry **index,
|
||||||
uint32_t index_nr,
|
uint32_t index_nr,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
uint16_t options)
|
uint16_t options)
|
||||||
|
@ -789,7 +803,6 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
|
||||||
static uint16_t flags = BITMAP_OPT_FULL_DAG;
|
static uint16_t flags = BITMAP_OPT_FULL_DAG;
|
||||||
struct strbuf tmp_file = STRBUF_INIT;
|
struct strbuf tmp_file = STRBUF_INIT;
|
||||||
struct hashfile *f;
|
struct hashfile *f;
|
||||||
uint32_t *commit_positions = NULL;
|
|
||||||
off_t *offsets = NULL;
|
off_t *offsets = NULL;
|
||||||
uint32_t i;
|
uint32_t i;
|
||||||
|
|
||||||
|
@ -802,34 +815,32 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
|
||||||
memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE));
|
memcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE));
|
||||||
header.version = htons(default_version);
|
header.version = htons(default_version);
|
||||||
header.options = htons(flags | options);
|
header.options = htons(flags | options);
|
||||||
header.entry_count = htonl(writer.selected_nr);
|
header.entry_count = htonl(writer->selected_nr);
|
||||||
hashcpy(header.checksum, writer.pack_checksum);
|
hashcpy(header.checksum, writer->pack_checksum);
|
||||||
|
|
||||||
hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz);
|
hashwrite(f, &header, sizeof(header) - GIT_MAX_RAWSZ + the_hash_algo->rawsz);
|
||||||
dump_bitmap(f, writer.commits);
|
dump_bitmap(f, writer->commits);
|
||||||
dump_bitmap(f, writer.trees);
|
dump_bitmap(f, writer->trees);
|
||||||
dump_bitmap(f, writer.blobs);
|
dump_bitmap(f, writer->blobs);
|
||||||
dump_bitmap(f, writer.tags);
|
dump_bitmap(f, writer->tags);
|
||||||
|
|
||||||
if (options & BITMAP_OPT_LOOKUP_TABLE)
|
if (options & BITMAP_OPT_LOOKUP_TABLE)
|
||||||
CALLOC_ARRAY(offsets, index_nr);
|
CALLOC_ARRAY(offsets, index_nr);
|
||||||
|
|
||||||
ALLOC_ARRAY(commit_positions, writer.selected_nr);
|
for (i = 0; i < writer->selected_nr; i++) {
|
||||||
|
struct bitmapped_commit *stored = &writer->selected[i];
|
||||||
for (i = 0; i < writer.selected_nr; i++) {
|
int commit_pos = oid_pos(&stored->commit->object.oid, index,
|
||||||
struct bitmapped_commit *stored = &writer.selected[i];
|
index_nr, oid_access);
|
||||||
int commit_pos = oid_pos(&stored->commit->object.oid, index, index_nr, oid_access);
|
|
||||||
|
|
||||||
if (commit_pos < 0)
|
if (commit_pos < 0)
|
||||||
BUG(_("trying to write commit not in index"));
|
BUG(_("trying to write commit not in index"));
|
||||||
|
stored->commit_pos = commit_pos;
|
||||||
commit_positions[i] = commit_pos;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
write_selected_commits_v1(f, commit_positions, offsets);
|
write_selected_commits_v1(writer, f, offsets);
|
||||||
|
|
||||||
if (options & BITMAP_OPT_LOOKUP_TABLE)
|
if (options & BITMAP_OPT_LOOKUP_TABLE)
|
||||||
write_lookup_table(f, commit_positions, offsets);
|
write_lookup_table(writer, f, offsets);
|
||||||
|
|
||||||
if (options & BITMAP_OPT_HASH_CACHE)
|
if (options & BITMAP_OPT_HASH_CACHE)
|
||||||
write_hash_cache(f, index, index_nr);
|
write_hash_cache(f, index, index_nr);
|
||||||
|
@ -844,6 +855,5 @@ void bitmap_writer_finish(struct pack_idx_entry **index,
|
||||||
die_errno("unable to rename temporary bitmap file to '%s'", filename);
|
die_errno("unable to rename temporary bitmap file to '%s'", filename);
|
||||||
|
|
||||||
strbuf_release(&tmp_file);
|
strbuf_release(&tmp_file);
|
||||||
free(commit_positions);
|
|
||||||
free(offsets);
|
free(offsets);
|
||||||
}
|
}
|
||||||
|
|
|
@ -97,9 +97,29 @@ int bitmap_has_oid_in_uninteresting(struct bitmap_index *, const struct object_i
|
||||||
|
|
||||||
off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *);
|
off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *);
|
||||||
|
|
||||||
void bitmap_writer_show_progress(int show);
|
struct bitmap_writer {
|
||||||
void bitmap_writer_set_checksum(const unsigned char *sha1);
|
struct ewah_bitmap *commits;
|
||||||
void bitmap_writer_build_type_index(struct packing_data *to_pack,
|
struct ewah_bitmap *trees;
|
||||||
|
struct ewah_bitmap *blobs;
|
||||||
|
struct ewah_bitmap *tags;
|
||||||
|
|
||||||
|
kh_oid_map_t *bitmaps;
|
||||||
|
struct packing_data *to_pack;
|
||||||
|
|
||||||
|
struct bitmapped_commit *selected;
|
||||||
|
unsigned int selected_nr, selected_alloc;
|
||||||
|
|
||||||
|
struct progress *progress;
|
||||||
|
int show_progress;
|
||||||
|
unsigned char pack_checksum[GIT_MAX_RAWSZ];
|
||||||
|
};
|
||||||
|
|
||||||
|
void bitmap_writer_init(struct bitmap_writer *writer);
|
||||||
|
void bitmap_writer_show_progress(struct bitmap_writer *writer, int show);
|
||||||
|
void bitmap_writer_set_checksum(struct bitmap_writer *writer,
|
||||||
|
const unsigned char *sha1);
|
||||||
|
void bitmap_writer_build_type_index(struct bitmap_writer *writer,
|
||||||
|
struct packing_data *to_pack,
|
||||||
struct pack_idx_entry **index,
|
struct pack_idx_entry **index,
|
||||||
uint32_t index_nr);
|
uint32_t index_nr);
|
||||||
uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
|
uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
|
||||||
|
@ -109,13 +129,17 @@ int rebuild_bitmap(const uint32_t *reposition,
|
||||||
struct bitmap *dest);
|
struct bitmap *dest);
|
||||||
struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
|
struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
|
||||||
struct commit *commit);
|
struct commit *commit);
|
||||||
void bitmap_writer_select_commits(struct commit **indexed_commits,
|
void bitmap_writer_select_commits(struct bitmap_writer *writer,
|
||||||
unsigned int indexed_commits_nr, int max_bitmaps);
|
struct commit **indexed_commits,
|
||||||
int bitmap_writer_build(struct packing_data *to_pack);
|
unsigned int indexed_commits_nr);
|
||||||
void bitmap_writer_finish(struct pack_idx_entry **index,
|
int bitmap_writer_build(struct bitmap_writer *writer,
|
||||||
|
struct packing_data *to_pack);
|
||||||
|
void bitmap_writer_finish(struct bitmap_writer *writer,
|
||||||
|
struct pack_idx_entry **index,
|
||||||
uint32_t index_nr,
|
uint32_t index_nr,
|
||||||
const char *filename,
|
const char *filename,
|
||||||
uint16_t options);
|
uint16_t options);
|
||||||
|
void bitmap_writer_free(struct bitmap_writer *writer);
|
||||||
char *midx_bitmap_filename(struct multi_pack_index *midx);
|
char *midx_bitmap_filename(struct multi_pack_index *midx);
|
||||||
char *pack_bitmap_filename(struct packed_git *p);
|
char *pack_bitmap_filename(struct packed_git *p);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue