aboutsummaryrefslogtreecommitdiffstats
path: root/commit-graph.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2025-09-04 14:49:58 +0200
committerJunio C Hamano <gitster@pobox.com>2025-09-04 16:16:22 -0700
commit88bc3500e5be888c13757d12c4a5cb16e39ec673 (patch)
tree90fb8694bf1b3f2cf01d100ea8a129870be12b07 /commit-graph.c
parentcommit-graph: return the prepared commit graph from `prepare_commit_graph()` (diff)
downloadgit-88bc3500e5be888c13757d12c4a5cb16e39ec673.tar.gz
git-88bc3500e5be888c13757d12c4a5cb16e39ec673.zip
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>
Diffstat (limited to 'commit-graph.c')
-rw-r--r--commit-graph.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/commit-graph.c b/commit-graph.c
index 62260a2026..16dfe58229 100644
--- a/commit-graph.c
+++ b/commit-graph.c
@@ -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,
- uint32_t *pos)
+struct commit_graph *repo_find_commit_pos_in_graph(struct repository *r,
+ struct commit *c,
+ uint32_t *pos)
{
struct commit_graph *g = prepare_commit_graph(r);
if (!g)
- return 0;
- return find_commit_pos_in_graph(c, g, pos);
+ return NULL;
+ 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)
@@ -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)
{
+ struct commit_graph *g;
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,