commit-graph: check mixed generation validation when loading chain file

In read_commit_graph_one(), we call validate_mixed_generation_chain() after loading the graph. Even though we don't check the return value, this has the side effect of clearing the read_generation_data flag, which is important when working with mixed generation numbers. But doing this in load_commit_graph_chain_fd_st() makes more sense: 1. We are calling it even when we did not load a chain at all, which is pointless (you cannot have mixed generations in a single file). 2. For now, all callers load the graph via read_commit_graph_one(). But the point of factoring out the open/load in the previous commit was to let "commit-graph verify" call them separately. So it needs to trigger this function as part of the load. Without this patch, the mixed-generation tests in t5324 would start failing on "git commit-graph verify" calls, once we switch to using a separate open/load call there. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 28, 2023 at 00:38 UTC 8298b54317772ca28fec2673f59a8c2048552ae6
1 file changed +27 -27
commit-graph.c
+27 -27
@@ -473,6 +473,31 @@ static struct commit_graph *load_commit_graph_v1(struct repository *r,
473 return g;
474 }
475
476 +/*
477 + * returns 1 if and only if all graphs in the chain have
478 + * corrected commit dates stored in the generation_data chunk.
479 + */
480 +static int validate_mixed_generation_chain(struct commit_graph *g)
481 +{
482 + int read_generation_data = 1;
483 + struct commit_graph *p = g;
484 +
485 + while (read_generation_data && p) {
486 + read_generation_data = p->read_generation_data;
487 + p = p->base_graph;
488 + }
489 +
490 + if (read_generation_data)
491 + return 1;
492 +
493 + while (g) {
494 + g->read_generation_data = 0;
495 + g = g->base_graph;
496 + }
497 +
498 + return 0;
499 +}
500 +
501 static int add_graph_to_chain(struct commit_graph *g,
502 struct commit_graph *chain,
503 struct object_id *oids,
@@ -581,6 +606,8 @@ struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
606 }
607 }
608
609 + validate_mixed_generation_chain(graph_chain);
610 +
611 free(oids);
612 fclose(fp);
613 strbuf_release(&line);
@@ -605,31 +632,6 @@ static struct commit_graph *load_commit_graph_chain(struct repository *r,
632 return g;
633 }
634
608 -/*
609 - * returns 1 if and only if all graphs in the chain have
610 - * corrected commit dates stored in the generation_data chunk.
611 - */
612 -static int validate_mixed_generation_chain(struct commit_graph *g)
613 -{
614 - int read_generation_data = 1;
615 - struct commit_graph *p = g;
616 -
617 - while (read_generation_data && p) {
618 - read_generation_data = p->read_generation_data;
619 - p = p->base_graph;
620 - }
621 -
622 - if (read_generation_data)
623 - return 1;
624 -
625 - while (g) {
626 - g->read_generation_data = 0;
627 - g = g->base_graph;
628 - }
629 -
630 - return 0;
631 -}
632 -
635 struct commit_graph *read_commit_graph_one(struct repository *r,
636 struct object_directory *odb)
637 {
@@ -638,8 +640,6 @@ struct commit_graph *read_commit_graph_one(struct repository *r,
640 if (!g)
641 g = load_commit_graph_chain(r, odb);
642
641 - validate_mixed_generation_chain(g);
642 -
643 return g;
644 }
645