Line | Count | Source |
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] = "in-memory", |
13 | | }; |
14 | | |
15 | | const char *odb_source_type_to_name(enum odb_source_type type) |
16 | 0 | { |
17 | 0 | const char *name; |
18 | 0 | if (type < 0 || type >= ARRAY_SIZE(odb_source_names_by_type)) |
19 | 0 | type = ODB_SOURCE_UNKNOWN; |
20 | 0 | name = odb_source_names_by_type[type]; |
21 | 0 | if (!name) |
22 | 0 | BUG("name missing in `odb_source_names_by_type` for '%d'", type); |
23 | 0 | return name; |
24 | 0 | } |
25 | | |
26 | | struct odb_source *odb_source_new(struct object_database *odb, |
27 | | const char *path, |
28 | | bool local) |
29 | 0 | { |
30 | 0 | return &odb_source_files_new(odb, path, local)->base; |
31 | 0 | } |
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 | 0 | { |
39 | 0 | source->odb = odb; |
40 | 0 | source->type = type; |
41 | 0 | source->local = local; |
42 | 0 | source->path = xstrdup(path); |
43 | 0 | } |
44 | | |
45 | | void odb_source_free(struct odb_source *source) |
46 | 0 | { |
47 | 0 | if (!source) |
48 | 0 | return; |
49 | 0 | source->free(source); |
50 | 0 | } |
51 | | |
52 | | void odb_source_release(struct odb_source *source) |
53 | 0 | { |
54 | 0 | if (!source) |
55 | 0 | return; |
56 | 0 | free(source->path); |
57 | 0 | } |