Skip to content

Commit 88bc350

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 199d452 commit 88bc350

File tree

3 files changed

+23
-15
lines changed

3 files changed

+23
-15
lines changed

bloom.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -452,10 +452,12 @@ struct bloom_filter *get_or_compute_bloom_filter(struct repository *r,
452452
filter = bloom_filter_slab_at(&bloom_filters, c);
453453

454454
if (!filter->data) {
455+
struct commit_graph *g;
455456
uint32_t graph_pos;
456-
if (repo_find_commit_pos_in_graph(r, c, &graph_pos))
457-
load_bloom_filter_from_graph(r->objects->commit_graph,
458-
filter, graph_pos);
457+
458+
g = repo_find_commit_pos_in_graph(r, c, &graph_pos);
459+
if (g)
460+
load_bloom_filter_from_graph(g, filter, graph_pos);
459461
}
460462

461463
if (filter->data && filter->len) {

commit-graph.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1003,13 +1003,16 @@ static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g,
10031003
}
10041004
}
10051005

1006-
int repo_find_commit_pos_in_graph(struct repository *r, struct commit *c,
1007-
uint32_t *pos)
1006+
struct commit_graph *repo_find_commit_pos_in_graph(struct repository *r,
1007+
struct commit *c,
1008+
uint32_t *pos)
10081009
{
10091010
struct commit_graph *g = prepare_commit_graph(r);
10101011
if (!g)
1011-
return 0;
1012-
return find_commit_pos_in_graph(c, g, pos);
1012+
return NULL;
1013+
if (!find_commit_pos_in_graph(c, g, pos))
1014+
return NULL;
1015+
return g;
10131016
}
10141017

10151018
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)
10751078

10761079
void load_commit_graph_info(struct repository *r, struct commit *item)
10771080
{
1081+
struct commit_graph *g;
10781082
uint32_t pos;
1079-
if (repo_find_commit_pos_in_graph(r, item, &pos))
1080-
fill_commit_graph_info(item, r->objects->commit_graph, pos);
1083+
1084+
g = repo_find_commit_pos_in_graph(r, item, &pos);
1085+
if (g)
1086+
fill_commit_graph_info(item, g, pos);
10811087
}
10821088

10831089
static struct tree *load_tree_for_commit(struct commit_graph *g,

commit-graph.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,19 @@ int open_commit_graph_chain(const char *chain_file, int *fd, struct stat *st,
4848
int parse_commit_in_graph(struct repository *r, struct commit *item);
4949

5050
/*
51-
* Fills `*pos` with the graph position of `c`, and returns 1 if `c` is
52-
* found in the commit-graph belonging to `r`, or 0 otherwise.
53-
* Initializes the commit-graph belonging to `r` if it hasn't been
54-
* already.
51+
* Fills `*pos` with the graph position of `c`, and returns the graph `c` is
52+
* found in, or NULL otherwise. Initializes the commit-graphs belonging to
53+
* `r` if it hasn't been already.
5554
*
5655
* Note: this is a low-level helper that does not alter any slab data
5756
* associated with `c`. Useful in circumstances where the slab data is
5857
* already being modified (e.g., writing the commit-graph itself).
5958
*
6059
* In most cases, callers should use `parse_commit_in_graph()` instead.
6160
*/
62-
int repo_find_commit_pos_in_graph(struct repository *r, struct commit *c,
63-
uint32_t *pos);
61+
struct commit_graph *repo_find_commit_pos_in_graph(struct repository *r,
62+
struct commit *c,
63+
uint32_t *pos);
6464

6565
/*
6666
* Look up the given commit ID in the commit-graph. This will only return a

0 commit comments

Comments
 (0)