]> git.ipfire.org Git - thirdparty/git.git/commitdiff
commit-graph: return commit graph from `repo_find_commit_pos_in_graph()`
authorPatrick Steinhardt <ps@pks.im>
Thu, 4 Sep 2025 12:49:58 +0000 (14:49 +0200)
committerJunio C Hamano <gitster@pobox.com>
Thu, 4 Sep 2025 23:16:22 +0000 (16:16 -0700)
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>
bloom.c
commit-graph.c
commit-graph.h

diff --git a/bloom.c b/bloom.c
index b86015f6d1babbe7473ce571ab1c109c240d5ff5..2d7b951e5bf24592e5f0c830ef04b7786768f359 100644 (file)
--- a/bloom.c
+++ b/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);
 
        if (!filter->data) {
+               struct commit_graph *g;
                uint32_t graph_pos;
-               if (repo_find_commit_pos_in_graph(r, c, &graph_pos))
-                       load_bloom_filter_from_graph(r->objects->commit_graph,
-                                                    filter, graph_pos);
+
+               g = repo_find_commit_pos_in_graph(r, c, &graph_pos);
+               if (g)
+                       load_bloom_filter_from_graph(g, filter, graph_pos);
        }
 
        if (filter->data && filter->len) {
index 62260a2026d839c5f8d8ad7bbdf3e7dd42dca592..16dfe582295073d16b7823df5c6691f5718b640b 100644 (file)
@@ -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,
index 4899b54ef8820721922f2807054deb529e31da56..f6a543364154538f6777f5374604ab82c99ab9d9 100644 (file)
@@ -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);
 
 /*
- * Fills `*pos` with the graph position of `c`, and returns 1 if `c` is
- * found in the commit-graph belonging to `r`, or 0 otherwise.
- * Initializes the commit-graph belonging to `r` if it hasn't been
- * already.
+ * Fills `*pos` with the graph position of `c`, and returns the graph `c` is
+ * found in, or NULL otherwise. Initializes the commit-graphs belonging to
+ * `r` if it hasn't been already.
  *
  * 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
@@ -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.
  */
-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);
 
 /*
  * Look up the given commit ID in the commit-graph. This will only return a