846
va_end(ap);
847
}
848
849
+#define GENERATION_ZERO_EXISTS 1
850
+#define GENERATION_NUMBER_EXISTS 2
851
+
852
int verify_commit_graph(struct repository *r, struct commit_graph *g)
853
{
854
uint32_t i, cur_fanout_pos = 0;
855
struct object_id prev_oid, cur_oid;
856
+ int generation_zero = 0;
857
858
if (!g) {
859
graph_report("no commit-graph file loaded");
915
for (i = 0; i < g->num_commits; i++) {
916
struct commit *graph_commit, *odb_commit;
917
struct commit_list *graph_parents, *odb_parents;
918
+ uint32_t max_generation = 0;
919
920
hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i);
921
950
oid_to_hex(&graph_parents->item->object.oid),
951
oid_to_hex(&odb_parents->item->object.oid));
952
953
+ if (graph_parents->item->generation > max_generation)
954
+ max_generation = graph_parents->item->generation;
955
+
956
graph_parents = graph_parents->next;
957
odb_parents = odb_parents->next;
958
}
960
if (odb_parents != NULL)
961
graph_report("commit-graph parent list for commit %s terminates early",
962
oid_to_hex(&cur_oid));
963
+
964
+ if (!graph_commit->generation) {
965
+ if (generation_zero == GENERATION_NUMBER_EXISTS)
966
+ graph_report("commit-graph has generation number zero for commit %s, but non-zero elsewhere",
967
+ oid_to_hex(&cur_oid));
968
+ generation_zero = GENERATION_ZERO_EXISTS;
969
+ } else if (generation_zero == GENERATION_ZERO_EXISTS)
970
+ graph_report("commit-graph has non-zero generation number for commit %s, but zero elsewhere",
971
+ oid_to_hex(&cur_oid));
972
+
973
+ if (generation_zero == GENERATION_ZERO_EXISTS)
974
+ continue;
975
+
976
+ /*
977
+ * If one of our parents has generation GENERATION_NUMBER_MAX, then
978
+ * our generation is also GENERATION_NUMBER_MAX. Decrement to avoid
979
+ * extra logic in the following condition.
980
+ */
981
+ if (max_generation == GENERATION_NUMBER_MAX)
982
+ max_generation--;
983
+
984
+ if (graph_commit->generation != max_generation + 1)
985
+ graph_report("commit-graph generation for commit %s is %u != %u",
986
+ oid_to_hex(&cur_oid),
987
+ graph_commit->generation,
988
+ max_generation + 1);
989
}
990
991
return verify_commit_graph_error;