mirror of
https://github.com/git/git.git
synced 2026-06-30 19:58:12 +00:00
Next to our typical object database sources, each object database also
has an implicit source of "cached" objects. These cached objects only
exist in memory and some use cases:
- They contain evergreen objects that we expect to always exist, like
for example the empty tree.
- They can be used to store temporary objects that we don't want to
persist to disk, which is used by git-blame(1) to create a fake
worktree commit.
Overall, their use is somewhat restricted though. For example, we don't
provide the ability to use it as a temporary object database source that
allows the user to write objects, but discard them after Git exists. So
while these cached objects behave almost like a source, they aren't used
as one.
This is about to change over the following commits, where we will turn
cached objects into a new "in-memory" source. This will allow us to use
it exactly the same as any other source by providing the same common
interface as the "files" source.
For now, the in-memory source only hosts the cached objects and doesn't
provide any logic yet. This will change with subsequent commits, where
we move respective functionality into the source.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
36 lines
1.1 KiB
C
36 lines
1.1 KiB
C
#ifndef ODB_SOURCE_INMEMORY_H
|
|
#define ODB_SOURCE_INMEMORY_H
|
|
|
|
#include "odb/source.h"
|
|
|
|
struct cached_object_entry;
|
|
|
|
/*
|
|
* 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 cached_object_entry *objects;
|
|
size_t objects_nr, objects_alloc;
|
|
};
|
|
|
|
/* 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 '%d' to in-memory", source->type);
|
|
return container_of(source, struct odb_source_inmemory, base);
|
|
}
|
|
|
|
#endif
|