Skip to content

Commit fc7fb0e

Browse files
pks-tgitster
authored andcommitted
odb/source: make write_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 6e76c3a commit fc7fb0e

3 files changed

Lines changed: 38 additions & 1 deletion

File tree

odb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1013,7 +1013,7 @@ int odb_write_object_stream(struct object_database *odb,
10131013
struct odb_write_stream *stream, size_t len,
10141014
struct object_id *oid)
10151015
{
1016-
return odb_source_loose_write_stream(odb->sources, stream, len, oid);
1016+
return odb_source_write_object_stream(odb->sources, stream, len, oid);
10171017
}
10181018

10191019
struct object_database *odb_new(struct repository *repo,

odb/source-files.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ static int odb_source_files_write_object(struct odb_source *source,
109109
oid, compat_oid, flags);
110110
}
111111

112+
static int odb_source_files_write_object_stream(struct odb_source *source,
113+
struct odb_write_stream *stream,
114+
size_t len,
115+
struct object_id *oid)
116+
{
117+
return odb_source_loose_write_stream(source, stream, len, oid);
118+
}
119+
112120
struct odb_source_files *odb_source_files_new(struct object_database *odb,
113121
const char *path,
114122
bool local)
@@ -128,6 +136,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb,
128136
files->base.for_each_object = odb_source_files_for_each_object;
129137
files->base.freshen_object = odb_source_files_freshen_object;
130138
files->base.write_object = odb_source_files_write_object;
139+
files->base.write_object_stream = odb_source_files_write_object_stream;
131140

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

odb/source.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ enum object_info_flags {
5353
struct object_id;
5454
struct object_info;
5555
struct odb_read_stream;
56+
struct odb_write_stream;
5657

5758
/*
5859
* A callback function that can be used to iterate through objects. If given,
@@ -218,6 +219,18 @@ struct odb_source {
218219
struct object_id *oid,
219220
struct object_id *compat_oid,
220221
unsigned flags);
222+
223+
/*
224+
* This callback is expected to persist the given object stream into
225+
* the object source.
226+
*
227+
* The resulting object ID shall be written into the out pointer. The
228+
* callback is expected to return 0 on success, a negative error code
229+
* otherwise.
230+
*/
231+
int (*write_object_stream)(struct odb_source *source,
232+
struct odb_write_stream *stream, size_t len,
233+
struct object_id *oid);
221234
};
222235

223236
/*
@@ -356,4 +369,19 @@ static inline int odb_source_write_object(struct odb_source *source,
356369
compat_oid, flags);
357370
}
358371

372+
/*
373+
* Write an object into the object database source via a stream. The overall
374+
* length of the object must be known in advance.
375+
*
376+
* Return 0 on success, a negative error code otherwise. Populates the given
377+
* out pointer for the object ID.
378+
*/
379+
static inline int odb_source_write_object_stream(struct odb_source *source,
380+
struct odb_write_stream *stream,
381+
size_t len,
382+
struct object_id *oid)
383+
{
384+
return source->write_object_stream(source, stream, len, oid);
385+
}
386+
359387
#endif

0 commit comments

Comments
 (0)