odb: get rid of the_repository when handling alternates

The functions to manage alternates all depend on `the_repository`.
Refactor them to accept an object database as a parameter and adjust all
callers. The functions are renamed accordingly.

Note that right now the situation is still somewhat weird because we end
up using the object store path provided by the object store's repository
anyway. Consequently, we could have instead passed in a pointer to the
repository instead of passing in the pointer to the object store. This
will be addressed in subsequent commits though, where we will start to
use the path owned by the object store itself.

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-07-01 14:22:20 +02:00
committed by Junio C Hamano
parent 1b1679c688
commit c44185f6c1
14 changed files with 83 additions and 64 deletions

53
odb.h
View File

@@ -13,6 +13,14 @@ struct oidtree;
struct strbuf;
struct repository;
/*
* Compute the exact path an alternate is at and returns it. In case of
* error NULL is returned and the human readable error is added to `err`
* `path` may be relative and should point to $GIT_DIR.
* `err` must not be null.
*/
char *compute_alternate_path(const char *path, struct strbuf *err);
/*
* The source is the part of the object database that stores the actual
* objects. It thus encapsulates the logic to read and write the specific
@@ -65,27 +73,11 @@ struct odb_source {
char *path;
};
void prepare_alt_odb(struct repository *r);
int has_alt_odb(struct repository *r);
char *compute_alternate_path(const char *path, struct strbuf *err);
typedef int alt_odb_fn(struct odb_source *, void *);
int foreach_alt_odb(alt_odb_fn, void*);
typedef void alternate_ref_fn(const struct object_id *oid, void *);
void for_each_alternate_ref(alternate_ref_fn, void *);
/*
* Add the directory to the on-disk alternates file; the new entry will also
* take effect in the current process.
*/
void add_to_alternates_file(const char *dir);
/*
* Add the directory to the in-memory list of alternates (along with any
* recursive alternates it points to), but do not modify the on-disk alternates
* file.
*/
void add_to_alternates_memory(const char *dir);
/*
* Replace the current writable object directory with the specified temporary
* object directory; returns the former primary object directory.
@@ -124,7 +116,7 @@ struct object_database {
/*
* A list of alternate object directories loaded from the environment;
* this should not generally need to be accessed directly, but will
* populate the "sources" list when prepare_alt_odb() is run.
* populate the "sources" list when odb_prepare_alternates() is run.
*/
char *alternate_db;
@@ -209,6 +201,33 @@ struct odb_source *odb_find_source(struct object_database *odb, const char *obj_
int odb_mkstemp(struct object_database *odb,
struct strbuf *temp_filename, const char *pattern);
/*
* Prepare alternate object sources for the given database by reading
* "objects/info/alternates" and opening the respective sources.
*/
void odb_prepare_alternates(struct object_database *odb);
/*
* Check whether the object database has any alternates. The primary object
* source does not count as alternate.
*/
int odb_has_alternates(struct object_database *odb);
/*
* Add the directory to the on-disk alternates file; the new entry will also
* take effect in the current process.
*/
void odb_add_to_alternates_file(struct object_database *odb,
const char *dir);
/*
* Add the directory to the in-memory list of alternate sources (along with any
* recursive alternates it points to), but do not modify the on-disk alternates
* file.
*/
void odb_add_to_alternates_memory(struct object_database *odb,
const char *dir);
void *repo_read_object_file(struct repository *r,
const struct object_id *oid,
enum object_type *type,