4 #include "git-compat-util.h"
12 #include "sha1-lookup.h"
13 #include "commit-graph.h"
14 #include "object-store.h"
17 #include "replace-object.h"
20 #include "commit-slab.h"
22 void git_test_write_commit_graph_or_die(void)
25 if (!git_env_bool(GIT_TEST_COMMIT_GRAPH
, 0))
28 if (git_env_bool(GIT_TEST_COMMIT_GRAPH_CHANGED_PATHS
, 0))
29 flags
= COMMIT_GRAPH_WRITE_BLOOM_FILTERS
;
31 if (write_commit_graph_reachable(the_repository
->objects
->odb
,
33 die("failed to write commit-graph under GIT_TEST_COMMIT_GRAPH");
36 #define GRAPH_SIGNATURE 0x43475048 /* "CGPH" */
37 #define GRAPH_CHUNKID_OIDFANOUT 0x4f494446 /* "OIDF" */
38 #define GRAPH_CHUNKID_OIDLOOKUP 0x4f49444c /* "OIDL" */
39 #define GRAPH_CHUNKID_DATA 0x43444154 /* "CDAT" */
40 #define GRAPH_CHUNKID_EXTRAEDGES 0x45444745 /* "EDGE" */
41 #define GRAPH_CHUNKID_BLOOMINDEXES 0x42494458 /* "BIDX" */
42 #define GRAPH_CHUNKID_BLOOMDATA 0x42444154 /* "BDAT" */
43 #define GRAPH_CHUNKID_BASE 0x42415345 /* "BASE" */
44 #define MAX_NUM_CHUNKS 7
46 #define GRAPH_DATA_WIDTH (the_hash_algo->rawsz + 16)
48 #define GRAPH_VERSION_1 0x1
49 #define GRAPH_VERSION GRAPH_VERSION_1
51 #define GRAPH_EXTRA_EDGES_NEEDED 0x80000000
52 #define GRAPH_EDGE_LAST_MASK 0x7fffffff
53 #define GRAPH_PARENT_NONE 0x70000000
55 #define GRAPH_LAST_EDGE 0x80000000
57 #define GRAPH_HEADER_SIZE 8
58 #define GRAPH_FANOUT_SIZE (4 * 256)
59 #define GRAPH_CHUNKLOOKUP_WIDTH 12
60 #define GRAPH_MIN_SIZE (GRAPH_HEADER_SIZE + 4 * GRAPH_CHUNKLOOKUP_WIDTH \
61 + GRAPH_FANOUT_SIZE + the_hash_algo->rawsz)
63 /* Remember to update object flag allocation in object.h */
64 #define REACHABLE (1u<<15)
66 /* Keep track of the order in which commits are added to our list. */
67 define_commit_slab(commit_pos
, int);
68 static struct commit_pos commit_pos
= COMMIT_SLAB_INIT(1, commit_pos
);
70 static void set_commit_pos(struct repository
*r
, const struct object_id
*oid
)
72 static int32_t max_pos
;
73 struct commit
*commit
= lookup_commit(r
, oid
);
76 return; /* should never happen, but be lenient */
78 *commit_pos_at(&commit_pos
, commit
) = max_pos
++;
81 static int commit_pos_cmp(const void *va
, const void *vb
)
83 const struct commit
*a
= *(const struct commit
**)va
;
84 const struct commit
*b
= *(const struct commit
**)vb
;
85 return commit_pos_at(&commit_pos
, a
) -
86 commit_pos_at(&commit_pos
, b
);
89 static int commit_gen_cmp(const void *va
, const void *vb
)
91 const struct commit
*a
= *(const struct commit
**)va
;
92 const struct commit
*b
= *(const struct commit
**)vb
;
94 /* lower generation commits first */
95 if (a
->generation
< b
->generation
)
97 else if (a
->generation
> b
->generation
)
100 /* use date as a heuristic when generations are equal */
101 if (a
->date
< b
->date
)
103 else if (a
->date
> b
->date
)
108 char *get_commit_graph_filename(struct object_directory
*obj_dir
)
110 return xstrfmt("%s/info/commit-graph", obj_dir
->path
);
113 static char *get_split_graph_filename(struct object_directory
*odb
,
116 return xstrfmt("%s/info/commit-graphs/graph-%s.graph", odb
->path
,
120 static char *get_chain_filename(struct object_directory
*odb
)
122 return xstrfmt("%s/info/commit-graphs/commit-graph-chain", odb
->path
);
125 static uint8_t oid_version(void)
130 static struct commit_graph
*alloc_commit_graph(void)
132 struct commit_graph
*g
= xcalloc(1, sizeof(*g
));
137 extern int read_replace_refs
;
139 static int commit_graph_compatible(struct repository
*r
)
144 if (read_replace_refs
) {
145 prepare_replace_object(r
);
146 if (hashmap_get_size(&r
->objects
->replace_map
->map
))
150 prepare_commit_graft(r
);
151 if (r
->parsed_objects
&& r
->parsed_objects
->grafts_nr
)
153 if (is_repository_shallow(r
))
159 int open_commit_graph(const char *graph_file
, int *fd
, struct stat
*st
)
161 *fd
= git_open(graph_file
);
164 if (fstat(*fd
, st
)) {
171 struct commit_graph
*load_commit_graph_one_fd_st(int fd
, struct stat
*st
,
172 struct object_directory
*odb
)
176 struct commit_graph
*ret
;
178 graph_size
= xsize_t(st
->st_size
);
180 if (graph_size
< GRAPH_MIN_SIZE
) {
182 error(_("commit-graph file is too small"));
185 graph_map
= xmmap(NULL
, graph_size
, PROT_READ
, MAP_PRIVATE
, fd
, 0);
187 ret
= parse_commit_graph(graph_map
, graph_size
);
192 munmap(graph_map
, graph_size
);
197 static int verify_commit_graph_lite(struct commit_graph
*g
)
200 * Basic validation shared between parse_commit_graph()
201 * which'll be called every time the graph is used, and the
202 * much more expensive verify_commit_graph() used by
203 * "commit-graph verify".
205 * There should only be very basic checks here to ensure that
206 * we don't e.g. segfault in fill_commit_in_graph(), but
207 * because this is a very hot codepath nothing that e.g. loops
208 * over g->num_commits, or runs a checksum on the commit-graph
211 if (!g
->chunk_oid_fanout
) {
212 error("commit-graph is missing the OID Fanout chunk");
215 if (!g
->chunk_oid_lookup
) {
216 error("commit-graph is missing the OID Lookup chunk");
219 if (!g
->chunk_commit_data
) {
220 error("commit-graph is missing the Commit Data chunk");
227 struct commit_graph
*parse_commit_graph(void *graph_map
, size_t graph_size
)
229 const unsigned char *data
, *chunk_lookup
;
231 struct commit_graph
*graph
;
232 uint64_t last_chunk_offset
;
233 uint32_t last_chunk_id
;
234 uint32_t graph_signature
;
235 unsigned char graph_version
, hash_version
;
240 if (graph_size
< GRAPH_MIN_SIZE
)
243 data
= (const unsigned char *)graph_map
;
245 graph_signature
= get_be32(data
);
246 if (graph_signature
!= GRAPH_SIGNATURE
) {
247 error(_("commit-graph signature %X does not match signature %X"),
248 graph_signature
, GRAPH_SIGNATURE
);
252 graph_version
= *(unsigned char*)(data
+ 4);
253 if (graph_version
!= GRAPH_VERSION
) {
254 error(_("commit-graph version %X does not match version %X"),
255 graph_version
, GRAPH_VERSION
);
259 hash_version
= *(unsigned char*)(data
+ 5);
260 if (hash_version
!= oid_version()) {
261 error(_("commit-graph hash version %X does not match version %X"),
262 hash_version
, oid_version());
266 graph
= alloc_commit_graph();
268 graph
->hash_len
= the_hash_algo
->rawsz
;
269 graph
->num_chunks
= *(unsigned char*)(data
+ 6);
270 graph
->data
= graph_map
;
271 graph
->data_len
= graph_size
;
274 last_chunk_offset
= 8;
275 chunk_lookup
= data
+ 8;
276 for (i
= 0; i
< graph
->num_chunks
; i
++) {
278 uint64_t chunk_offset
;
279 int chunk_repeated
= 0;
281 if (data
+ graph_size
- chunk_lookup
<
282 GRAPH_CHUNKLOOKUP_WIDTH
) {
283 error(_("commit-graph chunk lookup table entry missing; file may be incomplete"));
288 chunk_id
= get_be32(chunk_lookup
+ 0);
289 chunk_offset
= get_be64(chunk_lookup
+ 4);
291 chunk_lookup
+= GRAPH_CHUNKLOOKUP_WIDTH
;
293 if (chunk_offset
> graph_size
- the_hash_algo
->rawsz
) {
294 error(_("commit-graph improper chunk offset %08x%08x"), (uint32_t)(chunk_offset
>> 32),
295 (uint32_t)chunk_offset
);
301 case GRAPH_CHUNKID_OIDFANOUT
:
302 if (graph
->chunk_oid_fanout
)
305 graph
->chunk_oid_fanout
= (uint32_t*)(data
+ chunk_offset
);
308 case GRAPH_CHUNKID_OIDLOOKUP
:
309 if (graph
->chunk_oid_lookup
)
312 graph
->chunk_oid_lookup
= data
+ chunk_offset
;
315 case GRAPH_CHUNKID_DATA
:
316 if (graph
->chunk_commit_data
)
319 graph
->chunk_commit_data
= data
+ chunk_offset
;
322 case GRAPH_CHUNKID_EXTRAEDGES
:
323 if (graph
->chunk_extra_edges
)
326 graph
->chunk_extra_edges
= data
+ chunk_offset
;
329 case GRAPH_CHUNKID_BASE
:
330 if (graph
->chunk_base_graphs
)
333 graph
->chunk_base_graphs
= data
+ chunk_offset
;
336 case GRAPH_CHUNKID_BLOOMINDEXES
:
337 if (graph
->chunk_bloom_indexes
)
340 graph
->chunk_bloom_indexes
= data
+ chunk_offset
;
343 case GRAPH_CHUNKID_BLOOMDATA
:
344 if (graph
->chunk_bloom_data
)
347 uint32_t hash_version
;
348 graph
->chunk_bloom_data
= data
+ chunk_offset
;
349 hash_version
= get_be32(data
+ chunk_offset
);
351 if (hash_version
!= 1)
354 graph
->bloom_filter_settings
= xmalloc(sizeof(struct bloom_filter_settings
));
355 graph
->bloom_filter_settings
->hash_version
= hash_version
;
356 graph
->bloom_filter_settings
->num_hashes
= get_be32(data
+ chunk_offset
+ 4);
357 graph
->bloom_filter_settings
->bits_per_entry
= get_be32(data
+ chunk_offset
+ 8);
362 if (chunk_repeated
) {
363 error(_("commit-graph chunk id %08x appears multiple times"), chunk_id
);
368 if (last_chunk_id
== GRAPH_CHUNKID_OIDLOOKUP
)
370 graph
->num_commits
= (chunk_offset
- last_chunk_offset
)
374 last_chunk_id
= chunk_id
;
375 last_chunk_offset
= chunk_offset
;
378 if (graph
->chunk_bloom_indexes
&& graph
->chunk_bloom_data
) {
379 init_bloom_filters();
381 /* We need both the bloom chunks to exist together. Else ignore the data */
382 graph
->chunk_bloom_indexes
= NULL
;
383 graph
->chunk_bloom_data
= NULL
;
384 graph
->bloom_filter_settings
= NULL
;
387 hashcpy(graph
->oid
.hash
, graph
->data
+ graph
->data_len
- graph
->hash_len
);
389 if (verify_commit_graph_lite(graph
)) {
397 static struct commit_graph
*load_commit_graph_one(const char *graph_file
,
398 struct object_directory
*odb
)
403 struct commit_graph
*g
;
404 int open_ok
= open_commit_graph(graph_file
, &fd
, &st
);
409 g
= load_commit_graph_one_fd_st(fd
, &st
, odb
);
412 g
->filename
= xstrdup(graph_file
);
417 static struct commit_graph
*load_commit_graph_v1(struct repository
*r
,
418 struct object_directory
*odb
)
420 char *graph_name
= get_commit_graph_filename(odb
);
421 struct commit_graph
*g
= load_commit_graph_one(graph_name
, odb
);
427 static int add_graph_to_chain(struct commit_graph
*g
,
428 struct commit_graph
*chain
,
429 struct object_id
*oids
,
432 struct commit_graph
*cur_g
= chain
;
434 if (n
&& !g
->chunk_base_graphs
) {
435 warning(_("commit-graph has no base graphs chunk"));
443 !oideq(&oids
[n
], &cur_g
->oid
) ||
444 !hasheq(oids
[n
].hash
, g
->chunk_base_graphs
+ g
->hash_len
* n
)) {
445 warning(_("commit-graph chain does not match"));
449 cur_g
= cur_g
->base_graph
;
452 g
->base_graph
= chain
;
455 g
->num_commits_in_base
= chain
->num_commits
+ chain
->num_commits_in_base
;
460 static struct commit_graph
*load_commit_graph_chain(struct repository
*r
,
461 struct object_directory
*odb
)
463 struct commit_graph
*graph_chain
= NULL
;
464 struct strbuf line
= STRBUF_INIT
;
466 struct object_id
*oids
;
467 int i
= 0, valid
= 1, count
;
468 char *chain_name
= get_chain_filename(odb
);
472 fp
= fopen(chain_name
, "r");
473 stat_res
= stat(chain_name
, &st
);
478 st
.st_size
<= the_hash_algo
->hexsz
)
481 count
= st
.st_size
/ (the_hash_algo
->hexsz
+ 1);
482 oids
= xcalloc(count
, sizeof(struct object_id
));
486 for (i
= 0; i
< count
; i
++) {
487 struct object_directory
*odb
;
489 if (strbuf_getline_lf(&line
, fp
) == EOF
)
492 if (get_oid_hex(line
.buf
, &oids
[i
])) {
493 warning(_("invalid commit-graph chain: line '%s' not a hash"),
500 for (odb
= r
->objects
->odb
; odb
; odb
= odb
->next
) {
501 char *graph_name
= get_split_graph_filename(odb
, line
.buf
);
502 struct commit_graph
*g
= load_commit_graph_one(graph_name
, odb
);
507 if (add_graph_to_chain(g
, graph_chain
, oids
, i
)) {
517 warning(_("unable to find all commit-graph files"));
524 strbuf_release(&line
);
529 struct commit_graph
*read_commit_graph_one(struct repository
*r
,
530 struct object_directory
*odb
)
532 struct commit_graph
*g
= load_commit_graph_v1(r
, odb
);
535 g
= load_commit_graph_chain(r
, odb
);
540 static void prepare_commit_graph_one(struct repository
*r
,
541 struct object_directory
*odb
)
544 if (r
->objects
->commit_graph
)
547 r
->objects
->commit_graph
= read_commit_graph_one(r
, odb
);
551 * Return 1 if commit_graph is non-NULL, and 0 otherwise.
553 * On the first invocation, this function attempts to load the commit
554 * graph if the_repository is configured to have one.
556 static int prepare_commit_graph(struct repository
*r
)
558 struct object_directory
*odb
;
561 * This must come before the "already attempted?" check below, because
562 * we want to disable even an already-loaded graph file.
564 if (r
->commit_graph_disabled
)
567 if (r
->objects
->commit_graph_attempted
)
568 return !!r
->objects
->commit_graph
;
569 r
->objects
->commit_graph_attempted
= 1;
571 if (git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD
, 0))
572 die("dying as requested by the '%s' variable on commit-graph load!",
573 GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD
);
575 prepare_repo_settings(r
);
577 if (!git_env_bool(GIT_TEST_COMMIT_GRAPH
, 0) &&
578 r
->settings
.core_commit_graph
!= 1)
580 * This repository is not configured to use commit graphs, so
581 * do not load one. (But report commit_graph_attempted anyway
582 * so that commit graph loading is not attempted again for this
587 if (!commit_graph_compatible(r
))
591 for (odb
= r
->objects
->odb
;
592 !r
->objects
->commit_graph
&& odb
;
594 prepare_commit_graph_one(r
, odb
);
595 return !!r
->objects
->commit_graph
;
598 int generation_numbers_enabled(struct repository
*r
)
600 uint32_t first_generation
;
601 struct commit_graph
*g
;
602 if (!prepare_commit_graph(r
))
605 g
= r
->objects
->commit_graph
;
610 first_generation
= get_be32(g
->chunk_commit_data
+
611 g
->hash_len
+ 8) >> 2;
613 return !!first_generation
;
616 static void close_commit_graph_one(struct commit_graph
*g
)
621 close_commit_graph_one(g
->base_graph
);
622 free_commit_graph(g
);
625 void close_commit_graph(struct raw_object_store
*o
)
627 close_commit_graph_one(o
->commit_graph
);
628 o
->commit_graph
= NULL
;
631 static int bsearch_graph(struct commit_graph
*g
, struct object_id
*oid
, uint32_t *pos
)
633 return bsearch_hash(oid
->hash
, g
->chunk_oid_fanout
,
634 g
->chunk_oid_lookup
, g
->hash_len
, pos
);
637 static void load_oid_from_graph(struct commit_graph
*g
,
639 struct object_id
*oid
)
643 while (g
&& pos
< g
->num_commits_in_base
)
647 BUG("NULL commit-graph");
649 if (pos
>= g
->num_commits
+ g
->num_commits_in_base
)
650 die(_("invalid commit position. commit-graph is likely corrupt"));
652 lex_index
= pos
- g
->num_commits_in_base
;
654 hashcpy(oid
->hash
, g
->chunk_oid_lookup
+ g
->hash_len
* lex_index
);
657 static struct commit_list
**insert_parent_or_die(struct repository
*r
,
658 struct commit_graph
*g
,
660 struct commit_list
**pptr
)
663 struct object_id oid
;
665 if (pos
>= g
->num_commits
+ g
->num_commits_in_base
)
666 die("invalid parent position %"PRIu32
, pos
);
668 load_oid_from_graph(g
, pos
, &oid
);
669 c
= lookup_commit(r
, &oid
);
671 die(_("could not find commit %s"), oid_to_hex(&oid
));
673 return &commit_list_insert(c
, pptr
)->next
;
676 static void fill_commit_graph_info(struct commit
*item
, struct commit_graph
*g
, uint32_t pos
)
678 const unsigned char *commit_data
;
681 while (pos
< g
->num_commits_in_base
)
684 lex_index
= pos
- g
->num_commits_in_base
;
685 commit_data
= g
->chunk_commit_data
+ GRAPH_DATA_WIDTH
* lex_index
;
686 item
->graph_pos
= pos
;
687 item
->generation
= get_be32(commit_data
+ g
->hash_len
+ 8) >> 2;
690 static inline void set_commit_tree(struct commit
*c
, struct tree
*t
)
695 static int fill_commit_in_graph(struct repository
*r
,
697 struct commit_graph
*g
, uint32_t pos
)
700 uint32_t *parent_data_ptr
;
701 uint64_t date_low
, date_high
;
702 struct commit_list
**pptr
;
703 const unsigned char *commit_data
;
706 while (pos
< g
->num_commits_in_base
)
709 if (pos
>= g
->num_commits
+ g
->num_commits_in_base
)
710 die(_("invalid commit position. commit-graph is likely corrupt"));
713 * Store the "full" position, but then use the
714 * "local" position for the rest of the calculation.
716 item
->graph_pos
= pos
;
717 lex_index
= pos
- g
->num_commits_in_base
;
719 commit_data
= g
->chunk_commit_data
+ (g
->hash_len
+ 16) * lex_index
;
721 item
->object
.parsed
= 1;
723 set_commit_tree(item
, NULL
);
725 date_high
= get_be32(commit_data
+ g
->hash_len
+ 8) & 0x3;
726 date_low
= get_be32(commit_data
+ g
->hash_len
+ 12);
727 item
->date
= (timestamp_t
)((date_high
<< 32) | date_low
);
729 item
->generation
= get_be32(commit_data
+ g
->hash_len
+ 8) >> 2;
731 pptr
= &item
->parents
;
733 edge_value
= get_be32(commit_data
+ g
->hash_len
);
734 if (edge_value
== GRAPH_PARENT_NONE
)
736 pptr
= insert_parent_or_die(r
, g
, edge_value
, pptr
);
738 edge_value
= get_be32(commit_data
+ g
->hash_len
+ 4);
739 if (edge_value
== GRAPH_PARENT_NONE
)
741 if (!(edge_value
& GRAPH_EXTRA_EDGES_NEEDED
)) {
742 pptr
= insert_parent_or_die(r
, g
, edge_value
, pptr
);
746 parent_data_ptr
= (uint32_t*)(g
->chunk_extra_edges
+
747 4 * (uint64_t)(edge_value
& GRAPH_EDGE_LAST_MASK
));
749 edge_value
= get_be32(parent_data_ptr
);
750 pptr
= insert_parent_or_die(r
, g
,
751 edge_value
& GRAPH_EDGE_LAST_MASK
,
754 } while (!(edge_value
& GRAPH_LAST_EDGE
));
759 static int find_commit_in_graph(struct commit
*item
, struct commit_graph
*g
, uint32_t *pos
)
761 if (item
->graph_pos
!= COMMIT_NOT_FROM_GRAPH
) {
762 *pos
= item
->graph_pos
;
765 struct commit_graph
*cur_g
= g
;
768 while (cur_g
&& !bsearch_graph(cur_g
, &(item
->object
.oid
), &lex_index
))
769 cur_g
= cur_g
->base_graph
;
772 *pos
= lex_index
+ cur_g
->num_commits_in_base
;
780 static int parse_commit_in_graph_one(struct repository
*r
,
781 struct commit_graph
*g
,
786 if (item
->object
.parsed
)
789 if (find_commit_in_graph(item
, g
, &pos
))
790 return fill_commit_in_graph(r
, item
, g
, pos
);
795 int parse_commit_in_graph(struct repository
*r
, struct commit
*item
)
797 if (!prepare_commit_graph(r
))
799 return parse_commit_in_graph_one(r
, r
->objects
->commit_graph
, item
);
802 void load_commit_graph_info(struct repository
*r
, struct commit
*item
)
805 if (!prepare_commit_graph(r
))
807 if (find_commit_in_graph(item
, r
->objects
->commit_graph
, &pos
))
808 fill_commit_graph_info(item
, r
->objects
->commit_graph
, pos
);
811 static struct tree
*load_tree_for_commit(struct repository
*r
,
812 struct commit_graph
*g
,
815 struct object_id oid
;
816 const unsigned char *commit_data
;
818 while (c
->graph_pos
< g
->num_commits_in_base
)
821 commit_data
= g
->chunk_commit_data
+
822 GRAPH_DATA_WIDTH
* (c
->graph_pos
- g
->num_commits_in_base
);
824 hashcpy(oid
.hash
, commit_data
);
825 set_commit_tree(c
, lookup_tree(r
, &oid
));
827 return c
->maybe_tree
;
830 static struct tree
*get_commit_tree_in_graph_one(struct repository
*r
,
831 struct commit_graph
*g
,
832 const struct commit
*c
)
835 return c
->maybe_tree
;
836 if (c
->graph_pos
== COMMIT_NOT_FROM_GRAPH
)
837 BUG("get_commit_tree_in_graph_one called from non-commit-graph commit");
839 return load_tree_for_commit(r
, g
, (struct commit
*)c
);
842 struct tree
*get_commit_tree_in_graph(struct repository
*r
, const struct commit
*c
)
844 return get_commit_tree_in_graph_one(r
, r
->objects
->commit_graph
, c
);
847 struct packed_commit_list
{
848 struct commit
**list
;
853 struct packed_oid_list
{
854 struct object_id
*list
;
859 struct write_commit_graph_context
{
860 struct repository
*r
;
861 struct object_directory
*odb
;
863 struct packed_oid_list oids
;
864 struct packed_commit_list commits
;
866 unsigned long approx_nr_objects
;
867 struct progress
*progress
;
869 uint64_t progress_cnt
;
871 char *base_graph_name
;
872 int num_commit_graphs_before
;
873 int num_commit_graphs_after
;
874 char **commit_graph_filenames_before
;
875 char **commit_graph_filenames_after
;
876 char **commit_graph_hash_after
;
877 uint32_t new_num_commits_in_base
;
878 struct commit_graph
*new_base_graph
;
886 const struct split_commit_graph_opts
*split_opts
;
887 size_t total_bloom_filter_data_size
;
890 static void write_graph_chunk_fanout(struct hashfile
*f
,
891 struct write_commit_graph_context
*ctx
)
894 struct commit
**list
= ctx
->commits
.list
;
897 * Write the first-level table (the list is sorted,
898 * but we use a 256-entry lookup to be able to avoid
899 * having to do eight extra binary search iterations).
901 for (i
= 0; i
< 256; i
++) {
902 while (count
< ctx
->commits
.nr
) {
903 if ((*list
)->object
.oid
.hash
[0] != i
)
905 display_progress(ctx
->progress
, ++ctx
->progress_cnt
);
910 hashwrite_be32(f
, count
);
914 static void write_graph_chunk_oids(struct hashfile
*f
, int hash_len
,
915 struct write_commit_graph_context
*ctx
)
917 struct commit
**list
= ctx
->commits
.list
;
919 for (count
= 0; count
< ctx
->commits
.nr
; count
++, list
++) {
920 display_progress(ctx
->progress
, ++ctx
->progress_cnt
);
921 hashwrite(f
, (*list
)->object
.oid
.hash
, (int)hash_len
);
925 static const unsigned char *commit_to_sha1(size_t index
, void *table
)
927 struct commit
**commits
= table
;
928 return commits
[index
]->object
.oid
.hash
;
931 static void write_graph_chunk_data(struct hashfile
*f
, int hash_len
,
932 struct write_commit_graph_context
*ctx
)
934 struct commit
**list
= ctx
->commits
.list
;
935 struct commit
**last
= ctx
->commits
.list
+ ctx
->commits
.nr
;
936 uint32_t num_extra_edges
= 0;
938 while (list
< last
) {
939 struct commit_list
*parent
;
940 struct object_id
*tree
;
942 uint32_t packedDate
[2];
943 display_progress(ctx
->progress
, ++ctx
->progress_cnt
);
945 if (parse_commit_no_graph(*list
))
946 die(_("unable to parse commit %s"),
947 oid_to_hex(&(*list
)->object
.oid
));
948 tree
= get_commit_tree_oid(*list
);
949 hashwrite(f
, tree
->hash
, hash_len
);
951 parent
= (*list
)->parents
;
954 edge_value
= GRAPH_PARENT_NONE
;
956 edge_value
= sha1_pos(parent
->item
->object
.oid
.hash
,
962 edge_value
+= ctx
->new_num_commits_in_base
;
963 else if (ctx
->new_base_graph
) {
965 if (find_commit_in_graph(parent
->item
,
972 BUG("missing parent %s for commit %s",
973 oid_to_hex(&parent
->item
->object
.oid
),
974 oid_to_hex(&(*list
)->object
.oid
));
977 hashwrite_be32(f
, edge_value
);
980 parent
= parent
->next
;
983 edge_value
= GRAPH_PARENT_NONE
;
984 else if (parent
->next
)
985 edge_value
= GRAPH_EXTRA_EDGES_NEEDED
| num_extra_edges
;
987 edge_value
= sha1_pos(parent
->item
->object
.oid
.hash
,
993 edge_value
+= ctx
->new_num_commits_in_base
;
994 else if (ctx
->new_base_graph
) {
996 if (find_commit_in_graph(parent
->item
,
1003 BUG("missing parent %s for commit %s",
1004 oid_to_hex(&parent
->item
->object
.oid
),
1005 oid_to_hex(&(*list
)->object
.oid
));
1008 hashwrite_be32(f
, edge_value
);
1010 if (edge_value
& GRAPH_EXTRA_EDGES_NEEDED
) {
1013 parent
= parent
->next
;
1017 if (sizeof((*list
)->date
) > 4)
1018 packedDate
[0] = htonl(((*list
)->date
>> 32) & 0x3);
1022 packedDate
[0] |= htonl((*list
)->generation
<< 2);
1024 packedDate
[1] = htonl((*list
)->date
);
1025 hashwrite(f
, packedDate
, 8);
1031 static void write_graph_chunk_extra_edges(struct hashfile
*f
,
1032 struct write_commit_graph_context
*ctx
)
1034 struct commit
**list
= ctx
->commits
.list
;
1035 struct commit
**last
= ctx
->commits
.list
+ ctx
->commits
.nr
;
1036 struct commit_list
*parent
;
1038 while (list
< last
) {
1039 int num_parents
= 0;
1041 display_progress(ctx
->progress
, ++ctx
->progress_cnt
);
1043 for (parent
= (*list
)->parents
; num_parents
< 3 && parent
;
1044 parent
= parent
->next
)
1047 if (num_parents
<= 2) {
1052 /* Since num_parents > 2, this initializer is safe. */
1053 for (parent
= (*list
)->parents
->next
; parent
; parent
= parent
->next
) {
1054 int edge_value
= sha1_pos(parent
->item
->object
.oid
.hash
,
1059 if (edge_value
>= 0)
1060 edge_value
+= ctx
->new_num_commits_in_base
;
1061 else if (ctx
->new_base_graph
) {
1063 if (find_commit_in_graph(parent
->item
,
1064 ctx
->new_base_graph
,
1070 BUG("missing parent %s for commit %s",
1071 oid_to_hex(&parent
->item
->object
.oid
),
1072 oid_to_hex(&(*list
)->object
.oid
));
1073 else if (!parent
->next
)
1074 edge_value
|= GRAPH_LAST_EDGE
;
1076 hashwrite_be32(f
, edge_value
);
1083 static void write_graph_chunk_bloom_indexes(struct hashfile
*f
,
1084 struct write_commit_graph_context
*ctx
)
1086 struct commit
**list
= ctx
->commits
.list
;
1087 struct commit
**last
= ctx
->commits
.list
+ ctx
->commits
.nr
;
1088 uint32_t cur_pos
= 0;
1089 struct progress
*progress
= NULL
;
1092 if (ctx
->report_progress
)
1093 progress
= start_delayed_progress(
1094 _("Writing changed paths Bloom filters index"),
1097 while (list
< last
) {
1098 struct bloom_filter
*filter
= get_bloom_filter(ctx
->r
, *list
, 0);
1099 cur_pos
+= filter
->len
;
1100 display_progress(progress
, ++i
);
1101 hashwrite_be32(f
, cur_pos
);
1105 stop_progress(&progress
);
1108 static void write_graph_chunk_bloom_data(struct hashfile
*f
,
1109 struct write_commit_graph_context
*ctx
,
1110 const struct bloom_filter_settings
*settings
)
1112 struct commit
**list
= ctx
->commits
.list
;
1113 struct commit
**last
= ctx
->commits
.list
+ ctx
->commits
.nr
;
1114 struct progress
*progress
= NULL
;
1117 if (ctx
->report_progress
)
1118 progress
= start_delayed_progress(
1119 _("Writing changed paths Bloom filters data"),
1122 hashwrite_be32(f
, settings
->hash_version
);
1123 hashwrite_be32(f
, settings
->num_hashes
);
1124 hashwrite_be32(f
, settings
->bits_per_entry
);
1126 while (list
< last
) {
1127 struct bloom_filter
*filter
= get_bloom_filter(ctx
->r
, *list
, 0);
1128 display_progress(progress
, ++i
);
1129 hashwrite(f
, filter
->data
, filter
->len
* sizeof(unsigned char));
1133 stop_progress(&progress
);
1136 static int oid_compare(const void *_a
, const void *_b
)
1138 const struct object_id
*a
= (const struct object_id
*)_a
;
1139 const struct object_id
*b
= (const struct object_id
*)_b
;
1140 return oidcmp(a
, b
);
1143 static int add_packed_commits(const struct object_id
*oid
,
1144 struct packed_git
*pack
,
1148 struct write_commit_graph_context
*ctx
= (struct write_commit_graph_context
*)data
;
1149 enum object_type type
;
1150 off_t offset
= nth_packed_object_offset(pack
, pos
);
1151 struct object_info oi
= OBJECT_INFO_INIT
;
1154 display_progress(ctx
->progress
, ++ctx
->progress_done
);
1157 if (packed_object_info(ctx
->r
, pack
, offset
, &oi
) < 0)
1158 die(_("unable to get type of object %s"), oid_to_hex(oid
));
1160 if (type
!= OBJ_COMMIT
)
1163 ALLOC_GROW(ctx
->oids
.list
, ctx
->oids
.nr
+ 1, ctx
->oids
.alloc
);
1164 oidcpy(&(ctx
->oids
.list
[ctx
->oids
.nr
]), oid
);
1167 set_commit_pos(ctx
->r
, oid
);
1172 static void add_missing_parents(struct write_commit_graph_context
*ctx
, struct commit
*commit
)
1174 struct commit_list
*parent
;
1175 for (parent
= commit
->parents
; parent
; parent
= parent
->next
) {
1176 if (!(parent
->item
->object
.flags
& REACHABLE
)) {
1177 ALLOC_GROW(ctx
->oids
.list
, ctx
->oids
.nr
+ 1, ctx
->oids
.alloc
);
1178 oidcpy(&ctx
->oids
.list
[ctx
->oids
.nr
], &(parent
->item
->object
.oid
));
1180 parent
->item
->object
.flags
|= REACHABLE
;
1185 static void close_reachable(struct write_commit_graph_context
*ctx
)
1188 struct commit
*commit
;
1189 enum commit_graph_split_flags flags
= ctx
->split_opts
?
1190 ctx
->split_opts
->flags
: COMMIT_GRAPH_SPLIT_UNSPECIFIED
;
1192 if (ctx
->report_progress
)
1193 ctx
->progress
= start_delayed_progress(
1194 _("Loading known commits in commit graph"),
1196 for (i
= 0; i
< ctx
->oids
.nr
; i
++) {
1197 display_progress(ctx
->progress
, i
+ 1);
1198 commit
= lookup_commit(ctx
->r
, &ctx
->oids
.list
[i
]);
1200 commit
->object
.flags
|= REACHABLE
;
1202 stop_progress(&ctx
->progress
);
1205 * As this loop runs, ctx->oids.nr may grow, but not more
1206 * than the number of missing commits in the reachable
1209 if (ctx
->report_progress
)
1210 ctx
->progress
= start_delayed_progress(
1211 _("Expanding reachable commits in commit graph"),
1213 for (i
= 0; i
< ctx
->oids
.nr
; i
++) {
1214 display_progress(ctx
->progress
, i
+ 1);
1215 commit
= lookup_commit(ctx
->r
, &ctx
->oids
.list
[i
]);
1220 if ((!parse_commit(commit
) &&
1221 commit
->graph_pos
== COMMIT_NOT_FROM_GRAPH
) ||
1222 flags
== COMMIT_GRAPH_SPLIT_REPLACE
)
1223 add_missing_parents(ctx
, commit
);
1224 } else if (!parse_commit_no_graph(commit
))
1225 add_missing_parents(ctx
, commit
);
1227 stop_progress(&ctx
->progress
);
1229 if (ctx
->report_progress
)
1230 ctx
->progress
= start_delayed_progress(
1231 _("Clearing commit marks in commit graph"),
1233 for (i
= 0; i
< ctx
->oids
.nr
; i
++) {
1234 display_progress(ctx
->progress
, i
+ 1);
1235 commit
= lookup_commit(ctx
->r
, &ctx
->oids
.list
[i
]);
1238 commit
->object
.flags
&= ~REACHABLE
;
1240 stop_progress(&ctx
->progress
);
1243 static void compute_generation_numbers(struct write_commit_graph_context
*ctx
)
1246 struct commit_list
*list
= NULL
;
1248 if (ctx
->report_progress
)
1249 ctx
->progress
= start_delayed_progress(
1250 _("Computing commit graph generation numbers"),
1252 for (i
= 0; i
< ctx
->commits
.nr
; i
++) {
1253 display_progress(ctx
->progress
, i
+ 1);
1254 if (ctx
->commits
.list
[i
]->generation
!= GENERATION_NUMBER_INFINITY
&&
1255 ctx
->commits
.list
[i
]->generation
!= GENERATION_NUMBER_ZERO
)
1258 commit_list_insert(ctx
->commits
.list
[i
], &list
);
1260 struct commit
*current
= list
->item
;
1261 struct commit_list
*parent
;
1262 int all_parents_computed
= 1;
1263 uint32_t max_generation
= 0;
1265 for (parent
= current
->parents
; parent
; parent
= parent
->next
) {
1266 if (parent
->item
->generation
== GENERATION_NUMBER_INFINITY
||
1267 parent
->item
->generation
== GENERATION_NUMBER_ZERO
) {
1268 all_parents_computed
= 0;
1269 commit_list_insert(parent
->item
, &list
);
1271 } else if (parent
->item
->generation
> max_generation
) {
1272 max_generation
= parent
->item
->generation
;
1276 if (all_parents_computed
) {
1277 current
->generation
= max_generation
+ 1;
1280 if (current
->generation
> GENERATION_NUMBER_MAX
)
1281 current
->generation
= GENERATION_NUMBER_MAX
;
1285 stop_progress(&ctx
->progress
);
1288 static void compute_bloom_filters(struct write_commit_graph_context
*ctx
)
1291 struct progress
*progress
= NULL
;
1292 struct commit
**sorted_commits
;
1294 init_bloom_filters();
1296 if (ctx
->report_progress
)
1297 progress
= start_delayed_progress(
1298 _("Computing commit changed paths Bloom filters"),
1301 ALLOC_ARRAY(sorted_commits
, ctx
->commits
.nr
);
1302 COPY_ARRAY(sorted_commits
, ctx
->commits
.list
, ctx
->commits
.nr
);
1304 if (ctx
->order_by_pack
)
1305 QSORT(sorted_commits
, ctx
->commits
.nr
, commit_pos_cmp
);
1307 QSORT(sorted_commits
, ctx
->commits
.nr
, commit_gen_cmp
);
1309 for (i
= 0; i
< ctx
->commits
.nr
; i
++) {
1310 struct commit
*c
= sorted_commits
[i
];
1311 struct bloom_filter
*filter
= get_bloom_filter(ctx
->r
, c
, 1);
1312 ctx
->total_bloom_filter_data_size
+= sizeof(unsigned char) * filter
->len
;
1313 display_progress(progress
, i
+ 1);
1316 free(sorted_commits
);
1317 stop_progress(&progress
);
1320 struct refs_cb_data
{
1321 struct oidset
*commits
;
1322 struct progress
*progress
;
1325 static int add_ref_to_set(const char *refname
,
1326 const struct object_id
*oid
,
1327 int flags
, void *cb_data
)
1329 struct object_id peeled
;
1330 struct refs_cb_data
*data
= (struct refs_cb_data
*)cb_data
;
1332 if (!peel_ref(refname
, &peeled
))
1334 if (oid_object_info(the_repository
, oid
, NULL
) == OBJ_COMMIT
)
1335 oidset_insert(data
->commits
, oid
);
1337 display_progress(data
->progress
, oidset_size(data
->commits
));
1342 int write_commit_graph_reachable(struct object_directory
*odb
,
1343 enum commit_graph_write_flags flags
,
1344 const struct split_commit_graph_opts
*split_opts
)
1346 struct oidset commits
= OIDSET_INIT
;
1347 struct refs_cb_data data
;
1350 memset(&data
, 0, sizeof(data
));
1351 data
.commits
= &commits
;
1352 if (flags
& COMMIT_GRAPH_WRITE_PROGRESS
)
1353 data
.progress
= start_delayed_progress(
1354 _("Collecting referenced commits"), 0);
1356 for_each_ref(add_ref_to_set
, &data
);
1357 result
= write_commit_graph(odb
, NULL
, &commits
,
1360 oidset_clear(&commits
);
1362 stop_progress(&data
.progress
);
1366 static int fill_oids_from_packs(struct write_commit_graph_context
*ctx
,
1367 struct string_list
*pack_indexes
)
1370 struct strbuf progress_title
= STRBUF_INIT
;
1371 struct strbuf packname
= STRBUF_INIT
;
1374 strbuf_addf(&packname
, "%s/pack/", ctx
->odb
->path
);
1375 dirlen
= packname
.len
;
1376 if (ctx
->report_progress
) {
1377 strbuf_addf(&progress_title
,
1378 Q_("Finding commits for commit graph in %d pack",
1379 "Finding commits for commit graph in %d packs",
1382 ctx
->progress
= start_delayed_progress(progress_title
.buf
, 0);
1383 ctx
->progress_done
= 0;
1385 for (i
= 0; i
< pack_indexes
->nr
; i
++) {
1386 struct packed_git
*p
;
1387 strbuf_setlen(&packname
, dirlen
);
1388 strbuf_addstr(&packname
, pack_indexes
->items
[i
].string
);
1389 p
= add_packed_git(packname
.buf
, packname
.len
, 1);
1391 error(_("error adding pack %s"), packname
.buf
);
1394 if (open_pack_index(p
)) {
1395 error(_("error opening index for %s"), packname
.buf
);
1398 for_each_object_in_pack(p
, add_packed_commits
, ctx
,
1399 FOR_EACH_OBJECT_PACK_ORDER
);
1404 stop_progress(&ctx
->progress
);
1405 strbuf_release(&progress_title
);
1406 strbuf_release(&packname
);
1411 static int fill_oids_from_commits(struct write_commit_graph_context
*ctx
,
1412 struct oidset
*commits
)
1414 struct oidset_iter iter
;
1415 struct object_id
*oid
;
1417 if (!oidset_size(commits
))
1420 oidset_iter_init(commits
, &iter
);
1421 while ((oid
= oidset_iter_next(&iter
))) {
1422 ALLOC_GROW(ctx
->oids
.list
, ctx
->oids
.nr
+ 1, ctx
->oids
.alloc
);
1423 oidcpy(&ctx
->oids
.list
[ctx
->oids
.nr
], oid
);
1430 static void fill_oids_from_all_packs(struct write_commit_graph_context
*ctx
)
1432 if (ctx
->report_progress
)
1433 ctx
->progress
= start_delayed_progress(
1434 _("Finding commits for commit graph among packed objects"),
1435 ctx
->approx_nr_objects
);
1436 for_each_packed_object(add_packed_commits
, ctx
,
1437 FOR_EACH_OBJECT_PACK_ORDER
);
1438 if (ctx
->progress_done
< ctx
->approx_nr_objects
)
1439 display_progress(ctx
->progress
, ctx
->approx_nr_objects
);
1440 stop_progress(&ctx
->progress
);
1443 static uint32_t count_distinct_commits(struct write_commit_graph_context
*ctx
)
1445 uint32_t i
, count_distinct
= 1;
1447 if (ctx
->report_progress
)
1448 ctx
->progress
= start_delayed_progress(
1449 _("Counting distinct commits in commit graph"),
1451 display_progress(ctx
->progress
, 0); /* TODO: Measure QSORT() progress */
1452 QSORT(ctx
->oids
.list
, ctx
->oids
.nr
, oid_compare
);
1454 for (i
= 1; i
< ctx
->oids
.nr
; i
++) {
1455 display_progress(ctx
->progress
, i
+ 1);
1456 if (!oideq(&ctx
->oids
.list
[i
- 1], &ctx
->oids
.list
[i
])) {
1458 struct commit
*c
= lookup_commit(ctx
->r
, &ctx
->oids
.list
[i
]);
1460 if (!c
|| c
->graph_pos
!= COMMIT_NOT_FROM_GRAPH
)
1467 stop_progress(&ctx
->progress
);
1469 return count_distinct
;
1472 static void copy_oids_to_commits(struct write_commit_graph_context
*ctx
)
1475 enum commit_graph_split_flags flags
= ctx
->split_opts
?
1476 ctx
->split_opts
->flags
: COMMIT_GRAPH_SPLIT_UNSPECIFIED
;
1478 ctx
->num_extra_edges
= 0;
1479 if (ctx
->report_progress
)
1480 ctx
->progress
= start_delayed_progress(
1481 _("Finding extra edges in commit graph"),
1483 for (i
= 0; i
< ctx
->oids
.nr
; i
++) {
1484 unsigned int num_parents
;
1486 display_progress(ctx
->progress
, i
+ 1);
1487 if (i
> 0 && oideq(&ctx
->oids
.list
[i
- 1], &ctx
->oids
.list
[i
]))
1490 ALLOC_GROW(ctx
->commits
.list
, ctx
->commits
.nr
+ 1, ctx
->commits
.alloc
);
1491 ctx
->commits
.list
[ctx
->commits
.nr
] = lookup_commit(ctx
->r
, &ctx
->oids
.list
[i
]);
1493 if (ctx
->split
&& flags
!= COMMIT_GRAPH_SPLIT_REPLACE
&&
1494 ctx
->commits
.list
[ctx
->commits
.nr
]->graph_pos
!= COMMIT_NOT_FROM_GRAPH
)
1497 if (ctx
->split
&& flags
== COMMIT_GRAPH_SPLIT_REPLACE
)
1498 parse_commit(ctx
->commits
.list
[ctx
->commits
.nr
]);
1500 parse_commit_no_graph(ctx
->commits
.list
[ctx
->commits
.nr
]);
1502 num_parents
= commit_list_count(ctx
->commits
.list
[ctx
->commits
.nr
]->parents
);
1503 if (num_parents
> 2)
1504 ctx
->num_extra_edges
+= num_parents
- 1;
1508 stop_progress(&ctx
->progress
);
1511 static int write_graph_chunk_base_1(struct hashfile
*f
,
1512 struct commit_graph
*g
)
1519 num
= write_graph_chunk_base_1(f
, g
->base_graph
);
1520 hashwrite(f
, g
->oid
.hash
, the_hash_algo
->rawsz
);
1524 static int write_graph_chunk_base(struct hashfile
*f
,
1525 struct write_commit_graph_context
*ctx
)
1527 int num
= write_graph_chunk_base_1(f
, ctx
->new_base_graph
);
1529 if (num
!= ctx
->num_commit_graphs_after
- 1) {
1530 error(_("failed to write correct number of base graph ids"));
1537 static int write_commit_graph_file(struct write_commit_graph_context
*ctx
)
1542 struct lock_file lk
= LOCK_INIT
;
1543 uint32_t chunk_ids
[MAX_NUM_CHUNKS
+ 1];
1544 uint64_t chunk_offsets
[MAX_NUM_CHUNKS
+ 1];
1545 const unsigned hashsz
= the_hash_algo
->rawsz
;
1546 struct strbuf progress_title
= STRBUF_INIT
;
1548 struct object_id file_hash
;
1549 const struct bloom_filter_settings bloom_settings
= DEFAULT_BLOOM_FILTER_SETTINGS
;
1552 struct strbuf tmp_file
= STRBUF_INIT
;
1554 strbuf_addf(&tmp_file
,
1555 "%s/info/commit-graphs/tmp_graph_XXXXXX",
1557 ctx
->graph_name
= strbuf_detach(&tmp_file
, NULL
);
1559 ctx
->graph_name
= get_commit_graph_filename(ctx
->odb
);
1562 if (safe_create_leading_directories(ctx
->graph_name
)) {
1563 UNLEAK(ctx
->graph_name
);
1564 error(_("unable to create leading directories of %s"),
1570 char *lock_name
= get_chain_filename(ctx
->odb
);
1572 hold_lock_file_for_update(&lk
, lock_name
, LOCK_DIE_ON_ERROR
);
1574 fd
= git_mkstemp_mode(ctx
->graph_name
, 0444);
1576 error(_("unable to create temporary graph layer"));
1580 f
= hashfd(fd
, ctx
->graph_name
);
1582 hold_lock_file_for_update(&lk
, ctx
->graph_name
, LOCK_DIE_ON_ERROR
);
1583 fd
= lk
.tempfile
->fd
;
1584 f
= hashfd(lk
.tempfile
->fd
, lk
.tempfile
->filename
.buf
);
1587 chunk_ids
[0] = GRAPH_CHUNKID_OIDFANOUT
;
1588 chunk_ids
[1] = GRAPH_CHUNKID_OIDLOOKUP
;
1589 chunk_ids
[2] = GRAPH_CHUNKID_DATA
;
1590 if (ctx
->num_extra_edges
) {
1591 chunk_ids
[num_chunks
] = GRAPH_CHUNKID_EXTRAEDGES
;
1594 if (ctx
->changed_paths
) {
1595 chunk_ids
[num_chunks
] = GRAPH_CHUNKID_BLOOMINDEXES
;
1597 chunk_ids
[num_chunks
] = GRAPH_CHUNKID_BLOOMDATA
;
1600 if (ctx
->num_commit_graphs_after
> 1) {
1601 chunk_ids
[num_chunks
] = GRAPH_CHUNKID_BASE
;
1605 chunk_ids
[num_chunks
] = 0;
1607 chunk_offsets
[0] = 8 + (num_chunks
+ 1) * GRAPH_CHUNKLOOKUP_WIDTH
;
1608 chunk_offsets
[1] = chunk_offsets
[0] + GRAPH_FANOUT_SIZE
;
1609 chunk_offsets
[2] = chunk_offsets
[1] + hashsz
* ctx
->commits
.nr
;
1610 chunk_offsets
[3] = chunk_offsets
[2] + (hashsz
+ 16) * ctx
->commits
.nr
;
1613 if (ctx
->num_extra_edges
) {
1614 chunk_offsets
[num_chunks
+ 1] = chunk_offsets
[num_chunks
] +
1615 4 * ctx
->num_extra_edges
;
1618 if (ctx
->changed_paths
) {
1619 chunk_offsets
[num_chunks
+ 1] = chunk_offsets
[num_chunks
] +
1620 sizeof(uint32_t) * ctx
->commits
.nr
;
1623 chunk_offsets
[num_chunks
+ 1] = chunk_offsets
[num_chunks
] +
1624 sizeof(uint32_t) * 3 + ctx
->total_bloom_filter_data_size
;
1627 if (ctx
->num_commit_graphs_after
> 1) {
1628 chunk_offsets
[num_chunks
+ 1] = chunk_offsets
[num_chunks
] +
1629 hashsz
* (ctx
->num_commit_graphs_after
- 1);
1633 hashwrite_be32(f
, GRAPH_SIGNATURE
);
1635 hashwrite_u8(f
, GRAPH_VERSION
);
1636 hashwrite_u8(f
, oid_version());
1637 hashwrite_u8(f
, num_chunks
);
1638 hashwrite_u8(f
, ctx
->num_commit_graphs_after
- 1);
1640 for (i
= 0; i
<= num_chunks
; i
++) {
1641 uint32_t chunk_write
[3];
1643 chunk_write
[0] = htonl(chunk_ids
[i
]);
1644 chunk_write
[1] = htonl(chunk_offsets
[i
] >> 32);
1645 chunk_write
[2] = htonl(chunk_offsets
[i
] & 0xffffffff);
1646 hashwrite(f
, chunk_write
, 12);
1649 if (ctx
->report_progress
) {
1650 strbuf_addf(&progress_title
,
1651 Q_("Writing out commit graph in %d pass",
1652 "Writing out commit graph in %d passes",
1655 ctx
->progress
= start_delayed_progress(
1657 num_chunks
* ctx
->commits
.nr
);
1659 write_graph_chunk_fanout(f
, ctx
);
1660 write_graph_chunk_oids(f
, hashsz
, ctx
);
1661 write_graph_chunk_data(f
, hashsz
, ctx
);
1662 if (ctx
->num_extra_edges
)
1663 write_graph_chunk_extra_edges(f
, ctx
);
1664 if (ctx
->changed_paths
) {
1665 write_graph_chunk_bloom_indexes(f
, ctx
);
1666 write_graph_chunk_bloom_data(f
, ctx
, &bloom_settings
);
1668 if (ctx
->num_commit_graphs_after
> 1 &&
1669 write_graph_chunk_base(f
, ctx
)) {
1672 stop_progress(&ctx
->progress
);
1673 strbuf_release(&progress_title
);
1675 if (ctx
->split
&& ctx
->base_graph_name
&& ctx
->num_commit_graphs_after
> 1) {
1676 char *new_base_hash
= xstrdup(oid_to_hex(&ctx
->new_base_graph
->oid
));
1677 char *new_base_name
= get_split_graph_filename(ctx
->new_base_graph
->odb
, new_base_hash
);
1679 free(ctx
->commit_graph_filenames_after
[ctx
->num_commit_graphs_after
- 2]);
1680 free(ctx
->commit_graph_hash_after
[ctx
->num_commit_graphs_after
- 2]);
1681 ctx
->commit_graph_filenames_after
[ctx
->num_commit_graphs_after
- 2] = new_base_name
;
1682 ctx
->commit_graph_hash_after
[ctx
->num_commit_graphs_after
- 2] = new_base_hash
;
1685 close_commit_graph(ctx
->r
->objects
);
1686 finalize_hashfile(f
, file_hash
.hash
, CSUM_HASH_IN_STREAM
| CSUM_FSYNC
);
1689 FILE *chainf
= fdopen_lock_file(&lk
, "w");
1690 char *final_graph_name
;
1696 error(_("unable to open commit-graph chain file"));
1700 if (ctx
->base_graph_name
) {
1702 int idx
= ctx
->num_commit_graphs_after
- 1;
1703 if (ctx
->num_commit_graphs_after
> 1)
1706 dest
= ctx
->commit_graph_filenames_after
[idx
];
1708 if (strcmp(ctx
->base_graph_name
, dest
)) {
1709 result
= rename(ctx
->base_graph_name
, dest
);
1712 error(_("failed to rename base commit-graph file"));
1717 char *graph_name
= get_commit_graph_filename(ctx
->odb
);
1721 ctx
->commit_graph_hash_after
[ctx
->num_commit_graphs_after
- 1] = xstrdup(oid_to_hex(&file_hash
));
1722 final_graph_name
= get_split_graph_filename(ctx
->odb
,
1723 ctx
->commit_graph_hash_after
[ctx
->num_commit_graphs_after
- 1]);
1724 ctx
->commit_graph_filenames_after
[ctx
->num_commit_graphs_after
- 1] = final_graph_name
;
1726 result
= rename(ctx
->graph_name
, final_graph_name
);
1728 for (i
= 0; i
< ctx
->num_commit_graphs_after
; i
++)
1729 fprintf(lk
.tempfile
->fp
, "%s\n", ctx
->commit_graph_hash_after
[i
]);
1732 error(_("failed to rename temporary commit-graph file"));
1737 commit_lock_file(&lk
);
1742 static void split_graph_merge_strategy(struct write_commit_graph_context
*ctx
)
1744 struct commit_graph
*g
;
1745 uint32_t num_commits
;
1746 enum commit_graph_split_flags flags
= COMMIT_GRAPH_SPLIT_UNSPECIFIED
;
1749 int max_commits
= 0;
1752 if (ctx
->split_opts
) {
1753 max_commits
= ctx
->split_opts
->max_commits
;
1755 if (ctx
->split_opts
->size_multiple
)
1756 size_mult
= ctx
->split_opts
->size_multiple
;
1758 flags
= ctx
->split_opts
->flags
;
1761 g
= ctx
->r
->objects
->commit_graph
;
1762 num_commits
= ctx
->commits
.nr
;
1763 if (flags
== COMMIT_GRAPH_SPLIT_REPLACE
)
1764 ctx
->num_commit_graphs_after
= 1;
1766 ctx
->num_commit_graphs_after
= ctx
->num_commit_graphs_before
+ 1;
1768 if (flags
!= COMMIT_GRAPH_SPLIT_MERGE_PROHIBITED
&&
1769 flags
!= COMMIT_GRAPH_SPLIT_REPLACE
) {
1770 while (g
&& (g
->num_commits
<= size_mult
* num_commits
||
1771 (max_commits
&& num_commits
> max_commits
))) {
1772 if (g
->odb
!= ctx
->odb
)
1775 num_commits
+= g
->num_commits
;
1778 ctx
->num_commit_graphs_after
--;
1782 if (flags
!= COMMIT_GRAPH_SPLIT_REPLACE
)
1783 ctx
->new_base_graph
= g
;
1784 else if (ctx
->num_commit_graphs_after
!= 1)
1785 BUG("split_graph_merge_strategy: num_commit_graphs_after "
1786 "should be 1 with --split=replace");
1788 if (ctx
->num_commit_graphs_after
== 2) {
1789 char *old_graph_name
= get_commit_graph_filename(g
->odb
);
1791 if (!strcmp(g
->filename
, old_graph_name
) &&
1792 g
->odb
!= ctx
->odb
) {
1793 ctx
->num_commit_graphs_after
= 1;
1794 ctx
->new_base_graph
= NULL
;
1797 free(old_graph_name
);
1800 CALLOC_ARRAY(ctx
->commit_graph_filenames_after
, ctx
->num_commit_graphs_after
);
1801 CALLOC_ARRAY(ctx
->commit_graph_hash_after
, ctx
->num_commit_graphs_after
);
1803 for (i
= 0; i
< ctx
->num_commit_graphs_after
&&
1804 i
< ctx
->num_commit_graphs_before
; i
++)
1805 ctx
->commit_graph_filenames_after
[i
] = xstrdup(ctx
->commit_graph_filenames_before
[i
]);
1807 i
= ctx
->num_commit_graphs_before
- 1;
1808 g
= ctx
->r
->objects
->commit_graph
;
1811 if (i
< ctx
->num_commit_graphs_after
)
1812 ctx
->commit_graph_hash_after
[i
] = xstrdup(oid_to_hex(&g
->oid
));
1819 static void merge_commit_graph(struct write_commit_graph_context
*ctx
,
1820 struct commit_graph
*g
)
1823 uint32_t offset
= g
->num_commits_in_base
;
1825 ALLOC_GROW(ctx
->commits
.list
, ctx
->commits
.nr
+ g
->num_commits
, ctx
->commits
.alloc
);
1827 for (i
= 0; i
< g
->num_commits
; i
++) {
1828 struct object_id oid
;
1829 struct commit
*result
;
1831 display_progress(ctx
->progress
, i
+ 1);
1833 load_oid_from_graph(g
, i
+ offset
, &oid
);
1835 /* only add commits if they still exist in the repo */
1836 result
= lookup_commit_reference_gently(ctx
->r
, &oid
, 1);
1839 ctx
->commits
.list
[ctx
->commits
.nr
] = result
;
1845 static int commit_compare(const void *_a
, const void *_b
)
1847 const struct commit
*a
= *(const struct commit
**)_a
;
1848 const struct commit
*b
= *(const struct commit
**)_b
;
1849 return oidcmp(&a
->object
.oid
, &b
->object
.oid
);
1852 static void sort_and_scan_merged_commits(struct write_commit_graph_context
*ctx
)
1856 if (ctx
->report_progress
)
1857 ctx
->progress
= start_delayed_progress(
1858 _("Scanning merged commits"),
1861 QSORT(ctx
->commits
.list
, ctx
->commits
.nr
, commit_compare
);
1863 ctx
->num_extra_edges
= 0;
1864 for (i
= 0; i
< ctx
->commits
.nr
; i
++) {
1865 display_progress(ctx
->progress
, i
);
1867 if (i
&& oideq(&ctx
->commits
.list
[i
- 1]->object
.oid
,
1868 &ctx
->commits
.list
[i
]->object
.oid
)) {
1869 die(_("unexpected duplicate commit id %s"),
1870 oid_to_hex(&ctx
->commits
.list
[i
]->object
.oid
));
1872 unsigned int num_parents
;
1874 num_parents
= commit_list_count(ctx
->commits
.list
[i
]->parents
);
1875 if (num_parents
> 2)
1876 ctx
->num_extra_edges
+= num_parents
- 1;
1880 stop_progress(&ctx
->progress
);
1883 static void merge_commit_graphs(struct write_commit_graph_context
*ctx
)
1885 struct commit_graph
*g
= ctx
->r
->objects
->commit_graph
;
1886 uint32_t current_graph_number
= ctx
->num_commit_graphs_before
;
1888 while (g
&& current_graph_number
>= ctx
->num_commit_graphs_after
) {
1889 current_graph_number
--;
1891 if (ctx
->report_progress
)
1892 ctx
->progress
= start_delayed_progress(_("Merging commit-graph"), 0);
1894 merge_commit_graph(ctx
, g
);
1895 stop_progress(&ctx
->progress
);
1901 ctx
->new_base_graph
= g
;
1902 ctx
->new_num_commits_in_base
= g
->num_commits
+ g
->num_commits_in_base
;
1905 if (ctx
->new_base_graph
)
1906 ctx
->base_graph_name
= xstrdup(ctx
->new_base_graph
->filename
);
1908 sort_and_scan_merged_commits(ctx
);
1911 static void mark_commit_graphs(struct write_commit_graph_context
*ctx
)
1914 time_t now
= time(NULL
);
1916 for (i
= ctx
->num_commit_graphs_after
- 1; i
< ctx
->num_commit_graphs_before
; i
++) {
1918 struct utimbuf updated_time
;
1920 stat(ctx
->commit_graph_filenames_before
[i
], &st
);
1922 updated_time
.actime
= st
.st_atime
;
1923 updated_time
.modtime
= now
;
1924 utime(ctx
->commit_graph_filenames_before
[i
], &updated_time
);
1928 static void expire_commit_graphs(struct write_commit_graph_context
*ctx
)
1930 struct strbuf path
= STRBUF_INIT
;
1934 timestamp_t expire_time
= time(NULL
);
1936 if (ctx
->split_opts
&& ctx
->split_opts
->expire_time
)
1937 expire_time
= ctx
->split_opts
->expire_time
;
1939 char *chain_file_name
= get_chain_filename(ctx
->odb
);
1940 unlink(chain_file_name
);
1941 free(chain_file_name
);
1942 ctx
->num_commit_graphs_after
= 0;
1945 strbuf_addstr(&path
, ctx
->odb
->path
);
1946 strbuf_addstr(&path
, "/info/commit-graphs");
1947 dir
= opendir(path
.buf
);
1952 strbuf_addch(&path
, '/');
1953 dirnamelen
= path
.len
;
1954 while ((de
= readdir(dir
)) != NULL
) {
1956 uint32_t i
, found
= 0;
1958 strbuf_setlen(&path
, dirnamelen
);
1959 strbuf_addstr(&path
, de
->d_name
);
1961 stat(path
.buf
, &st
);
1963 if (st
.st_mtime
> expire_time
)
1965 if (path
.len
< 6 || strcmp(path
.buf
+ path
.len
- 6, ".graph"))
1968 for (i
= 0; i
< ctx
->num_commit_graphs_after
; i
++) {
1969 if (!strcmp(ctx
->commit_graph_filenames_after
[i
],
1981 strbuf_release(&path
);
1984 int write_commit_graph(struct object_directory
*odb
,
1985 struct string_list
*pack_indexes
,
1986 struct oidset
*commits
,
1987 enum commit_graph_write_flags flags
,
1988 const struct split_commit_graph_opts
*split_opts
)
1990 struct write_commit_graph_context
*ctx
;
1991 uint32_t i
, count_distinct
= 0;
1995 if (!commit_graph_compatible(the_repository
))
1998 ctx
= xcalloc(1, sizeof(struct write_commit_graph_context
));
1999 ctx
->r
= the_repository
;
2001 ctx
->append
= flags
& COMMIT_GRAPH_WRITE_APPEND
? 1 : 0;
2002 ctx
->report_progress
= flags
& COMMIT_GRAPH_WRITE_PROGRESS
? 1 : 0;
2003 ctx
->split
= flags
& COMMIT_GRAPH_WRITE_SPLIT
? 1 : 0;
2004 ctx
->split_opts
= split_opts
;
2005 ctx
->changed_paths
= flags
& COMMIT_GRAPH_WRITE_BLOOM_FILTERS
? 1 : 0;
2006 ctx
->total_bloom_filter_data_size
= 0;
2009 struct commit_graph
*g
;
2010 prepare_commit_graph(ctx
->r
);
2012 g
= ctx
->r
->objects
->commit_graph
;
2015 ctx
->num_commit_graphs_before
++;
2019 if (ctx
->num_commit_graphs_before
) {
2020 ALLOC_ARRAY(ctx
->commit_graph_filenames_before
, ctx
->num_commit_graphs_before
);
2021 i
= ctx
->num_commit_graphs_before
;
2022 g
= ctx
->r
->objects
->commit_graph
;
2025 ctx
->commit_graph_filenames_before
[--i
] = xstrdup(g
->filename
);
2030 if (ctx
->split_opts
)
2031 replace
= ctx
->split_opts
->flags
& COMMIT_GRAPH_SPLIT_REPLACE
;
2034 ctx
->approx_nr_objects
= approximate_object_count();
2035 ctx
->oids
.alloc
= ctx
->approx_nr_objects
/ 32;
2037 if (ctx
->split
&& split_opts
&& ctx
->oids
.alloc
> split_opts
->max_commits
)
2038 ctx
->oids
.alloc
= split_opts
->max_commits
;
2041 prepare_commit_graph_one(ctx
->r
, ctx
->odb
);
2042 if (ctx
->r
->objects
->commit_graph
)
2043 ctx
->oids
.alloc
+= ctx
->r
->objects
->commit_graph
->num_commits
;
2046 if (ctx
->oids
.alloc
< 1024)
2047 ctx
->oids
.alloc
= 1024;
2048 ALLOC_ARRAY(ctx
->oids
.list
, ctx
->oids
.alloc
);
2050 if (ctx
->append
&& ctx
->r
->objects
->commit_graph
) {
2051 struct commit_graph
*g
= ctx
->r
->objects
->commit_graph
;
2052 for (i
= 0; i
< g
->num_commits
; i
++) {
2053 const unsigned char *hash
= g
->chunk_oid_lookup
+ g
->hash_len
* i
;
2054 hashcpy(ctx
->oids
.list
[ctx
->oids
.nr
++].hash
, hash
);
2059 ctx
->order_by_pack
= 1;
2060 if ((res
= fill_oids_from_packs(ctx
, pack_indexes
)))
2065 if ((res
= fill_oids_from_commits(ctx
, commits
)))
2069 if (!pack_indexes
&& !commits
) {
2070 ctx
->order_by_pack
= 1;
2071 fill_oids_from_all_packs(ctx
);
2074 close_reachable(ctx
);
2076 count_distinct
= count_distinct_commits(ctx
);
2078 if (count_distinct
>= GRAPH_EDGE_LAST_MASK
) {
2079 error(_("the commit graph format cannot write %d commits"), count_distinct
);
2084 ctx
->commits
.alloc
= count_distinct
;
2085 ALLOC_ARRAY(ctx
->commits
.list
, ctx
->commits
.alloc
);
2087 copy_oids_to_commits(ctx
);
2089 if (ctx
->commits
.nr
>= GRAPH_EDGE_LAST_MASK
) {
2090 error(_("too many commits to write graph"));
2095 if (!ctx
->commits
.nr
&& !replace
)
2099 split_graph_merge_strategy(ctx
);
2102 merge_commit_graphs(ctx
);
2104 ctx
->num_commit_graphs_after
= 1;
2106 compute_generation_numbers(ctx
);
2108 if (ctx
->changed_paths
)
2109 compute_bloom_filters(ctx
);
2111 res
= write_commit_graph_file(ctx
);
2114 mark_commit_graphs(ctx
);
2116 expire_commit_graphs(ctx
);
2119 free(ctx
->graph_name
);
2120 free(ctx
->commits
.list
);
2121 free(ctx
->oids
.list
);
2123 if (ctx
->commit_graph_filenames_after
) {
2124 for (i
= 0; i
< ctx
->num_commit_graphs_after
; i
++) {
2125 free(ctx
->commit_graph_filenames_after
[i
]);
2126 free(ctx
->commit_graph_hash_after
[i
]);
2129 for (i
= 0; i
< ctx
->num_commit_graphs_before
; i
++)
2130 free(ctx
->commit_graph_filenames_before
[i
]);
2132 free(ctx
->commit_graph_filenames_after
);
2133 free(ctx
->commit_graph_filenames_before
);
2134 free(ctx
->commit_graph_hash_after
);
2142 #define VERIFY_COMMIT_GRAPH_ERROR_HASH 2
2143 static int verify_commit_graph_error
;
2145 static void graph_report(const char *fmt
, ...)
2149 verify_commit_graph_error
= 1;
2151 vfprintf(stderr
, fmt
, ap
);
2152 fprintf(stderr
, "\n");
2156 #define GENERATION_ZERO_EXISTS 1
2157 #define GENERATION_NUMBER_EXISTS 2
2159 int verify_commit_graph(struct repository
*r
, struct commit_graph
*g
, int flags
)
2161 uint32_t i
, cur_fanout_pos
= 0;
2162 struct object_id prev_oid
, cur_oid
, checksum
;
2163 int generation_zero
= 0;
2166 struct progress
*progress
= NULL
;
2167 int local_error
= 0;
2170 graph_report("no commit-graph file loaded");
2174 verify_commit_graph_error
= verify_commit_graph_lite(g
);
2175 if (verify_commit_graph_error
)
2176 return verify_commit_graph_error
;
2178 devnull
= open("/dev/null", O_WRONLY
);
2179 f
= hashfd(devnull
, NULL
);
2180 hashwrite(f
, g
->data
, g
->data_len
- g
->hash_len
);
2181 finalize_hashfile(f
, checksum
.hash
, CSUM_CLOSE
);
2182 if (!hasheq(checksum
.hash
, g
->data
+ g
->data_len
- g
->hash_len
)) {
2183 graph_report(_("the commit-graph file has incorrect checksum and is likely corrupt"));
2184 verify_commit_graph_error
= VERIFY_COMMIT_GRAPH_ERROR_HASH
;
2187 for (i
= 0; i
< g
->num_commits
; i
++) {
2188 struct commit
*graph_commit
;
2190 hashcpy(cur_oid
.hash
, g
->chunk_oid_lookup
+ g
->hash_len
* i
);
2192 if (i
&& oidcmp(&prev_oid
, &cur_oid
) >= 0)
2193 graph_report(_("commit-graph has incorrect OID order: %s then %s"),
2194 oid_to_hex(&prev_oid
),
2195 oid_to_hex(&cur_oid
));
2197 oidcpy(&prev_oid
, &cur_oid
);
2199 while (cur_oid
.hash
[0] > cur_fanout_pos
) {
2200 uint32_t fanout_value
= get_be32(g
->chunk_oid_fanout
+ cur_fanout_pos
);
2202 if (i
!= fanout_value
)
2203 graph_report(_("commit-graph has incorrect fanout value: fanout[%d] = %u != %u"),
2204 cur_fanout_pos
, fanout_value
, i
);
2208 graph_commit
= lookup_commit(r
, &cur_oid
);
2209 if (!parse_commit_in_graph_one(r
, g
, graph_commit
))
2210 graph_report(_("failed to parse commit %s from commit-graph"),
2211 oid_to_hex(&cur_oid
));
2214 while (cur_fanout_pos
< 256) {
2215 uint32_t fanout_value
= get_be32(g
->chunk_oid_fanout
+ cur_fanout_pos
);
2217 if (g
->num_commits
!= fanout_value
)
2218 graph_report(_("commit-graph has incorrect fanout value: fanout[%d] = %u != %u"),
2219 cur_fanout_pos
, fanout_value
, i
);
2224 if (verify_commit_graph_error
& ~VERIFY_COMMIT_GRAPH_ERROR_HASH
)
2225 return verify_commit_graph_error
;
2227 if (flags
& COMMIT_GRAPH_WRITE_PROGRESS
)
2228 progress
= start_progress(_("Verifying commits in commit graph"),
2231 for (i
= 0; i
< g
->num_commits
; i
++) {
2232 struct commit
*graph_commit
, *odb_commit
;
2233 struct commit_list
*graph_parents
, *odb_parents
;
2234 uint32_t max_generation
= 0;
2236 display_progress(progress
, i
+ 1);
2237 hashcpy(cur_oid
.hash
, g
->chunk_oid_lookup
+ g
->hash_len
* i
);
2239 graph_commit
= lookup_commit(r
, &cur_oid
);
2240 odb_commit
= (struct commit
*)create_object(r
, &cur_oid
, alloc_commit_node(r
));
2241 if (parse_commit_internal(odb_commit
, 0, 0)) {
2242 graph_report(_("failed to parse commit %s from object database for commit-graph"),
2243 oid_to_hex(&cur_oid
));
2247 if (!oideq(&get_commit_tree_in_graph_one(r
, g
, graph_commit
)->object
.oid
,
2248 get_commit_tree_oid(odb_commit
)))
2249 graph_report(_("root tree OID for commit %s in commit-graph is %s != %s"),
2250 oid_to_hex(&cur_oid
),
2251 oid_to_hex(get_commit_tree_oid(graph_commit
)),
2252 oid_to_hex(get_commit_tree_oid(odb_commit
)));
2254 graph_parents
= graph_commit
->parents
;
2255 odb_parents
= odb_commit
->parents
;
2257 while (graph_parents
) {
2258 if (odb_parents
== NULL
) {
2259 graph_report(_("commit-graph parent list for commit %s is too long"),
2260 oid_to_hex(&cur_oid
));
2264 /* parse parent in case it is in a base graph */
2265 parse_commit_in_graph_one(r
, g
, graph_parents
->item
);
2267 if (!oideq(&graph_parents
->item
->object
.oid
, &odb_parents
->item
->object
.oid
))
2268 graph_report(_("commit-graph parent for %s is %s != %s"),
2269 oid_to_hex(&cur_oid
),
2270 oid_to_hex(&graph_parents
->item
->object
.oid
),
2271 oid_to_hex(&odb_parents
->item
->object
.oid
));
2273 if (graph_parents
->item
->generation
> max_generation
)
2274 max_generation
= graph_parents
->item
->generation
;
2276 graph_parents
= graph_parents
->next
;
2277 odb_parents
= odb_parents
->next
;
2280 if (odb_parents
!= NULL
)
2281 graph_report(_("commit-graph parent list for commit %s terminates early"),
2282 oid_to_hex(&cur_oid
));
2284 if (!graph_commit
->generation
) {
2285 if (generation_zero
== GENERATION_NUMBER_EXISTS
)
2286 graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"),
2287 oid_to_hex(&cur_oid
));
2288 generation_zero
= GENERATION_ZERO_EXISTS
;
2289 } else if (generation_zero
== GENERATION_ZERO_EXISTS
)
2290 graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"),
2291 oid_to_hex(&cur_oid
));
2293 if (generation_zero
== GENERATION_ZERO_EXISTS
)
2297 * If one of our parents has generation GENERATION_NUMBER_MAX, then
2298 * our generation is also GENERATION_NUMBER_MAX. Decrement to avoid
2299 * extra logic in the following condition.
2301 if (max_generation
== GENERATION_NUMBER_MAX
)
2304 if (graph_commit
->generation
!= max_generation
+ 1)
2305 graph_report(_("commit-graph generation for commit %s is %u != %u"),
2306 oid_to_hex(&cur_oid
),
2307 graph_commit
->generation
,
2308 max_generation
+ 1);
2310 if (graph_commit
->date
!= odb_commit
->date
)
2311 graph_report(_("commit date for commit %s in commit-graph is %"PRItime
" != %"PRItime
),
2312 oid_to_hex(&cur_oid
),
2316 stop_progress(&progress
);
2318 local_error
= verify_commit_graph_error
;
2320 if (!(flags
& COMMIT_GRAPH_VERIFY_SHALLOW
) && g
->base_graph
)
2321 local_error
|= verify_commit_graph(r
, g
->base_graph
, flags
);
2326 void free_commit_graph(struct commit_graph
*g
)
2331 munmap((void *)g
->data
, g
->data_len
);
2335 free(g
->bloom_filter_settings
);
2339 void disable_commit_graph(struct repository
*r
)
2341 r
->commit_graph_disabled
= 1;