Merge branch 'kl/test-fixes'
[git/gitster.git] / pack-bitmap.h
blob1171e6d989379376a6bc839646f8eca0dd15ae35
1 #ifndef PACK_BITMAP_H
2 #define PACK_BITMAP_H
4 #include "ewah/ewok.h"
5 #include "khash.h"
6 #include "pack.h"
7 #include "pack-objects.h"
8 #include "string-list.h"
10 struct commit;
11 struct repository;
12 struct rev_info;
14 static const char BITMAP_IDX_SIGNATURE[] = {'B', 'I', 'T', 'M'};
16 struct bitmap_disk_header {
17 char magic[ARRAY_SIZE(BITMAP_IDX_SIGNATURE)];
18 uint16_t version;
19 uint16_t options;
20 uint32_t entry_count;
21 unsigned char checksum[GIT_MAX_RAWSZ];
24 #define BITMAP_PSEUDO_MERGE (1u<<21)
25 #define NEEDS_BITMAP (1u<<22)
28 * The width in bytes of a single triplet in the lookup table
29 * extension:
30 * (commit_pos, offset, xor_row)
32 * whose fields ar 32-, 64-, 32- bits wide, respectively.
34 #define BITMAP_LOOKUP_TABLE_TRIPLET_WIDTH (16)
36 enum pack_bitmap_opts {
37 BITMAP_OPT_FULL_DAG = 0x1,
38 BITMAP_OPT_HASH_CACHE = 0x4,
39 BITMAP_OPT_LOOKUP_TABLE = 0x10,
40 BITMAP_OPT_PSEUDO_MERGES = 0x20,
43 enum pack_bitmap_flags {
44 BITMAP_FLAG_REUSE = 0x1
47 typedef int (*show_reachable_fn)(
48 const struct object_id *oid,
49 enum object_type type,
50 int flags,
51 uint32_t hash,
52 struct packed_git *found_pack,
53 off_t found_offset);
55 struct bitmap_index;
57 struct bitmapped_pack {
58 struct packed_git *p;
60 uint32_t bitmap_pos;
61 uint32_t bitmap_nr;
63 uint32_t pack_int_id; /* MIDX only */
66 struct bitmap_index *prepare_bitmap_git(struct repository *r);
67 struct bitmap_index *prepare_midx_bitmap_git(struct multi_pack_index *midx);
68 void count_bitmap_commit_list(struct bitmap_index *, uint32_t *commits,
69 uint32_t *trees, uint32_t *blobs, uint32_t *tags);
70 void traverse_bitmap_commit_list(struct bitmap_index *,
71 struct rev_info *revs,
72 show_reachable_fn show_reachable);
73 void test_bitmap_walk(struct rev_info *revs);
74 int test_bitmap_commits(struct repository *r);
75 int test_bitmap_hashes(struct repository *r);
76 int test_bitmap_pseudo_merges(struct repository *r);
77 int test_bitmap_pseudo_merge_commits(struct repository *r, uint32_t n);
78 int test_bitmap_pseudo_merge_objects(struct repository *r, uint32_t n);
80 #define GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL \
81 "GIT_TEST_PACK_USE_BITMAP_BOUNDARY_TRAVERSAL"
83 struct bitmap_index *prepare_bitmap_walk(struct rev_info *revs,
84 int filter_provided_objects);
85 void reuse_partial_packfile_from_bitmap(struct bitmap_index *bitmap_git,
86 struct bitmapped_pack **packs_out,
87 size_t *packs_nr_out,
88 struct bitmap **reuse_out,
89 int multi_pack_reuse);
90 int rebuild_existing_bitmaps(struct bitmap_index *, struct packing_data *mapping,
91 kh_oid_map_t *reused_bitmaps, int show_progress);
92 void free_bitmap_index(struct bitmap_index *);
93 int bitmap_walk_contains(struct bitmap_index *,
94 struct bitmap *bitmap, const struct object_id *oid);
97 * After a traversal has been performed by prepare_bitmap_walk(), this can be
98 * queried to see if a particular object was reachable from any of the
99 * objects flagged as UNINTERESTING.
101 int bitmap_has_oid_in_uninteresting(struct bitmap_index *, const struct object_id *oid);
103 off_t get_disk_usage_from_bitmap(struct bitmap_index *, struct rev_info *);
105 struct bitmap_writer {
106 struct ewah_bitmap *commits;
107 struct ewah_bitmap *trees;
108 struct ewah_bitmap *blobs;
109 struct ewah_bitmap *tags;
111 kh_oid_map_t *bitmaps;
112 struct packing_data *to_pack;
114 struct bitmapped_commit *selected;
115 unsigned int selected_nr, selected_alloc;
117 struct string_list pseudo_merge_groups;
118 kh_oid_map_t *pseudo_merge_commits; /* oid -> pseudo merge(s) */
119 uint32_t pseudo_merges_nr;
121 struct progress *progress;
122 int show_progress;
123 unsigned char pack_checksum[GIT_MAX_RAWSZ];
126 void bitmap_writer_init(struct bitmap_writer *writer, struct repository *r);
127 void bitmap_writer_show_progress(struct bitmap_writer *writer, int show);
128 void bitmap_writer_set_checksum(struct bitmap_writer *writer,
129 const unsigned char *sha1);
130 void bitmap_writer_build_type_index(struct bitmap_writer *writer,
131 struct packing_data *to_pack,
132 struct pack_idx_entry **index,
133 uint32_t index_nr);
134 int bitmap_writer_has_bitmapped_object_id(struct bitmap_writer *writer,
135 const struct object_id *oid);
136 void bitmap_writer_push_commit(struct bitmap_writer *writer,
137 struct commit *commit, unsigned pseudo_merge);
138 uint32_t *create_bitmap_mapping(struct bitmap_index *bitmap_git,
139 struct packing_data *mapping);
140 int rebuild_bitmap(const uint32_t *reposition,
141 struct ewah_bitmap *source,
142 struct bitmap *dest);
143 struct ewah_bitmap *bitmap_for_commit(struct bitmap_index *bitmap_git,
144 struct commit *commit);
145 struct ewah_bitmap *pseudo_merge_bitmap_for_commit(struct bitmap_index *bitmap_git,
146 struct commit *commit);
147 void bitmap_writer_select_commits(struct bitmap_writer *writer,
148 struct commit **indexed_commits,
149 unsigned int indexed_commits_nr);
150 int bitmap_writer_build(struct bitmap_writer *writer,
151 struct packing_data *to_pack);
152 void bitmap_writer_finish(struct bitmap_writer *writer,
153 struct pack_idx_entry **index,
154 uint32_t index_nr,
155 const char *filename,
156 uint16_t options);
157 void bitmap_writer_free(struct bitmap_writer *writer);
158 char *midx_bitmap_filename(struct multi_pack_index *midx);
159 char *pack_bitmap_filename(struct packed_git *p);
161 int bitmap_is_midx(struct bitmap_index *bitmap_git);
163 const struct string_list *bitmap_preferred_tips(struct repository *r);
164 int bitmap_is_preferred_refname(struct repository *r, const char *refname);
166 int verify_bitmap_files(struct repository *r);
168 struct ewah_bitmap *read_bitmap(const unsigned char *map,
169 size_t map_size, size_t *map_pos);
170 #endif