From 1b65c850a5a898d15bd52e2d9d5b53d14fb56fda Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Mon, 31 Aug 2026 12:02:11 +0200 Subject: [PATCH] builtin/clone: write alternates via `odb_create_on_disk()` When creating a repository with alternates we first initialize the object database and then write alternates to it in a separate step. This is unfortunate due to a couple of reasons: - It requires us to have a `write_alternates()` callback, which is unfortunate as we never even write alternates to an object database after it has been created. - We're about to make alternates an implementation detail of the object database's backend in a future patch series, so having this callback is suboptimal there. - The backend has more flexibility with how exactly alternates are configured when it itself is in full control over their setup at the time where it creates the object database itself. We have thus introduced the ability to write alternates right at creation time in the preceding commits, and we have unified setup of alternates into a single location. All that's left to do for us now is to wire up alternates as an option for the database creation. Do so. Signed-off-by: Patrick Steinhardt Signed-off-by: Junio C Hamano --- builtin/clone.c | 5 +---- setup.c | 9 ++++++--- setup.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/builtin/clone.c b/builtin/clone.c index 2e3473fddf..48ac379b1d 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -1368,11 +1368,8 @@ int cmd_clone(int argc, if (option_local > 0 && !is_local) warning(_("--local is ignored")); - create_object_database(the_repository); collect_alternates(&alternates, path, is_local); - - for (size_t i = 0; i < alternates.nr; i++) - odb_add_to_alternates_file(the_repository->objects, alternates.v[i]); + create_object_database(the_repository, &alternates); transport = transport_get(remote, path ? path : remote->url.v[0]); transport_set_verbosity(transport, option_verbosity, option_progress); diff --git a/setup.c b/setup.c index 426cc7dff8..cfa286ff59 100644 --- a/setup.c +++ b/setup.c @@ -2647,9 +2647,12 @@ static int create_default_files(struct repository *repo, return reinit; } -void create_object_database(struct repository *repo) +void create_object_database(struct repository *repo, + const struct strvec *alternates) { - struct odb_create_on_disk_options opts = { 0 }; + struct odb_create_on_disk_options opts = { + .alternates = alternates, + }; /* * Create the "objects" directory in the common directory. This is done @@ -2907,7 +2910,7 @@ int init_db(struct repository *repo, if (!(flags & INIT_DB_SKIP_REFDB)) create_reference_database(repo, initial_branch, flags & INIT_DB_QUIET); if (!(flags & INIT_DB_SKIP_ODB)) - create_object_database(repo); + create_object_database(repo, NULL); startup_info->have_repository = 1; diff --git a/setup.h b/setup.h index 570ebcd150..34e86dad37 100644 --- a/setup.h +++ b/setup.h @@ -277,7 +277,7 @@ void initialize_repository_version(struct repository *repo, enum ref_storage_format ref_storage_format, int reinit); void create_reference_database(struct repository *repo, const char *initial_branch, int quiet); -void create_object_database(struct repository *repo); +void create_object_database(struct repository *repo, const struct strvec *alternates); /* * NOTE NOTE NOTE!!