Skip to content

Commit 1bba3c0

Browse files
pks-tgitster
authored andcommitted
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>
1 parent 7fa8c61 commit 1bba3c0

4 files changed

Lines changed: 19 additions & 19 deletions

File tree

odb/source-files.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
269269
CALLOC_ARRAY(files, 1);
270270
odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local);
271271
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);
273273

274274
files->base.free = odb_source_files_free;
275275
files->base.close = odb_source_files_close;

odb/source-packed.c

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -585,23 +585,22 @@ static void report_pack_garbage(struct string_list *list)
585585
}
586586

587587
struct prepare_pack_data {
588-
struct odb_source *source;
588+
struct odb_source_packed *source;
589589
struct string_list *garbage;
590590
};
591591

592592
static void prepare_pack(const char *full_name, size_t full_name_len,
593593
const char *file_name, void *_data)
594594
{
595595
struct prepare_pack_data *data = (struct prepare_pack_data *)_data;
596-
struct odb_source_files *files = odb_source_files_downcast(data->source);
597596
size_t base_len = full_name_len;
598597

599598
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))) {
602601
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);
605604
free(trimmed_path);
606605
}
607606

@@ -626,15 +625,15 @@ static void prepare_pack(const char *full_name, size_t full_name_len,
626625
report_garbage(PACKDIR_FILE_GARBAGE, full_name);
627626
}
628627

629-
static void prepare_packed_git_one(struct odb_source *source)
628+
static void prepare_packed_git_one(struct odb_source_packed *source)
630629
{
631630
struct string_list garbage = STRING_LIST_INIT_DUP;
632631
struct prepare_pack_data data = {
633632
.source = source,
634633
.garbage = &garbage,
635634
};
636635

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);
638637

639638
report_pack_garbage(data.garbage);
640639
string_list_clear(data.garbage, 0);
@@ -675,7 +674,7 @@ void odb_source_packed_prepare(struct odb_source_packed *source)
675674
return;
676675

677676
prepare_multi_pack_index_one(source);
678-
prepare_packed_git_one(&source->files->base);
677+
prepare_packed_git_one(source);
679678

680679
sort_packs(&source->packs.head, sort_pack);
681680
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)
733732
free(packed);
734733
}
735734

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)
737738
{
738739
struct odb_source_packed *packed;
739740

740741
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);
744743
strmap_init(&packed->packs_by_path);
745744

746745
packed->base.free = odb_source_packed_free;
@@ -758,7 +757,7 @@ struct odb_source_packed *odb_source_packed_new(struct odb_source_files *parent)
758757
packed->base.read_alternates = odb_source_packed_read_alternates;
759758
packed->base.write_alternate = odb_source_packed_write_alternate;
760759

761-
if (!is_absolute_path(parent->base.path))
760+
if (!is_absolute_path(path))
762761
chdir_notify_register(NULL, odb_source_packed_reparent, packed);
763762

764763
return packed;

odb/source-packed.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
*/
1111
struct odb_source_packed {
1212
struct odb_source base;
13-
struct odb_source_files *files;
1413

1514
/*
1615
* The list of packfiles in the order in which they have been most
@@ -66,9 +65,11 @@ struct odb_source_packed {
6665

6766
/*
6867
* Allocate and initialize a new empty packfile store for the given object
69-
* database source.
68+
* database.
7069
*/
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);
7273

7374
/*
7475
* Cast the given object database source to the packed backend. This will cause

packfile.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -801,7 +801,7 @@ struct packed_git *packfile_store_load_pack(struct odb_source_packed *store,
801801

802802
p = strmap_get(&store->packs_by_path, key.buf);
803803
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,
805805
strlen(idx_path), local);
806806
if (p)
807807
packfile_store_add_pack(store, p);

0 commit comments

Comments
 (0)