Sync with 'maint'
[git/gitster.git] / midx.h
blob42d4f8d149e9a286de62feaf739f97d019ff4215
1 #ifndef MIDX_H
2 #define MIDX_H
4 #include "string-list.h"
6 struct object_id;
7 struct pack_entry;
8 struct repository;
9 struct bitmapped_pack;
11 #define MIDX_SIGNATURE 0x4d494458 /* "MIDX" */
12 #define MIDX_VERSION 1
13 #define MIDX_BYTE_FILE_VERSION 4
14 #define MIDX_BYTE_HASH_VERSION 5
15 #define MIDX_BYTE_NUM_CHUNKS 6
16 #define MIDX_BYTE_NUM_PACKS 8
17 #define MIDX_HEADER_SIZE 12
19 #define MIDX_CHUNK_ALIGNMENT 4
20 #define MIDX_CHUNKID_PACKNAMES 0x504e414d /* "PNAM" */
21 #define MIDX_CHUNKID_BITMAPPEDPACKS 0x42544d50 /* "BTMP" */
22 #define MIDX_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
23 #define MIDX_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
24 #define MIDX_CHUNKID_OBJECTOFFSETS 0x4f4f4646 /* "OOFF" */
25 #define MIDX_CHUNKID_LARGEOFFSETS 0x4c4f4646 /* "LOFF" */
26 #define MIDX_CHUNKID_REVINDEX 0x52494458 /* "RIDX" */
27 #define MIDX_CHUNKID_BASE 0x42415345 /* "BASE" */
28 #define MIDX_CHUNK_OFFSET_WIDTH (2 * sizeof(uint32_t))
29 #define MIDX_LARGE_OFFSET_NEEDED 0x80000000
31 #define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"
32 #define GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL \
33 "GIT_TEST_MULTI_PACK_INDEX_WRITE_INCREMENTAL"
35 struct multi_pack_index {
36 struct multi_pack_index *next;
38 const unsigned char *data;
39 size_t data_len;
41 const uint32_t *revindex_data;
42 const uint32_t *revindex_map;
43 size_t revindex_len;
45 uint32_t signature;
46 unsigned char version;
47 unsigned char hash_len;
48 unsigned char num_chunks;
49 uint32_t num_packs;
50 uint32_t num_objects;
51 int preferred_pack_idx;
53 int local;
54 int has_chain;
56 const unsigned char *chunk_pack_names;
57 size_t chunk_pack_names_len;
58 const uint32_t *chunk_bitmapped_packs;
59 size_t chunk_bitmapped_packs_len;
60 const uint32_t *chunk_oid_fanout;
61 const unsigned char *chunk_oid_lookup;
62 const unsigned char *chunk_object_offsets;
63 const unsigned char *chunk_large_offsets;
64 size_t chunk_large_offsets_len;
65 const unsigned char *chunk_revindex;
66 size_t chunk_revindex_len;
68 struct multi_pack_index *base_midx;
69 uint32_t num_objects_in_base;
70 uint32_t num_packs_in_base;
72 const char **pack_names;
73 struct packed_git **packs;
74 char object_dir[FLEX_ARRAY];
77 #define MIDX_PROGRESS (1 << 0)
78 #define MIDX_WRITE_REV_INDEX (1 << 1)
79 #define MIDX_WRITE_BITMAP (1 << 2)
80 #define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3)
81 #define MIDX_WRITE_BITMAP_LOOKUP_TABLE (1 << 4)
82 #define MIDX_WRITE_INCREMENTAL (1 << 5)
84 #define MIDX_EXT_REV "rev"
85 #define MIDX_EXT_BITMAP "bitmap"
86 #define MIDX_EXT_MIDX "midx"
88 const unsigned char *get_midx_checksum(struct multi_pack_index *m);
89 void get_midx_filename(struct strbuf *out, const char *object_dir);
90 void get_midx_filename_ext(struct strbuf *out, const char *object_dir,
91 const unsigned char *hash, const char *ext);
92 void get_midx_chain_dirname(struct strbuf *buf, const char *object_dir);
93 void get_midx_chain_filename(struct strbuf *buf, const char *object_dir);
94 void get_split_midx_filename_ext(struct strbuf *buf, const char *object_dir,
95 const unsigned char *hash, const char *ext);
97 struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
98 int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
99 struct packed_git *nth_midxed_pack(struct multi_pack_index *m,
100 uint32_t pack_int_id);
101 int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
102 struct bitmapped_pack *bp, uint32_t pack_int_id);
103 int bsearch_one_midx(const struct object_id *oid, struct multi_pack_index *m,
104 uint32_t *result);
105 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m,
106 uint32_t *result);
107 int midx_has_oid(struct multi_pack_index *m, const struct object_id *oid);
108 off_t nth_midxed_offset(struct multi_pack_index *m, uint32_t pos);
109 uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos);
110 struct object_id *nth_midxed_object_oid(struct object_id *oid,
111 struct multi_pack_index *m,
112 uint32_t n);
113 int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
114 int midx_contains_pack(struct multi_pack_index *m,
115 const char *idx_or_pack_name);
116 int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
117 int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
120 * Variant of write_midx_file which writes a MIDX containing only the packs
121 * specified in packs_to_include.
123 int write_midx_file(const char *object_dir,
124 const char *preferred_pack_name,
125 const char *refs_snapshot,
126 unsigned flags);
127 int write_midx_file_only(const char *object_dir,
128 struct string_list *packs_to_include,
129 const char *preferred_pack_name,
130 const char *refs_snapshot,
131 unsigned flags);
132 void clear_midx_file(struct repository *r);
133 int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags);
134 int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags);
135 int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags);
137 void close_midx(struct multi_pack_index *m);
139 #endif