Skip to content

Commit 1f3fd68

Browse files
pks-tgitster
authored andcommitted
odb/source: make read_object_stream() 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 5946a56 commit 1f3fd68

3 files changed

Lines changed: 37 additions & 7 deletions

File tree

odb/source-files.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ static int odb_source_files_read_object_info(struct odb_source *source,
5555
return -1;
5656
}
5757

58+
static int odb_source_files_read_object_stream(struct odb_read_stream **out,
59+
struct odb_source *source,
60+
const struct object_id *oid)
61+
{
62+
struct odb_source_files *files = odb_source_files_downcast(source);
63+
if (!packfile_store_read_object_stream(out, files->packed, oid) ||
64+
!odb_source_loose_read_object_stream(out, source, oid))
65+
return 0;
66+
return -1;
67+
}
68+
5869
struct odb_source_files *odb_source_files_new(struct object_database *odb,
5970
const char *path,
6071
bool local)
@@ -70,6 +81,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
7081
files->base.close = odb_source_files_close;
7182
files->base.reprepare = odb_source_files_reprepare;
7283
files->base.read_object_info = odb_source_files_read_object_info;
84+
files->base.read_object_stream = odb_source_files_read_object_stream;
7385

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

odb/source.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ enum object_info_flags {
5050

5151
struct object_id;
5252
struct object_info;
53+
struct odb_read_stream;
5354

5455
/*
5556
* The source is the part of the object database that stores the actual
@@ -138,6 +139,17 @@ struct odb_source {
138139
const struct object_id *oid,
139140
struct object_info *oi,
140141
enum object_info_flags flags);
142+
143+
/*
144+
* This callback is expected to create a new read stream that can be
145+
* used to stream the object identified by the given ID.
146+
*
147+
* The callback is expected to return a negative error code in case
148+
* creating the object stream has failed, 0 otherwise.
149+
*/
150+
int (*read_object_stream)(struct odb_read_stream **out,
151+
struct odb_source *source,
152+
const struct object_id *oid);
141153
};
142154

143155
/*
@@ -209,4 +221,15 @@ static inline int odb_source_read_object_info(struct odb_source *source,
209221
return source->read_object_info(source, oid, oi, flags);
210222
}
211223

224+
/*
225+
* Create a new read stream for the given object ID. Returns 0 on success, a
226+
* negative error code otherwise.
227+
*/
228+
static inline int odb_source_read_object_stream(struct odb_read_stream **out,
229+
struct odb_source *source,
230+
const struct object_id *oid)
231+
{
232+
return source->read_object_stream(out, source, oid);
233+
}
234+
212235
#endif

odb/streaming.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@
66
#include "convert.h"
77
#include "environment.h"
88
#include "repository.h"
9-
#include "object-file.h"
109
#include "odb.h"
1110
#include "odb/streaming.h"
1211
#include "replace-object.h"
13-
#include "packfile.h"
1412

1513
#define FILTER_BUFFER (1024*16)
1614

@@ -186,12 +184,9 @@ static int istream_source(struct odb_read_stream **out,
186184
struct odb_source *source;
187185

188186
odb_prepare_alternates(odb);
189-
for (source = odb->sources; source; source = source->next) {
190-
struct odb_source_files *files = odb_source_files_downcast(source);
191-
if (!packfile_store_read_object_stream(out, files->packed, oid) ||
192-
!odb_source_loose_read_object_stream(out, source, oid))
187+
for (source = odb->sources; source; source = source->next)
188+
if (!odb_source_read_object_stream(out, source, oid))
193189
return 0;
194-
}
195190

196191
return open_istream_incore(out, odb, oid);
197192
}

0 commit comments

Comments
 (0)