Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 1 | #ifndef PACK_BITMAP_H |
| 2 | #define PACK_BITMAP_H |
| 3 | |
| 4 | #include "ewah/ewok.h" |
| 5 | #include "khash.h" |
Jeff King | 40d18ff | 2019-12-18 12:25:39 +0100 | [diff] [blame] | 6 | #include "pack.h" |
Vicent Marti | 7cc8f97 | 2013-12-21 09:00:16 -0500 | [diff] [blame] | 7 | #include "pack-objects.h" |
Taylor Blau | 3f267a1 | 2021-03-31 21:32:14 -0400 | [diff] [blame] | 8 | #include "string-list.h" |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 9 | |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 10 | struct commit; |
Nguyễn Thái Ngọc Duy | 7c14112 | 2018-11-10 06:49:08 +0100 | [diff] [blame] | 11 | struct repository; |
Elijah Newren | ef3ca95 | 2018-08-15 10:54:05 -0700 | [diff] [blame] | 12 | struct rev_info; |
| 13 | |
Denton Liu | af26e2a | 2019-09-25 01:20:59 -0700 | [diff] [blame] | 14 | static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'}; |
| 15 | |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 16 | struct bitmap_disk_header { |
Denton Liu | af26e2a | 2019-09-25 01:20:59 -0700 | [diff] [blame] | 17 | char magic[ARRAY_SIZE(BITMAP_IDX_SIGNATURE)]; |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 18 | uint16_t version; |
| 19 | uint16_t options; |
| 20 | uint32_t entry_count; |
brian m. carlson | 0f4d6ca | 2019-02-19 00:04:54 +0000 | [diff] [blame] | 21 | unsigned char checksum[GIT_MAX_RAWSZ]; |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 22 | }; |
| 23 | |
Vicent Marti | 7cc8f97 | 2013-12-21 09:00:16 -0500 | [diff] [blame] | 24 | #define NEEDS_BITMAP (1u<<22) |
| 25 | |
Abhradeep Chakraborty | 28cd730 | 2022-08-14 16:55:10 +0000 | [diff] [blame] | 26 | /* |
| 27 | * The width in bytes of a single triplet in the lookup table |
| 28 | * extension: |
| 29 | * (commit_pos, offset, xor_row) |
| 30 | * |
| 31 | * whose fields ar 32-, 64-, 32- bits wide, respectively. |
| 32 | */ |
| 33 | #define BITMAP_LOOKUP_TABLE_TRIPLET_WIDTH (16) |
| 34 | |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 35 | enum pack_bitmap_opts { |
Abhradeep Chakraborty | 93eb41e | 2022-08-14 16:55:08 +0000 | [diff] [blame] | 36 | BITMAP_OPT_FULL_DAG = 0x1, |
| 37 | BITMAP_OPT_HASH_CACHE = 0x4, |
| 38 | BITMAP_OPT_LOOKUP_TABLE = 0x10, |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 39 | }; |
| 40 | |
Vicent Marti | 7cc8f97 | 2013-12-21 09:00:16 -0500 | [diff] [blame] | 41 | enum pack_bitmap_flags { |
| 42 | BITMAP_FLAG_REUSE = 0x1 |
| 43 | }; |
| 44 | |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 45 | typedef int (*show_reachable_fn)( |
brian m. carlson | 2066496 | 2017-10-15 22:07:00 +0000 | [diff] [blame] | 46 | const struct object_id *oid, |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 47 | enum object_type type, |
| 48 | int flags, |
| 49 | uint32_t hash, |
| 50 | struct packed_git *found_pack, |
| 51 | off_t found_offset); |
| 52 | |
Jonathan Tan | 3ae5fa0 | 2018-06-07 12:04:13 -0700 | [diff] [blame] | 53 | struct bitmap_index; |
| 54 | |
Nguyễn Thái Ngọc Duy | 7c14112 | 2018-11-10 06:49:08 +0100 | [diff] [blame] | 55 | struct bitmap_index *prepare_bitmap_git(struct repository *r); |
Jeff King | bfbb60d | 2021-09-09 15:56:58 -0400 | [diff] [blame] | 56 | struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx); |
Jonathan Tan | 3ae5fa0 | 2018-06-07 12:04:13 -0700 | [diff] [blame] | 57 | void count_bitmap_commit_list(struct bitmap_index *, uint32_t *commits, |
| 58 | uint32_t *trees, uint32_t *blobs, uint32_t *tags); |
| 59 | void traverse_bitmap_commit_list(struct bitmap_index *, |
Jeff King | 4eb707e | 2020-02-14 13:22:27 -0500 | [diff] [blame] | 60 | struct rev_info *revs, |
Jonathan Tan | 3ae5fa0 | 2018-06-07 12:04:13 -0700 | [diff] [blame] | 61 | show_reachable_fn show_reachable); |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 62 | void test_bitmap_walk(struct rev_info *revs); |
Taylor Blau | dff5e49 | 2021-03-31 21:32:07 -0400 | [diff] [blame] | 63 | int test_bitmap_commits(struct repository *r); |
Taylor Blau | a05f02b | 2021-09-14 18:06:02 -0400 | [diff] [blame] | 64 | int test_bitmap_hashes(struct repository *r); |
Jeff King | 6663ae0 | 2020-02-14 13:22:29 -0500 | [diff] [blame] | 65 | struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs, |
Patrick Steinhardt | 9cf68b2 | 2021-04-19 13:47:06 +0200 | [diff] [blame] | 66 | int filter_provided_objects); |
Taylor Blau | 6d08b9d | 2021-09-28 21:55:20 -0400 | [diff] [blame] | 67 | uint32_t midx_preferred_pack(struct bitmap_index *bitmap_git); |
Jonathan Tan | 3ae5fa0 | 2018-06-07 12:04:13 -0700 | [diff] [blame] | 68 | int reuse_partial_packfile_from_bitmap(struct bitmap_index *, |
| 69 | struct packed_git **packfile, |
Jeff King | bb514de | 2019-12-18 12:25:45 +0100 | [diff] [blame] | 70 | uint32_t *entries, |
| 71 | struct bitmap **reuse_out); |
Jonathan Tan | 3ae5fa0 | 2018-06-07 12:04:13 -0700 | [diff] [blame] | 72 | int rebuild_existing_bitmaps(struct bitmap_index *, struct packing_data *mapping, |
Jeff King | d2bc62b | 2019-06-20 03:41:35 -0400 | [diff] [blame] | 73 | kh_oid_map_t *reused_bitmaps, int show_progress); |
Jonathan Tan | f3c23db | 2018-06-07 12:04:14 -0700 | [diff] [blame] | 74 | void free_bitmap_index(struct bitmap_index *); |
Jeff King | 40d18ff | 2019-12-18 12:25:39 +0100 | [diff] [blame] | 75 | int bitmap_walk_contains(struct bitmap_index *, |
| 76 | struct bitmap *bitmap, const struct object_id *oid); |
Vicent Marti | 7cc8f97 | 2013-12-21 09:00:16 -0500 | [diff] [blame] | 77 | |
Jeff King | 30cdc33 | 2018-08-21 15:07:01 -0400 | [diff] [blame] | 78 | /* |
Jeff King | 5476fb0 | 2018-09-01 03:44:48 -0400 | [diff] [blame] | 79 | * After a traversal has been performed by prepare_bitmap_walk(), this can be |
Jeff King | 30cdc33 | 2018-08-21 15:07:01 -0400 | [diff] [blame] | 80 | * queried to see if a particular object was reachable from any of the |
| 81 | * objects flagged as UNINTERESTING. |
| 82 | */ |
brian m. carlson | 3c77144 | 2019-02-19 00:04:58 +0000 | [diff] [blame] | 83 | int bitmap_has_oid_in_uninteresting(struct bitmap_index *, const struct object_id *oid); |
Jeff King | 30cdc33 | 2018-08-21 15:07:01 -0400 | [diff] [blame] | 84 | |
Jeff King | 16950f8 | 2021-02-09 05:53:50 -0500 | [diff] [blame] | 85 | off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *); |
| 86 | |
Vicent Marti | 7cc8f97 | 2013-12-21 09:00:16 -0500 | [diff] [blame] | 87 | void bitmap_writer_show_progress(int show); |
Derrick Stolee | 5766524 | 2022-07-19 15:26:04 +0000 | [diff] [blame] | 88 | void bitmap_writer_set_checksum(const unsigned char *sha1); |
Nguyễn Thái Ngọc Duy | 06af3bb | 2018-04-14 17:35:04 +0200 | [diff] [blame] | 89 | void bitmap_writer_build_type_index(struct packing_data *to_pack, |
| 90 | struct pack_idx_entry **index, |
| 91 | uint32_t index_nr); |
Jeff King | 449fa5e | 2020-12-08 17:04:34 -0500 | [diff] [blame] | 92 | uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git, |
| 93 | struct packing_data *mapping); |
| 94 | int rebuild_bitmap(const uint32_t *reposition, |
| 95 | struct ewah_bitmap *source, |
| 96 | struct bitmap *dest); |
Taylor Blau | 98c31f3 | 2020-12-08 17:05:09 -0500 | [diff] [blame] | 97 | struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git, |
| 98 | struct commit *commit); |
Vicent Marti | 7cc8f97 | 2013-12-21 09:00:16 -0500 | [diff] [blame] | 99 | void bitmap_writer_select_commits(struct commit **indexed_commits, |
| 100 | unsigned int indexed_commits_nr, int max_bitmaps); |
Taylor Blau | 3ba3d06 | 2021-08-24 12:15:54 -0400 | [diff] [blame] | 101 | int bitmap_writer_build(struct packing_data *to_pack); |
Vicent Marti | 7cc8f97 | 2013-12-21 09:00:16 -0500 | [diff] [blame] | 102 | void bitmap_writer_finish(struct pack_idx_entry **index, |
| 103 | uint32_t index_nr, |
Vicent Marti | ae4f07f | 2013-12-21 09:00:45 -0500 | [diff] [blame] | 104 | const char *filename, |
| 105 | uint16_t options); |
Taylor Blau | 0f533c7 | 2021-08-31 16:52:21 -0400 | [diff] [blame] | 106 | char *midx_bitmap_filename(struct multi_pack_index *midx); |
| 107 | char *pack_bitmap_filename(struct packed_git *p); |
| 108 | |
| 109 | int bitmap_is_midx(struct bitmap_index *bitmap_git); |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 110 | |
Taylor Blau | 3f267a1 | 2021-03-31 21:32:14 -0400 | [diff] [blame] | 111 | const struct string_list *bitmap_preferred_tips(struct repository *r); |
Taylor Blau | 711260f | 2021-08-31 16:52:16 -0400 | [diff] [blame] | 112 | int bitmap_is_preferred_refname(struct repository *r, const char *refname); |
Taylor Blau | 3f267a1 | 2021-03-31 21:32:14 -0400 | [diff] [blame] | 113 | |
Vicent Marti | fff4275 | 2013-12-21 09:00:01 -0500 | [diff] [blame] | 114 | #endif |