]> git.proxmox.com Git - libgit2.git/blob - src/midx.h
New upstream version 1.1.0+dfsg.1
[libgit2.git] / src / midx.h
1 /*
2 * Copyright (C) the libgit2 contributors. All rights reserved.
3 *
4 * This file is part of libgit2, distributed under the GNU GPL v2 with
5 * a Linking Exception. For full terms see the included COPYING file.
6 */
7
8 #ifndef INCLUDE_midx_h__
9 #define INCLUDE_midx_h__
10
11 #include "common.h"
12
13 #include <ctype.h>
14
15 #include "map.h"
16 #include "mwindow.h"
17
18 /*
19 * A multi-pack-index file.
20 *
21 * This file contains a merged index for multiple independent .pack files. This
22 * can help speed up locating objects without requiring a garbage collection
23 * cycle to create a single .pack file.
24 *
25 * Support for this feature was added in git 2.21, and requires the
26 * `core.multiPackIndex` config option to be set.
27 */
28 typedef struct git_midx_file {
29 git_map index_map;
30
31 /* The table of Packfile Names. */
32 git_vector packfile_names;
33
34 /* The OID Fanout table. */
35 const uint32_t *oid_fanout;
36 /* The total number of objects in the index. */
37 uint32_t num_objects;
38
39 /* The OID Lookup table. */
40 git_oid *oid_lookup;
41
42 /* The Object Offsets table. Each entry has two 4-byte fields with the pack index and the offset. */
43 const unsigned char *object_offsets;
44
45 /* The Object Large Offsets table. */
46 const unsigned char *object_large_offsets;
47 /* The number of entries in the Object Large Offsets table. Each entry has an 8-byte with an offset */
48 size_t num_object_large_offsets;
49
50 /* The trailer of the file. Contains the SHA1-checksum of the whole file. */
51 git_oid checksum;
52 } git_midx_file;
53
54 /*
55 * An entry in the multi-pack-index file. Similar in purpose to git_pack_entry.
56 */
57 typedef struct git_midx_entry {
58 /* The index within idx->packfile_names where the packfile name can be found. */
59 size_t pack_index;
60 /* The offset within the .pack file where the requested object is found. */
61 off64_t offset;
62 /* The SHA-1 hash of the requested object. */
63 git_oid sha1;
64 } git_midx_entry;
65
66 int git_midx_open(
67 git_midx_file **idx_out,
68 const char *path);
69 int git_midx_entry_find(
70 git_midx_entry *e,
71 git_midx_file *idx,
72 const git_oid *short_oid,
73 size_t len);
74 void git_midx_close(git_midx_file *idx);
75 void git_midx_free(git_midx_file *idx);
76
77 /* This is exposed for use in the fuzzers. */
78 int git_midx_parse(
79 git_midx_file *idx,
80 const unsigned char *data,
81 size_t size);
82
83 #endif