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