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

[PATCH 8/8] odb/source: remove the ability to write alternates

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

There are no users of `odb_source_write_alternates()` in our tree anymore. Remove that function and its supporting infrastructure.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 odb.c                 |  9 ---------
 odb.h                 |  7 -------
 odb/source-files.c    | 55 ---------------------------------------------------
 odb/source-inmemory.c |  7 -------
 odb/source-loose.c    |  7 -------
 odb/source-packed.c   |  7 -------
 odb/source.h          | 26 ------------------------
 7 files changed, 118 deletions(-)
diff --git a/odb.c b/odb.c
index 67d98d64fc..b531cf8fb3 100644
--- a/odb.c
+++ b/odb.c
@@ -239,15 +239,6 @@ static struct odb_source *odb_add_alternate_recursively(struct object_database *
 	return alternate;
 }
 
-void odb_add_to_alternates_file(struct object_database *odb,
-				const char *dir)
-{
-	int ret = odb_source_write_alternate(odb->sources, dir);
-	if (ret < 0)
-		die(NULL);
-	odb_add_alternate_recursively(odb, dir, 0);
-}
-
 struct odb_source *odb_add_to_alternates_memory(struct object_database *odb,
 						const char *dir)
 {
diff --git a/odb.h b/odb.h
index b9e0db56ec..2d002461f8 100644
--- a/odb.h
+++ b/odb.h
@@ -270,13 +270,6 @@ int odb_mkstemp(struct object_database *odb,
  */
 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
diff --git a/odb/source-files.c b/odb/source-files.c
index 5e77b21d9f..feef9e169a 100644
--- a/odb/source-files.c
+++ b/odb/source-files.c
@@ -4,7 +4,6 @@
 #include "chdir-notify.h"
 #include "config.h"
 #include "gettext.h"
-#include "lockfile.h"
 #include "object-file.h"
 #include "odb.h"
 #include "odb/source.h"
@@ -303,59 +302,6 @@ static int odb_source_files_read_alternates(struct odb_source *source,
 	return 0;
 }
 
-static int odb_source_files_write_alternate(struct odb_source *source,
-					    const char *alternate)
-{
-	struct lock_file lock = LOCK_INIT;
-	char *path = xstrfmt("%s/%s", source->path, "info/alternates");
-	FILE *in, *out;
-	int found = 0;
-	int ret;
-
-	repo_hold_lock_file_for_update(source->odb->repo, &lock, path,
-				       LOCK_DIE_ON_ERROR);
-	out = fdopen_lock_file(&lock, "w");
-	if (!out) {
-		ret = error_errno(_("unable to fdopen alternates lockfile"));
-		goto out;
-	}
-
-	in = fopen(path, "r");
-	if (in) {
-		struct strbuf line = STRBUF_INIT;
-
-		while (strbuf_getline(&line, in) != EOF) {
-			if (!strcmp(alternate, line.buf)) {
-				found = 1;
-				break;
-			}
-			fprintf_or_die(out, "%s\n", line.buf);
-		}
-
-		strbuf_release(&line);
-		fclose(in);
-	} else if (errno != ENOENT) {
-		ret = error_errno(_("unable to read alternates file"));
-		goto out;
-	}
-
-	if (found) {
-		rollback_lock_file(&lock);
-	} else {
-		fprintf_or_die(out, "%s\n", alternate);
-		if (commit_lock_file(&lock)) {
-			ret = error_errno(_("unable to move new alternates file into place"));
-			goto out;
-		}
-	}
-
-	ret = 0;
-
-out:
-	free(path);
-	return ret;
-}
-
 static int too_many_loose_objects(struct odb_source_files *files, int limit)
 {
 	unsigned long loose_count;
@@ -839,7 +785,6 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
 	files->base.write_object_stream = odb_source_files_write_object_stream;
 	files->base.begin_transaction = odb_source_files_begin_transaction;
 	files->base.read_alternates = odb_source_files_read_alternates;
-	files->base.write_alternate = odb_source_files_write_alternate;
 	files->base.optimize = odb_source_files_optimize;
 	files->base.optimize_required = odb_source_files_optimize_required;
 
diff --git a/odb/source-inmemory.c b/odb/source-inmemory.c
index 795672adf2..b00248dfb2 100644
--- a/odb/source-inmemory.c
+++ b/odb/source-inmemory.c
@@ -326,12 +326,6 @@ static int odb_source_inmemory_read_alternates(struct odb_source *source UNUSED,
 	return 0;
 }
 
-static int odb_source_inmemory_write_alternate(struct odb_source *source UNUSED,
-					       const char *alternate UNUSED)
-{
-	return error("in-memory source does not support alternates");
-}
-
 static void odb_source_inmemory_close(struct odb_source *source UNUSED)
 {
 }
@@ -388,7 +382,6 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
 	source->base.freshen_object = odb_source_inmemory_freshen_object;
 	source->base.begin_transaction = odb_source_inmemory_begin_transaction;
 	source->base.read_alternates = odb_source_inmemory_read_alternates;
-	source->base.write_alternate = odb_source_inmemory_write_alternate;
 
 	return source;
 }
diff --git a/odb/source-loose.c b/odb/source-loose.c
index bb3455dfbd..0f9b30bac1 100644
--- a/odb/source-loose.c
+++ b/odb/source-loose.c
@@ -982,12 +982,6 @@ static int odb_source_loose_read_alternates(struct odb_source *source UNUSED,
 	return 0;
 }
 
-static int odb_source_loose_write_alternate(struct odb_source *source UNUSED,
-					    const char *alternate UNUSED)
-{
-	return error("loose source does not support alternates");
-}
-
 static void odb_source_loose_clear_cache(struct odb_source_loose *loose)
 {
 	oidtree_clear(loose->cache);
@@ -1053,7 +1047,6 @@ struct odb_source_loose *odb_source_loose_new(struct object_database *odb,
 	loose->base.write_object_stream = odb_source_loose_write_object_stream;
 	loose->base.begin_transaction = odb_source_loose_begin_transaction;
 	loose->base.read_alternates = odb_source_loose_read_alternates;
-	loose->base.write_alternate = odb_source_loose_write_alternate;
 
 	if (!is_absolute_path(loose->base.path))
 		chdir_notify_register(NULL, odb_source_loose_reparent, loose);
diff --git a/odb/source-packed.c b/odb/source-packed.c
index 630d955585..c2d253759c 100644
--- a/odb/source-packed.c
+++ b/odb/source-packed.c
@@ -628,12 +628,6 @@ static int odb_source_packed_read_alternates(struct odb_source *source UNUSED,
 	return 0;
 }
 
-static int odb_source_packed_write_alternate(struct odb_source *source UNUSED,
-					     const char *alternate UNUSED)
-{
-	return error("packed backend cannot write alternates");
-}
-
 void (*report_garbage)(unsigned seen_bits, const char *path);
 
 static void report_helper(const struct string_list *list,
@@ -849,7 +843,6 @@ struct odb_source_packed *odb_source_packed_new(struct object_database *odb,
 	packed->base.write_object_stream = odb_source_packed_write_object_stream;
 	packed->base.begin_transaction = odb_source_packed_begin_transaction;
 	packed->base.read_alternates = odb_source_packed_read_alternates;
-	packed->base.write_alternate = odb_source_packed_write_alternate;
 
 	if (!is_absolute_path(path))
 		chdir_notify_register(NULL, odb_source_packed_reparent, packed);
diff --git a/odb/source.h b/odb/source.h
index 86b82fab3b..5ee769e839 100644
--- a/odb/source.h
+++ b/odb/source.h
@@ -287,19 +287,6 @@ struct odb_source {
 	int (*read_alternates)(struct odb_source *source,
 			       struct strvec *out);
 
-	/*
-	 * This callback is expected to persist the singular alternate passed
-	 * to it into its list of alternates. Any pre-existing alternates are
-	 * expected to remain active. Subsequent calls to `read_alternates` are
-	 * thus expected to yield the pre-existing list of alternates plus the
-	 * newly added alternate appended to its end.
-	 *
-	 * The callback is expected to return 0 on success, a negative error
-	 * code otherwise.
-	 */
-	int (*write_alternate)(struct odb_source *source,
-			       const char *alternate);
-
 	/*
 	 * This callback is expected to optimize the object database source.
 	 * Returns 0 on success, a negative error code otherwise.
@@ -519,19 +506,6 @@ static inline int odb_source_read_alternates(struct odb_source *source,
 	return source->read_alternates(source, out);
 }
 
-/*
- * Write and persist a new alternate object database source for the given
- * source. Any preexisting alternates are expected to stay valid, and the new
- * alternate shall be appended to the end of the list.
- *
- * Returns 0 on success, a negative error code otherwise.
- */
-static inline int odb_source_write_alternate(struct odb_source *source,
-					      const char *alternate)
-{
-	return source->write_alternate(source, alternate);
-}
-
 /*
  * Create a new transaction that can be used to write objects into a temporary
  * staging area. The objects will only be persisted when the transaction is
-- 
2.55.0.822.g20453c30eb.dirty
Previous: Patrick SteinhardtNext: Toon Claes
Message 9 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.