diff --git a/odb.c b/odb.c index c9f42c5afd..5eb60063dc 100644 --- a/odb.c +++ b/odb.c @@ -1005,8 +1005,8 @@ int odb_write_object_ext(struct object_database *odb, struct object_id *compat_oid, unsigned flags) { - return odb_source_loose_write_object(odb->sources, buf, len, type, - oid, compat_oid, flags); + return odb_source_write_object(odb->sources, buf, len, type, + oid, compat_oid, flags); } int odb_write_object_stream(struct object_database *odb, diff --git a/odb/source-files.c b/odb/source-files.c index a6447909e0..67c2aff659 100644 --- a/odb/source-files.c +++ b/odb/source-files.c @@ -98,6 +98,17 @@ static int odb_source_files_freshen_object(struct odb_source *source, return 0; } +static int odb_source_files_write_object(struct odb_source *source, + const void *buf, unsigned long len, + enum object_type type, + struct object_id *oid, + struct object_id *compat_oid, + unsigned flags) +{ + return odb_source_loose_write_object(source, buf, len, type, + oid, compat_oid, flags); +} + struct odb_source_files *odb_source_files_new(struct object_database *odb, const char *path, bool local) @@ -116,6 +127,7 @@ struct odb_source_files *odb_source_files_new(struct object_database *odb, files->base.read_object_stream = odb_source_files_read_object_stream; files->base.for_each_object = odb_source_files_for_each_object; files->base.freshen_object = odb_source_files_freshen_object; + files->base.write_object = odb_source_files_write_object; /* * Ideally, we would only ever store absolute paths in the source. This diff --git a/odb/source.h b/odb/source.h index 9324fce2ba..a6ef7f782c 100644 --- a/odb/source.h +++ b/odb/source.h @@ -1,6 +1,8 @@ #ifndef ODB_SOURCE_H #define ODB_SOURCE_H +#include "object.h" + enum odb_source_type { /* * The "unknown" type, which should never be in use. This is type @@ -196,6 +198,24 @@ struct odb_source { */ int (*freshen_object)(struct odb_source *source, const struct object_id *oid); + + /* + * This callback is expected to persist the given object into the + * object source. In case the object already exists it shall be + * freshened. + * + * The flags field is a combination of `WRITE_OBJECT` flags. + * + * The resulting object ID (and optionally the compatibility object ID) + * shall be written into the out pointers. The callback is expected to + * return 0 on success, a negative error code otherwise. + */ + int (*write_object)(struct odb_source *source, + const void *buf, unsigned long len, + enum object_type type, + struct object_id *oid, + struct object_id *compat_oid, + unsigned flags); }; /* @@ -315,4 +335,20 @@ static inline int odb_source_freshen_object(struct odb_source *source, return source->freshen_object(source, oid); } +/* + * Write an object into the object database source. Returns 0 on success, a + * negative error code otherwise. Populates the given out pointers for the + * object ID and the compatibility object ID, if non-NULL. + */ +static inline int odb_source_write_object(struct odb_source *source, + const void *buf, unsigned long len, + enum object_type type, + struct object_id *oid, + struct object_id *compat_oid, + unsigned flags) +{ + return source->write_object(source, buf, len, type, oid, + compat_oid, flags); +} + #endif