Files
Junio C Hamano 32d7b72031 Merge branch 'ps/odb-object-storage-extension' into next
The object storage format has been made configurable via the
'extensions.objectStorage' configuration variable, allowing users
to specify the storage backend and an optional payload, mirroring
the design of 'extensions.refStorage'.

* ps/odb-object-storage-extension:
  builtin/submodule: propagate "--object-storage-format="
  builtin/clone: introduce "--object-storage-format="
  builtin/init: introduce handling of object storage format
  builtin: expose the object storage format
  setup: allow overriding object storage format via environment
  setup: introduce object storage extension
  loose: drop unused `repo_write_loose_object_map()`
2026-11-01 09:26:57 -08:00

67 lines
1.5 KiB
C

#include "git-compat-util.h"
#include "object-file.h"
#include "odb/source-files.h"
#include "odb/source.h"
#include "packfile.h"
static const char * const odb_source_names_by_type[] = {
[ODB_SOURCE_UNKNOWN] = "unknown",
[ODB_SOURCE_FILES] = "files",
[ODB_SOURCE_LOOSE] = "loose",
[ODB_SOURCE_PACKED] = "packed",
[ODB_SOURCE_INMEMORY] = "in-memory",
};
const char *odb_source_type_to_name(enum odb_source_type type)
{
const char *name;
if (type < 0 || type >= ARRAY_SIZE(odb_source_names_by_type))
type = ODB_SOURCE_UNKNOWN;
name = odb_source_names_by_type[type];
if (!name)
BUG("name missing in `odb_source_names_by_type` for '%d'", type);
return name;
}
struct odb_source *odb_source_new(struct object_database *odb,
enum object_storage_format format,
const char *payload,
enum odb_new_flags flags)
{
struct odb_source *source;
switch (format) {
case OBJECT_STORAGE_FORMAT_FILES:
source = &odb_source_files_new(odb, payload, flags)->base;
break;
default:
BUG("unknown object storage format");
}
return source;
}
void odb_source_init(struct odb_source *source,
struct object_database *odb,
enum odb_source_type type,
const char *path)
{
source->odb = odb;
source->type = type;
source->path = xstrdup(path);
}
void odb_source_free(struct odb_source *source)
{
if (!source)
return;
source->free(source);
}
void odb_source_release(struct odb_source *source)
{
if (!source)
return;
free(source->path);
}