odb/source-inmemory: implement `read_object_info()` callback
Implement the `read_object_info()` callback function for the in-memory source. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>main
parent
87de1b31e0
commit
ec45c1e8bf
39
odb.c
39
odb.c
|
|
@ -32,25 +32,6 @@
|
|||
KHASH_INIT(odb_path_map, const char * /* key: odb_path */,
|
||||
struct odb_source *, 1, fspathhash, fspatheq)
|
||||
|
||||
static const struct cached_object *find_cached_object(struct object_database *object_store,
|
||||
const struct object_id *oid)
|
||||
{
|
||||
static const struct cached_object empty_tree = {
|
||||
.type = OBJ_TREE,
|
||||
.buf = "",
|
||||
};
|
||||
const struct cached_object_entry *co = object_store->inmemory_objects->objects;
|
||||
|
||||
for (size_t i = 0; i < object_store->inmemory_objects->objects_nr; i++, co++)
|
||||
if (oideq(&co->oid, oid))
|
||||
return &co->value;
|
||||
|
||||
if (oid->algo && oideq(oid, hash_algos[oid->algo].empty_tree))
|
||||
return &empty_tree;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int odb_mkstemp(struct object_database *odb,
|
||||
struct strbuf *temp_filename, const char *pattern)
|
||||
{
|
||||
|
|
@ -570,7 +551,6 @@ static int do_oid_object_info_extended(struct object_database *odb,
|
|||
const struct object_id *oid,
|
||||
struct object_info *oi, unsigned flags)
|
||||
{
|
||||
const struct cached_object *co;
|
||||
const struct object_id *real = oid;
|
||||
int already_retried = 0;
|
||||
|
||||
|
|
@ -580,25 +560,8 @@ static int do_oid_object_info_extended(struct object_database *odb,
|
|||
if (is_null_oid(real))
|
||||
return -1;
|
||||
|
||||
co = find_cached_object(odb, real);
|
||||
if (co) {
|
||||
if (oi) {
|
||||
if (oi->typep)
|
||||
*(oi->typep) = co->type;
|
||||
if (oi->sizep)
|
||||
*(oi->sizep) = co->size;
|
||||
if (oi->disk_sizep)
|
||||
*(oi->disk_sizep) = 0;
|
||||
if (oi->delta_base_oid)
|
||||
oidclr(oi->delta_base_oid, odb->repo->hash_algo);
|
||||
if (oi->contentp)
|
||||
*oi->contentp = xmemdupz(co->buf, co->size);
|
||||
if (oi->mtimep)
|
||||
*oi->mtimep = 0;
|
||||
oi->whence = OI_CACHED;
|
||||
}
|
||||
if (!odb_source_read_object_info(&odb->inmemory_objects->base, oid, oi, flags))
|
||||
return 0;
|
||||
}
|
||||
|
||||
odb_prepare_alternates(odb);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,57 @@
|
|||
#include "git-compat-util.h"
|
||||
#include "odb.h"
|
||||
#include "odb/source-inmemory.h"
|
||||
#include "repository.h"
|
||||
|
||||
static const struct cached_object *find_cached_object(struct odb_source_inmemory *source,
|
||||
const struct object_id *oid)
|
||||
{
|
||||
static const struct cached_object empty_tree = {
|
||||
.type = OBJ_TREE,
|
||||
.buf = "",
|
||||
};
|
||||
const struct cached_object_entry *co = source->objects;
|
||||
|
||||
for (size_t i = 0; i < source->objects_nr; i++, co++)
|
||||
if (oideq(&co->oid, oid))
|
||||
return &co->value;
|
||||
|
||||
if (oid->algo && oideq(oid, hash_algos[oid->algo].empty_tree))
|
||||
return &empty_tree;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int odb_source_inmemory_read_object_info(struct odb_source *source,
|
||||
const struct object_id *oid,
|
||||
struct object_info *oi,
|
||||
enum object_info_flags flags UNUSED)
|
||||
{
|
||||
struct odb_source_inmemory *inmemory = odb_source_inmemory_downcast(source);
|
||||
const struct cached_object *object;
|
||||
|
||||
object = find_cached_object(inmemory, oid);
|
||||
if (!object)
|
||||
return -1;
|
||||
|
||||
if (oi) {
|
||||
if (oi->typep)
|
||||
*(oi->typep) = object->type;
|
||||
if (oi->sizep)
|
||||
*(oi->sizep) = object->size;
|
||||
if (oi->disk_sizep)
|
||||
*(oi->disk_sizep) = 0;
|
||||
if (oi->delta_base_oid)
|
||||
oidclr(oi->delta_base_oid, source->odb->repo->hash_algo);
|
||||
if (oi->contentp)
|
||||
*oi->contentp = xmemdupz(object->buf, object->size);
|
||||
if (oi->mtimep)
|
||||
*oi->mtimep = 0;
|
||||
oi->whence = OI_CACHED;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void odb_source_inmemory_free(struct odb_source *source)
|
||||
{
|
||||
|
|
@ -19,6 +71,7 @@ struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb)
|
|||
odb_source_init(&source->base, odb, ODB_SOURCE_INMEMORY, "source", false);
|
||||
|
||||
source->base.free = odb_source_inmemory_free;
|
||||
source->base.read_object_info = odb_source_inmemory_read_object_info;
|
||||
|
||||
return source;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue