Raw
1 #ifndef ODB_SOURCE_FILES_H
2 #define ODB_SOURCE_FILES_H
3
4 #include "odb/source.h"
5
6 struct odb_source_loose;
7 struct odb_source_packed;
8
9 /*
10 * The files object database source uses a combination of loose objects and
11 * packfiles. It is the default backend used by Git to store objects.
12 */
13 struct odb_source_files {
14 struct odb_source base;
15 struct odb_source_loose *loose;
16 struct odb_source_packed *packed;
17 };
18
19 /* Allocate and initialize a new object source. */
20 struct odb_source_files *odb_source_files_new(struct object_database *odb,
21 const char *path,
22 bool local);
23
24 /*
25 * Optimize the files object database source by repacking loose objects and
26 * packfiles as needed. Returns 0 on success, a negative error code otherwise.
27 */
28 int odb_source_files_optimize(struct odb_source *source,
29 const struct odb_optimize_options *opts);
30
31 /*
32 * Check whether optimization of the files object database source is required
33 * given the provided options. Returns true if optimization should be
34 * performed, false otherwise.
35 */
36 bool odb_source_files_optimize_required(struct odb_source *source,
37 const struct odb_optimize_options *opts);
38
39 /*
40 * Cast the given object database source to the files backend. This will cause
41 * a BUG in case the source doesn't use this backend.
42 */
43 static inline struct odb_source_files *odb_source_files_downcast(struct odb_source *source)
44 {
45 if (source->type != ODB_SOURCE_FILES)
46 BUG("trying to downcast source of type '%s' to '%s'",
47 odb_source_type_to_name(source->type),
48 odb_source_type_to_name(ODB_SOURCE_FILES));
49 return container_of(source, struct odb_source_files, base);
50 }
51
52 #endif