interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / commit-graph.h

231 lines · 7664 bytes Raw Blame History
1#ifndef COMMIT_GRAPH_H
2#define COMMIT_GRAPH_H
3
4#include "odb.h"
5#include "oidset.h"
6
7#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
8#define GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE "GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE"
9#define GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS "GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS"
10
11/*
12 * This environment variable controls whether commits looked up via the
13 * commit graph will be double checked to exist in the object database.
14 */
15#define GIT_COMMIT_GRAPH_PARANOIA "GIT_COMMIT_GRAPH_PARANOIA"
16
17/*
18 * This method is only used to enhance coverage of the commit-graph
19 * feature in the test suite with the GIT_TEST_COMMIT_GRAPH and
20 * GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS environment variables. Do not
21 * call this method outside of a builtin, and only if you know what
22 * you are doing!
23 */
24void git_test_write_commit_graph_or_die(struct repository *repo);
25
26struct commit;
27struct bloom_filter_settings;
28struct repository;
29struct object_database;
30struct string_list;
31
32char *get_commit_graph_filename(const char *dir);
33char *get_commit_graph_chain_filename(const char *dir);
34struct commit_graph *prepare_commit_graph(struct repository *r);
35int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
36int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st,
37 const struct git_hash_algo *hash_algo);
38
39/*
40 * Given a commit struct, try to fill the commit struct info, including:
41 * 1. tree object
42 * 2. date
43 * 3. parents.
44 *
45 * Returns 1 if and only if the commit was found in the packed graph.
46 *
47 * See parse_commit_buffer() for the fallback after this call.
48 */
49int parse_commit_in_graph(struct repository *r, struct commit *item);
50
51/*
52 * Fills `*pos` with the graph position of `c`, and returns the graph `c` is
53 * found in, or NULL otherwise. Initializes the commit-graphs belonging to
54 * `r` if it hasn't been already.
55 *
56 * Note: this is a low-level helper that does not alter any slab data
57 * associated with `c`. Useful in circumstances where the slab data is
58 * already being modified (e.g., writing the commit-graph itself).
59 *
60 * In most cases, callers should use `parse_commit_in_graph()` instead.
61 */
62struct commit_graph *repo_find_commit_pos_in_graph(struct repository *r,
63 struct commit *c,
64 uint32_t *pos);
65
66/*
67 * Look up the given commit ID in the commit-graph. This will only return a
68 * commit if the ID exists both in the graph and in the object database such
69 * that we don't return commits whose object has been pruned. Otherwise, this
70 * function returns `NULL`.
71 */
72struct commit *lookup_commit_in_graph(struct repository *repo, const struct object_id *id);
73
74/*
75 * It is possible that we loaded commit contents from the commit buffer,
76 * but we also want to ensure the commit-graph content is correctly
77 * checked and filled. Fill the graph_pos and generation members of
78 * the given commit.
79 */
80void load_commit_graph_info(struct repository *r, struct commit *item);
81
82struct tree *get_commit_tree_in_graph(struct repository *r,
83 const struct commit *c);
84
85struct commit_graph {
86 const unsigned char *data;
87 size_t data_len;
88
89 struct repository *repo;
90 const struct git_hash_algo *hash_algo;
91 unsigned char num_chunks;
92 uint32_t num_commits;
93 struct object_id oid;
94 char *dir;
95 char *filename;
96
97 uint32_t num_commits_in_base;
98 unsigned int read_generation_data;
99 struct commit_graph *base_graph;
100
101 const uint32_t *chunk_oid_fanout;
102 const unsigned char *chunk_oid_lookup;
103 const unsigned char *chunk_commit_data;
104 const unsigned char *chunk_generation_data;
105 const unsigned char *chunk_generation_data_overflow;
106 size_t chunk_generation_data_overflow_size;
107 const unsigned char *chunk_extra_edges;
108 size_t chunk_extra_edges_size;
109 const unsigned char *chunk_base_graphs;
110 size_t chunk_base_graphs_size;
111 const unsigned char *chunk_bloom_indexes;
112 const unsigned char *chunk_bloom_data;
113 size_t chunk_bloom_data_size;
114
115 struct topo_level_slab *topo_levels;
116 struct bloom_filter_settings *bloom_filter_settings;
117};
118
119/*
120 * Load commit graphs from the given object directory `dir`. The directory may
121 * be given as a relative path; it is canonicalized internally so that graphs
122 * loaded from the same directory compare equal regardless of how the caller
123 * spelled the path.
124 */
125struct commit_graph *load_commit_graph_one_fd_st(struct repository *repo,
126 const char *dir,
127 int fd, struct stat *st);
128struct commit_graph *load_commit_graph_chain_fd_st(struct object_database *odb,
129 int fd, struct stat *st,
130 int *incomplete_chain);
131struct commit_graph *read_commit_graph_one(struct repository *repo,
132 const char *dir);
133
134struct repo_settings;
135
136/*
137 * Callers should initialize the repo_settings with prepare_repo_settings()
138 * prior to calling parse_commit_graph().
139 */
140struct commit_graph *parse_commit_graph(struct repository *r,
141 void *graph_map, size_t graph_size);
142
143/*
144 * Return 1 if and only if the repository has a commit-graph
145 * file and generation numbers are computed in that file.
146 */
147int generation_numbers_enabled(struct repository *r);
148
149/*
150 * Return 1 if and only if the repository has a commit-graph
151 * file and generation data chunk has been written for the file.
152 */
153int corrected_commit_dates_enabled(struct repository *r);
154
155struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r);
156
157enum commit_graph_write_flags {
158 COMMIT_GRAPH_WRITE_APPEND = (1 << 0),
159 COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),
160 COMMIT_GRAPH_WRITE_SPLIT = (1 << 2),
161 COMMIT_GRAPH_WRITE_BLOOM_FILTERS = (1 << 3),
162 COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS = (1 << 4),
163};
164
165enum commit_graph_split_flags {
166 COMMIT_GRAPH_SPLIT_UNSPECIFIED = 0,
167 COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED = 1,
168 COMMIT_GRAPH_SPLIT_REPLACE = 2
169};
170
171struct commit_graph_opts {
172 int size_multiple;
173 int max_commits;
174 timestamp_t expire_time;
175 enum commit_graph_split_flags split_flags;
176 int max_new_filters;
177};
178
179/*
180 * The write_commit_graph* methods return zero on success
181 * and a negative value on failure. Note that if the repository
182 * is not compatible with the commit-graph feature, then the
183 * methods will return 0 without writing a commit-graph.
184 *
185 * The object directory `dir` may be given as a relative path; it is
186 * canonicalized internally so that it compares equal to the directory of
187 * graphs that have already been loaded.
188 */
189int write_commit_graph_reachable(struct repository *repo,
190 const char *dir,
191 enum commit_graph_write_flags flags,
192 const struct commit_graph_opts *opts);
193int write_commit_graph(struct repository *r,
194 const char *dir,
195 const struct string_list *pack_indexes,
196 struct oidset *commits,
197 enum commit_graph_write_flags flags,
198 const struct commit_graph_opts *opts);
199
200#define COMMIT_GRAPH_VERIFY_SHALLOW (1 << 0)
201
202int verify_commit_graph(struct commit_graph *g, int flags);
203
204void close_commit_graph(struct object_database *);
205void free_commit_graph(struct commit_graph *);
206
207/*
208 * Disable further use of the commit graph in this process when parsing a
209 * "struct commit".
210 */
211void disable_commit_graph(struct repository *r);
212
213struct commit_graph_data {
214 uint32_t graph_pos;
215 timestamp_t generation;
216};
217
218/*
219 * Commits should be parsed before accessing generation, graph positions.
220 */
221timestamp_t commit_graph_generation(const struct commit *);
222uint32_t commit_graph_position(const struct commit *);
223
224/*
225 * After this method, all commits reachable from those in the given
226 * list will have non-zero, non-infinite generation numbers.
227 */
228void ensure_generations_valid(struct repository *r,
229 struct commit **commits, size_t nr);
230
231#endif