interplane.Get Omega
Read in your language

git

[Ported from github.com/git/git] Sync with Git 2.56.1

Brought by drakestapleton

branch master Branches Tags History

git / odb / source.c

66 lines · 1485 bytes Raw Blame History
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
7static 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
15const 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
26struct odb_source *odb_source_new(struct object_database *odb,
27 enum object_storage_format format,
28 const char *payload,
29 enum odb_new_flags flags)
30{
31 struct odb_source *source;
32
33 switch (format) {
34 case OBJECT_STORAGE_FORMAT_FILES:
35 source = &odb_source_files_new(odb, payload, flags)->base;
36 break;
37 default:
38 BUG("unknown object storage format");
39 }
40
41 return source;
42}
43
44void odb_source_init(struct odb_source *source,
45 struct object_database *odb,
46 enum odb_source_type type,
47 const char *path)
48{
49 source->odb = odb;
50 source->type = type;
51 source->path = xstrdup(path);
52}
53
54void odb_source_free(struct odb_source *source)
55{
56 if (!source)
57 return;
58 source->free(source);
59}
60
61void odb_source_release(struct odb_source *source)
62{
63 if (!source)
64 return;
65 free(source->path);
66}