4 #include "string-list.h"
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
;
40 const uint32_t *revindex_data
;
41 const uint32_t *revindex_map
;
45 unsigned char version
;
46 unsigned char hash_len
;
47 unsigned char num_chunks
;
50 int preferred_pack_idx
;
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 #define MIDX_EXT_REV "rev"
78 #define MIDX_EXT_BITMAP "bitmap"
80 const unsigned char *get_midx_checksum(struct multi_pack_index
*m
);
81 void get_midx_filename(struct strbuf
*out
, const char *object_dir
);
82 void get_midx_filename_ext(struct strbuf
*out
, const char *object_dir
,
83 const unsigned char *hash
, const char *ext
);
85 struct multi_pack_index
*load_multi_pack_index(const char *object_dir
, int local
);
86 int prepare_midx_pack(struct repository
*r
, struct multi_pack_index
*m
, uint32_t pack_int_id
);
87 int nth_bitmapped_pack(struct repository
*r
, struct multi_pack_index
*m
,
88 struct bitmapped_pack
*bp
, uint32_t pack_int_id
);
89 int bsearch_midx(const struct object_id
*oid
, struct multi_pack_index
*m
, uint32_t *result
);
90 off_t
nth_midxed_offset(struct multi_pack_index
*m
, uint32_t pos
);
91 uint32_t nth_midxed_pack_int_id(struct multi_pack_index
*m
, uint32_t pos
);
92 struct object_id
*nth_midxed_object_oid(struct object_id
*oid
,
93 struct multi_pack_index
*m
,
95 int fill_midx_entry(struct repository
*r
, const struct object_id
*oid
, struct pack_entry
*e
, struct multi_pack_index
*m
);
96 int midx_contains_pack(struct multi_pack_index
*m
,
97 const char *idx_or_pack_name
);
98 int midx_locate_pack(struct multi_pack_index
*m
, const char *idx_or_pack_name
,
100 int midx_preferred_pack(struct multi_pack_index
*m
, uint32_t *pack_int_id
);
101 int prepare_multi_pack_index_one(struct repository
*r
, const char *object_dir
, int local
);
104 * Variant of write_midx_file which writes a MIDX containing only the packs
105 * specified in packs_to_include.
107 int write_midx_file(const char *object_dir
,
108 const char *preferred_pack_name
,
109 const char *refs_snapshot
,
111 int write_midx_file_only(const char *object_dir
,
112 struct string_list
*packs_to_include
,
113 const char *preferred_pack_name
,
114 const char *refs_snapshot
,
116 void clear_midx_file(struct repository
*r
);
117 int verify_midx_file(struct repository
*r
, const char *object_dir
, unsigned flags
);
118 int expire_midx_packs(struct repository
*r
, const char *object_dir
, unsigned flags
);
119 int midx_repack(struct repository
*r
, const char *object_dir
, size_t batch_size
, unsigned flags
);
121 void close_midx(struct multi_pack_index
*m
);