void *buf, unsigned long len, enum object_type type,
struct object_id *oid)
{
- struct cached_object_entry *co;
- char *co_buf;
-
hash_object_file(odb->repo->hash_algo, buf, len, type, oid);
if (odb_has_object(odb, oid, 0))
return 0;
- ALLOC_GROW(odb->inmemory_objects->objects,
- odb->inmemory_objects->objects_nr + 1,
- odb->inmemory_objects->objects_alloc);
- co = &odb->inmemory_objects->objects[odb->inmemory_objects->objects_nr++];
- co->value.size = len;
- co->value.type = type;
- co_buf = xmalloc(len);
- memcpy(co_buf, buf, len);
- co->value.buf = co_buf;
- oidcpy(&co->oid, oid);
- return 0;
+ return odb_source_write_object(&odb->inmemory_objects->base,
+ buf, len, type, oid, NULL, 0);
}
void *odb_read_object(struct object_database *odb,
#include "git-compat-util.h"
+#include "object-file.h"
#include "odb.h"
#include "odb/source-inmemory.h"
#include "odb/streaming.h"
return 0;
}
+static int odb_source_inmemory_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 UNUSED,
+ enum odb_write_object_flags flags UNUSED)
+{
+ struct odb_source_inmemory *inmemory = odb_source_inmemory_downcast(source);
+ struct cached_object_entry *object;
+
+ hash_object_file(source->odb->repo->hash_algo, buf, len, type, oid);
+
+ ALLOC_GROW(inmemory->objects, inmemory->objects_nr + 1,
+ inmemory->objects_alloc);
+ object = &inmemory->objects[inmemory->objects_nr++];
+ object->value.size = len;
+ object->value.type = type;
+ object->value.buf = xmemdupz(buf, len);
+ oidcpy(&object->oid, oid);
+
+ return 0;
+}
+
static void odb_source_inmemory_free(struct odb_source *source)
{
struct odb_source_inmemory *inmemory = odb_source_inmemory_downcast(source);
source->base.free = odb_source_inmemory_free;
source->base.read_object_info = odb_source_inmemory_read_object_info;
source->base.read_object_stream = odb_source_inmemory_read_object_stream;
+ source->base.write_object = odb_source_inmemory_write_object;
return source;
}