| 1 | #include "git-compat-util.h" |
| 2 | #include "object-file.h" |
| 3 | #include "odb/source-files.h" |
| 4 | #include "odb/source.h" |
| 5 | #include "packfile.h" |
| 6 | |
| 7 | static const char * const odb_source_names_by_type[] = { |
| 8 | [ODB_SOURCE_UNKNOWN] = "unknown", |
| 9 | [ODB_SOURCE_FILES] = "files", |
| 10 | [ODB_SOURCE_LOOSE] = "loose", |
| 11 | [ODB_SOURCE_PACKED] = "packed", |
| 12 | [ODB_SOURCE_INMEMORY] = "inmemory", |
| 13 | }; |
| 14 | |
| 15 | const char *odb_source_type_to_name(enum odb_source_type type) |
| 16 | { |
| 17 | const char *name; |
| 18 | if (type < 0 || type >= ARRAY_SIZE(odb_source_names_by_type)) |
| 19 | type = ODB_SOURCE_UNKNOWN; |
| 20 | name = odb_source_names_by_type[type]; |
| 21 | if (!name) |
| 22 | BUG("name missing in `odb_source_names_by_type` for '%d'", type); |
| 23 | return name; |
| 24 | } |
| 25 | |
| 26 | struct odb_source *odb_source_new(struct object_database *odb, |
| 27 | const char *path, |
| 28 | bool local) |
| 29 | { |
| 30 | return &odb_source_files_new(odb, path, local)->base; |
| 31 | } |
| 32 | |
| 33 | void odb_source_init(struct odb_source *source, |
| 34 | struct object_database *odb, |
| 35 | enum odb_source_type type, |
| 36 | const char *path, |
| 37 | bool local) |
| 38 | { |
| 39 | source->odb = odb; |
| 40 | source->type = type; |
| 41 | source->local = local; |
| 42 | source->path = xstrdup(path); |
| 43 | } |
| 44 | |
| 45 | void odb_source_free(struct odb_source *source) |
| 46 | { |
| 47 | if (!source) |
| 48 | return; |
| 49 | source->free(source); |
| 50 | } |
| 51 | |
| 52 | void odb_source_release(struct odb_source *source) |
| 53 | { |
| 54 | if (!source) |
| 55 | return; |
| 56 | free(source->path); |
| 57 | } |