Skip to content

Commit c08645b

Browse files
ttaylorrderrickstolee
authored andcommitted
commit-graph: introduce ensure_generations_valid()
Use the just-introduced compute_reachable_generation_numbers_1() to implement a function which dynamically computes topological levels (or corrected commit dates) for out-of-graph commits. This will be useful for the ahead-behind algorithm we are about to introduce, which needs accurate topological levels on _all_ commits reachable from the tips in order to avoid over-counting. Co-authored-by: Derrick Stolee <[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 2ee11f7 commit c08645b

File tree

2 files changed

+37
-0
lines changed

2 files changed

+37
-0
lines changed

commit-graph.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,35 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx)
16041604
stop_progress(&ctx->progress);
16051605
}
16061606

1607+
static void set_generation_in_graph_data(struct commit *c, timestamp_t t,
1608+
void *data)
1609+
{
1610+
commit_graph_data_at(c)->generation = t;
1611+
}
1612+
1613+
/*
1614+
* After this method, all commits reachable from those in the given
1615+
* list will have non-zero, non-infinite generation numbers.
1616+
*/
1617+
void ensure_generations_valid(struct repository *r,
1618+
struct commit **commits, size_t nr)
1619+
{
1620+
int generation_version = get_configured_generation_version(r);
1621+
struct packed_commit_list list = {
1622+
.list = commits,
1623+
.alloc = nr,
1624+
.nr = nr,
1625+
};
1626+
struct compute_generation_info info = {
1627+
.r = r,
1628+
.commits = &list,
1629+
.get_generation = get_generation_from_graph_data,
1630+
.set_generation = set_generation_in_graph_data,
1631+
};
1632+
1633+
compute_reachable_generation_numbers(&info, generation_version);
1634+
}
1635+
16071636
static void trace2_bloom_filter_write_statistics(struct write_commit_graph_context *ctx)
16081637
{
16091638
trace2_data_intmax("commit-graph", ctx->r, "filter-computed",

commit-graph.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,12 @@ struct commit_graph_data {
190190
*/
191191
timestamp_t commit_graph_generation(const struct commit *);
192192
uint32_t commit_graph_position(const struct commit *);
193+
194+
/*
195+
* After this method, all commits reachable from those in the given
196+
* list will have non-zero, non-infinite generation numbers.
197+
*/
198+
void ensure_generations_valid(struct repository *r,
199+
struct commit **commits, size_t nr);
200+
193201
#endif

0 commit comments

Comments
 (0)