BreakingChanges: document upcoming change from "sha1" to "sha256"
[git.git] / midx.h
blobdc477dff4413747f84258791c070303047256926
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_CHUNK_OFFSET_WIDTH (2 * sizeof(uint32_t))
28 #define MIDX_LARGE_OFFSET_NEEDED 0x80000000
30 #define GIT_TEST_MULTI_PACK_INDEX "GIT_TEST_MULTI_PACK_INDEX"
31 #define GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP \
32 "GIT_TEST_MULTI_PACK_INDEX_WRITE_BITMAP"
34 struct multi_pack_index {
35 struct multi_pack_index *next;
37 const unsigned char *data;
38 size_t data_len;
40 const uint32_t *revindex_data;
41 const uint32_t *revindex_map;
42 size_t revindex_len;
44 uint32_t signature;
45 unsigned char version;
46 unsigned char hash_len;
47 unsigned char num_chunks;
48 uint32_t num_packs;
49 uint32_t num_objects;
50 int preferred_pack_idx;
52 int local;
54 const unsigned char *chunk_pack_names;
55 size_t chunk_pack_names_len;
56 const uint32_t *chunk_bitmapped_packs;
57 size_t chunk_bitmapped_packs_len;
58 const uint32_t *chunk_oid_fanout;
59 const unsigned char *chunk_oid_lookup;
60 const unsigned char *chunk_object_offsets;
61 const unsigned char *chunk_large_offsets;
62 size_t chunk_large_offsets_len;
63 const unsigned char *chunk_revindex;
64 size_t chunk_revindex_len;
66 const char **pack_names;
67 struct packed_git **packs;
68 char object_dir[FLEX_ARRAY];
71 #define MIDX_PROGRESS (1 << 0)
72 #define MIDX_WRITE_REV_INDEX (1 << 1)
73 #define MIDX_WRITE_BITMAP (1 << 2)
74 #define MIDX_WRITE_BITMAP_HASH_CACHE (1 << 3)
75 #define MIDX_WRITE_BITMAP_LOOKUP_TABLE (1 << 4)
77 const unsigned char *get_midx_checksum(struct multi_pack_index *m);
78 void get_midx_filename(struct strbuf *out, const char *object_dir);
79 void get_midx_rev_filename(struct strbuf *out, struct multi_pack_index *m);
81 struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local);
82 int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t pack_int_id);
83 int nth_bitmapped_pack(struct repository *r, struct multi_pack_index *m,
84 struct bitmapped_pack *bp, uint32_t pack_int_id);
85 int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result);
86 off_t nth_midxed_offset(struct multi_pack_index *m, uint32_t pos);
87 uint32_t nth_midxed_pack_int_id(struct multi_pack_index *m, uint32_t pos);
88 struct object_id *nth_midxed_object_oid(struct object_id *oid,
89 struct multi_pack_index *m,
90 uint32_t n);
91 int fill_midx_entry(struct repository *r, const struct object_id *oid, struct pack_entry *e, struct multi_pack_index *m);
92 int midx_contains_pack(struct multi_pack_index *m,
93 const char *idx_or_pack_name);
94 int midx_locate_pack(struct multi_pack_index *m, const char *idx_or_pack_name,
95 uint32_t *pos);
96 int midx_preferred_pack(struct multi_pack_index *m, uint32_t *pack_int_id);
97 int prepare_multi_pack_index_one(struct repository *r, const char *object_dir, int local);
100 * Variant of write_midx_file which writes a MIDX containing only the packs
101 * specified in packs_to_include.
103 int write_midx_file(const char *object_dir,
104 const char *preferred_pack_name,
105 const char *refs_snapshot,
106 unsigned flags);
107 int write_midx_file_only(const char *object_dir,
108 struct string_list *packs_to_include,
109 const char *preferred_pack_name,
110 const char *refs_snapshot,
111 unsigned flags);
112 void clear_midx_file(struct repository *r);
113 int verify_midx_file(struct repository *r, const char *object_dir, unsigned flags);
114 int expire_midx_packs(struct repository *r, const char *object_dir, unsigned flags);
115 int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, unsigned flags);
117 void close_midx(struct multi_pack_index *m);
119 #endif