| 913 | } |
| 914 | |
| 915 | int bitmap_writer_build(struct bitmap_writer *writer) |
| 916 | { |
| 917 | struct bitmap_builder bb; |
| 918 | size_t i; |
| 919 | int nr_stored = 0; /* for progress */ |
| 920 | struct prio_queue queue = { compare_commits_by_gen_then_commit_date }; |
| 921 | struct prio_queue tree_queue = { NULL }; |
| 922 | struct bitmap_index *old_bitmap; |
| 923 | uint32_t *mapping = NULL; |
| 924 | int closed = 1; /* until proven otherwise */ |
| 925 | |
| 926 | if (writer->show_progress) |
| 927 | writer->progress = start_progress(writer->repo, |
| 928 | "Building bitmaps", |
| 929 | writer->selected_nr); |
| 930 | |
| 931 | writer->pos_cache_hits = 0; |
| 932 | writer->pos_cache_misses = 0; |
| 933 | |
| 934 | trace2_region_enter("pack-bitmap-write", "building_bitmaps_total", |
| 935 | writer->repo); |
| 936 | |
| 937 | old_bitmap = prepare_bitmap_git(writer->to_pack->repo); |
| 938 | if (old_bitmap) |
| 939 | mapping = create_bitmap_mapping(old_bitmap, writer->to_pack); |
| 940 | else |
| 941 | mapping = NULL; |
| 942 | |
| 943 | bitmap_builder_init(&bb, writer, old_bitmap); |
| 944 | for (i = bb.commits.nr; i > 0; i--) { |
| 945 | struct commit *commit = bb.commits.items[i-1]; |
| 946 | struct bb_commit *ent = bb_data_at(&bb.data, commit); |
| 947 | struct commit *child; |
| 948 | int reused = 0; |
| 949 | |
| 950 | if (fill_bitmap_commit(writer, ent, commit, &queue, &tree_queue, |
| 951 | old_bitmap, mapping) < 0) { |
| 952 | closed = 0; |
| 953 | break; |
| 954 | } |
| 955 | |
| 956 | if (ent->selected) { |
| 957 | store_selected(writer, ent, commit); |
| 958 | nr_stored++; |
| 959 | display_progress(writer->progress, nr_stored); |
| 960 | } |
| 961 | |
| 962 | while ((child = pop_commit(&ent->reverse_edges))) { |
| 963 | struct bb_commit *child_ent = |
| 964 | bb_data_at(&bb.data, child); |
| 965 | |
| 966 | if (child_ent->bitmap) |
| 967 | bitmap_or(child_ent->bitmap, ent->bitmap); |
| 968 | else if (reused) |
| 969 | child_ent->bitmap = bitmap_dup(ent->bitmap); |
| 970 | else { |
| 971 | child_ent->bitmap = ent->bitmap; |
| 972 | reused = 1; |