blob: 765221cdcc11410271ac93e5bf275e5ae21027cb [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"
Taylor Blau0bd52e22020-02-03 21:51:50 -08005#include "object-store.h"
Taylor Blau6830c362020-04-13 22:04:25 -06006#include "oidset.h"
Derrick Stolee2a2e32b2018-04-10 08:56:02 -04007
Derrick Stolee859fdc02018-08-29 05:49:04 -07008#define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH"
Derrick Stolee7b671f82020-06-23 17:47:01 +00009#define GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE "GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE"
Garima Singhd5b873c2020-04-06 16:59:55 +000010#define GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS "GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS"
Derrick Stolee859fdc02018-08-29 05:49:04 -070011
Derrick Stoleeb23ea972020-04-16 20:14:03 +000012/*
13 * This method is only used to enhance coverage of the commit-graph
14 * feature in the test suite with the GIT_TEST_COMMIT_GRAPH and
15 * GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS environment variables. Do not
16 * call this method oustide of a builtin, and only if you know what
17 * you are doing!
18 */
19void git_test_write_commit_graph_or_die(void);
20
Jonathan Tane5c5ca22018-07-11 15:42:39 -070021struct commit;
Garima Singh76ffbca2020-04-06 16:59:49 +000022struct bloom_filter_settings;
SZEDER Gáborfa796532020-06-05 13:00:28 +000023struct repository;
24struct raw_object_store;
25struct string_list;
Jonathan Tane5c5ca22018-07-11 15:42:39 -070026
Taylor Blauad2dd5b2020-02-03 13:18:02 -080027char *get_commit_graph_filename(struct object_directory *odb);
Derrick Stolee663b2b12020-09-17 18:11:46 +000028char *get_commit_graph_chain_filename(struct object_directory *odb);
Ævar Arnfjörð Bjarmason61df89c2019-03-25 13:08:30 +010029int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040030
Derrick Stolee177722b2018-04-10 08:56:05 -040031/*
32 * Given a commit struct, try to fill the commit struct info, including:
33 * 1. tree object
34 * 2. date
35 * 3. parents.
36 *
37 * Returns 1 if and only if the commit was found in the packed graph.
38 *
39 * See parse_commit_buffer() for the fallback after this call.
40 */
Jonathan Tandade47c2018-07-11 15:42:42 -070041int parse_commit_in_graph(struct repository *r, struct commit *item);
Derrick Stolee177722b2018-04-10 08:56:05 -040042
Derrick Stoleee2838d82018-05-01 12:47:13 +000043/*
44 * It is possible that we loaded commit contents from the commit buffer,
45 * but we also want to ensure the commit-graph content is correctly
46 * checked and filled. Fill the graph_pos and generation members of
47 * the given commit.
48 */
Jonathan Tandade47c2018-07-11 15:42:42 -070049void load_commit_graph_info(struct repository *r, struct commit *item);
Derrick Stoleee2838d82018-05-01 12:47:13 +000050
Jonathan Tandade47c2018-07-11 15:42:42 -070051struct tree *get_commit_tree_in_graph(struct repository *r,
52 const struct commit *c);
Derrick Stolee7b8a21d2018-04-06 19:09:46 +000053
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040054struct commit_graph {
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040055 const unsigned char *data;
56 size_t data_len;
57
58 unsigned char hash_len;
59 unsigned char num_chunks;
60 uint32_t num_commits;
61 struct object_id oid;
Derrick Stolee6c622f92019-06-18 11:14:27 -070062 char *filename;
Taylor Blau13c24992020-02-03 13:18:00 -080063 struct object_directory *odb;
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040064
Derrick Stoleed4f4d602019-06-18 11:14:24 -070065 uint32_t num_commits_in_base;
66 struct commit_graph *base_graph;
67
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040068 const uint32_t *chunk_oid_fanout;
69 const unsigned char *chunk_oid_lookup;
70 const unsigned char *chunk_commit_data;
SZEDER Gábor5af74172019-01-19 21:21:13 +010071 const unsigned char *chunk_extra_edges;
Derrick Stolee118bd572019-06-18 11:14:26 -070072 const unsigned char *chunk_base_graphs;
Garima Singh76ffbca2020-04-06 16:59:49 +000073 const unsigned char *chunk_bloom_indexes;
74 const unsigned char *chunk_bloom_data;
75
76 struct bloom_filter_settings *bloom_filter_settings;
Derrick Stolee2a2e32b2018-04-10 08:56:02 -040077};
78
Taylor Blaua7df60c2020-02-03 13:18:04 -080079struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st,
80 struct object_directory *odb);
Taylor Blau13c24992020-02-03 13:18:00 -080081struct commit_graph *read_commit_graph_one(struct repository *r,
82 struct object_directory *odb);
Jeff Kingc8828532020-04-23 15:41:13 -060083struct commit_graph *parse_commit_graph(void *graph_map, size_t graph_size);
Josh Steadmonaa658572019-01-15 14:25:50 -080084
Derrick Stolee6cc01742018-07-20 16:33:30 +000085/*
86 * Return 1 if and only if the repository has a commit-graph
87 * file and generation numbers are computed in that file.
88 */
89int generation_numbers_enabled(struct repository *r);
90
SZEDER Gábor39d88312019-08-05 10:02:39 +020091enum commit_graph_write_flags {
92 COMMIT_GRAPH_WRITE_APPEND = (1 << 0),
93 COMMIT_GRAPH_WRITE_PROGRESS = (1 << 1),
SZEDER Gábor7c5c9b92019-08-05 10:02:40 +020094 COMMIT_GRAPH_WRITE_SPLIT = (1 << 2),
Taylor Blau2f00c352020-05-13 15:59:55 -060095 COMMIT_GRAPH_WRITE_BLOOM_FILTERS = (1 << 3),
Junio C Hamano70cdbbe2020-07-30 13:20:31 -070096 COMMIT_GRAPH_NO_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
Abhishek Kumar48448122020-06-17 14:44:09 +0530140struct commit_graph_data {
141 uint32_t graph_pos;
142 uint32_t generation;
143};
144
145/*
146 * Commits should be parsed before accessing generation, graph positions.
147 */
148uint32_t commit_graph_generation(const struct commit *);
149uint32_t commit_graph_position(const struct commit *);
Derrick Stolee08fd81c2018-04-02 16:34:19 -0400150#endif