blob: 4212766a4f0507f52fb5d4f42edbf1b977fc5cae [file] [log] [blame]
Derrick Stolee08fd81c2018-04-02 16:34:19 -04001#ifndef COMMIT_GRAPH_H
2#define COMMIT_GRAPH_H
3
Derrick Stolee2a2e32b2018-04-10 08:56:02 -04004#include "git-compat-util.h"
Derrick Stolee283e68c2018-06-27 09:24:32 -04005#include "repository.h"
Derrick Stoleed88b14b2018-06-27 09:24:44 -04006#include "string-list.h"
Elijah Newrenef3ca952018-08-15 10:54:05 -07007#include "cache.h"
Taylor Blau0bd52e22020-02-03 21:51:50 -08008#include "object-store.h"
Taylor Blau6830c362020-04-13 22:04:25 -06009#include "oidset.h"
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040010
Derrick Stolee859fdc02018-08-29 05:49:04 -070011#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
Ævar Arnfjörð Bjarmason43d35612019-03-25 13:08:33 +010012#define GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD "GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD"
Garima Singhd5b873c2020-04-06 16:59:55 +000013#define GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS "GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS"
Derrick Stolee859fdc02018-08-29 05:49:04 -070014
Derrick Stoleeb23ea972020-04-16 20:14:03 +000015/*
16 * This method is only used to enhance coverage of the commit-graph
17 * feature in the test suite with the GIT_TEST_COMMIT_GRAPH and
18 * GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS environment variables. Do not
19 * call this method oustide of a builtin, and only if you know what
20 * you are doing!
21 */
22void git_test_write_commit_graph_or_die(void);
23
Jonathan Tane5c5ca22018-07-11 15:42:39 -070024struct commit;
Garima Singh76ffbca2020-04-06 16:59:49 +000025struct bloom_filter_settings;
Jonathan Tane5c5ca22018-07-11 15:42:39 -070026
Taylor Blauad2dd5b2020-02-03 13:18:02 -080027char *get_commit_graph_filename(struct object_directory *odb);
Ævar Arnfjörð Bjarmason61df89c2019-03-25 13:08:30 +010028int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040029
Derrick Stolee177722b2018-04-10 08:56:05 -040030/*
31 * Given a commit struct, try to fill the commit struct info, including:
32 * 1. tree object
33 * 2. date
34 * 3. parents.
35 *
36 * Returns 1 if and only if the commit was found in the packed graph.
37 *
38 * See parse_commit_buffer() for the fallback after this call.
39 */
Jonathan Tandade47c2018-07-11 15:42:42 -070040int parse_commit_in_graph(struct repository *r, struct commit *item);
Derrick Stolee177722b2018-04-10 08:56:05 -040041
Derrick Stoleee2838d82018-05-01 12:47:13 +000042/*
43 * It is possible that we loaded commit contents from the commit buffer,
44 * but we also want to ensure the commit-graph content is correctly
45 * checked and filled. Fill the graph_pos and generation members of
46 * the given commit.
47 */
Jonathan Tandade47c2018-07-11 15:42:42 -070048void load_commit_graph_info(struct repository *r, struct commit *item);
Derrick Stoleee2838d82018-05-01 12:47:13 +000049
Jonathan Tandade47c2018-07-11 15:42:42 -070050struct tree *get_commit_tree_in_graph(struct repository *r,
51 const struct commit *c);
Derrick Stolee7b8a21d2018-04-06 19:09:46 +000052
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040053struct commit_graph {
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040054 const unsigned char *data;
55 size_t data_len;
56
57 unsigned char hash_len;
58 unsigned char num_chunks;
59 uint32_t num_commits;
60 struct object_id oid;
Derrick Stolee6c622f92019-06-18 11:14:27 -070061 char *filename;
Taylor Blau13c24992020-02-03 13:18:00 -080062 struct object_directory *odb;
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040063
Derrick Stoleed4f4d602019-06-18 11:14:24 -070064 uint32_t num_commits_in_base;
65 struct commit_graph *base_graph;
66
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040067 const uint32_t *chunk_oid_fanout;
68 const unsigned char *chunk_oid_lookup;
69 const unsigned char *chunk_commit_data;
SZEDER Gábor5af74172019-01-19 21:21:13 +010070 const unsigned char *chunk_extra_edges;
Derrick Stolee118bd572019-06-18 11:14:26 -070071 const unsigned char *chunk_base_graphs;
Garima Singh76ffbca2020-04-06 16:59:49 +000072 const unsigned char *chunk_bloom_indexes;
73 const unsigned char *chunk_bloom_data;
74
75 struct bloom_filter_settings *bloom_filter_settings;
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040076};
77
Taylor Blaua7df60c2020-02-03 13:18:04 -080078struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
79 struct object_directory *odb);
Taylor Blau13c24992020-02-03 13:18:00 -080080struct commit_graph *read_commit_graph_one(struct repository *r,
81 struct object_directory *odb);
Jeff Kingc8828532020-04-23 15:41:13 -060082struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size);
Josh Steadmonaa658572019-01-15 14:25:50 -080083
Derrick Stolee6cc01742018-07-20 16:33:30 +000084/*
85 * Return 1 if and only if the repository has a commit-graph
86 * file and generation numbers are computed in that file.
87 */
88int generation_numbers_enabled(struct repository *r);
89
SZEDER Gábor39d88312019-08-05 10:02:39 +020090enum commit_graph_write_flags {
91 COMMIT_GRAPH_WRITE_APPEND = (1 << 0),
92 COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),
SZEDER Gábor7c5c9b92019-08-05 10:02:40 +020093 COMMIT_GRAPH_WRITE_SPLIT = (1 << 2),
94 /* Make sure that each OID in the input is a valid commit OID. */
Garima Singhf97b9322020-03-30 00:31:28 +000095 COMMIT_GRAPH_WRITE_CHECK_OIDS = (1 << 3),
96 COMMIT_GRAPH_WRITE_BLOOM_FILTERS = (1 << 4),
SZEDER Gábor39d88312019-08-05 10:02:39 +020097};
Derrick Stolee5af80392019-06-12 06:29:38 -070098
Taylor Blau4f027352020-04-13 22:04:08 -060099enum commit_graph_split_flags {
Taylor Blaufdbde822020-04-13 22:04:12 -0600100 COMMIT_GRAPH_SPLIT_UNSPECIFIED = 0,
Taylor Blau8a6ac282020-04-13 22:04:17 -0600101 COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED = 1,
102 COMMIT_GRAPH_SPLIT_REPLACE = 2
Taylor Blau4f027352020-04-13 22:04:08 -0600103};
104
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700105struct split_commit_graph_opts {
106 int size_multiple;
107 int max_commits;
108 timestamp_t expire_time;
Taylor Blau4f027352020-04-13 22:04:08 -0600109 enum commit_graph_split_flags flags;
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700110};
111
Derrick Stoleee103f722019-06-12 06:29:37 -0700112/*
113 * The write_commit_graph* methods return zero on success
114 * and a negative value on failure. Note that if the repository
115 * is not compatible with the commit-graph feature, then the
116 * methods will return 0 without writing a commit-graph.
117 */
Taylor Blau0bd52e22020-02-03 21:51:50 -0800118int write_commit_graph_reachable(struct object_directory *odb,
SZEDER Gábor39d88312019-08-05 10:02:39 +0200119 enum commit_graph_write_flags flags,
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700120 const struct split_commit_graph_opts *split_opts);
Taylor Blau0bd52e22020-02-03 21:51:50 -0800121int write_commit_graph(struct object_directory *odb,
Derrick Stoleee103f722019-06-12 06:29:37 -0700122 struct string_list *pack_indexes,
Taylor Blau6830c362020-04-13 22:04:25 -0600123 struct oidset *commits,
SZEDER Gábor39d88312019-08-05 10:02:39 +0200124 enum commit_graph_write_flags flags,
Derrick Stoleec2bc6e62019-06-18 11:14:32 -0700125 const struct split_commit_graph_opts *split_opts);
Derrick Stolee08fd81c2018-04-02 16:34:19 -0400126
Derrick Stolee3da4b602019-06-18 11:14:32 -0700127#define COMMIT_GRAPH_VERIFY_SHALLOW (1 << 0)
128
129int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
Derrick Stolee283e68c2018-06-27 09:24:32 -0400130
Derrick Stoleec3a3a962019-05-17 11:41:47 -0700131void close_commit_graph(struct raw_object_store *);
Jonathan Tanc3756d52018-07-11 15:42:40 -0700132void free_commit_graph(struct commit_graph *);
133
Jeff King6abada12019-09-12 10:44:45 -0400134/*
135 * Disable further use of the commit graph in this process when parsing a
136 * "struct commit".
137 */
138void disable_commit_graph(struct repository *r);
139
Derrick Stolee08fd81c2018-04-02 16:34:19 -0400140#endif