Skip to content

Commit 05151cf

Browse files
pks-tgitster
authored andcommitted
odb/source: make reprepare() function pluggable
Introduce a new callback function in `struct odb_source` to make the function pluggable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 47b9650 commit 05151cf

3 files changed

Lines changed: 27 additions & 5 deletions

File tree

odb.c

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1119,11 +1119,8 @@ void odb_reprepare(struct object_database *o)
11191119
o->loaded_alternates = 0;
11201120
odb_prepare_alternates(o);
11211121

1122-
for (source = o->sources; source; source = source->next) {
1123-
struct odb_source_files *files = odb_source_files_downcast(source);
1124-
odb_source_loose_reprepare(source);
1125-
packfile_store_reprepare(files->packed);
1126-
}
1122+
for (source = o->sources; source; source = source->next)
1123+
odb_source_reprepare(source);
11271124

11281125
o->approximate_object_count_valid = 0;
11291126

odb/source-files.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ static void odb_source_files_free(struct odb_source *source)
2828
free(files);
2929
}
3030

31+
static void odb_source_files_reprepare(struct odb_source *source)
32+
{
33+
struct odb_source_files *files = odb_source_files_downcast(source);
34+
odb_source_loose_reprepare(&files->base);
35+
packfile_store_reprepare(files->packed);
36+
}
37+
3138
struct odb_source_files *odb_source_files_new(struct object_database *odb,
3239
const char *path,
3340
bool local)
@@ -40,6 +47,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
4047
files->packed = packfile_store_new(&files->base);
4148

4249
files->base.free = odb_source_files_free;
50+
files->base.reprepare = odb_source_files_reprepare;
4351

4452
/*
4553
* Ideally, we would only ever store absolute paths in the source. This

odb/source.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,13 @@ struct odb_source {
5757
* all associated resources. The function will never be called with a NULL pointer.
5858
*/
5959
void (*free)(struct odb_source *source);
60+
61+
/*
62+
* This callback is expected to clear underlying caches of the object
63+
* database source. The function is called when the repository has for
64+
* example just been repacked so that new objects will become visible.
65+
*/
66+
void (*reprepare)(struct odb_source *source);
6067
};
6168

6269
/*
@@ -96,4 +103,14 @@ void odb_source_free(struct odb_source *source);
96103
*/
97104
void odb_source_release(struct odb_source *source);
98105

106+
/*
107+
* Reprepare the object database source and clear any caches. Depending on the
108+
* backend used this may have the effect that concurrently-written objects
109+
* become visible.
110+
*/
111+
static inline void odb_source_reprepare(struct odb_source *source)
112+
{
113+
source->reprepare(source);
114+
}
115+
99116
#endif

0 commit comments

Comments
 (0)