Files
git/odb/source-files.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

38 lines
1.1 KiB
C

#ifndef ODB_SOURCE_FILES_H
#define ODB_SOURCE_FILES_H
#include "odb/source.h"
struct odb_source_loose;
struct odb_source_packed;
/*
* The files object database source uses a combination of loose objects and
* packfiles. It is the default backend used by Git to store objects.
*/
struct odb_source_files {
struct odb_source base;
struct odb_source_loose *loose;
struct odb_source_packed *packed;
};
/* Allocate and initialize a new object source. */
struct odb_source_files *odb_source_files_new(struct object_database *odb,
const char *path,
bool local);
/*
* Cast the given object database source to the files backend. This will cause
* a BUG in case the source doesn't use this backend.
*/
static inline struct odb_source_files *odb_source_files_downcast(struct odb_source *source)
{
if (source->type != ODB_SOURCE_FILES)
BUG("trying to downcast source of type '%s' to '%s'",
odb_source_type_to_name(source->type),
odb_source_type_to_name(ODB_SOURCE_FILES));
return container_of(source, struct odb_source_files, base);
}
#endif