summaryrefslogtreecommitdiff
path: root/odb/source-files.h
blob: 9630b5f962e15f61ac9c36cd0dac8f21f133fc95 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef ODB_SOURCE_FILES_H
#define ODB_SOURCE_FILES_H

#include "odb/source.h"

struct odb_source_loose;
struct odb_source_packed;

/*
 * The files object database source uses a combination of loose objects and
 * packfiles. It is the default backend used by Git to store objects.
 */
struct odb_source_files {
	struct odb_source base;
	struct odb_source_loose *loose;
	struct odb_source_packed *packed;
};

/* Allocate and initialize a new object source. */
struct odb_source_files *odb_source_files_new(struct object_database *odb,
					      const char *path,
					      bool local);

/*
 * Optimize the files object database source by repacking loose objects and
 * packfiles as needed. Returns 0 on success, a negative error code otherwise.
 */
int odb_source_files_optimize(struct odb_source *source,
			      const struct odb_optimize_options *opts);

/*
 * Check whether optimization of the files object database source is required
 * given the provided options. Returns true if optimization should be
 * performed, false otherwise.
 */
bool odb_source_files_optimize_required(struct odb_source *source,
					const struct odb_optimize_options *opts);

/*
 * Cast the given object database source to the files backend. This will cause
 * a BUG in case the source doesn't use this backend.
 */
static inline struct odb_source_files *odb_source_files_downcast(struct odb_source *source)
{
	if (source->type != ODB_SOURCE_FILES)
		BUG("trying to downcast source of type '%s' to '%s'",
		    odb_source_type_to_name(source->type),
		    odb_source_type_to_name(ODB_SOURCE_FILES));
	return container_of(source, struct odb_source_files, base);
}

#endif