Files
git/odb/source-inmemory.h
Patrick Steinhardt 335fe2545e odb/source: introduce function to map source type to name
Introduce a new function that maps an object source's type to a
human-readable name. Use the function to provide better human-readable
error messages for the downcasting functions.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2026-08-06 21:24:25 -07:00

36 lines
1.1 KiB
C

#ifndef ODB_SOURCE_INMEMORY_H
#define ODB_SOURCE_INMEMORY_H
#include "odb/source.h"
struct oidtree;
/*
* An in-memory source that you can write objects to that shall be made
* available for reading, but that shouldn't ever be persisted to disk. Note
* that any objects written to this source will be stored in memory, so the
* number of objects you can store is limited by available system memory.
*/
struct odb_source_inmemory {
struct odb_source base;
struct oidtree *objects;
};
/* Create a new in-memory object database source. */
struct odb_source_inmemory *odb_source_inmemory_new(struct object_database *odb);
/*
* Cast the given object database source to the in-memory backend. This will
* cause a BUG in case the source doesn't use this backend.
*/
static inline struct odb_source_inmemory *odb_source_inmemory_downcast(struct odb_source *source)
{
if (source->type != ODB_SOURCE_INMEMORY)
BUG("trying to downcast source of type '%s' to '%s'",
odb_source_type_to_name(source->type),
odb_source_type_to_name(ODB_SOURCE_INMEMORY));
return container_of(source, struct odb_source_inmemory, base);
}
#endif