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

[PATCH 01/10] packfile: create store via its owning source

From
Patrick Steinhardt <ps@pks.im>
Date
Dec 15, 2025, 07:36 UTC
Message-ID
<20251215-b4-pks-pack-store-via-source-v1-1-433aac465295@pks.im>
In-Reply-To
<20251215-b4-pks-pack-store-via-source-v1-0-433aac465295@pks.im>

In subsequent patches we're about to move the packfile store from the object database layer into the object database source layer. Once done, we'll have one packfile store per source, where the source is owning the store.

Prepare for this future and refactor `packfile_store_new()` to be initialized via an object database source instead of via the object database itself.

This refactoring leads to a weird in-between state where the store is owned by the object database but created via the source. But this makes subsequent refactorings easier because we can now start to access the owning source of a given store.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 odb.c      |  2 +-
 packfile.c | 20 ++++++++++----------
 packfile.h |  6 +++---
 3 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/odb.c b/odb.c
index 45b6600800..94144a69f5 100644
--- a/odb.c
+++ b/odb.c
@@ -1056,7 +1056,6 @@ struct object_database *odb_new(struct repository *repo,
 
 	memset(o, 0, sizeof(*o));
 	o->repo = repo;
-	o->packfiles = packfile_store_new(o);
 	pthread_mutex_init(&o->replace_mutex, NULL);
 	string_list_init_dup(&o->submodule_source_paths);
 
@@ -1065,6 +1064,7 @@ struct object_database *odb_new(struct repository *repo,
 	o->sources = odb_source_new(o, primary_source, true);
 	o->sources_tail = &o->sources->next;
 	o->alternate_db = xstrdup_or_null(secondary_sources);
+	o->packfiles = packfile_store_new(o->sources);
 
 	free(to_free);
 
diff --git a/packfile.c b/packfile.c
index c88bd92619..0a05a10daa 100644
--- a/packfile.c
+++ b/packfile.c
@@ -876,7 +876,7 @@ struct packed_git *packfile_store_load_pack(struct packfile_store *store,
 
 	p = strmap_get(&store->packs_by_path, key.buf);
 	if (!p) {
-		p = add_packed_git(store->odb->repo, idx_path,
+		p = add_packed_git(store->source->odb->repo, idx_path,
 				   strlen(idx_path), local);
 		if (p)
 			packfile_store_add_pack(store, p);
@@ -1068,8 +1068,8 @@ void packfile_store_prepare(struct packfile_store *store)
 	if (store->initialized)
 		return;
 
-	odb_prepare_alternates(store->odb);
-	for (source = store->odb->sources; source; source = source->next) {
+	odb_prepare_alternates(store->source->odb);
+	for (source = store->source->odb->sources; source; source = source->next) {
 		prepare_multi_pack_index_one(source);
 		prepare_packed_git_one(source);
 	}
@@ -1092,7 +1092,7 @@ struct packfile_list_entry *packfile_store_get_packs(struct packfile_store *stor
 {
 	packfile_store_prepare(store);
 
-	for (struct odb_source *source = store->odb->sources; source; source = source->next) {
+	for (struct odb_source *source = store->source->odb->sources; source; source = source->next) {
 		struct multi_pack_index *m = source->midx;
 		if (!m)
 			continue;
@@ -2121,7 +2121,7 @@ int packfile_store_freshen_object(struct packfile_store *store,
 				  const struct object_id *oid)
 {
 	struct pack_entry e;
-	if (!find_pack_entry(store->odb->repo, oid, &e))
+	if (!find_pack_entry(store->source->odb->repo, oid, &e))
 		return 0;
 	if (e.p->is_cruft)
 		return 0;
@@ -2142,7 +2142,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
 	struct pack_entry e;
 	int rtype;
 
-	if (!find_pack_entry(store->odb->repo, oid, &e))
+	if (!find_pack_entry(store->source->odb->repo, oid, &e))
 		return 1;
 
 	/*
@@ -2152,7 +2152,7 @@ int packfile_store_read_object_info(struct packfile_store *store,
 	if (oi == &blank_oi)
 		return 0;
 
-	rtype = packed_object_info(store->odb->repo, e.p, e.offset, oi);
+	rtype = packed_object_info(store->source->odb->repo, e.p, e.offset, oi);
 	if (rtype < 0) {
 		mark_bad_packed_object(e.p, oid);
 		return -1;
@@ -2411,11 +2411,11 @@ int parse_pack_header_option(const char *in, unsigned char *out, unsigned int *l
 	return 0;
 }
 
-struct packfile_store *packfile_store_new(struct object_database *odb)
+struct packfile_store *packfile_store_new(struct odb_source *source)
 {
 	struct packfile_store *store;
 	CALLOC_ARRAY(store, 1);
-	store->odb = odb;
+	store->source = source;
 	strmap_init(&store->packs_by_path);
 	return store;
 }
@@ -2534,7 +2534,7 @@ int packfile_store_read_object_stream(struct odb_read_stream **out,
 
 	if (packfile_store_read_object_info(store, oid, &oi, 0) ||
 	    oi.u.packed.is_delta ||
-	    repo_settings_get_big_file_threshold(store->odb->repo) >= size)
+	    repo_settings_get_big_file_threshold(store->source->odb->repo) >= size)
 		return -1;
 
 	in_pack_type = unpack_object_header(oi.u.packed.pack,
diff --git a/packfile.h b/packfile.h
index 59d162a3f4..33cc1c1654 100644
--- a/packfile.h
+++ b/packfile.h
@@ -77,7 +77,7 @@ struct packed_git *packfile_list_find_oid(struct packfile_list_entry *packs,
  * A store that manages packfiles for a given object database.
  */
 struct packfile_store {
-	struct object_database *odb;
+	struct odb_source *source;
 
 	/*
 	 * The list of packfiles in the order in which they have been most
@@ -129,9 +129,9 @@ struct packfile_store {
 
 /*
  * Allocate and initialize a new empty packfile store for the given object
- * database.
+ * database source.
  */
-struct packfile_store *packfile_store_new(struct object_database *odb);
+struct packfile_store *packfile_store_new(struct odb_source *source);
 
 /*
  * Free the packfile store and all its associated state. All packfiles
-- 
2.52.0.351.gbe84eed79e.dirty
Previous: Patrick SteinhardtNext: Justin Tobler
Message 2 of 52 in “Start tracking packfiles per object database source”
  1. 00/10 Start tracking packfiles per object database sourcePatrick Steinhardt, Dec 15, 2025
  2. 01/10 packfile: create store via its owning sourcePatrick Steinhardt, Dec 15, 2025
  3. Justin ToblerDec 15, 2025
  4. Patrick SteinhardtDec 16, 2025
  5. 02/10 packfile: pass source to `prepare_pack()`Patrick Steinhardt, Dec 15, 2025
  6. Justin ToblerDec 15, 2025
  7. 03/10 packfile: refactor kept-pack cache to work with packfile storesPatrick Steinhardt, Dec 15, 2025
  8. Justin ToblerDec 15, 2025
  9. Patrick SteinhardtDec 16, 2025
  10. 04/10 packfile: refactor misleading code when unusing pack windowsPatrick Steinhardt, Dec 15, 2025
  11. 05/10 packfile: move packfile store into object sourcePatrick Steinhardt, Dec 15, 2025
  12. Justin ToblerDec 18, 2025
  13. Patrick SteinhardtDec 18, 2025
  14. 06/10 packfile: only prepare owning store in `packfile_store_get_packs()`Patrick Steinhardt, Dec 15, 2025
  15. Justin ToblerDec 18, 2025
  16. 07/10 packfile: only prepare owning store in `packfile_store_prepare()`Patrick Steinhardt, Dec 15, 2025
  17. 08/10 packfile: inline `find_kept_pack_entry()`Patrick Steinhardt, Dec 15, 2025
  18. Justin ToblerDec 18, 2025
  19. Patrick SteinhardtDec 18, 2025
  20. 09/10 packfile: refactor `find_pack_entry()` to work on the packfile storePatrick Steinhardt, Dec 15, 2025
  21. 10/10 packfile: move MIDX into packfile storePatrick Steinhardt, Dec 15, 2025
  22. 00/10 Start tracking packfiles per object database sourcePatrick Steinhardt, Dec 18, 2025
  23. 01/10 packfile: create store via its owning sourcePatrick Steinhardt, Dec 18, 2025
  24. 02/10 packfile: pass source to `prepare_pack()`Patrick Steinhardt, Dec 18, 2025
  25. 03/10 packfile: refactor kept-pack cache to work with packfile storesPatrick Steinhardt, Dec 18, 2025
  26. Toon ClaesJan 6, 2026
  27. 04/10 packfile: refactor misleading code when unusing pack windowsPatrick Steinhardt, Dec 18, 2025
  28. Toon ClaesJan 7, 2026
  29. 05/10 packfile: move packfile store into object sourcePatrick Steinhardt, Dec 18, 2025
  30. Toon ClaesJan 7, 2026
  31. 06/10 packfile: only prepare owning store in `packfile_store_get_packs()`Patrick Steinhardt, Dec 18, 2025
  32. 07/10 packfile: only prepare owning store in `packfile_store_prepare()`Patrick Steinhardt, Dec 18, 2025
  33. Toon ClaesJan 7, 2026
  34. 08/10 packfile: inline `find_kept_pack_entry()`Patrick Steinhardt, Dec 18, 2025
  35. Kristoffer HaugsbakkJan 8, 2026
  36. Patrick SteinhardtJan 9, 2026
  37. 09/10 packfile: refactor `find_pack_entry()` to work on the packfile storePatrick Steinhardt, Dec 18, 2025
  38. 10/10 packfile: move MIDX into packfile storePatrick Steinhardt, Dec 18, 2025
  39. 00/10 Start tracking packfiles per object database sourcePatrick Steinhardt, Jan 9, 2026
  40. 01/10 packfile: create store via its owning sourcePatrick Steinhardt, Jan 9, 2026
  41. 02/10 packfile: pass source to `prepare_pack()`Patrick Steinhardt, Jan 9, 2026
  42. 03/10 packfile: refactor kept-pack cache to work with packfile storesPatrick Steinhardt, Jan 9, 2026
  43. 04/10 packfile: refactor misleading code when unusing pack windowsPatrick Steinhardt, Jan 9, 2026
  44. Karthik NayakJan 12, 2026
  45. 05/10 packfile: move packfile store into object sourcePatrick Steinhardt, Jan 9, 2026
  46. 06/10 packfile: only prepare owning store in `packfile_store_get_packs()`Patrick Steinhardt, Jan 9, 2026
  47. 07/10 packfile: only prepare owning store in `packfile_store_prepare()`Patrick Steinhardt, Jan 9, 2026
  48. 08/10 packfile: inline `find_kept_pack_entry()`Patrick Steinhardt, Jan 9, 2026
  49. 09/10 packfile: refactor `find_pack_entry()` to work on the packfile storePatrick Steinhardt, Jan 9, 2026
  50. 10/10 packfile: move MIDX into packfile storePatrick Steinhardt, Jan 9, 2026
  51. Junio C HamanoJan 11, 2026
  52. Justin ToblerJan 12, 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.