git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 7/8] builtin/clone: write alternates via `odb_create_on_disk()`

From
Patrick Steinhardt <ps@pks.im>
Date
Aug 25, 2026, 14:11 UTC
Message-ID
<20260825-pks-odb-write-alternates-at-creation-time-v1-7-911513ba95c3@pks.im>
In-Reply-To
<20260825-pks-odb-write-alternates-at-creation-time-v1-0-911513ba95c3@pks.im>

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 <ps@pks.im>
---
 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!!
-- 
2.55.0.822.g20453c30eb.dirty
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 8 of 85 in “odb: write alternates at creation time”
  1. 0/8 odb: write alternates at creation timePatrick Steinhardt, Aug 25, 2026
  2. 1/8 builtin/clone: defer setup of the object databasePatrick Steinhardt, Aug 25, 2026
  3. 2/8 builtin/clone: move around `setup_reference()`Patrick Steinhardt, Aug 25, 2026
  4. 3/8 builtin/clone: refactor handling of "--reference{,-if-able}"Patrick Steinhardt, Aug 25, 2026
  5. 4/8 builtin/clone: move setup of alternates for shared local clonesPatrick Steinhardt, Aug 25, 2026
  6. 5/8 builtin/clone: move setup of alternates for non-shared local clonesPatrick Steinhardt, Aug 25, 2026
  7. 6/8 odb/source: support writing alternates when creating the databasePatrick Steinhardt, Aug 25, 2026
  8. 7/8 builtin/clone: write alternates via `odb_create_on_disk()`Patrick Steinhardt, Aug 25, 2026
  9. 8/8 odb/source: remove the ability to write alternatesPatrick Steinhardt, Aug 25, 2026
  10. Toon ClaesAug 28, 2026
  11. Toon ClaesAug 28, 2026
  12. Toon ClaesAug 28, 2026
  13. Toon ClaesAug 28, 2026
  14. Toon ClaesAug 28, 2026
  15. Junio C HamanoAug 28, 2026
  16. Patrick SteinhardtAug 31, 2026
  17. Patrick SteinhardtAug 31, 2026
  18. Patrick SteinhardtAug 31, 2026
  19. Patrick SteinhardtAug 31, 2026
  20. 0/8 odb: write alternates at creation timePatrick Steinhardt, Aug 31, 2026
  21. 1/8 builtin/clone: defer setup of the object databasePatrick Steinhardt, Aug 31, 2026
  22. 2/8 builtin/clone: move around `setup_reference()`Patrick Steinhardt, Aug 31, 2026
  23. 3/8 builtin/clone: refactor handling of "--reference{,-if-able}"Patrick Steinhardt, Aug 31, 2026
  24. 4/8 builtin/clone: move setup of alternates for shared local clonesPatrick Steinhardt, Aug 31, 2026
  25. 5/8 builtin/clone: move setup of alternates for non-shared local clonesPatrick Steinhardt, Aug 31, 2026
  26. 6/8 odb/source: support writing alternates when creating the databasePatrick Steinhardt, Aug 31, 2026
  27. 7/8 builtin/clone: write alternates via `odb_create_on_disk()`Patrick Steinhardt, Aug 31, 2026
  28. 8/8 odb/source: remove the ability to write alternatesPatrick Steinhardt, Aug 31, 2026
  29. Toon ClaesSep 1, 2026
  30. Justin ToblerSep 6, 2026
  31. Justin ToblerSep 6, 2026
  32. Justin ToblerSep 6, 2026
  33. Patrick SteinhardtSep 7, 2026
  34. Patrick SteinhardtSep 7, 2026
  35. 0/9 odb: write alternates at creation timePatrick Steinhardt, Sep 7, 2026
  36. 1/9 setup: split up concerns of `init_db()`Patrick Steinhardt, Sep 7, 2026
  37. 2/9 builtin/clone: defer setup of the object databasePatrick Steinhardt, Sep 7, 2026
  38. 3/9 builtin/clone: move around `setup_reference()`Patrick Steinhardt, Sep 7, 2026
  39. 4/9 builtin/clone: refactor handling of "--reference{,-if-able}"Patrick Steinhardt, Sep 7, 2026
  40. 5/9 builtin/clone: move setup of alternates for shared local clonesPatrick Steinhardt, Sep 7, 2026
  41. 6/9 builtin/clone: move setup of alternates for non-shared local clonesPatrick Steinhardt, Sep 7, 2026
  42. 7/9 odb/source: support writing alternates when creating the databasePatrick Steinhardt, Sep 7, 2026
  43. 8/9 builtin/clone: write alternates via `odb_create_on_disk()`Patrick Steinhardt, Sep 7, 2026
  44. 9/9 odb/source: remove the ability to write alternatesPatrick Steinhardt, Sep 7, 2026
  45. Justin ToblerSep 8, 2026
  46. Justin ToblerSep 8, 2026
  47. Justin ToblerSep 8, 2026
  48. Justin ToblerSep 8, 2026
  49. Patrick SteinhardtSep 9, 2026
  50. Patrick SteinhardtSep 9, 2026
  51. 0/9 odb: write alternates at creation timePatrick Steinhardt, Sep 9, 2026
  52. 1/9 setup: split up concerns of `init_db()`Patrick Steinhardt, Sep 9, 2026
  53. 2/9 builtin/clone: defer setup of the object databasePatrick Steinhardt, Sep 9, 2026
  54. 3/9 builtin/clone: move around `setup_reference()`Patrick Steinhardt, Sep 9, 2026
  55. 4/9 builtin/clone: refactor handling of "--reference{,-if-able}"Patrick Steinhardt, Sep 9, 2026
  56. 5/9 builtin/clone: move setup of alternates for shared local clonesPatrick Steinhardt, Sep 9, 2026
  57. 6/9 builtin/clone: move setup of alternates for non-shared local clonesPatrick Steinhardt, Sep 9, 2026
  58. 7/9 odb/source: support writing alternates when creating the databasePatrick Steinhardt, Sep 9, 2026
  59. 8/9 builtin/clone: write alternates via `odb_create_on_disk()`Patrick Steinhardt, Sep 9, 2026
  60. 9/9 odb/source: remove the ability to write alternatesPatrick Steinhardt, Sep 9, 2026
  61. Justin ToblerSep 9, 2026
  62. Karthik NayakSep 10, 2026
  63. Karthik NayakSep 10, 2026
  64. Karthik NayakSep 10, 2026
  65. Karthik NayakSep 10, 2026
  66. Karthik NayakSep 10, 2026
  67. Karthik NayakSep 10, 2026
  68. Karthik NayakSep 10, 2026
  69. Karthik NayakSep 10, 2026
  70. Patrick SteinhardtSep 10, 2026
  71. Patrick SteinhardtSep 10, 2026
  72. 0/9 odb: write alternates at creation timePatrick Steinhardt, Sep 10, 2026
  73. 1/9 setup: split up concerns of `init_db()`Patrick Steinhardt, Sep 10, 2026
  74. 2/9 builtin/clone: defer setup of the object databasePatrick Steinhardt, Sep 10, 2026
  75. 3/9 builtin/clone: move around `setup_reference()`Patrick Steinhardt, Sep 10, 2026
  76. 4/9 builtin/clone: refactor handling of "--reference{,-if-able}"Patrick Steinhardt, Sep 10, 2026
  77. 5/9 builtin/clone: move setup of alternates for shared local clonesPatrick Steinhardt, Sep 10, 2026
  78. 6/9 builtin/clone: move setup of alternates for non-shared local clonesPatrick Steinhardt, Sep 10, 2026
  79. 7/9 odb/source: support writing alternates when creating the databasePatrick Steinhardt, Sep 10, 2026
  80. 8/9 builtin/clone: write alternates via `odb_create_on_disk()`Patrick Steinhardt, Sep 10, 2026
  81. 9/9 odb/source: remove the ability to write alternatesPatrick Steinhardt, Sep 10, 2026
  82. Karthik NayakSep 10, 2026
  83. Patrick SteinhardtSep 11, 2026
  84. Patrick SteinhardtSep 11, 2026
  85. Karthik NayakSep 14, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.