Skip to content

Commit 9c2c0a8

Browse files
derrickstoleegitster
authored andcommitted
commit-graph: compute generations separately
The compute_generation_numbers() method was introduced by 3258c66 (commit-graph: compute generation numbers, 2018-05-01) to compute what is now known as "topological levels". These are still stored in the commit-graph file for compatibility sake while c1a0911 (commit-graph: implement corrected commit date, 2021-01-16) updated the method to also compute the new version of generation numbers: corrected commit date. It makes sense why these are grouped. They perform very similar walks of the necessary commits and compute similar maximums over each parent. However, having these two together conflates them in subtle ways that is hard to separate. In particular, the topo_level slab is used to store the topological levels in all cases, but the commit_graph_data_at(c)->generation member stores different values depending on the state of the existing commit-graph file. * If the existing commit-graph file has a "GDAT" chunk, then these values represent corrected commit dates. * If the existing commit-graph file doesn't have a "GDAT" chunk, then these values are actually the topological levels. This issue only occurs only when upgrading an existing commit-graph file into one that has the "GDAT" chunk. The current change does not resolve this upgrade problem, but splitting the implementation into two pieces here helps with that process, which will follow in the next change. The important thing this helps with is the case where the num_generation_data_overflows was being incremented incorrectly, triggering a write of the overflow chunk. Signed-off-by: Derrick Stolee <[email protected]> Reviewed-by: Taylor Blau <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 448a39e commit 9c2c0a8

File tree

1 file changed

+56
-14
lines changed

1 file changed

+56
-14
lines changed

commit-graph.c

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1446,27 +1446,24 @@ static void close_reachable(struct write_commit_graph_context *ctx)
14461446
stop_progress(&ctx->progress);
14471447
}
14481448

1449-
static void compute_generation_numbers(struct write_commit_graph_context *ctx)
1449+
static void compute_topological_levels(struct write_commit_graph_context *ctx)
14501450
{
14511451
int i;
14521452
struct commit_list *list = NULL;
14531453

14541454
if (ctx->report_progress)
14551455
ctx->progress = start_delayed_progress(
1456-
_("Computing commit graph generation numbers"),
1456+
_("Computing commit graph topological levels"),
14571457
ctx->commits.nr);
14581458
for (i = 0; i < ctx->commits.nr; i++) {
14591459
struct commit *c = ctx->commits.list[i];
14601460
uint32_t level;
1461-
timestamp_t corrected_commit_date;
14621461

14631462
repo_parse_commit(ctx->r, c);
14641463
level = *topo_level_slab_at(ctx->topo_levels, c);
1465-
corrected_commit_date = commit_graph_data_at(c)->generation;
14661464

14671465
display_progress(ctx->progress, i + 1);
1468-
if (level != GENERATION_NUMBER_ZERO &&
1469-
corrected_commit_date != GENERATION_NUMBER_ZERO)
1466+
if (level != GENERATION_NUMBER_ZERO)
14701467
continue;
14711468

14721469
commit_list_insert(c, &list);
@@ -1475,25 +1472,19 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
14751472
struct commit_list *parent;
14761473
int all_parents_computed = 1;
14771474
uint32_t max_level = 0;
1478-
timestamp_t max_corrected_commit_date = 0;
14791475

14801476
for (parent = current->parents; parent; parent = parent->next) {
14811477
repo_parse_commit(ctx->r, parent->item);
14821478
level = *topo_level_slab_at(ctx->topo_levels, parent->item);
1483-
corrected_commit_date = commit_graph_data_at(parent->item)->generation;
14841479

1485-
if (level == GENERATION_NUMBER_ZERO ||
1486-
corrected_commit_date == GENERATION_NUMBER_ZERO) {
1480+
if (level == GENERATION_NUMBER_ZERO) {
14871481
all_parents_computed = 0;
14881482
commit_list_insert(parent->item, &list);
14891483
break;
14901484
}
14911485

14921486
if (level > max_level)
14931487
max_level = level;
1494-
1495-
if (corrected_commit_date > max_corrected_commit_date)
1496-
max_corrected_commit_date = corrected_commit_date;
14971488
}
14981489

14991490
if (all_parents_computed) {
@@ -1502,6 +1493,55 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
15021493
if (max_level > GENERATION_NUMBER_V1_MAX - 1)
15031494
max_level = GENERATION_NUMBER_V1_MAX - 1;
15041495
*topo_level_slab_at(ctx->topo_levels, current) = max_level + 1;
1496+
}
1497+
}
1498+
}
1499+
stop_progress(&ctx->progress);
1500+
}
1501+
1502+
static void compute_generation_numbers(struct write_commit_graph_context *ctx)
1503+
{
1504+
int i;
1505+
struct commit_list *list = NULL;
1506+
1507+
if (ctx->report_progress)
1508+
ctx->progress = start_delayed_progress(
1509+
_("Computing commit graph generation numbers"),
1510+
ctx->commits.nr);
1511+
for (i = 0; i < ctx->commits.nr; i++) {
1512+
struct commit *c = ctx->commits.list[i];
1513+
timestamp_t corrected_commit_date;
1514+
1515+
repo_parse_commit(ctx->r, c);
1516+
corrected_commit_date = commit_graph_data_at(c)->generation;
1517+
1518+
display_progress(ctx->progress, i + 1);
1519+
if (corrected_commit_date != GENERATION_NUMBER_ZERO)
1520+
continue;
1521+
1522+
commit_list_insert(c, &list);
1523+
while (list) {
1524+
struct commit *current = list->item;
1525+
struct commit_list *parent;
1526+
int all_parents_computed = 1;
1527+
timestamp_t max_corrected_commit_date = 0;
1528+
1529+
for (parent = current->parents; parent; parent = parent->next) {
1530+
repo_parse_commit(ctx->r, parent->item);
1531+
corrected_commit_date = commit_graph_data_at(parent->item)->generation;
1532+
1533+
if (corrected_commit_date == GENERATION_NUMBER_ZERO) {
1534+
all_parents_computed = 0;
1535+
commit_list_insert(parent->item, &list);
1536+
break;
1537+
}
1538+
1539+
if (corrected_commit_date > max_corrected_commit_date)
1540+
max_corrected_commit_date = corrected_commit_date;
1541+
}
1542+
1543+
if (all_parents_computed) {
1544+
pop_commit(&list);
15051545

15061546
if (current->date && current->date > max_corrected_commit_date)
15071547
max_corrected_commit_date = current->date - 1;
@@ -2401,7 +2441,9 @@ int write_commit_graph(struct object_directory *odb,
24012441

24022442
validate_mixed_generation_chain(ctx->r->objects->commit_graph);
24032443

2404-
compute_generation_numbers(ctx);
2444+
compute_topological_levels(ctx);
2445+
if (ctx->write_generation_data)
2446+
compute_generation_numbers(ctx);
24052447

24062448
if (ctx->changed_paths)
24072449
compute_bloom_filters(ctx);

0 commit comments

Comments
 (0)