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,
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)
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
#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 type mostly
*/
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);
};
/*
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