1 #include "git-compat-util.h"
10 #include "sha1-lookup.h"
11 #include "commit-graph.h"
12 #include "object-store.h"
15 #include "replace-object.h"
18 #include "commit-slab.h"
20 #include "json-writer.h"
23 void git_test_write_commit_graph_or_die(void)
26 if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0))
29 if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS, 0))
30 flags = COMMIT_GRAPH_WRITE_BLOOM_FILTERS;
32 if (write_commit_graph_reachable(the_repository->objects->odb,
34 die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
37 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
38 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
39 #define GRAPH_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
40 #define GRAPH_CHUNKID_DATA 0x43444154 /* "CDAT" */
41 #define GRAPH_CHUNKID_EXTRAEDGES 0x45444745 /* "EDGE" */
42 #define GRAPH_CHUNKID_BLOOMINDEXES 0x42494458 /* "BIDX" */
43 #define GRAPH_CHUNKID_BLOOMDATA 0x42444154 /* "BDAT" */
44 #define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
45 #define MAX_NUM_CHUNKS 7
47 #define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
49 #define GRAPH_VERSION_1 0x1
50 #define GRAPH_VERSION GRAPH_VERSION_1
52 #define GRAPH_EXTRA_EDGES_NEEDED 0x80000000
53 #define GRAPH_EDGE_LAST_MASK 0x7fffffff
54 #define GRAPH_PARENT_NONE 0x70000000
56 #define GRAPH_LAST_EDGE 0x80000000
58 #define GRAPH_HEADER_SIZE 8
59 #define GRAPH_FANOUT_SIZE (4 * 256)
60 #define GRAPH_CHUNKLOOKUP_WIDTH 12
61 #define GRAPH_MIN_SIZE (GRAPH_HEADER_SIZE + 4 * GRAPH_CHUNKLOOKUP_WIDTH \
62 + GRAPH_FANOUT_SIZE + the_hash_algo->rawsz)
64 /* Remember to update object flag allocation in object.h */
65 #define REACHABLE (1u<<15)
67 /* Keep track of the order in which commits are added to our list. */
68 define_commit_slab(commit_pos, int);
69 static struct commit_pos commit_pos = COMMIT_SLAB_INIT(1, commit_pos);
71 static void set_commit_pos(struct repository *r, const struct object_id *oid)
73 static int32_t max_pos;
74 struct commit *commit = lookup_commit(r, oid);
77 return; /* should never happen, but be lenient */
79 *commit_pos_at(&commit_pos, commit) = max_pos++;
82 static int commit_pos_cmp(const void *va, const void *vb)
84 const struct commit *a = *(const struct commit **)va;
85 const struct commit *b = *(const struct commit **)vb;
86 return commit_pos_at(&commit_pos, a) -
87 commit_pos_at(&commit_pos, b);
90 define_commit_slab(commit_graph_data_slab, struct commit_graph_data);
91 static struct commit_graph_data_slab commit_graph_data_slab =
92 COMMIT_SLAB_INIT(1, commit_graph_data_slab);
94 uint32_t commit_graph_position(const struct commit *c)
96 struct commit_graph_data *data =
97 commit_graph_data_slab_peek(&commit_graph_data_slab, c);
99 return data ? data->graph_pos : COMMIT_NOT_FROM_GRAPH;
102 uint32_t commit_graph_generation(const struct commit *c)
104 struct commit_graph_data *data =
105 commit_graph_data_slab_peek(&commit_graph_data_slab, c);
108 return GENERATION_NUMBER_INFINITY;
109 else if (data->graph_pos == COMMIT_NOT_FROM_GRAPH)
110 return GENERATION_NUMBER_INFINITY;
112 return data->generation;
115 static struct commit_graph_data *commit_graph_data_at(const struct commit *c)
117 unsigned int i, nth_slab;
118 struct commit_graph_data *data =
119 commit_graph_data_slab_peek(&commit_graph_data_slab, c);
124 nth_slab = c->index / commit_graph_data_slab.slab_size;
125 data = commit_graph_data_slab_at(&commit_graph_data_slab, c);
128 * commit-slab initializes elements with zero, overwrite this with
129 * COMMIT_NOT_FROM_GRAPH for graph_pos.
131 * We avoid initializing generation with checking if graph position
132 * is not COMMIT_NOT_FROM_GRAPH.
134 for (i = 0; i < commit_graph_data_slab.slab_size; i++) {
135 commit_graph_data_slab.slab[nth_slab][i].graph_pos =
136 COMMIT_NOT_FROM_GRAPH;
142 static int commit_gen_cmp(const void *va, const void *vb)
144 const struct commit *a = *(const struct commit **)va;
145 const struct commit *b = *(const struct commit **)vb;
147 uint32_t generation_a = commit_graph_generation(a);
148 uint32_t generation_b = commit_graph_generation(b);
149 /* lower generation commits first */
150 if (generation_a < generation_b)
152 else if (generation_a > generation_b)
155 /* use date as a heuristic when generations are equal */
156 if (a->date < b->date)
158 else if (a->date > b->date)
163 char *get_commit_graph_filename(struct object_directory *obj_dir)
165 return xstrfmt("%s/info/commit-graph", obj_dir->path);
168 static char *get_split_graph_filename(struct object_directory *odb,
171 return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb->path,
175 static char *get_chain_filename(struct object_directory *odb)
177 return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb->path);
180 static uint8_t oid_version(void)
185 static struct commit_graph *alloc_commit_graph(void)
187 struct commit_graph *g = xcalloc(1, sizeof(*g));
192 extern int read_replace_refs;
194 static int commit_graph_compatible(struct repository *r)
199 if (read_replace_refs) {
200 prepare_replace_object(r);
201 if (hashmap_get_size(&r->objects->replace_map->map))
205 prepare_commit_graft(r);
206 if (r->parsed_objects &&
207 (r->parsed_objects->grafts_nr || r->parsed_objects->substituted_parent))
209 if (is_repository_shallow(r))
215 int open_commit_graph(const char *graph_file, int *fd, struct stat *st)
217 *fd = git_open(graph_file);
220 if (fstat(*fd, st)) {
227 struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
228 int fd, struct stat *st,
229 struct object_directory *odb)
233 struct commit_graph *ret;
235 graph_size = xsize_t(st->st_size);
237 if (graph_size < GRAPH_MIN_SIZE) {
239 error(_("commit-graph file is too small"));
242 graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0);
244 ret = parse_commit_graph(r, graph_map, graph_size);
249 munmap(graph_map, graph_size);
254 static int verify_commit_graph_lite(struct commit_graph *g)
257 * Basic validation shared between parse_commit_graph()
258 * which'll be called every time the graph is used, and the
259 * much more expensive verify_commit_graph() used by
260 * "commit-graph verify".
262 * There should only be very basic checks here to ensure that
263 * we don't e.g. segfault in fill_commit_in_graph(), but
264 * because this is a very hot codepath nothing that e.g. loops
265 * over g->num_commits, or runs a checksum on the commit-graph
268 if (!g->chunk_oid_fanout) {
269 error("commit-graph is missing the OID Fanout chunk");
272 if (!g->chunk_oid_lookup) {
273 error("commit-graph is missing the OID Lookup chunk");
276 if (!g->chunk_commit_data) {
277 error("commit-graph is missing the Commit Data chunk");
284 struct commit_graph *parse_commit_graph(struct repository *r,
285 void *graph_map, size_t graph_size)
287 const unsigned char *data, *chunk_lookup;
289 struct commit_graph *graph;
290 uint64_t next_chunk_offset;
291 uint32_t graph_signature;
292 unsigned char graph_version, hash_version;
297 if (graph_size < GRAPH_MIN_SIZE)
300 data = (const unsigned char *)graph_map;
302 graph_signature = get_be32(data);
303 if (graph_signature != GRAPH_SIGNATURE) {
304 error(_("commit-graph signature %X does not match signature %X"),
305 graph_signature, GRAPH_SIGNATURE);
309 graph_version = *(unsigned char*)(data + 4);
310 if (graph_version != GRAPH_VERSION) {
311 error(_("commit-graph version %X does not match version %X"),
312 graph_version, GRAPH_VERSION);
316 hash_version = *(unsigned char*)(data + 5);
317 if (hash_version != oid_version()) {
318 error(_("commit-graph hash version %X does not match version %X"),
319 hash_version, oid_version());
323 prepare_repo_settings(r);
325 graph = alloc_commit_graph();
327 graph->hash_len = the_hash_algo->rawsz;
328 graph->num_chunks = *(unsigned char*)(data + 6);
329 graph->data = graph_map;
330 graph->data_len = graph_size;
332 if (graph_size < GRAPH_HEADER_SIZE +
333 (graph->num_chunks + 1) * GRAPH_CHUNKLOOKUP_WIDTH +
334 GRAPH_FANOUT_SIZE + the_hash_algo->rawsz) {
335 error(_("commit-graph file is too small to hold %u chunks"),
341 chunk_lookup = data + 8;
342 next_chunk_offset = get_be64(chunk_lookup + 4);
343 for (i = 0; i < graph->num_chunks; i++) {
345 uint64_t chunk_offset = next_chunk_offset;
346 int chunk_repeated = 0;
348 chunk_id = get_be32(chunk_lookup + 0);
350 chunk_lookup += GRAPH_CHUNKLOOKUP_WIDTH;
351 next_chunk_offset = get_be64(chunk_lookup + 4);
353 if (chunk_offset > graph_size - the_hash_algo->rawsz) {
354 error(_("commit-graph improper chunk offset %08x%08x"), (uint32_t)(chunk_offset >> 32),
355 (uint32_t)chunk_offset);
356 goto free_and_return;
360 case GRAPH_CHUNKID_OIDFANOUT:
361 if (graph->chunk_oid_fanout)
364 graph->chunk_oid_fanout = (uint32_t*)(data + chunk_offset);
367 case GRAPH_CHUNKID_OIDLOOKUP:
368 if (graph->chunk_oid_lookup)
371 graph->chunk_oid_lookup = data + chunk_offset;
372 graph->num_commits = (next_chunk_offset - chunk_offset)
377 case GRAPH_CHUNKID_DATA:
378 if (graph->chunk_commit_data)
381 graph->chunk_commit_data = data + chunk_offset;
384 case GRAPH_CHUNKID_EXTRAEDGES:
385 if (graph->chunk_extra_edges)
388 graph->chunk_extra_edges = data + chunk_offset;
391 case GRAPH_CHUNKID_BASE:
392 if (graph->chunk_base_graphs)
395 graph->chunk_base_graphs = data + chunk_offset;
398 case GRAPH_CHUNKID_BLOOMINDEXES:
399 if (graph->chunk_bloom_indexes)
401 else if (r->settings.commit_graph_read_changed_paths)
402 graph->chunk_bloom_indexes = data + chunk_offset;
405 case GRAPH_CHUNKID_BLOOMDATA:
406 if (graph->chunk_bloom_data)
408 else if (r->settings.commit_graph_read_changed_paths) {
409 uint32_t hash_version;
410 graph->chunk_bloom_data = data + chunk_offset;
411 hash_version = get_be32(data + chunk_offset);
413 if (hash_version != 1)
416 graph->bloom_filter_settings = xmalloc(sizeof(struct bloom_filter_settings));
417 graph->bloom_filter_settings->hash_version = hash_version;
418 graph->bloom_filter_settings->num_hashes = get_be32(data + chunk_offset + 4);
419 graph->bloom_filter_settings->bits_per_entry = get_be32(data + chunk_offset + 8);
420 graph->bloom_filter_settings->max_changed_paths = DEFAULT_BLOOM_MAX_CHANGES;
425 if (chunk_repeated) {
426 error(_("commit-graph chunk id %08x appears multiple times"), chunk_id);
427 goto free_and_return;
431 if (graph->chunk_bloom_indexes && graph->chunk_bloom_data) {
432 init_bloom_filters();
434 /* We need both the bloom chunks to exist together. Else ignore the data */
435 graph->chunk_bloom_indexes = NULL;
436 graph->chunk_bloom_data = NULL;
437 FREE_AND_NULL(graph->bloom_filter_settings);
440 hashcpy(graph->oid.hash, graph->data + graph->data_len - graph->hash_len);
442 if (verify_commit_graph_lite(graph))
443 goto free_and_return;
448 free(graph->bloom_filter_settings);
453 static struct commit_graph *load_commit_graph_one(struct repository *r,
454 const char *graph_file,
455 struct object_directory *odb)
460 struct commit_graph *g;
461 int open_ok = open_commit_graph(graph_file, &fd, &st);
466 g = load_commit_graph_one_fd_st(r, fd, &st, odb);
469 g->filename = xstrdup(graph_file);
474 static struct commit_graph *load_commit_graph_v1(struct repository *r,
475 struct object_directory *odb)
477 char *graph_name = get_commit_graph_filename(odb);
478 struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
484 static int add_graph_to_chain(struct commit_graph *g,
485 struct commit_graph *chain,
486 struct object_id *oids,
489 struct commit_graph *cur_g = chain;
491 if (n && !g->chunk_base_graphs) {
492 warning(_("commit-graph has no base graphs chunk"));
500 !oideq(&oids[n], &cur_g->oid) ||
501 !hasheq(oids[n].hash, g->chunk_base_graphs + g->hash_len * n)) {
502 warning(_("commit-graph chain does not match"));
506 cur_g = cur_g->base_graph;
509 g->base_graph = chain;
512 g->num_commits_in_base = chain->num_commits + chain->num_commits_in_base;
517 static struct commit_graph *load_commit_graph_chain(struct repository *r,
518 struct object_directory *odb)
520 struct commit_graph *graph_chain = NULL;
521 struct strbuf line = STRBUF_INIT;
523 struct object_id *oids;
524 int i = 0, valid = 1, count;
525 char *chain_name = get_chain_filename(odb);
529 fp = fopen(chain_name, "r");
530 stat_res = stat(chain_name, &st);
535 st.st_size <= the_hash_algo->hexsz)
538 count = st.st_size / (the_hash_algo->hexsz + 1);
539 oids = xcalloc(count, sizeof(struct object_id));
543 for (i = 0; i < count; i++) {
544 struct object_directory *odb;
546 if (strbuf_getline_lf(&line, fp) == EOF)
549 if (get_oid_hex(line.buf, &oids[i])) {
550 warning(_("invalid commit-graph chain: line '%s' not a hash"),
557 for (odb = r->objects->odb; odb; odb = odb->next) {
558 char *graph_name = get_split_graph_filename(odb, line.buf);
559 struct commit_graph *g = load_commit_graph_one(r, graph_name, odb);
564 if (add_graph_to_chain(g, graph_chain, oids, i)) {
574 warning(_("unable to find all commit-graph files"));
581 strbuf_release(&line);
586 struct commit_graph *read_commit_graph_one(struct repository *r,
587 struct object_directory *odb)
589 struct commit_graph *g = load_commit_graph_v1(r, odb);
592 g = load_commit_graph_chain(r, odb);
597 static void prepare_commit_graph_one(struct repository *r,
598 struct object_directory *odb)
601 if (r->objects->commit_graph)
604 r->objects->commit_graph = read_commit_graph_one(r, odb);
608 * Return 1 if commit_graph is non-NULL, and 0 otherwise.
610 * On the first invocation, this function attempts to load the commit
611 * graph if the_repository is configured to have one.
613 static int prepare_commit_graph(struct repository *r)
615 struct object_directory *odb;
618 * This must come before the "already attempted?" check below, because
619 * we want to disable even an already-loaded graph file.
621 if (r->commit_graph_disabled)
624 if (r->objects->commit_graph_attempted)
625 return !!r->objects->commit_graph;
626 r->objects->commit_graph_attempted = 1;
628 prepare_repo_settings(r);
630 if (!git_env_bool(GIT_TEST_COMMIT_GRAPH, 0) &&
631 r->settings.core_commit_graph != 1)
633 * This repository is not configured to use commit graphs, so
634 * do not load one. (But report commit_graph_attempted anyway
635 * so that commit graph loading is not attempted again for this
640 if (!commit_graph_compatible(r))
644 for (odb = r->objects->odb;
645 !r->objects->commit_graph && odb;
647 prepare_commit_graph_one(r, odb);
648 return !!r->objects->commit_graph;
651 int generation_numbers_enabled(struct repository *r)
653 uint32_t first_generation;
654 struct commit_graph *g;
655 if (!prepare_commit_graph(r))
658 g = r->objects->commit_graph;
663 first_generation = get_be32(g->chunk_commit_data +
664 g->hash_len + 8) >> 2;
666 return !!first_generation;
669 struct bloom_filter_settings *get_bloom_filter_settings(struct repository *r)
671 struct commit_graph *g = r->objects->commit_graph;
673 if (g->bloom_filter_settings)
674 return g->bloom_filter_settings;
680 static void close_commit_graph_one(struct commit_graph *g)
685 close_commit_graph_one(g->base_graph);
686 free_commit_graph(g);
689 void close_commit_graph(struct raw_object_store *o)
691 close_commit_graph_one(o->commit_graph);
692 o->commit_graph = NULL;
695 static int bsearch_graph(struct commit_graph *g, struct object_id *oid, uint32_t *pos)
697 return bsearch_hash(oid->hash, g->chunk_oid_fanout,
698 g->chunk_oid_lookup, g->hash_len, pos);
701 static void load_oid_from_graph(struct commit_graph *g,
703 struct object_id *oid)
707 while (g && pos < g->num_commits_in_base)
711 BUG("NULL commit-graph");
713 if (pos >= g->num_commits + g->num_commits_in_base)
714 die(_("invalid commit position. commit-graph is likely corrupt"));
716 lex_index = pos - g->num_commits_in_base;
718 hashcpy(oid->hash, g->chunk_oid_lookup + g->hash_len * lex_index);
721 static struct commit_list **insert_parent_or_die(struct repository *r,
722 struct commit_graph *g,
724 struct commit_list **pptr)
727 struct object_id oid;
729 if (pos >= g->num_commits + g->num_commits_in_base)
730 die("invalid parent position %"PRIu32, pos);
732 load_oid_from_graph(g, pos, &oid);
733 c = lookup_commit(r, &oid);
735 die(_("could not find commit %s"), oid_to_hex(&oid));
736 commit_graph_data_at(c)->graph_pos = pos;
737 return &commit_list_insert(c, pptr)->next;
740 static void fill_commit_graph_info(struct commit *item, struct commit_graph *g, uint32_t pos)
742 const unsigned char *commit_data;
743 struct commit_graph_data *graph_data;
746 while (pos < g->num_commits_in_base)
749 lex_index = pos - g->num_commits_in_base;
750 commit_data = g->chunk_commit_data + GRAPH_DATA_WIDTH * lex_index;
752 graph_data = commit_graph_data_at(item);
753 graph_data->graph_pos = pos;
754 graph_data->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
757 static inline void set_commit_tree(struct commit *c, struct tree *t)
762 static int fill_commit_in_graph(struct repository *r,
764 struct commit_graph *g, uint32_t pos)
767 uint32_t *parent_data_ptr;
768 uint64_t date_low, date_high;
769 struct commit_list **pptr;
770 struct commit_graph_data *graph_data;
771 const unsigned char *commit_data;
774 while (pos < g->num_commits_in_base)
777 if (pos >= g->num_commits + g->num_commits_in_base)
778 die(_("invalid commit position. commit-graph is likely corrupt"));
781 * Store the "full" position, but then use the
782 * "local" position for the rest of the calculation.
784 graph_data = commit_graph_data_at(item);
785 graph_data->graph_pos = pos;
786 lex_index = pos - g->num_commits_in_base;
788 commit_data = g->chunk_commit_data + (g->hash_len + 16) * lex_index;
790 item->object.parsed = 1;
792 set_commit_tree(item, NULL);
794 date_high = get_be32(commit_data + g->hash_len + 8) & 0x3;
795 date_low = get_be32(commit_data + g->hash_len + 12);
796 item->date = (timestamp_t)((date_high << 32) | date_low);
798 graph_data->generation = get_be32(commit_data + g->hash_len + 8) >> 2;
800 pptr = &item->parents;
802 edge_value = get_be32(commit_data + g->hash_len);
803 if (edge_value == GRAPH_PARENT_NONE)
805 pptr = insert_parent_or_die(r, g, edge_value, pptr);
807 edge_value = get_be32(commit_data + g->hash_len + 4);
808 if (edge_value == GRAPH_PARENT_NONE)
810 if (!(edge_value & GRAPH_EXTRA_EDGES_NEEDED)) {
811 pptr = insert_parent_or_die(r, g, edge_value, pptr);
815 parent_data_ptr = (uint32_t*)(g->chunk_extra_edges +
816 4 * (uint64_t)(edge_value & GRAPH_EDGE_LAST_MASK));
818 edge_value = get_be32(parent_data_ptr);
819 pptr = insert_parent_or_die(r, g,
820 edge_value & GRAPH_EDGE_LAST_MASK,
823 } while (!(edge_value & GRAPH_LAST_EDGE));
828 static int find_commit_in_graph(struct commit *item, struct commit_graph *g, uint32_t *pos)
830 uint32_t graph_pos = commit_graph_position(item);
831 if (graph_pos != COMMIT_NOT_FROM_GRAPH) {
835 struct commit_graph *cur_g = g;
838 while (cur_g && !bsearch_graph(cur_g, &(item->object.oid), &lex_index))
839 cur_g = cur_g->base_graph;
842 *pos = lex_index + cur_g->num_commits_in_base;
850 static int parse_commit_in_graph_one(struct repository *r,
851 struct commit_graph *g,
856 if (item->object.parsed)
859 if (find_commit_in_graph(item, g, &pos))
860 return fill_commit_in_graph(r, item, g, pos);
865 int parse_commit_in_graph(struct repository *r, struct commit *item)
867 static int checked_env = 0;
870 git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE, 0))
871 die("dying as requested by the '%s' variable on commit-graph parse!",
872 GIT_TEST_COMMIT_GRAPH_DIE_ON_PARSE);
875 if (!prepare_commit_graph(r))
877 return parse_commit_in_graph_one(r, r->objects->commit_graph, item);
880 void load_commit_graph_info(struct repository *r, struct commit *item)
883 if (!prepare_commit_graph(r))
885 if (find_commit_in_graph(item, r->objects->commit_graph, &pos))
886 fill_commit_graph_info(item, r->objects->commit_graph, pos);
889 static struct tree *load_tree_for_commit(struct repository *r,
890 struct commit_graph *g,
893 struct object_id oid;
894 const unsigned char *commit_data;
895 uint32_t graph_pos = commit_graph_position(c);
897 while (graph_pos < g->num_commits_in_base)
900 commit_data = g->chunk_commit_data +
901 GRAPH_DATA_WIDTH * (graph_pos - g->num_commits_in_base);
903 hashcpy(oid.hash, commit_data);
904 set_commit_tree(c, lookup_tree(r, &oid));
906 return c->maybe_tree;
909 static struct tree *get_commit_tree_in_graph_one(struct repository *r,
910 struct commit_graph *g,
911 const struct commit *c)
914 return c->maybe_tree;
915 if (commit_graph_position(c) == COMMIT_NOT_FROM_GRAPH)
916 BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
918 return load_tree_for_commit(r, g, (struct commit *)c);
921 struct tree *get_commit_tree_in_graph(struct repository *r, const struct commit *c)
923 return get_commit_tree_in_graph_one(r, r->objects->commit_graph, c);
926 struct packed_commit_list {
927 struct commit **list;
932 struct packed_oid_list {
933 struct object_id *list;
938 struct write_commit_graph_context {
939 struct repository *r;
940 struct object_directory *odb;
942 struct packed_oid_list oids;
943 struct packed_commit_list commits;
945 unsigned long approx_nr_objects;
946 struct progress *progress;
948 uint64_t progress_cnt;
950 char *base_graph_name;
951 int num_commit_graphs_before;
952 int num_commit_graphs_after;
953 char **commit_graph_filenames_before;
954 char **commit_graph_filenames_after;
955 char **commit_graph_hash_after;
956 uint32_t new_num_commits_in_base;
957 struct commit_graph *new_base_graph;
965 const struct split_commit_graph_opts *split_opts;
966 size_t total_bloom_filter_data_size;
967 const struct bloom_filter_settings *bloom_settings;
969 int count_bloom_filter_computed;
970 int count_bloom_filter_not_computed;
971 int count_bloom_filter_trunc_large;
974 static int write_graph_chunk_fanout(struct hashfile *f,
975 struct write_commit_graph_context *ctx)
978 struct commit **list = ctx->commits.list;
981 * Write the first-level table (the list is sorted,
982 * but we use a 256-entry lookup to be able to avoid
983 * having to do eight extra binary search iterations).
985 for (i = 0; i < 256; i++) {
986 while (count < ctx->commits.nr) {
987 if ((*list)->object.oid.hash[0] != i)
989 display_progress(ctx->progress, ++ctx->progress_cnt);
994 hashwrite_be32(f, count);
1000 static int write_graph_chunk_oids(struct hashfile *f,
1001 struct write_commit_graph_context *ctx)
1003 struct commit **list = ctx->commits.list;
1005 for (count = 0; count < ctx->commits.nr; count++, list++) {
1006 display_progress(ctx->progress, ++ctx->progress_cnt);
1007 hashwrite(f, (*list)->object.oid.hash, the_hash_algo->rawsz);
1013 static const unsigned char *commit_to_sha1(size_t index, void *table)
1015 struct commit **commits = table;
1016 return commits[index]->object.oid.hash;
1019 static int write_graph_chunk_data(struct hashfile *f,
1020 struct write_commit_graph_context *ctx)
1022 struct commit **list = ctx->commits.list;
1023 struct commit **last = ctx->commits.list + ctx->commits.nr;
1024 uint32_t num_extra_edges = 0;
1026 while (list < last) {
1027 struct commit_list *parent;
1028 struct object_id *tree;
1030 uint32_t packedDate[2];
1031 display_progress(ctx->progress, ++ctx->progress_cnt);
1033 if (parse_commit_no_graph(*list))
1034 die(_("unable to parse commit %s"),
1035 oid_to_hex(&(*list)->object.oid));
1036 tree = get_commit_tree_oid(*list);
1037 hashwrite(f, tree->hash, the_hash_algo->rawsz);
1039 parent = (*list)->parents;
1042 edge_value = GRAPH_PARENT_NONE;
1044 edge_value = sha1_pos(parent->item->object.oid.hash,
1049 if (edge_value >= 0)
1050 edge_value += ctx->new_num_commits_in_base;
1051 else if (ctx->new_base_graph) {
1053 if (find_commit_in_graph(parent->item,
1054 ctx->new_base_graph,
1060 BUG("missing parent %s for commit %s",
1061 oid_to_hex(&parent->item->object.oid),
1062 oid_to_hex(&(*list)->object.oid));
1065 hashwrite_be32(f, edge_value);
1068 parent = parent->next;
1071 edge_value = GRAPH_PARENT_NONE;
1072 else if (parent->next)
1073 edge_value = GRAPH_EXTRA_EDGES_NEEDED | num_extra_edges;
1075 edge_value = sha1_pos(parent->item->object.oid.hash,
1080 if (edge_value >= 0)
1081 edge_value += ctx->new_num_commits_in_base;
1082 else if (ctx->new_base_graph) {
1084 if (find_commit_in_graph(parent->item,
1085 ctx->new_base_graph,
1091 BUG("missing parent %s for commit %s",
1092 oid_to_hex(&parent->item->object.oid),
1093 oid_to_hex(&(*list)->object.oid));
1096 hashwrite_be32(f, edge_value);
1098 if (edge_value & GRAPH_EXTRA_EDGES_NEEDED) {
1101 parent = parent->next;
1105 if (sizeof((*list)->date) > 4)
1106 packedDate[0] = htonl(((*list)->date >> 32) & 0x3);
1110 packedDate[0] |= htonl(commit_graph_data_at(*list)->generation << 2);
1112 packedDate[1] = htonl((*list)->date);
1113 hashwrite(f, packedDate, 8);
1121 static int write_graph_chunk_extra_edges(struct hashfile *f,
1122 struct write_commit_graph_context *ctx)
1124 struct commit **list = ctx->commits.list;
1125 struct commit **last = ctx->commits.list + ctx->commits.nr;
1126 struct commit_list *parent;
1128 while (list < last) {
1129 int num_parents = 0;
1131 display_progress(ctx->progress, ++ctx->progress_cnt);
1133 for (parent = (*list)->parents; num_parents < 3 && parent;
1134 parent = parent->next)
1137 if (num_parents <= 2) {
1142 /* Since num_parents > 2, this initializer is safe. */
1143 for (parent = (*list)->parents->next; parent; parent = parent->next) {
1144 int edge_value = sha1_pos(parent->item->object.oid.hash,
1149 if (edge_value >= 0)
1150 edge_value += ctx->new_num_commits_in_base;
1151 else if (ctx->new_base_graph) {
1153 if (find_commit_in_graph(parent->item,
1154 ctx->new_base_graph,
1160 BUG("missing parent %s for commit %s",
1161 oid_to_hex(&parent->item->object.oid),
1162 oid_to_hex(&(*list)->object.oid));
1163 else if (!parent->next)
1164 edge_value |= GRAPH_LAST_EDGE;
1166 hashwrite_be32(f, edge_value);
1175 static int write_graph_chunk_bloom_indexes(struct hashfile *f,
1176 struct write_commit_graph_context *ctx)
1178 struct commit **list = ctx->commits.list;
1179 struct commit **last = ctx->commits.list + ctx->commits.nr;
1180 uint32_t cur_pos = 0;
1182 while (list < last) {
1183 struct bloom_filter *filter = get_bloom_filter(ctx->r, *list);
1184 size_t len = filter ? filter->len : 0;
1186 display_progress(ctx->progress, ++ctx->progress_cnt);
1187 hashwrite_be32(f, cur_pos);
1194 static void trace2_bloom_filter_settings(struct write_commit_graph_context *ctx)
1196 struct json_writer jw = JSON_WRITER_INIT;
1198 jw_object_begin(&jw, 0);
1199 jw_object_intmax(&jw, "hash_version", ctx->bloom_settings->hash_version);
1200 jw_object_intmax(&jw, "num_hashes", ctx->bloom_settings->num_hashes);
1201 jw_object_intmax(&jw, "bits_per_entry", ctx->bloom_settings->bits_per_entry);
1202 jw_object_intmax(&jw, "max_changed_paths", ctx->bloom_settings->max_changed_paths);
1205 trace2_data_json("bloom", ctx->r, "settings", &jw);
1210 static int write_graph_chunk_bloom_data(struct hashfile *f,
1211 struct write_commit_graph_context *ctx)
1213 struct commit **list = ctx->commits.list;
1214 struct commit **last = ctx->commits.list + ctx->commits.nr;
1216 trace2_bloom_filter_settings(ctx);
1218 hashwrite_be32(f, ctx->bloom_settings->hash_version);
1219 hashwrite_be32(f, ctx->bloom_settings->num_hashes);
1220 hashwrite_be32(f, ctx->bloom_settings->bits_per_entry);
1222 while (list < last) {
1223 struct bloom_filter *filter = get_bloom_filter(ctx->r, *list);
1224 size_t len = filter ? filter->len : 0;
1226 display_progress(ctx->progress, ++ctx->progress_cnt);
1228 hashwrite(f, filter->data, len * sizeof(unsigned char));
1235 static int oid_compare(const void *_a, const void *_b)
1237 const struct object_id *a = (const struct object_id *)_a;
1238 const struct object_id *b = (const struct object_id *)_b;
1239 return oidcmp(a, b);
1242 static int add_packed_commits(const struct object_id *oid,
1243 struct packed_git *pack,
1247 struct write_commit_graph_context *ctx = (struct write_commit_graph_context*)data;
1248 enum object_type type;
1249 off_t offset = nth_packed_object_offset(pack, pos);
1250 struct object_info oi = OBJECT_INFO_INIT;
1253 display_progress(ctx->progress, ++ctx->progress_done);
1256 if (packed_object_info(ctx->r, pack, offset, &oi) < 0)
1257 die(_("unable to get type of object %s"), oid_to_hex(oid));
1259 if (type != OBJ_COMMIT)
1262 ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
1263 oidcpy(&(ctx->oids.list[ctx->oids.nr]), oid);
1266 set_commit_pos(ctx->r, oid);
1271 static void add_missing_parents(struct write_commit_graph_context *ctx, struct commit *commit)
1273 struct commit_list *parent;
1274 for (parent = commit->parents; parent; parent = parent->next) {
1275 if (!(parent->item->object.flags & REACHABLE)) {
1276 ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
1277 oidcpy(&ctx->oids.list[ctx->oids.nr], &(parent->item->object.oid));
1279 parent->item->object.flags |= REACHABLE;
1284 static void close_reachable(struct write_commit_graph_context *ctx)
1287 struct commit *commit;
1288 enum commit_graph_split_flags flags = ctx->split_opts ?
1289 ctx->split_opts->flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED;
1291 if (ctx->report_progress)
1292 ctx->progress = start_delayed_progress(
1293 _("Loading known commits in commit graph"),
1295 for (i = 0; i < ctx->oids.nr; i++) {
1296 display_progress(ctx->progress, i + 1);
1297 commit = lookup_commit(ctx->r, &ctx->oids.list[i]);
1299 commit->object.flags |= REACHABLE;
1301 stop_progress(&ctx->progress);
1304 * As this loop runs, ctx->oids.nr may grow, but not more
1305 * than the number of missing commits in the reachable
1308 if (ctx->report_progress)
1309 ctx->progress = start_delayed_progress(
1310 _("Expanding reachable commits in commit graph"),
1312 for (i = 0; i < ctx->oids.nr; i++) {
1313 display_progress(ctx->progress, i + 1);
1314 commit = lookup_commit(ctx->r, &ctx->oids.list[i]);
1319 if ((!parse_commit(commit) &&
1320 commit_graph_position(commit) == COMMIT_NOT_FROM_GRAPH) ||
1321 flags == COMMIT_GRAPH_SPLIT_REPLACE)
1322 add_missing_parents(ctx, commit);
1323 } else if (!parse_commit_no_graph(commit))
1324 add_missing_parents(ctx, commit);
1326 stop_progress(&ctx->progress);
1328 if (ctx->report_progress)
1329 ctx->progress = start_delayed_progress(
1330 _("Clearing commit marks in commit graph"),
1332 for (i = 0; i < ctx->oids.nr; i++) {
1333 display_progress(ctx->progress, i + 1);
1334 commit = lookup_commit(ctx->r, &ctx->oids.list[i]);
1337 commit->object.flags &= ~REACHABLE;
1339 stop_progress(&ctx->progress);
1342 static void compute_generation_numbers(struct write_commit_graph_context *ctx)
1345 struct commit_list *list = NULL;
1347 if (ctx->report_progress)
1348 ctx->progress = start_delayed_progress(
1349 _("Computing commit graph generation numbers"),
1351 for (i = 0; i < ctx->commits.nr; i++) {
1352 uint32_t generation = commit_graph_data_at(ctx->commits.list[i])->generation;
1354 display_progress(ctx->progress, i + 1);
1355 if (generation != GENERATION_NUMBER_INFINITY &&
1356 generation != GENERATION_NUMBER_ZERO)
1359 commit_list_insert(ctx->commits.list[i], &list);
1361 struct commit *current = list->item;
1362 struct commit_list *parent;
1363 int all_parents_computed = 1;
1364 uint32_t max_generation = 0;
1366 for (parent = current->parents; parent; parent = parent->next) {
1367 generation = commit_graph_data_at(parent->item)->generation;
1369 if (generation == GENERATION_NUMBER_INFINITY ||
1370 generation == GENERATION_NUMBER_ZERO) {
1371 all_parents_computed = 0;
1372 commit_list_insert(parent->item, &list);
1374 } else if (generation > max_generation) {
1375 max_generation = generation;
1379 if (all_parents_computed) {
1380 struct commit_graph_data *data = commit_graph_data_at(current);
1382 data->generation = max_generation + 1;
1385 if (data->generation > GENERATION_NUMBER_MAX)
1386 data->generation = GENERATION_NUMBER_MAX;
1390 stop_progress(&ctx->progress);
1393 static void trace2_bloom_filter_write_statistics(struct write_commit_graph_context *ctx)
1395 trace2_data_intmax("commit-graph", ctx->r, "filter-computed",
1396 ctx->count_bloom_filter_computed);
1397 trace2_data_intmax("commit-graph", ctx->r, "filter-not-computed",
1398 ctx->count_bloom_filter_not_computed);
1399 trace2_data_intmax("commit-graph", ctx->r, "filter-trunc-large",
1400 ctx->count_bloom_filter_trunc_large);
1403 static void compute_bloom_filters(struct write_commit_graph_context *ctx)
1406 struct progress *progress = NULL;
1407 struct commit **sorted_commits;
1409 init_bloom_filters();
1411 if (ctx->report_progress)
1412 progress = start_delayed_progress(
1413 _("Computing commit changed paths Bloom filters"),
1416 ALLOC_ARRAY(sorted_commits, ctx->commits.nr);
1417 COPY_ARRAY(sorted_commits, ctx->commits.list, ctx->commits.nr);
1419 if (ctx->order_by_pack)
1420 QSORT(sorted_commits, ctx->commits.nr, commit_pos_cmp);
1422 QSORT(sorted_commits, ctx->commits.nr, commit_gen_cmp);
1424 for (i = 0; i < ctx->commits.nr; i++) {
1425 enum bloom_filter_computed computed = 0;
1426 struct commit *c = sorted_commits[i];
1427 struct bloom_filter *filter = get_or_compute_bloom_filter(
1431 ctx->bloom_settings,
1433 if (computed & BLOOM_COMPUTED) {
1434 ctx->count_bloom_filter_computed++;
1435 if (computed & BLOOM_TRUNC_LARGE)
1436 ctx->count_bloom_filter_trunc_large++;
1437 } else if (computed & BLOOM_NOT_COMPUTED)
1438 ctx->count_bloom_filter_not_computed++;
1439 ctx->total_bloom_filter_data_size += sizeof(unsigned char) * filter->len;
1440 display_progress(progress, i + 1);
1443 if (trace2_is_enabled())
1444 trace2_bloom_filter_write_statistics(ctx);
1446 free(sorted_commits);
1447 stop_progress(&progress);
1450 struct refs_cb_data {
1451 struct oidset *commits;
1452 struct progress *progress;
1455 static int add_ref_to_set(const char *refname,
1456 const struct object_id *oid,
1457 int flags, void *cb_data)
1459 struct object_id peeled;
1460 struct refs_cb_data *data = (struct refs_cb_data *)cb_data;
1462 if (!peel_ref(refname, &peeled))
1464 if (oid_object_info(the_repository, oid, NULL) == OBJ_COMMIT)
1465 oidset_insert(data->commits, oid);
1467 display_progress(data->progress, oidset_size(data->commits));
1472 int write_commit_graph_reachable(struct object_directory *odb,
1473 enum commit_graph_write_flags flags,
1474 const struct split_commit_graph_opts *split_opts)
1476 struct oidset commits = OIDSET_INIT;
1477 struct refs_cb_data data;
1480 memset(&data, 0, sizeof(data));
1481 data.commits = &commits;
1482 if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
1483 data.progress = start_delayed_progress(
1484 _("Collecting referenced commits"), 0);
1486 for_each_ref(add_ref_to_set, &data);
1488 stop_progress(&data.progress);
1490 result = write_commit_graph(odb, NULL, &commits,
1493 oidset_clear(&commits);
1497 static int fill_oids_from_packs(struct write_commit_graph_context *ctx,
1498 struct string_list *pack_indexes)
1501 struct strbuf progress_title = STRBUF_INIT;
1502 struct strbuf packname = STRBUF_INIT;
1505 strbuf_addf(&packname, "%s/pack/", ctx->odb->path);
1506 dirlen = packname.len;
1507 if (ctx->report_progress) {
1508 strbuf_addf(&progress_title,
1509 Q_("Finding commits for commit graph in %d pack",
1510 "Finding commits for commit graph in %d packs",
1513 ctx->progress = start_delayed_progress(progress_title.buf, 0);
1514 ctx->progress_done = 0;
1516 for (i = 0; i < pack_indexes->nr; i++) {
1517 struct packed_git *p;
1518 strbuf_setlen(&packname, dirlen);
1519 strbuf_addstr(&packname, pack_indexes->items[i].string);
1520 p = add_packed_git(packname.buf, packname.len, 1);
1522 error(_("error adding pack %s"), packname.buf);
1525 if (open_pack_index(p)) {
1526 error(_("error opening index for %s"), packname.buf);
1529 for_each_object_in_pack(p, add_packed_commits, ctx,
1530 FOR_EACH_OBJECT_PACK_ORDER);
1535 stop_progress(&ctx->progress);
1536 strbuf_release(&progress_title);
1537 strbuf_release(&packname);
1542 static int fill_oids_from_commits(struct write_commit_graph_context *ctx,
1543 struct oidset *commits)
1545 struct oidset_iter iter;
1546 struct object_id *oid;
1548 if (!oidset_size(commits))
1551 oidset_iter_init(commits, &iter);
1552 while ((oid = oidset_iter_next(&iter))) {
1553 ALLOC_GROW(ctx->oids.list, ctx->oids.nr + 1, ctx->oids.alloc);
1554 oidcpy(&ctx->oids.list[ctx->oids.nr], oid);
1561 static void fill_oids_from_all_packs(struct write_commit_graph_context *ctx)
1563 if (ctx->report_progress)
1564 ctx->progress = start_delayed_progress(
1565 _("Finding commits for commit graph among packed objects"),
1566 ctx->approx_nr_objects);
1567 for_each_packed_object(add_packed_commits, ctx,
1568 FOR_EACH_OBJECT_PACK_ORDER);
1569 if (ctx->progress_done < ctx->approx_nr_objects)
1570 display_progress(ctx->progress, ctx->approx_nr_objects);
1571 stop_progress(&ctx->progress);
1574 static uint32_t count_distinct_commits(struct write_commit_graph_context *ctx)
1576 uint32_t i, count_distinct = 1;
1578 if (ctx->report_progress)
1579 ctx->progress = start_delayed_progress(
1580 _("Counting distinct commits in commit graph"),
1582 display_progress(ctx->progress, 0); /* TODO: Measure QSORT() progress */
1583 QSORT(ctx->oids.list, ctx->oids.nr, oid_compare);
1585 for (i = 1; i < ctx->oids.nr; i++) {
1586 display_progress(ctx->progress, i + 1);
1587 if (!oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i])) {
1589 struct commit *c = lookup_commit(ctx->r, &ctx->oids.list[i]);
1591 if (!c || commit_graph_position(c) != COMMIT_NOT_FROM_GRAPH)
1598 stop_progress(&ctx->progress);
1600 return count_distinct;
1603 static void copy_oids_to_commits(struct write_commit_graph_context *ctx)
1606 enum commit_graph_split_flags flags = ctx->split_opts ?
1607 ctx->split_opts->flags : COMMIT_GRAPH_SPLIT_UNSPECIFIED;
1609 ctx->num_extra_edges = 0;
1610 if (ctx->report_progress)
1611 ctx->progress = start_delayed_progress(
1612 _("Finding extra edges in commit graph"),
1614 for (i = 0; i < ctx->oids.nr; i++) {
1615 unsigned int num_parents;
1617 display_progress(ctx->progress, i + 1);
1618 if (i > 0 && oideq(&ctx->oids.list[i - 1], &ctx->oids.list[i]))
1621 ALLOC_GROW(ctx->commits.list, ctx->commits.nr + 1, ctx->commits.alloc);
1622 ctx->commits.list[ctx->commits.nr] = lookup_commit(ctx->r, &ctx->oids.list[i]);
1624 if (ctx->split && flags != COMMIT_GRAPH_SPLIT_REPLACE &&
1625 commit_graph_position(ctx->commits.list[ctx->commits.nr]) != COMMIT_NOT_FROM_GRAPH)
1628 if (ctx->split && flags == COMMIT_GRAPH_SPLIT_REPLACE)
1629 parse_commit(ctx->commits.list[ctx->commits.nr]);
1631 parse_commit_no_graph(ctx->commits.list[ctx->commits.nr]);
1633 num_parents = commit_list_count(ctx->commits.list[ctx->commits.nr]->parents);
1634 if (num_parents > 2)
1635 ctx->num_extra_edges += num_parents - 1;
1639 stop_progress(&ctx->progress);
1642 static int write_graph_chunk_base_1(struct hashfile *f,
1643 struct commit_graph *g)
1650 num = write_graph_chunk_base_1(f, g->base_graph);
1651 hashwrite(f, g->oid.hash, the_hash_algo->rawsz);
1655 static int write_graph_chunk_base(struct hashfile *f,
1656 struct write_commit_graph_context *ctx)
1658 int num = write_graph_chunk_base_1(f, ctx->new_base_graph);
1660 if (num != ctx->num_commit_graphs_after - 1) {
1661 error(_("failed to write correct number of base graph ids"));
1668 typedef int (*chunk_write_fn)(struct hashfile *f,
1669 struct write_commit_graph_context *ctx);
1674 chunk_write_fn write_fn;
1677 static int write_commit_graph_file(struct write_commit_graph_context *ctx)
1682 struct lock_file lk = LOCK_INIT;
1683 struct chunk_info chunks[MAX_NUM_CHUNKS + 1];
1684 const unsigned hashsz = the_hash_algo->rawsz;
1685 struct strbuf progress_title = STRBUF_INIT;
1687 uint64_t chunk_offset;
1688 struct object_id file_hash;
1691 struct strbuf tmp_file = STRBUF_INIT;
1693 strbuf_addf(&tmp_file,
1694 "%s/info/commit-graphs/tmp_graph_XXXXXX",
1696 ctx->graph_name = strbuf_detach(&tmp_file, NULL);
1698 ctx->graph_name = get_commit_graph_filename(ctx->odb);
1701 if (safe_create_leading_directories(ctx->graph_name)) {
1702 UNLEAK(ctx->graph_name);
1703 error(_("unable to create leading directories of %s"),
1709 char *lock_name = get_chain_filename(ctx->odb);
1711 hold_lock_file_for_update_mode(&lk, lock_name,
1712 LOCK_DIE_ON_ERROR, 0444);
1714 fd = git_mkstemp_mode(ctx->graph_name, 0444);
1716 error(_("unable to create temporary graph layer"));
1720 if (adjust_shared_perm(ctx->graph_name)) {
1721 error(_("unable to adjust shared permissions for '%s'"),
1726 f = hashfd(fd, ctx->graph_name);
1728 hold_lock_file_for_update_mode(&lk, ctx->graph_name,
1729 LOCK_DIE_ON_ERROR, 0444);
1730 fd = lk.tempfile->fd;
1731 f = hashfd(lk.tempfile->fd, lk.tempfile->filename.buf);
1734 chunks[0].id = GRAPH_CHUNKID_OIDFANOUT;
1735 chunks[0].size = GRAPH_FANOUT_SIZE;
1736 chunks[0].write_fn = write_graph_chunk_fanout;
1737 chunks[1].id = GRAPH_CHUNKID_OIDLOOKUP;
1738 chunks[1].size = hashsz * ctx->commits.nr;
1739 chunks[1].write_fn = write_graph_chunk_oids;
1740 chunks[2].id = GRAPH_CHUNKID_DATA;
1741 chunks[2].size = (hashsz + 16) * ctx->commits.nr;
1742 chunks[2].write_fn = write_graph_chunk_data;
1743 if (ctx->num_extra_edges) {
1744 chunks[num_chunks].id = GRAPH_CHUNKID_EXTRAEDGES;
1745 chunks[num_chunks].size = 4 * ctx->num_extra_edges;
1746 chunks[num_chunks].write_fn = write_graph_chunk_extra_edges;
1749 if (ctx->changed_paths) {
1750 chunks[num_chunks].id = GRAPH_CHUNKID_BLOOMINDEXES;
1751 chunks[num_chunks].size = sizeof(uint32_t) * ctx->commits.nr;
1752 chunks[num_chunks].write_fn = write_graph_chunk_bloom_indexes;
1754 chunks[num_chunks].id = GRAPH_CHUNKID_BLOOMDATA;
1755 chunks[num_chunks].size = sizeof(uint32_t) * 3
1756 + ctx->total_bloom_filter_data_size;
1757 chunks[num_chunks].write_fn = write_graph_chunk_bloom_data;
1760 if (ctx->num_commit_graphs_after > 1) {
1761 chunks[num_chunks].id = GRAPH_CHUNKID_BASE;
1762 chunks[num_chunks].size = hashsz * (ctx->num_commit_graphs_after - 1);
1763 chunks[num_chunks].write_fn = write_graph_chunk_base;
1767 chunks[num_chunks].id = 0;
1768 chunks[num_chunks].size = 0;
1770 hashwrite_be32(f, GRAPH_SIGNATURE);
1772 hashwrite_u8(f, GRAPH_VERSION);
1773 hashwrite_u8(f, oid_version());
1774 hashwrite_u8(f, num_chunks);
1775 hashwrite_u8(f, ctx->num_commit_graphs_after - 1);
1777 chunk_offset = 8 + (num_chunks + 1) * GRAPH_CHUNKLOOKUP_WIDTH;
1778 for (i = 0; i <= num_chunks; i++) {
1779 uint32_t chunk_write[3];
1781 chunk_write[0] = htonl(chunks[i].id);
1782 chunk_write[1] = htonl(chunk_offset >> 32);
1783 chunk_write[2] = htonl(chunk_offset & 0xffffffff);
1784 hashwrite(f, chunk_write, 12);
1786 chunk_offset += chunks[i].size;
1789 if (ctx->report_progress) {
1790 strbuf_addf(&progress_title,
1791 Q_("Writing out commit graph in %d pass",
1792 "Writing out commit graph in %d passes",
1795 ctx->progress = start_delayed_progress(
1797 num_chunks * ctx->commits.nr);
1800 for (i = 0; i < num_chunks; i++) {
1801 uint64_t start_offset = f->total + f->offset;
1803 if (chunks[i].write_fn(f, ctx))
1806 if (f->total + f->offset != start_offset + chunks[i].size)
1807 BUG("expected to write %"PRId64" bytes to chunk %"PRIx32", but wrote %"PRId64" instead",
1808 chunks[i].size, chunks[i].id,
1809 f->total + f->offset - start_offset);
1812 stop_progress(&ctx->progress);
1813 strbuf_release(&progress_title);
1815 if (ctx->split && ctx->base_graph_name && ctx->num_commit_graphs_after > 1) {
1816 char *new_base_hash = xstrdup(oid_to_hex(&ctx->new_base_graph->oid));
1817 char *new_base_name = get_split_graph_filename(ctx->new_base_graph->odb, new_base_hash);
1819 free(ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2]);
1820 free(ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2]);
1821 ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 2] = new_base_name;
1822 ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 2] = new_base_hash;
1825 close_commit_graph(ctx->r->objects);
1826 finalize_hashfile(f, file_hash.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC);
1829 FILE *chainf = fdopen_lock_file(&lk, "w");
1830 char *final_graph_name;
1836 error(_("unable to open commit-graph chain file"));
1840 if (ctx->base_graph_name) {
1842 int idx = ctx->num_commit_graphs_after - 1;
1843 if (ctx->num_commit_graphs_after > 1)
1846 dest = ctx->commit_graph_filenames_after[idx];
1848 if (strcmp(ctx->base_graph_name, dest)) {
1849 result = rename(ctx->base_graph_name, dest);
1852 error(_("failed to rename base commit-graph file"));
1857 char *graph_name = get_commit_graph_filename(ctx->odb);
1861 ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1] = xstrdup(oid_to_hex(&file_hash));
1862 final_graph_name = get_split_graph_filename(ctx->odb,
1863 ctx->commit_graph_hash_after[ctx->num_commit_graphs_after - 1]);
1864 ctx->commit_graph_filenames_after[ctx->num_commit_graphs_after - 1] = final_graph_name;
1866 result = rename(ctx->graph_name, final_graph_name);
1868 for (i = 0; i < ctx->num_commit_graphs_after; i++)
1869 fprintf(lk.tempfile->fp, "%s\n", ctx->commit_graph_hash_after[i]);
1872 error(_("failed to rename temporary commit-graph file"));
1877 commit_lock_file(&lk);
1882 static void split_graph_merge_strategy(struct write_commit_graph_context *ctx)
1884 struct commit_graph *g;
1885 uint32_t num_commits;
1886 enum commit_graph_split_flags flags = COMMIT_GRAPH_SPLIT_UNSPECIFIED;
1889 int max_commits = 0;
1892 if (ctx->split_opts) {
1893 max_commits = ctx->split_opts->max_commits;
1895 if (ctx->split_opts->size_multiple)
1896 size_mult = ctx->split_opts->size_multiple;
1898 flags = ctx->split_opts->flags;
1901 g = ctx->r->objects->commit_graph;
1902 num_commits = ctx->commits.nr;
1903 if (flags == COMMIT_GRAPH_SPLIT_REPLACE)
1904 ctx->num_commit_graphs_after = 1;
1906 ctx->num_commit_graphs_after = ctx->num_commit_graphs_before + 1;
1908 if (flags != COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED &&
1909 flags != COMMIT_GRAPH_SPLIT_REPLACE) {
1910 while (g && (g->num_commits <= size_mult * num_commits ||
1911 (max_commits && num_commits > max_commits))) {
1912 if (g->odb != ctx->odb)
1915 num_commits += g->num_commits;
1918 ctx->num_commit_graphs_after--;
1922 if (flags != COMMIT_GRAPH_SPLIT_REPLACE)
1923 ctx->new_base_graph = g;
1924 else if (ctx->num_commit_graphs_after != 1)
1925 BUG("split_graph_merge_strategy: num_commit_graphs_after "
1926 "should be 1 with --split=replace");
1928 if (ctx->num_commit_graphs_after == 2) {
1929 char *old_graph_name = get_commit_graph_filename(g->odb);
1931 if (!strcmp(g->filename, old_graph_name) &&
1932 g->odb != ctx->odb) {
1933 ctx->num_commit_graphs_after = 1;
1934 ctx->new_base_graph = NULL;
1937 free(old_graph_name);
1940 CALLOC_ARRAY(ctx->commit_graph_filenames_after, ctx->num_commit_graphs_after);
1941 CALLOC_ARRAY(ctx->commit_graph_hash_after, ctx->num_commit_graphs_after);
1943 for (i = 0; i < ctx->num_commit_graphs_after &&
1944 i < ctx->num_commit_graphs_before; i++)
1945 ctx->commit_graph_filenames_after[i] = xstrdup(ctx->commit_graph_filenames_before[i]);
1947 i = ctx->num_commit_graphs_before - 1;
1948 g = ctx->r->objects->commit_graph;
1951 if (i < ctx->num_commit_graphs_after)
1952 ctx->commit_graph_hash_after[i] = xstrdup(oid_to_hex(&g->oid));
1959 static void merge_commit_graph(struct write_commit_graph_context *ctx,
1960 struct commit_graph *g)
1963 uint32_t offset = g->num_commits_in_base;
1965 ALLOC_GROW(ctx->commits.list, ctx->commits.nr + g->num_commits, ctx->commits.alloc);
1967 for (i = 0; i < g->num_commits; i++) {
1968 struct object_id oid;
1969 struct commit *result;
1971 display_progress(ctx->progress, i + 1);
1973 load_oid_from_graph(g, i + offset, &oid);
1975 /* only add commits if they still exist in the repo */
1976 result = lookup_commit_reference_gently(ctx->r, &oid, 1);
1979 ctx->commits.list[ctx->commits.nr] = result;
1985 static int commit_compare(const void *_a, const void *_b)
1987 const struct commit *a = *(const struct commit **)_a;
1988 const struct commit *b = *(const struct commit **)_b;
1989 return oidcmp(&a->object.oid, &b->object.oid);
1992 static void sort_and_scan_merged_commits(struct write_commit_graph_context *ctx)
1996 if (ctx->report_progress)
1997 ctx->progress = start_delayed_progress(
1998 _("Scanning merged commits"),
2001 QSORT(ctx->commits.list, ctx->commits.nr, commit_compare);
2003 ctx->num_extra_edges = 0;
2004 for (i = 0; i < ctx->commits.nr; i++) {
2005 display_progress(ctx->progress, i);
2007 if (i && oideq(&ctx->commits.list[i - 1]->object.oid,
2008 &ctx->commits.list[i]->object.oid)) {
2009 die(_("unexpected duplicate commit id %s"),
2010 oid_to_hex(&ctx->commits.list[i]->object.oid));
2012 unsigned int num_parents;
2014 num_parents = commit_list_count(ctx->commits.list[i]->parents);
2015 if (num_parents > 2)
2016 ctx->num_extra_edges += num_parents - 1;
2020 stop_progress(&ctx->progress);
2023 static void merge_commit_graphs(struct write_commit_graph_context *ctx)
2025 struct commit_graph *g = ctx->r->objects->commit_graph;
2026 uint32_t current_graph_number = ctx->num_commit_graphs_before;
2028 while (g && current_graph_number >= ctx->num_commit_graphs_after) {
2029 current_graph_number--;
2031 if (ctx->report_progress)
2032 ctx->progress = start_delayed_progress(_("Merging commit-graph"), 0);
2034 merge_commit_graph(ctx, g);
2035 stop_progress(&ctx->progress);
2041 ctx->new_base_graph = g;
2042 ctx->new_num_commits_in_base = g->num_commits + g->num_commits_in_base;
2045 if (ctx->new_base_graph)
2046 ctx->base_graph_name = xstrdup(ctx->new_base_graph->filename);
2048 sort_and_scan_merged_commits(ctx);
2051 static void mark_commit_graphs(struct write_commit_graph_context *ctx)
2054 time_t now = time(NULL);
2056 for (i = ctx->num_commit_graphs_after - 1; i < ctx->num_commit_graphs_before; i++) {
2058 struct utimbuf updated_time;
2060 stat(ctx->commit_graph_filenames_before[i], &st);
2062 updated_time.actime = st.st_atime;
2063 updated_time.modtime = now;
2064 utime(ctx->commit_graph_filenames_before[i], &updated_time);
2068 static void expire_commit_graphs(struct write_commit_graph_context *ctx)
2070 struct strbuf path = STRBUF_INIT;
2074 timestamp_t expire_time = time(NULL);
2076 if (ctx->split_opts && ctx->split_opts->expire_time)
2077 expire_time = ctx->split_opts->expire_time;
2079 char *chain_file_name = get_chain_filename(ctx->odb);
2080 unlink(chain_file_name);
2081 free(chain_file_name);
2082 ctx->num_commit_graphs_after = 0;
2085 strbuf_addstr(&path, ctx->odb->path);
2086 strbuf_addstr(&path, "/info/commit-graphs");
2087 dir = opendir(path.buf);
2092 strbuf_addch(&path, '/');
2093 dirnamelen = path.len;
2094 while ((de = readdir(dir)) != NULL) {
2096 uint32_t i, found = 0;
2098 strbuf_setlen(&path, dirnamelen);
2099 strbuf_addstr(&path, de->d_name);
2101 stat(path.buf, &st);
2103 if (st.st_mtime > expire_time)
2105 if (path.len < 6 || strcmp(path.buf + path.len - 6, ".graph"))
2108 for (i = 0; i < ctx->num_commit_graphs_after; i++) {
2109 if (!strcmp(ctx->commit_graph_filenames_after[i],
2121 strbuf_release(&path);
2124 int write_commit_graph(struct object_directory *odb,
2125 struct string_list *pack_indexes,
2126 struct oidset *commits,
2127 enum commit_graph_write_flags flags,
2128 const struct split_commit_graph_opts *split_opts)
2130 struct write_commit_graph_context *ctx;
2131 uint32_t i, count_distinct = 0;
2134 struct bloom_filter_settings bloom_settings = DEFAULT_BLOOM_FILTER_SETTINGS;
2136 if (!commit_graph_compatible(the_repository))
2139 ctx = xcalloc(1, sizeof(struct write_commit_graph_context));
2140 ctx->r = the_repository;
2142 ctx->append = flags & COMMIT_GRAPH_WRITE_APPEND ? 1 : 0;
2143 ctx->report_progress = flags & COMMIT_GRAPH_WRITE_PROGRESS ? 1 : 0;
2144 ctx->split = flags & COMMIT_GRAPH_WRITE_SPLIT ? 1 : 0;
2145 ctx->split_opts = split_opts;
2146 ctx->total_bloom_filter_data_size = 0;
2148 bloom_settings.bits_per_entry = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_BITS_PER_ENTRY",
2149 bloom_settings.bits_per_entry);
2150 bloom_settings.num_hashes = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_NUM_HASHES",
2151 bloom_settings.num_hashes);
2152 bloom_settings.max_changed_paths = git_env_ulong("GIT_TEST_BLOOM_SETTINGS_MAX_CHANGED_PATHS",
2153 bloom_settings.max_changed_paths);
2154 ctx->bloom_settings = &bloom_settings;
2156 if (flags & COMMIT_GRAPH_WRITE_BLOOM_FILTERS)
2157 ctx->changed_paths = 1;
2158 if (!(flags & COMMIT_GRAPH_NO_WRITE_BLOOM_FILTERS)) {
2159 struct commit_graph *g;
2160 prepare_commit_graph_one(ctx->r, ctx->odb);
2162 g = ctx->r->objects->commit_graph;
2164 /* We have changed-paths already. Keep them in the next graph */
2165 if (g && g->chunk_bloom_data) {
2166 ctx->changed_paths = 1;
2167 ctx->bloom_settings = g->bloom_filter_settings;
2172 struct commit_graph *g;
2173 prepare_commit_graph(ctx->r);
2175 g = ctx->r->objects->commit_graph;
2178 ctx->num_commit_graphs_before++;
2182 if (ctx->num_commit_graphs_before) {
2183 ALLOC_ARRAY(ctx->commit_graph_filenames_before, ctx->num_commit_graphs_before);
2184 i = ctx->num_commit_graphs_before;
2185 g = ctx->r->objects->commit_graph;
2188 ctx->commit_graph_filenames_before[--i] = xstrdup(g->filename);
2193 if (ctx->split_opts)
2194 replace = ctx->split_opts->flags & COMMIT_GRAPH_SPLIT_REPLACE;
2197 ctx->approx_nr_objects = approximate_object_count();
2198 ctx->oids.alloc = ctx->approx_nr_objects / 32;
2200 if (ctx->split && split_opts && ctx->oids.alloc > split_opts->max_commits)
2201 ctx->oids.alloc = split_opts->max_commits;
2204 prepare_commit_graph_one(ctx->r, ctx->odb);
2205 if (ctx->r->objects->commit_graph)
2206 ctx->oids.alloc += ctx->r->objects->commit_graph->num_commits;
2209 if (ctx->oids.alloc < 1024)
2210 ctx->oids.alloc = 1024;
2211 ALLOC_ARRAY(ctx->oids.list, ctx->oids.alloc);
2213 if (ctx->append && ctx->r->objects->commit_graph) {
2214 struct commit_graph *g = ctx->r->objects->commit_graph;
2215 for (i = 0; i < g->num_commits; i++) {
2216 const unsigned char *hash = g->chunk_oid_lookup + g->hash_len * i;
2217 hashcpy(ctx->oids.list[ctx->oids.nr++].hash, hash);
2222 ctx->order_by_pack = 1;
2223 if ((res = fill_oids_from_packs(ctx, pack_indexes)))
2228 if ((res = fill_oids_from_commits(ctx, commits)))
2232 if (!pack_indexes && !commits) {
2233 ctx->order_by_pack = 1;
2234 fill_oids_from_all_packs(ctx);
2237 close_reachable(ctx);
2239 count_distinct = count_distinct_commits(ctx);
2241 if (count_distinct >= GRAPH_EDGE_LAST_MASK) {
2242 error(_("the commit graph format cannot write %d commits"), count_distinct);
2247 ctx->commits.alloc = count_distinct;
2248 ALLOC_ARRAY(ctx->commits.list, ctx->commits.alloc);
2250 copy_oids_to_commits(ctx);
2252 if (ctx->commits.nr >= GRAPH_EDGE_LAST_MASK) {
2253 error(_("too many commits to write graph"));
2258 if (!ctx->commits.nr && !replace)
2262 split_graph_merge_strategy(ctx);
2265 merge_commit_graphs(ctx);
2267 ctx->num_commit_graphs_after = 1;
2269 compute_generation_numbers(ctx);
2271 if (ctx->changed_paths)
2272 compute_bloom_filters(ctx);
2274 res = write_commit_graph_file(ctx);
2277 mark_commit_graphs(ctx);
2279 expire_commit_graphs(ctx);
2282 free(ctx->graph_name);
2283 free(ctx->commits.list);
2284 free(ctx->oids.list);
2286 if (ctx->commit_graph_filenames_after) {
2287 for (i = 0; i < ctx->num_commit_graphs_after; i++) {
2288 free(ctx->commit_graph_filenames_after[i]);
2289 free(ctx->commit_graph_hash_after[i]);
2292 for (i = 0; i < ctx->num_commit_graphs_before; i++)
2293 free(ctx->commit_graph_filenames_before[i]);
2295 free(ctx->commit_graph_filenames_after);
2296 free(ctx->commit_graph_filenames_before);
2297 free(ctx->commit_graph_hash_after);
2305 #define VERIFY_COMMIT_GRAPH_ERROR_HASH 2
2306 static int verify_commit_graph_error;
2308 static void graph_report(const char *fmt, ...)
2312 verify_commit_graph_error = 1;
2314 vfprintf(stderr, fmt, ap);
2315 fprintf(stderr, "\n");
2319 #define GENERATION_ZERO_EXISTS 1
2320 #define GENERATION_NUMBER_EXISTS 2
2322 int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags)
2324 uint32_t i, cur_fanout_pos = 0;
2325 struct object_id prev_oid, cur_oid, checksum;
2326 int generation_zero = 0;
2329 struct progress *progress = NULL;
2330 int local_error = 0;
2333 graph_report("no commit-graph file loaded");
2337 verify_commit_graph_error = verify_commit_graph_lite(g);
2338 if (verify_commit_graph_error)
2339 return verify_commit_graph_error;
2341 devnull = open("/dev/null", O_WRONLY);
2342 f = hashfd(devnull, NULL);
2343 hashwrite(f, g->data, g->data_len - g->hash_len);
2344 finalize_hashfile(f, checksum.hash, CSUM_CLOSE);
2345 if (!hasheq(checksum.hash, g->data + g->data_len - g->hash_len)) {
2346 graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
2347 verify_commit_graph_error = VERIFY_COMMIT_GRAPH_ERROR_HASH;
2350 for (i = 0; i < g->num_commits; i++) {
2351 struct commit *graph_commit;
2353 hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
2355 if (i && oidcmp(&prev_oid, &cur_oid) >= 0)
2356 graph_report(_("commit-graph has incorrect OID order: %s then %s"),
2357 oid_to_hex(&prev_oid),
2358 oid_to_hex(&cur_oid));
2360 oidcpy(&prev_oid, &cur_oid);
2362 while (cur_oid.hash[0] > cur_fanout_pos) {
2363 uint32_t fanout_value = get_be32(g->chunk_oid_fanout + cur_fanout_pos);
2365 if (i != fanout_value)
2366 graph_report(_("commit-graph has incorrect fanout value: fanout[%d] = %u != %u"),
2367 cur_fanout_pos, fanout_value, i);
2371 graph_commit = lookup_commit(r, &cur_oid);
2372 if (!parse_commit_in_graph_one(r, g, graph_commit))
2373 graph_report(_("failed to parse commit %s from commit-graph"),
2374 oid_to_hex(&cur_oid));
2377 while (cur_fanout_pos < 256) {
2378 uint32_t fanout_value = get_be32(g->chunk_oid_fanout + cur_fanout_pos);
2380 if (g->num_commits != fanout_value)
2381 graph_report(_("commit-graph has incorrect fanout value: fanout[%d] = %u != %u"),
2382 cur_fanout_pos, fanout_value, i);
2387 if (verify_commit_graph_error & ~VERIFY_COMMIT_GRAPH_ERROR_HASH)
2388 return verify_commit_graph_error;
2390 if (flags & COMMIT_GRAPH_WRITE_PROGRESS)
2391 progress = start_progress(_("Verifying commits in commit graph"),
2394 for (i = 0; i < g->num_commits; i++) {
2395 struct commit *graph_commit, *odb_commit;
2396 struct commit_list *graph_parents, *odb_parents;
2397 uint32_t max_generation = 0;
2398 uint32_t generation;
2400 display_progress(progress, i + 1);
2401 hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
2403 graph_commit = lookup_commit(r, &cur_oid);
2404 odb_commit = (struct commit *)create_object(r, &cur_oid, alloc_commit_node(r));
2405 if (parse_commit_internal(odb_commit, 0, 0)) {
2406 graph_report(_("failed to parse commit %s from object database for commit-graph"),
2407 oid_to_hex(&cur_oid));
2411 if (!oideq(&get_commit_tree_in_graph_one(r, g, graph_commit)->object.oid,
2412 get_commit_tree_oid(odb_commit)))
2413 graph_report(_("root tree OID for commit %s in commit-graph is %s != %s"),
2414 oid_to_hex(&cur_oid),
2415 oid_to_hex(get_commit_tree_oid(graph_commit)),
2416 oid_to_hex(get_commit_tree_oid(odb_commit)));
2418 graph_parents = graph_commit->parents;
2419 odb_parents = odb_commit->parents;
2421 while (graph_parents) {
2422 if (odb_parents == NULL) {
2423 graph_report(_("commit-graph parent list for commit %s is too long"),
2424 oid_to_hex(&cur_oid));
2428 /* parse parent in case it is in a base graph */
2429 parse_commit_in_graph_one(r, g, graph_parents->item);
2431 if (!oideq(&graph_parents->item->object.oid, &odb_parents->item->object.oid))
2432 graph_report(_("commit-graph parent for %s is %s != %s"),
2433 oid_to_hex(&cur_oid),
2434 oid_to_hex(&graph_parents->item->object.oid),
2435 oid_to_hex(&odb_parents->item->object.oid));
2437 generation = commit_graph_generation(graph_parents->item);
2438 if (generation > max_generation)
2439 max_generation = generation;
2441 graph_parents = graph_parents->next;
2442 odb_parents = odb_parents->next;
2445 if (odb_parents != NULL)
2446 graph_report(_("commit-graph parent list for commit %s terminates early"),
2447 oid_to_hex(&cur_oid));
2449 if (!commit_graph_generation(graph_commit)) {
2450 if (generation_zero == GENERATION_NUMBER_EXISTS)
2451 graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"),
2452 oid_to_hex(&cur_oid));
2453 generation_zero = GENERATION_ZERO_EXISTS;
2454 } else if (generation_zero == GENERATION_ZERO_EXISTS)
2455 graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"),
2456 oid_to_hex(&cur_oid));
2458 if (generation_zero == GENERATION_ZERO_EXISTS)
2462 * If one of our parents has generation GENERATION_NUMBER_MAX, then
2463 * our generation is also GENERATION_NUMBER_MAX. Decrement to avoid
2464 * extra logic in the following condition.
2466 if (max_generation == GENERATION_NUMBER_MAX)
2469 generation = commit_graph_generation(graph_commit);
2470 if (generation != max_generation + 1)
2471 graph_report(_("commit-graph generation for commit %s is %u != %u"),
2472 oid_to_hex(&cur_oid),
2474 max_generation + 1);
2476 if (graph_commit->date != odb_commit->date)
2477 graph_report(_("commit date for commit %s in commit-graph is %"PRItime" != %"PRItime),
2478 oid_to_hex(&cur_oid),
2482 stop_progress(&progress);
2484 local_error = verify_commit_graph_error;
2486 if (!(flags & COMMIT_GRAPH_VERIFY_SHALLOW) && g->base_graph)
2487 local_error |= verify_commit_graph(r, g->base_graph, flags);
2492 void free_commit_graph(struct commit_graph *g)
2497 munmap((void *)g->data, g->data_len);
2501 free(g->bloom_filter_settings);
2505 void disable_commit_graph(struct repository *r)
2507 r->commit_graph_disabled = 1;