commit-graph: introduce `repo_find_commit_pos_in_graph()`
Low-level callers in systems that are adjacent to the commit-graph (like the changed-path Bloom filter code) could benefit from being able to call a function like `parse_commit_in_graph()` without modifying the corresponding commit slab data. This is useful in contexts where that slab data is being used to prepare for an upcoming commit-graph write, where Git must be careful to avoid clobbering any of that data during a read operation. Introduce a low-level variant of `parse_commit_in_graph()` which returns the graph position of a given commit only, without modifying any of the slab data. Signed-off-by: Taylor Blau <me@ttaylorr.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Taylor Blau committed
Jul 12, 2022 at 19:10 UTC
7805360b7a3be02057385bc9d17aa493120b9538
2 files changed
+24
-3
commit-graph.c
+9
-3
@@ -898,6 +898,14 @@ static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g,
898
}
899
}
900
901
+int repo_find_commit_pos_in_graph(struct repository *r, struct commit *c,
902
+ uint32_t *pos)
903
+{
904
+ if (!prepare_commit_graph(r))
905
+ return 0;
906
+ return find_commit_pos_in_graph(c, r->objects->commit_graph, pos);
907
+}
908
+
909
struct commit *lookup_commit_in_graph(struct repository *repo, const struct object_id *id)
910
{
911
struct commit *commit;
@@ -955,9 +963,7 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
963
void load_commit_graph_info(struct repository *r, struct commit *item)
964
{
965
uint32_t pos;
958
- if (!prepare_commit_graph(r))
959
- return;
960
- if (find_commit_pos_in_graph(item, r->objects->commit_graph, &pos))
966
+ if (repo_find_commit_pos_in_graph(r, item, &pos))
967
fill_commit_graph_info(item, r->objects->commit_graph, pos);
968
}
969
commit-graph.h
+15
@@ -40,6 +40,21 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
40
*/
41
int parse_commit_in_graph(struct repository *r, struct commit *item);
42
43
+/*
44
+ * Fills `*pos` with the graph position of `c`, and returns 1 if `c` is
45
+ * found in the commit-graph belonging to `r`, or 0 otherwise.
46
+ * Initializes the commit-graph belonging to `r` if it hasn't been
47
+ * already.
48
+ *
49
+ * Note: this is a low-level helper that does not alter any slab data
50
+ * associated with `c`. Useful in circumstances where the slab data is
51
+ * already being modified (e.g., writing the commit-graph itself).
52
+ *
53
+ * In most cases, callers should use `parse_commit_in_graph()` instead.
54
+ */
55
+int repo_find_commit_pos_in_graph(struct repository *r, struct commit *c,
56
+ uint32_t *pos);
57
+
58
/*
59
* Look up the given commit ID in the commit-graph. This will only return a
60
* commit if the ID exists both in the graph and in the object database such