commit-graph: stop passing in redundant repository

Many of the commit-graph related functions take in both a repository and
the object database source (directly or via `struct commit_graph`) for
which we are supposed to load such a commit-graph. In the best case this
information is simply redundant as the source already contains a
reference to its owning object database, which in turn has a reference
to its repository. In the worst case this information could even
mismatch when passing in a source that doesn't belong to the same
repository.

Refactor the code so that we only pass in the object database source in
those cases.

There is one exception though, namely `load_commit_graph_chain_fd_st()`,
which is responsible for loading a commit-graph chain. It is expected
that parts of the commit-graph chain aren't located in the same object
source as the chain file itself, but in a different one. Consequently,
this function doesn't work on the source level but on the database level
instead.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Patrick Steinhardt
2025-08-15 07:49:52 +02:00
committed by Junio C Hamano
parent ddacfc7466
commit 7be9e410b2
4 changed files with 59 additions and 81 deletions

View File

@@ -114,14 +114,12 @@ struct commit_graph {
struct bloom_filter_settings *bloom_filter_settings;
};
struct commit_graph *load_commit_graph_one_fd_st(struct repository *r,
int fd, struct stat *st,
struct odb_source *source);
struct commit_graph *load_commit_graph_chain_fd_st(struct repository *r,
struct commit_graph *load_commit_graph_one_fd_st(struct odb_source *source,
int fd, struct stat *st);
struct commit_graph *load_commit_graph_chain_fd_st(struct object_database *odb,
int fd, struct stat *st,
int *incomplete_chain);
struct commit_graph *read_commit_graph_one(struct repository *r,
struct odb_source *source);
struct commit_graph *read_commit_graph_one(struct odb_source *source);
struct repo_settings;
@@ -185,7 +183,7 @@ int write_commit_graph(struct odb_source *source,
#define COMMIT_GRAPH_VERIFY_SHALLOW (1 << 0)
int verify_commit_graph(struct repository *r, struct commit_graph *g, int flags);
int verify_commit_graph(struct commit_graph *g, int flags);
void close_commit_graph(struct object_database *);
void free_commit_graph(struct commit_graph *);