odb/source-packed: drop pointer to "files" parent source
Over the last commits we have turned the packfile store into a proper object database source that can be used as a standalone backend. As such, it is no longer necessary to have it coupled to the "files" parent source. Remove the pointer to the owning "files" source so that the "packed" source can be used as a standalone entity. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jun 17, 2026 at 08:40 UTC
1bba3c035d2283456edcb159e965b8be2015e114
4 files changed
+19
-19
odb/source-files.c
+1
-1
@@ -269,7 +269,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
269
CALLOC_ARRAY(files, 1);
270
odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local);
271
files->loose = odb_source_loose_new(odb, path, local);
272
- files->packed = odb_source_packed_new(files);
272
+ files->packed = odb_source_packed_new(odb, path, local);
273
274
files->base.free = odb_source_files_free;
275
files->base.close = odb_source_files_close;
odb/source-packed.c
+13
-14
@@ -585,7 +585,7 @@ static void report_pack_garbage(struct string_list *list)
585
}
586
587
struct prepare_pack_data {
588
- struct odb_source *source;
588
+ struct odb_source_packed *source;
589
struct string_list *garbage;
590
};
591
@@ -593,15 +593,14 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
593
const char *file_name, void *_data)
594
{
595
struct prepare_pack_data *data = (struct prepare_pack_data *)_data;
596
- struct odb_source_files *files = odb_source_files_downcast(data->source);
596
size_t base_len = full_name_len;
597
598
if (strip_suffix_mem(full_name, &base_len, ".idx") &&
600
- !(files->packed->midx &&
601
- midx_contains_pack(files->packed->midx, file_name))) {
599
+ !(data->source->midx &&
600
+ midx_contains_pack(data->source->midx, file_name))) {
601
char *trimmed_path = xstrndup(full_name, full_name_len);
603
- packfile_store_load_pack(files->packed,
604
- trimmed_path, data->source->local);
602
+ packfile_store_load_pack(data->source,
603
+ trimmed_path, data->source->base.local);
604
free(trimmed_path);
605
}
606
@@ -626,7 +625,7 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
625
report_garbage(PACKDIR_FILE_GARBAGE, full_name);
626
}
627
629
-static void prepare_packed_git_one(struct odb_source *source)
628
+static void prepare_packed_git_one(struct odb_source_packed *source)
629
{
630
struct string_list garbage = STRING_LIST_INIT_DUP;
631
struct prepare_pack_data data = {
@@ -634,7 +633,7 @@ static void prepare_packed_git_one(struct odb_source *source)
633
.garbage = &garbage,
634
};
635
637
- for_each_file_in_pack_dir(source->path, prepare_pack, &data);
636
+ for_each_file_in_pack_dir(source->base.path, prepare_pack, &data);
637
638
report_pack_garbage(data.garbage);
639
string_list_clear(data.garbage, 0);
@@ -675,7 +674,7 @@ void odb_source_packed_prepare(struct odb_source_packed *source)
674
return;
675
676
prepare_multi_pack_index_one(source);
678
- prepare_packed_git_one(&source->files->base);
677
+ prepare_packed_git_one(source);
678
679
sort_packs(&source->packs.head, sort_pack);
680
for (struct packfile_list_entry *e = source->packs.head; e; e = e->next)
@@ -733,14 +732,14 @@ static void odb_source_packed_free(struct odb_source *source)
732
free(packed);
733
}
734
736
-struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
735
+struct odb_source_packed *odb_source_packed_new(struct object_database *odb,
736
+ const char *path,
737
+ bool local)
738
{
739
struct odb_source_packed *packed;
740
741
CALLOC_ARRAY(packed, 1);
741
- odb_source_init(&packed->base, parent->base.odb, ODB_SOURCE_PACKED,
742
- parent->base.path, parent->base.local);
743
- packed->files = parent;
742
+ odb_source_init(&packed->base, odb, ODB_SOURCE_PACKED, path, local);
743
strmap_init(&packed->packs_by_path);
744
745
packed->base.free = odb_source_packed_free;
@@ -758,7 +757,7 @@ struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
757
packed->base.read_alternates = odb_source_packed_read_alternates;
758
packed->base.write_alternate = odb_source_packed_write_alternate;
759
761
- if (!is_absolute_path(parent->base.path))
760
+ if (!is_absolute_path(path))
761
chdir_notify_register(NULL, odb_source_packed_reparent, packed);
762
763
return packed;
odb/source-packed.h
+4
-3
@@ -10,7 +10,6 @@
10
*/
11
struct odb_source_packed {
12
struct odb_source base;
13
- struct odb_source_files *files;
13
14
/*
15
* The list of packfiles in the order in which they have been most
@@ -66,9 +65,11 @@ struct odb_source_packed {
65
66
/*
67
* Allocate and initialize a new empty packfile store for the given object
69
- * database source.
68
+ * database.
69
*/
71
-struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent);
70
+struct odb_source_packed *odb_source_packed_new(struct object_database *odb,
71
+ const char *path,
72
+ bool local);
73
74
/*
75
* Cast the given object database source to the packed backend. This will cause
packfile.c
+1
-1
@@ -801,7 +801,7 @@ struct packed_git *packfile_store_load_pack(struct odb_source_packed *store,
801
802
p = strmap_get(&store->packs_by_path, key.buf);
803
if (!p) {
804
- p = add_packed_git(store->files->base.odb->repo, idx_path,
804
+ p = add_packed_git(store->base.odb->repo, idx_path,
805
strlen(idx_path), local);
806
if (p)
807
packfile_store_add_pack(store, p);