commit-graph: return commit graph from `repo_find_commit_pos_in_graph()`
The function `repo_find_commit_pos_in_graph()` takes a commit as input and tries to figure out whether the given repository has a commit graph that contains that specific commit. If so, it returns the corresponding position of that commit inside the graph. Right now though we only return the position, but not the actual graph that the commit has been found in. This is sensible as repositories always have the graph in `struct repository::objects::commit_graph`. Consequently, the caller always knows where to find it. But in a subsequent change we're going to move the graph into the object sources. This would require callers of the function to loop through all sources to find the relevant commit graph. Refactor the code so that we instead return the commit-graph that the commit has been found with. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>seen
parent
199d452758
commit
88bc3500e5
8
bloom.c
8
bloom.c
|
@ -452,10 +452,12 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
|
||||||
filter = bloom_filter_slab_at(&bloom_filters, c);
|
filter = bloom_filter_slab_at(&bloom_filters, c);
|
||||||
|
|
||||||
if (!filter->data) {
|
if (!filter->data) {
|
||||||
|
struct commit_graph *g;
|
||||||
uint32_t graph_pos;
|
uint32_t graph_pos;
|
||||||
if (repo_find_commit_pos_in_graph(r, c, &graph_pos))
|
|
||||||
load_bloom_filter_from_graph(r->objects->commit_graph,
|
g = repo_find_commit_pos_in_graph(r, c, &graph_pos);
|
||||||
filter, graph_pos);
|
if (g)
|
||||||
|
load_bloom_filter_from_graph(g, filter, graph_pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filter->data && filter->len) {
|
if (filter->data && filter->len) {
|
||||||
|
|
|
@ -1003,13 +1003,16 @@ static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int repo_find_commit_pos_in_graph(struct repository *r, struct commit *c,
|
struct commit_graph *repo_find_commit_pos_in_graph(struct repository *r,
|
||||||
uint32_t *pos)
|
struct commit *c,
|
||||||
|
uint32_t *pos)
|
||||||
{
|
{
|
||||||
struct commit_graph *g = prepare_commit_graph(r);
|
struct commit_graph *g = prepare_commit_graph(r);
|
||||||
if (!g)
|
if (!g)
|
||||||
return 0;
|
return NULL;
|
||||||
return find_commit_pos_in_graph(c, g, pos);
|
if (!find_commit_pos_in_graph(c, g, pos))
|
||||||
|
return NULL;
|
||||||
|
return g;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct commit *lookup_commit_in_graph(struct repository *repo, const struct object_id *id)
|
struct commit *lookup_commit_in_graph(struct repository *repo, const struct object_id *id)
|
||||||
|
@ -1075,9 +1078,12 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
|
||||||
|
|
||||||
void load_commit_graph_info(struct repository *r, struct commit *item)
|
void load_commit_graph_info(struct repository *r, struct commit *item)
|
||||||
{
|
{
|
||||||
|
struct commit_graph *g;
|
||||||
uint32_t pos;
|
uint32_t pos;
|
||||||
if (repo_find_commit_pos_in_graph(r, item, &pos))
|
|
||||||
fill_commit_graph_info(item, r->objects->commit_graph, pos);
|
g = repo_find_commit_pos_in_graph(r, item, &pos);
|
||||||
|
if (g)
|
||||||
|
fill_commit_graph_info(item, g, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
static struct tree *load_tree_for_commit(struct commit_graph *g,
|
static struct tree *load_tree_for_commit(struct commit_graph *g,
|
||||||
|
|
|
@ -48,10 +48,9 @@ int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st,
|
||||||
int parse_commit_in_graph(struct repository *r, struct commit *item);
|
int parse_commit_in_graph(struct repository *r, struct commit *item);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Fills `*pos` with the graph position of `c`, and returns 1 if `c` is
|
* Fills `*pos` with the graph position of `c`, and returns the graph `c` is
|
||||||
* found in the commit-graph belonging to `r`, or 0 otherwise.
|
* found in, or NULL otherwise. Initializes the commit-graphs belonging to
|
||||||
* Initializes the commit-graph belonging to `r` if it hasn't been
|
* `r` if it hasn't been already.
|
||||||
* already.
|
|
||||||
*
|
*
|
||||||
* Note: this is a low-level helper that does not alter any slab data
|
* Note: this is a low-level helper that does not alter any slab data
|
||||||
* associated with `c`. Useful in circumstances where the slab data is
|
* associated with `c`. Useful in circumstances where the slab data is
|
||||||
|
@ -59,8 +58,9 @@ int parse_commit_in_graph(struct repository *r, struct commit *item);
|
||||||
*
|
*
|
||||||
* In most cases, callers should use `parse_commit_in_graph()` instead.
|
* In most cases, callers should use `parse_commit_in_graph()` instead.
|
||||||
*/
|
*/
|
||||||
int repo_find_commit_pos_in_graph(struct repository *r, struct commit *c,
|
struct commit_graph *repo_find_commit_pos_in_graph(struct repository *r,
|
||||||
uint32_t *pos);
|
struct commit *c,
|
||||||
|
uint32_t *pos);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Look up the given commit ID in the commit-graph. This will only return a
|
* Look up the given commit ID in the commit-graph. This will only return a
|
||||||
|
|
Loading…
Reference in New Issue