mirror of
https://github.com/git/git.git
synced 2026-03-04 22:47:35 +01:00
odb/source: make write_object() 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>
This commit is contained in:
committed by
Junio C Hamano
parent
941c1fad13
commit
bf6737bcd5
4
odb.c
4
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,
|
||||
|
||||
@@ -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
|
||||
|
||||
36
odb/source.h
36
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
|
||||
|
||||
Reference in New Issue
Block a user