| 1 | #ifndef ODB_SOURCE_LOOSE_H |
| 2 | #define ODB_SOURCE_LOOSE_H |
| 3 | |
| 4 | #include "odb/source.h" |
| 5 | |
| 6 | struct odb_source_files; |
| 7 | struct object_database; |
| 8 | struct oidtree; |
| 9 | |
| 10 | /* |
| 11 | * An object database source that stores its objects in loose format, one |
| 12 | * file per object. |
| 13 | */ |
| 14 | struct odb_source_loose { |
| 15 | struct odb_source base; |
| 16 | |
| 17 | /* |
| 18 | * Used to store the results of readdir(3) calls when we are OK |
| 19 | * sacrificing accuracy due to races for speed. That includes |
| 20 | * object existence with OBJECT_INFO_QUICK, as well as |
| 21 | * our search for unique abbreviated hashes. Don't use it for tasks |
| 22 | * requiring greater accuracy! |
| 23 | * |
| 24 | * Be sure to call odb_load_loose_cache() before using. |
| 25 | */ |
| 26 | uint32_t subdir_seen[8]; /* 256 bits */ |
| 27 | struct oidtree *cache; |
| 28 | |
| 29 | /* Map between object IDs for loose objects. */ |
| 30 | struct loose_object_map *map; |
| 31 | }; |
| 32 | |
| 33 | struct odb_source_loose *odb_source_loose_new(struct object_database *odb, |
| 34 | const char *path, |
| 35 | bool local); |
| 36 | |
| 37 | /* |
| 38 | * Cast the given object database source to the loose backend. This will cause |
| 39 | * a BUG in case the source doesn't use this backend. |
| 40 | */ |
| 41 | static inline struct odb_source_loose *odb_source_loose_downcast(struct odb_source *source) |
| 42 | { |
| 43 | if (source->type != ODB_SOURCE_LOOSE) |
| 44 | BUG("trying to downcast source of type '%d' to loose", source->type); |
| 45 | return container_of(source, struct odb_source_loose, base); |
| 46 | } |
| 47 | |
| 48 | #endif |