Message ID | f31994ac78aa7aff11d923a77be6b0652f3af70d.1678111599.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | ahead-behind: new builtin for counting multiple commit ranges | expand |
"Taylor Blau via GitGitGadget" <gitgitgadget@gmail.com> writes: > From: Taylor Blau <me@ttaylorr.com> > > 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. Interesting and nice to see it done with so small a change thanks to the previous refactoring. > > Co-authored-by: Derrick Stolee <derrickstolee@github.com> > Signed-off-by: Taylor Blau <me@ttaylorr.com> > Signed-off-by: Derrick Stolee <derrickstolee@github.com> > --- > commit-graph.c | 29 +++++++++++++++++++++++++++++ > commit-graph.h | 7 +++++++ > 2 files changed, 36 insertions(+) > > diff --git a/commit-graph.c b/commit-graph.c > index f04b02be1bb..a573d1b89ff 100644 > --- a/commit-graph.c > +++ b/commit-graph.c > @@ -1610,6 +1610,35 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx) > stop_progress(&ctx->progress); > } > > +static void set_generation_in_graph_data(struct commit *c, timestamp_t t, > + void *data) > +{ > + commit_graph_data_at(c)->generation = t; > +} > + > +/* > + * After this method, all commits reachable from those in the given > + * list will have non-zero, non-infinite generation numbers. > + */ > +void ensure_generations_valid(struct commit **commits, size_t nr) > +{ > + struct repository *r = the_repository; > + int generation_version = get_configured_generation_version(r); > + struct packed_commit_list list = { > + .list = commits, > + .alloc = nr, > + .nr = nr, > + }; > + struct compute_generation_info info = { > + .r = r, > + .commits = &list, > + .get_generation = get_generation_from_graph_data, > + .set_generation = set_generation_in_graph_data, > + }; > + > + compute_reachable_generation_numbers_1(&info, generation_version); > +} > + > static void trace2_bloom_filter_write_statistics(struct write_commit_graph_context *ctx) > { > trace2_data_intmax("commit-graph", ctx->r, "filter-computed", > diff --git a/commit-graph.h b/commit-graph.h > index 37faee6b66d..a529c62b518 100644 > --- a/commit-graph.h > +++ b/commit-graph.h > @@ -190,4 +190,11 @@ struct commit_graph_data { > */ > timestamp_t commit_graph_generation(const struct commit *); > uint32_t commit_graph_position(const struct commit *); > + > +/* > + * After this method, all commits reachable from those in the given > + * list will have non-zero, non-infinite generation numbers. > + */ > +void ensure_generations_valid(struct commit **commits, size_t nr); > + > #endif
On Mon, Mar 06, 2023 at 10:52:20AM -0800, Junio C Hamano wrote: > "Taylor Blau via GitGitGadget" <gitgitgadget@gmail.com> writes: > > > From: Taylor Blau <me@ttaylorr.com> > > > > 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. > > Interesting and nice to see it done with so small a change thanks to > the previous refactoring. Stolee did all of the hard work ;-). But chiming in to say that I remember all of these changes well and they look faithful to my original read of them (as well as what I wrote in this patch). So, LGTM so far. Thanks, Taylor
diff --git a/commit-graph.c b/commit-graph.c index f04b02be1bb..a573d1b89ff 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -1610,6 +1610,35 @@ static void compute_generation_numbers(struct write_commit_graph_context *ctx) stop_progress(&ctx->progress); } +static void set_generation_in_graph_data(struct commit *c, timestamp_t t, + void *data) +{ + commit_graph_data_at(c)->generation = t; +} + +/* + * After this method, all commits reachable from those in the given + * list will have non-zero, non-infinite generation numbers. + */ +void ensure_generations_valid(struct commit **commits, size_t nr) +{ + struct repository *r = the_repository; + int generation_version = get_configured_generation_version(r); + struct packed_commit_list list = { + .list = commits, + .alloc = nr, + .nr = nr, + }; + struct compute_generation_info info = { + .r = r, + .commits = &list, + .get_generation = get_generation_from_graph_data, + .set_generation = set_generation_in_graph_data, + }; + + compute_reachable_generation_numbers_1(&info, generation_version); +} + static void trace2_bloom_filter_write_statistics(struct write_commit_graph_context *ctx) { trace2_data_intmax("commit-graph", ctx->r, "filter-computed", diff --git a/commit-graph.h b/commit-graph.h index 37faee6b66d..a529c62b518 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -190,4 +190,11 @@ struct commit_graph_data { */ timestamp_t commit_graph_generation(const struct commit *); uint32_t commit_graph_position(const struct commit *); + +/* + * After this method, all commits reachable from those in the given + * list will have non-zero, non-infinite generation numbers. + */ +void ensure_generations_valid(struct commit **commits, size_t nr); + #endif