Skip to content

Commit 80c928d

Browse files
derrickstoleettaylorr
authored andcommitted
commit-graph: simplify compute_generation_numbers()
The previous change introduced the generic algorithm compute_reachable_generation_numbers() and used it as the core functionality of compute_topological_levels(). Now, use it as the core functionality of compute_generation_numbers(). The main difference here is that we use generation version 2, which is used in to toggle the logic in compute_generation_from_max() for computing the corrected commit date based on the corrected commit dates of the parent commits (and the commit date of the current commit). It also uses different methods for (get|set)_generation in the vtable in order to store and access the value in the correct places. Co-authored-by: Taylor Blau <[email protected]> Signed-off-by: Taylor Blau <[email protected]> Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 368d19b commit 80c928d

File tree

1 file changed

+21
-43
lines changed

1 file changed

+21
-43
lines changed

commit-graph.c

Lines changed: 21 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,13 +1559,31 @@ static void compute_topological_levels(struct write_commit_graph_context *ctx)
15591559
stop_progress(&ctx->progress);
15601560
}
15611561

1562+
static timestamp_t get_generation_from_graph_data(struct commit *c, void *data)
1563+
{
1564+
return commit_graph_data_at(c)->generation;
1565+
}
1566+
1567+
static void set_generation_v2(struct commit *c, timestamp_t t, void *data)
1568+
{
1569+
struct commit_graph_data *g = commit_graph_data_at(c);
1570+
g->generation = (uint32_t)t;
1571+
}
1572+
15621573
static void compute_generation_numbers(struct write_commit_graph_context *ctx)
15631574
{
15641575
int i;
1565-
struct commit_list *list = NULL;
1576+
struct compute_generation_info info = {
1577+
.r = ctx->r,
1578+
.commits = &ctx->commits,
1579+
.get_generation = get_generation_from_graph_data,
1580+
.set_generation = set_generation_v2,
1581+
.data = ctx,
1582+
};
15661583

15671584
if (ctx->report_progress)
1568-
ctx->progress = start_delayed_progress(
1585+
info.progress = ctx->progress
1586+
= start_delayed_progress(
15691587
_("Computing commit graph generation numbers"),
15701588
ctx->commits.nr);
15711589

@@ -1577,47 +1595,7 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
15771595
}
15781596
}
15791597

1580-
for (i = 0; i < ctx->commits.nr; i++) {
1581-
struct commit *c = ctx->commits.list[i];
1582-
timestamp_t corrected_commit_date;
1583-
1584-
repo_parse_commit(ctx->r, c);
1585-
corrected_commit_date = commit_graph_data_at(c)->generation;
1586-
1587-
display_progress(ctx->progress, i + 1);
1588-
if (corrected_commit_date != GENERATION_NUMBER_ZERO)
1589-
continue;
1590-
1591-
commit_list_insert(c, &list);
1592-
while (list) {
1593-
struct commit *current = list->item;
1594-
struct commit_list *parent;
1595-
int all_parents_computed = 1;
1596-
timestamp_t max_corrected_commit_date = 0;
1597-
1598-
for (parent = current->parents; parent; parent = parent->next) {
1599-
repo_parse_commit(ctx->r, parent->item);
1600-
corrected_commit_date = commit_graph_data_at(parent->item)->generation;
1601-
1602-
if (corrected_commit_date == GENERATION_NUMBER_ZERO) {
1603-
all_parents_computed = 0;
1604-
commit_list_insert(parent->item, &list);
1605-
break;
1606-
}
1607-
1608-
if (corrected_commit_date > max_corrected_commit_date)
1609-
max_corrected_commit_date = corrected_commit_date;
1610-
}
1611-
1612-
if (all_parents_computed) {
1613-
pop_commit(&list);
1614-
1615-
if (current->date && current->date > max_corrected_commit_date)
1616-
max_corrected_commit_date = current->date - 1;
1617-
commit_graph_data_at(current)->generation = max_corrected_commit_date + 1;
1618-
}
1619-
}
1620-
}
1598+
compute_reachable_generation_numbers(&info, 2);
16211599

16221600
for (i = 0; i < ctx->commits.nr; i++) {
16231601
struct commit *c = ctx->commits.list[i];

0 commit comments

Comments
 (0)