]> git.proxmox.com Git - libgit2.git/blob - src/midx.h
4ce17ce73a8f30055fcb5acaae2cf89117afd484
[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 "git2/sys/midx.h"
16
17 #include "map.h"
18 #include "mwindow.h"
19 #include "odb.h"
20
21 /*
22 * A multi-pack-index file.
23 *
24 * This file contains a merged index for multiple independent .pack files. This
25 * can help speed up locating objects without requiring a garbage collection
26 * cycle to create a single .pack file.
27 *
28 * Support for this feature was added in git 2.21, and requires the
29 * `core.multiPackIndex` config option to be set.
30 */
31 typedef struct git_midx_file {
32 git_map index_map;
33
34 /* The table of Packfile Names. */
35 git_vector packfile_names;
36
37 /* The OID Fanout table. */
38 const uint32_t *oid_fanout;
39 /* The total number of objects in the index. */
40 uint32_t num_objects;
41
42 /* The OID Lookup table. */
43 git_oid *oid_lookup;
44
45 /* The Object Offsets table. Each entry has two 4-byte fields with the pack index and the offset. */
46 const unsigned char *object_offsets;
47
48 /* The Object Large Offsets table. */
49 const unsigned char *object_large_offsets;
50 /* The number of entries in the Object Large Offsets table. Each entry has an 8-byte with an offset */
51 size_t num_object_large_offsets;
52
53 /* The trailer of the file. Contains the SHA1-checksum of the whole file. */
54 git_oid checksum;
55
56 /* something like ".git/objects/pack/multi-pack-index". */
57 git_buf filename;
58 } git_midx_file;
59
60 /*
61 * An entry in the multi-pack-index file. Similar in purpose to git_pack_entry.
62 */
63 typedef struct git_midx_entry {
64 /* The index within idx->packfile_names where the packfile name can be found. */
65 size_t pack_index;
66 /* The offset within the .pack file where the requested object is found. */
67 off64_t offset;
68 /* The SHA-1 hash of the requested object. */
69 git_oid sha1;
70 } git_midx_entry;
71
72 /*
73 * A writer for `multi-pack-index` files.
74 */
75 struct git_midx_writer {
76 /*
77 * The path of the directory where the .pack/.idx files are stored. The
78 * `multi-pack-index` file will be written to the same directory.
79 */
80 git_buf pack_dir;
81
82 /* The list of `git_pack_file`s. */
83 git_vector packs;
84 };
85
86 int git_midx_open(
87 git_midx_file **idx_out,
88 const char *path);
89 bool git_midx_needs_refresh(
90 const git_midx_file *idx,
91 const char *path);
92 int git_midx_entry_find(
93 git_midx_entry *e,
94 git_midx_file *idx,
95 const git_oid *short_oid,
96 size_t len);
97 int git_midx_foreach_entry(
98 git_midx_file *idx,
99 git_odb_foreach_cb cb,
100 void *data);
101 int git_midx_close(git_midx_file *idx);
102 void git_midx_free(git_midx_file *idx);
103
104 /* This is exposed for use in the fuzzers. */
105 int git_midx_parse(
106 git_midx_file *idx,
107 const unsigned char *data,
108 size_t size);
109
110 #endif