Raw
1 #ifndef PACK_BITMAP_H
2 #define PACK_BITMAP_H
3
4 #include "ewah/ewok.h"
5 #include "khash.h"
6 #include "pack.h"
7 #include "pack-objects.h"
8 #include "refs.h"
9 #include "string-list.h"
10
11 struct commit;
12 struct repository;
13 struct rev_info;
14
15 static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
16
17 struct bitmap_disk_header {
18 char magic[ARRAY_SIZE(BITMAP_IDX_SIGNATURE)];
19 uint16_t version;
20 uint16_t options;
21 uint32_t entry_count;
22 unsigned char checksum[GIT_MAX_RAWSZ];
23 };
24
25 #define BITMAP_PSEUDO_MERGE (1u<<21)
26 #define NEEDS_BITMAP (1u<<22)
27
28 /*
29 * The width in bytes of a single triplet in the lookup table
30 * extension:
31 * (commit_pos, offset, xor_row)
32 *
33 * whose fields ar 32-, 64-, 32- bits wide, respectively.
34 */
35 #define BITMAP_LOOKUP_TABLE_TRIPLET_WIDTH (16)
36
37 enum pack_bitmap_opts {
38 BITMAP_OPT_FULL_DAG = 0x1,
39 BITMAP_OPT_HASH_CACHE = 0x4,
40 BITMAP_OPT_LOOKUP_TABLE = 0x10,
41 BITMAP_OPT_PSEUDO_MERGES = 0x20,
42 };
43
44 enum pack_bitmap_flags {
45 BITMAP_FLAG_REUSE = 0x1
46 };
47
48 typedef int (*show_reachable_fn)(
49 const struct object_id *oid,
50 enum object_type type,
51 int flags,
52 uint32_t hash,
53 struct packed_git *found_pack,
54 off_t found_offset,
55 void *payload);
56
57 struct bitmap_index;
58
59 struct bitmapped_pack {
60 struct packed_git *p;
61
62 uint32_t bitmap_pos;
63 uint32_t bitmap_nr;
64
65 struct multi_pack_index *from_midx; /* MIDX only */
66 uint32_t pack_int_id; /* MIDX only */
67 };
68
69 struct bitmap_index *prepare_bitmap_git(struct repository *r);
70 struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx);
71
72 /*
73 * Given a bitmap index, determine whether it contains the pack either directly
74 * or via the multi-pack-index.
75 */
76 int bitmap_index_contains_pack(struct bitmap_index *bitmap, struct packed_git *pack);
77
78 void count_bitmap_commit_list(struct bitmap_index *, uint32_t *commits,
79 uint32_t *trees, uint32_t *blobs, uint32_t *tags);
80 void traverse_bitmap_commit_list(struct bitmap_index *,
81 struct rev_info *revs,
82 show_reachable_fn show_reachable);
83 void test_bitmap_walk(struct rev_info *revs);
84 int test_bitmap_commits(struct repository *r);
85 int test_bitmap_commits_with_offset(struct repository *r);
86 int test_bitmap_hashes(struct repository *r);
87 int test_bitmap_pseudo_merges(struct repository *r);
88 int test_bitmap_pseudo_merge_commits(struct repository *r, uint32_t n);
89 int test_bitmap_pseudo_merge_objects(struct repository *r, uint32_t n);
90
91 struct list_objects_filter_options;
92
93 /*
94 * Filter bitmapped objects and iterate through all resulting objects,
95 * executing `show_reach` for each of them. Returns `-1` in case the filter is
96 * not supported, `0` otherwise.
97 */
98 int for_each_bitmapped_object(struct bitmap_index *bitmap_git,
99 struct list_objects_filter_options *filter,
100 show_reachable_fn show_reach,
101 void *payload);
102
103 /*
104 * Iterate over all references that are configured as preferred bitmap tips via
105 * "pack.preferBitmapTips" and invoke the callback on each function.
106 */
107 void for_each_preferred_bitmap_tip(struct repository *repo,
108 refs_for_each_cb cb, void *cb_data);
109
110 #define GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL \
111 "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL"
112
113 struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
114 int filter_provided_objects);
115 void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
116 struct bitmapped_pack **packs_out,
117 size_t *packs_nr_out,
118 struct bitmap **reuse_out,
119 int multi_pack_reuse);
120 int rebuild_existing_bitmaps(struct bitmap_index *, struct packing_data *mapping,
121 kh_oid_map_t *reused_bitmaps, int show_progress);
122 void free_bitmap_index(struct bitmap_index *);
123 int bitmap_walk_contains(struct bitmap_index *,
124 struct bitmap *bitmap, const struct object_id *oid);
125
126 /*
127 * After a traversal has been performed by prepare_bitmap_walk(), this can be
128 * queried to see if a particular object was reachable from any of the
129 * objects flagged as UNINTERESTING.
130 */
131 int bitmap_has_oid_in_uninteresting(struct bitmap_index *, const struct object_id *oid);
132
133 off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *);
134
135 struct bitmap_pos_cache_entry;
136
137 struct bitmap_writer {
138 struct repository *repo;
139 struct ewah_bitmap *commits;
140 struct ewah_bitmap *trees;
141 struct ewah_bitmap *blobs;
142 struct ewah_bitmap *tags;
143
144 kh_oid_map_t *bitmaps;
145 struct packing_data *to_pack;
146 struct multi_pack_index *midx; /* if appending to a MIDX chain */
147
148 struct bitmap_pos_cache_entry *pos_cache;
149 size_t pos_cache_nr;
150 uint64_t pos_cache_hits;
151 uint64_t pos_cache_misses;
152
153 struct bitmapped_commit *selected;
154 unsigned int selected_nr, selected_alloc;
155
156 struct string_list pseudo_merge_groups;
157 kh_oid_map_t *pseudo_merge_commits; /* oid -> pseudo merge(s) */
158 uint32_t pseudo_merges_nr;
159
160 struct progress *progress;
161 int show_progress;
162 unsigned char pack_checksum[GIT_MAX_RAWSZ];
163 };
164
165 void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r,
166 struct packing_data *pdata,
167 struct multi_pack_index *midx);
168 void bitmap_writer_show_progress(struct bitmap_writer *writer, int show);
169 void bitmap_writer_set_checksum(struct bitmap_writer *writer,
170 const unsigned char *sha1);
171 void bitmap_writer_build_type_index(struct bitmap_writer *writer,
172 struct pack_idx_entry **index);
173 int bitmap_writer_has_bitmapped_object_id(struct bitmap_writer *writer,
174 const struct object_id *oid);
175 void bitmap_writer_push_commit(struct bitmap_writer *writer,
176 struct commit *commit, unsigned pseudo_merge);
177 uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
178 struct packing_data *mapping);
179 int rebuild_bitmap(const uint32_t *reposition,
180 struct ewah_bitmap *source,
181 struct bitmap *dest);
182 struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
183 struct commit *commit);
184 struct ewah_bitmap *pseudo_merge_bitmap_for_commit(struct bitmap_index *bitmap_git,
185 struct commit *commit);
186 void bitmap_writer_select_commits(struct bitmap_writer *writer,
187 struct commit **indexed_commits,
188 unsigned int indexed_commits_nr);
189 int bitmap_writer_build(struct bitmap_writer *writer);
190 void bitmap_writer_finish(struct bitmap_writer *writer,
191 struct pack_idx_entry **index,
192 const char *filename,
193 uint16_t options);
194 void bitmap_writer_free(struct bitmap_writer *writer);
195 char *midx_bitmap_filename(struct multi_pack_index *midx);
196 char *pack_bitmap_filename(struct packed_git *p);
197
198 int bitmap_is_midx(struct bitmap_index *bitmap_git);
199
200 int bitmap_is_preferred_refname(struct repository *r, const char *refname);
201
202 int verify_bitmap_files(struct repository *r);
203
204 struct ewah_bitmap *read_bitmap(const unsigned char *map,
205 size_t map_size, size_t *map_pos);
206 #endif