summaryrefslogtreecommitdiff
path: root/odb/source-loose.h
blob: 3cf2e1f8f1d5e2a78109b154ddd18b9a287e068d (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
#ifndef ODB_SOURCE_LOOSE_H
#define ODB_SOURCE_LOOSE_H

#include "odb/source.h"

struct odb_source_files;
struct object_database;
struct oidtree;

/*
 * An object database source that stores its objects in loose format, one
 * file per object.
 */
struct odb_source_loose {
	struct odb_source base;

	/*
	 * Used to store the results of readdir(3) calls when we are OK
	 * sacrificing accuracy due to races for speed. That includes
	 * object existence with OBJECT_INFO_QUICK, as well as
	 * our search for unique abbreviated hashes. Don't use it for tasks
	 * requiring greater accuracy!
	 *
	 * Be sure to call odb_load_loose_cache() before using.
	 */
	uint32_t subdir_seen[8]; /* 256 bits */
	struct oidtree *cache;

	/* Map between object IDs for loose objects. */
	struct loose_object_map *map;
};

struct odb_source_loose *odb_source_loose_new(struct object_database *odb,
					      const char *path,
					      bool local);

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

#endif