struct odb_source_files *files;
CALLOC_ARRAY(files, 1);
- odb_source_init(&files->base, odb, path, local);
+ odb_source_init(&files->base, odb, ODB_SOURCE_FILES, path, local);
files->loose = odb_source_loose_new(&files->base);
files->packed = packfile_store_new(&files->base);
void odb_source_files_free(struct odb_source_files *files);
/*
- * Cast the given object database source to the files backend.
+ * 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 '%d' to files", source->type);
return container_of(source, struct odb_source_files, base);
}
void odb_source_init(struct odb_source *source,
struct object_database *odb,
+ enum odb_source_type type,
const char *path,
bool local)
{
source->odb = odb;
+ source->type = type;
source->local = local;
source->path = xstrdup(path);
}
#ifndef ODB_SOURCE_H
#define ODB_SOURCE_H
+enum odb_source_type {
+ /*
+ * The "unknown" type, which should never be in use. This type mostly
+ * exists to catch cases where the type field remains zeroed out.
+ */
+ ODB_SOURCE_UNKNOWN,
+
+ /* The "files" backend that uses loose objects and packfiles. */
+ ODB_SOURCE_FILES,
+};
+
/*
* The source is the part of the object database that stores the actual
* objects. It thus encapsulates the logic to read and write the specific
/* Object database that owns this object source. */
struct object_database *odb;
+ /* The type used by this source. */
+ enum odb_source_type type;
+
/*
* Figure out whether this is the local source of the owning
* repository, which would typically be its ".git/objects" directory.
*/
void odb_source_init(struct odb_source *source,
struct object_database *odb,
+ enum odb_source_type type,
const char *path,
bool local);