From: Patrick Steinhardt Date: Mon, 07 Sep 2026 08:25:37 GMT Subject: [PATCH v3 0/9] odb: write alternates at creation time Message-ID: <20260907-pks-odb-write-alternates-at-creation-time-v3-0-735d0b5b3e00@pks.im> In-Reply-To: <20260825-pks-odb-write-alternates-at-creation-time-v1-0-911513ba95c3@pks.im> Hi, writing alternates into the object database currently happens via `odb_source_write_alternate()`. But while that creates the ability to create alternates at arbitrary points of a source's lifetime, we don't use that functionality in the first place. Instead, we only ever write alternates when creating a new repository. This design is suboptimal due to a couple of reasons: - It requires us to have a `write_alternates()` callback, which is overblown 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 alternate implementations may not even support them. - 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. This patch series thus refactors how we handle alternates so that we don't write them ad-hoc anymore. Instead, the series introduces a new option for `odb_source_create_on_disk()` that makes it handle those alternates at creation time. This is part of the bigger goal of moving handling of alternates into the "files" backend. This series is built on top of 2c3adbb2c4 (The 18th batch, 2026-08-24) with ps/odb-eagerly-load-alternates at 0076dc9f81 (odb: drop `alternates_db` field, 2026-08-17) merged into it. Changes in v3: - Refactor `init_db()` to not create the reference and object database at all anymore. Instead, it's now called `create_repository()` and it is responsible for creating the initial repository skeleton, only. This allows us to get rid of the flags and overall makes the logic more straight-forward by moving the command-specific logic into the respective commands. - A couple of typo fixes. - Link to v2: https://patch.msgid.link/20260831-pks-odb-write-alternates-at-creation-time-v2-0-aecd2382ba1c@pks.im Changes in v2: - Use a lockfile to write "info/alternates" during creation time. - Remove useless "strvec.h" include by reordering declarations a bit. - Link to v1: https://patch.msgid.link/20260825-pks-odb-write-alternates-at-creation-time-v1-0-911513ba95c3@pks.im Thanks! Patrick --- Patrick Steinhardt (9): setup: split up concerns of `init_db()` builtin/clone: defer setup of the object database builtin/clone: move around `setup_reference()` builtin/clone: refactor handling of "--reference{,-if-able}" builtin/clone: move setup of alternates for shared local clones builtin/clone: move setup of alternates for non-shared local clones odb/source: support writing alternates when creating the database builtin/clone: write alternates via `odb_create_on_disk()` odb/source: remove the ability to write alternates builtin/clone.c | 111 +++++++++++++++++++++++--------------- builtin/init-db.c | 32 ++++++++--- odb.c | 9 ---- odb.h | 7 --- odb/source-files.c | 130 ++++++++++++++++++++++++++------------------- odb/source-inmemory.c | 7 --- odb/source-loose.c | 7 --- odb/source-packed.c | 7 --- odb/source.h | 43 +++++---------- setup.c | 61 ++++++++------------- setup.h | 22 ++++---- t/t5604-clone-reference.sh | 25 +++++++++ 12 files changed, 239 insertions(+), 222 deletions(-) Range-diff versus v2: 1: 1a1580185a < -: ---------- builtin/clone: defer setup of the object database -: ---------- > 1: 512e7d1ef2 setup: split up concerns of `init_db()` -: ---------- > 2: a8808bcacf builtin/clone: defer setup of the object database 2: 7d0d4832ed = 3: 0193fb3ada builtin/clone: move around `setup_reference()` 3: d547e62b5b ! 4: 3c53ad13f2 builtin/clone: refactor handling of "--reference{,-if-able}" @@ Commit message In subsequent commits we're about to consolidate the complete setup of alternates into this function, and furthermore we'll refactor the setup of the object database to handle doing this for us instead of writing - the alterantes into it one by one. + the alternates into it one by one. Prepare for this refactoring by collecting the alternates into a strvec. Rename the function to `collect_alternates()` to clarify its scope. 4: ceb90593c8 = 5: 4fbcab0026 builtin/clone: move setup of alternates for shared local clones 5: d9587585f3 ! 6: b658ca0799 builtin/clone: move setup of alternates for non-shared local clones @@ Commit message purpose. Add two tests, the first one of which exercises this bug to avoid future - regressions. The second patch ensures that we properly handle relative + regressions. The second test ensures that we properly handle relative alternates for a referenced worktree. Signed-off-by: Patrick Steinhardt 6: 7575379b17 = 7: bec8115803 odb/source: support writing alternates when creating the database 7: c07fd20d85 ! 8: 3deaa7ef64 builtin/clone: write alternates via `odb_create_on_disk()` @@ builtin/clone.c: int cmd_clone(int argc, transport = transport_get(remote, path ? path : remote->url.v[0]); transport_set_verbosity(transport, option_verbosity, option_progress); + ## builtin/init-db.c ## +@@ builtin/init-db.c: int cmd_init_db(int argc, + template_dir, hash_algo, ref_storage_format, + init_shared_repository, &reinit); + create_reference_database(the_repository, initial_branch, quiet); +- create_object_database(the_repository); ++ create_object_database(the_repository, NULL); + + if (!quiet) { + int len = strlen(git_dir); + ## setup.c ## @@ setup.c: static int create_default_files(struct repository *repo, return reinit; @@ setup.c: static int create_default_files(struct repository *repo, /* * Create the "objects" directory in the common directory. This is done -@@ setup.c: 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; - ## setup.h ## @@ setup.h: void initialize_repository_version(struct repository *repo, 8: a8b9f51897 = 9: d751b886b3 odb/source: remove the ability to write alternates --- base-commit: afa255aeb620346d56a2c01fb5ae9163513c56d7 change-id: 20260813-pks-odb-write-alternates-at-creation-time-64010deb94a0