Skip to content

Commit 7805360

Browse files
ttaylorrgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2dd804c commit 7805360

File tree

2 files changed

+24
-3
lines changed

2 files changed

+24
-3
lines changed

commit-graph.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -898,6 +898,14 @@ static int find_commit_pos_in_graph(struct commit *item, struct commit_graph *g,
898898
}
899899
}
900900

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+
901909
struct commit *lookup_commit_in_graph(struct repository *repo, const struct object_id *id)
902910
{
903911
struct commit *commit;
@@ -955,9 +963,7 @@ int parse_commit_in_graph(struct repository *r, struct commit *item)
955963
void load_commit_graph_info(struct repository *r, struct commit *item)
956964
{
957965
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))
961967
fill_commit_graph_info(item, r->objects->commit_graph, pos);
962968
}
963969

commit-graph.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,21 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st);
4040
*/
4141
int parse_commit_in_graph(struct repository *r, struct commit *item);
4242

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+
4358
/*
4459
* Look up the given commit ID in the commit-graph. This will only return a
4560
* commit if the ID exists both in the graph and in the object database such

0 commit comments

Comments
 (0)