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

[PATCH 08/13] tmp-objdir: manage quarantine as an object directory

From
Patrick Steinhardt <ps@pks.im>
Date
Oct 2, 2026, 10:08 UTC
Message-ID
<20261002-pks-odb-move-alternates-v1-8-8a63507b88c4@pks.im>
In-Reply-To
<20261002-pks-odb-move-alternates-v1-0-8a63507b88c4@pks.im>

When creating a quarantine directory via the "tmp-objdir" subsystem we create a new "files" backend that new objects part of the transaction can be written to. In a future commit though we'll move handling of alternates into the "files" backend, and as part of that it will no longer be possible for us to have multiple sources attached to a single object database.

In a preceding commit, we have prepared the "files" backend to be able to handle multiple object directories. We don't use that mechanism for alternates yet, but will start doing so in a subsequent commit. But with that infrastructure ready we can already migrate tmp-objdirs over to use this new mechanism.

Adapt the subsystem so we create a `struct odb_files_dir` instead of a new "files" source.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 object-file.c |  4 ++--
 tmp-objdir.c  | 48 +++++++++++++++++++++++++++++-------------------
 tmp-objdir.h  |  4 ++--
 3 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/object-file.c b/object-file.c
index a4cbf8b081..fe9139c96d 100644
--- a/object-file.c
+++ b/object-file.c
@@ -488,7 +488,7 @@ struct odb_transaction_files {
 	enum odb_transaction_flags flags;
 
 	struct tmp_objdir *objdir;
-	struct odb_source *quarantine;
+	struct odb_files_dir *quarantine;
 	struct transaction_packfile packfile;
 	const char *prefix;
 
@@ -1443,7 +1443,7 @@ static int odb_transaction_files_write_pack(struct odb_transaction *base,
 			return -1;
 		}
 
-		odb_source_prepare(transaction->quarantine,
+		odb_source_prepare(&transaction->quarantine->packed->base,
 				   ODB_PREPARE_FLUSH_CACHES);
 	}
 
diff --git a/tmp-objdir.c b/tmp-objdir.c
index 31a7920be7..a3903b6e6d 100644
--- a/tmp-objdir.c
+++ b/tmp-objdir.c
@@ -12,13 +12,17 @@
 #include "quote.h"
 #include "odb.h"
 #include "odb/source.h"
+#include "odb/source-files.h"
+#include "odb/source-loose.h"
+#include "odb/source-packed.h"
 #include "repository.h"
 
 struct tmp_objdir {
 	struct repository *repo;
 	struct strbuf path;
 	struct strvec env;
-	struct odb_source *prev_source;
+	struct odb_files_dir *temp_dir;
+	struct odb_files_dir *orig_dir;
 	int will_destroy;
 };
 
@@ -57,18 +61,19 @@ static void tmp_objdir_reparent(const char *old_cwd,
  */
 static void tmp_objdir_restore_source(struct tmp_objdir *t)
 {
-	struct odb_source *cur_source = t->repo->objects->sources;
+	struct odb_source_files *files = odb_source_files_downcast(t->repo->objects->sources);
+	struct odb_files_dir *cur_dir = files->dirs;
 
-	if (strcmp(t->path.buf, cur_source->path))
+	if (t->temp_dir != files->dirs)
 		BUG("expected %s as primary object store; found %s",
-		    t->path.buf, cur_source->path);
+		    t->temp_dir->abspath, cur_dir->abspath);
 
-	if (cur_source->next != t->prev_source)
+	if (t->temp_dir->next != t->orig_dir)
 		BUG("we expect the old primary object store to be the first alternate");
 
 	t->repo->disable_ref_updates = false;
-	t->repo->objects->sources = t->prev_source;
-	odb_source_free(cur_source);
+	files->dirs = t->orig_dir;
+	odb_files_dir_free(cur_dir);
 }
 
 int tmp_objdir_destroy(struct tmp_objdir *t)
@@ -81,7 +86,7 @@ int tmp_objdir_destroy(struct tmp_objdir *t)
 	if (t == the_tmp_objdir)
 		the_tmp_objdir = NULL;
 
-	if (t->prev_source)
+	if (t->orig_dir)
 		tmp_objdir_restore_source(t);
 
 	err = remove_dir_recursively(&t->path, 0);
@@ -315,11 +320,11 @@ int tmp_objdir_migrate(struct tmp_objdir *t)
 	if (!t)
 		return 0;
 
-	if (t->prev_source) {
-		if (t->repo->objects->sources->will_destroy)
+	if (t->orig_dir) {
+		if (t->will_destroy)
 			BUG("migrating an ODB that was marked for destruction");
 		tmp_objdir_restore_source(t);
-		t->prev_source = NULL;
+		t->orig_dir = NULL;
 	}
 
 	strbuf_addbuf(&src, &t->path);
@@ -341,10 +346,12 @@ const char **tmp_objdir_env(const struct tmp_objdir *t)
 	return t->env.v;
 }
 
-struct odb_source *tmp_objdir_replace_primary_odb(struct tmp_objdir *t,
-						  int will_destroy)
+struct odb_files_dir *tmp_objdir_replace_primary_odb(struct tmp_objdir *t,
+						     int will_destroy)
 {
-	if (t->prev_source)
+	struct odb_source_files *files = odb_source_files_downcast(t->repo->objects->sources);
+
+	if (t->temp_dir)
 		BUG("the primary object database is already replaced");
 	t->will_destroy = will_destroy;
 
@@ -353,11 +360,14 @@ struct odb_source *tmp_objdir_replace_primary_odb(struct tmp_objdir *t,
 	 * alternate. Disable ref updates while a temporary source is active,
 	 * since the objects in the database may roll back.
 	 */
-	t->prev_source = t->repo->objects->sources;
-	t->repo->objects->sources = odb_source_new(t->repo->objects, t->path.buf, false);
-	t->repo->objects->sources->next = t->prev_source;
-	t->repo->objects->sources->will_destroy = will_destroy;
+	t->temp_dir = odb_files_dir_new(t->repo->objects, t->path.buf, false);
+	t->temp_dir->loose->base.will_destroy = will_destroy;
+	t->temp_dir->packed->base.will_destroy = will_destroy;
+	t->temp_dir->next = files->dirs;
+
+	t->orig_dir = files->dirs;
+	files->dirs = t->temp_dir;
 	t->repo->disable_ref_updates = true;
 
-	return t->repo->objects->sources;
+	return t->temp_dir;
 }
diff --git a/tmp-objdir.h b/tmp-objdir.h
index 05f0d08d10..5ed0db1ee0 100644
--- a/tmp-objdir.h
+++ b/tmp-objdir.h
@@ -61,7 +61,7 @@ void tmp_objdir_discard_objects(struct tmp_objdir *);
  * If will_destroy is nonzero, the object directory may not be migrated. Returns
  * the newly installed primary source.
  */
-struct odb_source *tmp_objdir_replace_primary_odb(struct tmp_objdir *,
-						  int will_destroy);
+struct odb_files_dir *tmp_objdir_replace_primary_odb(struct tmp_objdir *,
+						     int will_destroy);
 
 #endif /* TMP_OBJDIR_H */
-- 
2.56.0.379.gc618271300.dirty
Previous: Patrick SteinhardtNext: Karthik Nayak
Message 15 of 41 in “odb/source-files: move alternates into the backend”
  1. 00/13 odb/source-files: move alternates into the backendPatrick Steinhardt, Oct 2, 2026
  2. 01/13 commit-graph: require resolved packfile paths for `stdin_packs`Patrick Steinhardt, Oct 2, 2026
  3. Karthik NayakOct 5, 2026
  4. Patrick SteinhardtOct 6, 2026
  5. 02/13 commit-graph: stop depending on `struct odb_source`Patrick Steinhardt, Oct 2, 2026
  6. Karthik NayakOct 5, 2026
  7. Patrick SteinhardtOct 6, 2026
  8. Karthik NayakOct 6, 2026
  9. 03/13 odb/source-files: introduce `struct odb_files_dir`Patrick Steinhardt, Oct 2, 2026
  10. 04/13 odb: refactor `odb_for_each_alternate()` to yield dirsPatrick Steinhardt, Oct 2, 2026
  11. Karthik NayakOct 6, 2026
  12. 05/13 odb: refactor `odb_find_source()` to yield dirsPatrick Steinhardt, Oct 2, 2026
  13. 06/13 odb/source-files: add the ability to have multiple object dirsPatrick Steinhardt, Oct 2, 2026
  14. 07/13 tmp-objdir: absorb logic to set and restore primary sourcesPatrick Steinhardt, Oct 2, 2026
  15. 08/13 tmp-objdir: manage quarantine as an object directoryPatrick Steinhardt, Oct 2, 2026
  16. Karthik NayakOct 6, 2026
  17. Karthik NayakOct 6, 2026
  18. 09/13 tmp-objdir: replace primary source at creation timePatrick Steinhardt, Oct 2, 2026
  19. 10/13 odb/source: make `will_destroy` an implementation detailPatrick Steinhardt, Oct 2, 2026
  20. 11/13 odb/source-files: extract reading alternatesPatrick Steinhardt, Oct 2, 2026
  21. 12/13 odb/source-files: move alternates into the backendPatrick Steinhardt, Oct 2, 2026
  22. Karthik NayakOct 6, 2026
  23. Patrick SteinhardtOct 7, 2026
  24. 13/13 odb/source: drop `read_alternates` callbackPatrick Steinhardt, Oct 2, 2026
  25. Karthik NayakOct 6, 2026
  26. Patrick SteinhardtOct 7, 2026
  27. 00/13 odb/source-files: move alternates into the backendPatrick Steinhardt, Oct 8, 2026
  28. 01/13 commit-graph: require resolved packfile paths for `stdin_packs`Patrick Steinhardt, Oct 8, 2026
  29. 02/13 commit-graph: stop depending on `struct odb_source`Patrick Steinhardt, Oct 8, 2026
  30. 03/13 odb/source-files: introduce `struct odb_files_dir`Patrick Steinhardt, Oct 8, 2026
  31. 04/13 odb: refactor `odb_for_each_alternate()` to yield dirsPatrick Steinhardt, Oct 8, 2026
  32. 05/13 odb: refactor `odb_find_source()` to yield dirsPatrick Steinhardt, Oct 8, 2026
  33. 06/13 odb/source-files: add the ability to have multiple object dirsPatrick Steinhardt, Oct 8, 2026
  34. 07/13 tmp-objdir: absorb logic to set and restore primary sourcesPatrick Steinhardt, Oct 8, 2026
  35. 08/13 tmp-objdir: manage quarantine as an object directoryPatrick Steinhardt, Oct 8, 2026
  36. 09/13 tmp-objdir: replace primary source at creation timePatrick Steinhardt, Oct 8, 2026
  37. 10/13 odb/source: make `will_destroy` an implementation detailPatrick Steinhardt, Oct 8, 2026
  38. 11/13 odb/source-files: extract reading alternatesPatrick Steinhardt, Oct 8, 2026
  39. 12/13 odb/source-files: move alternates into the backendPatrick Steinhardt, Oct 8, 2026
  40. 13/13 odb/source: drop `read_alternates` callbackPatrick Steinhardt, Oct 8, 2026
  41. Karthik NayakOct 8, 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.