| 1 | #ifndef ODB_SOURCE_PACKED_H |
| 2 | #define ODB_SOURCE_PACKED_H |
| 3 | |
| 4 | #include "odb/source.h" |
| 5 | #include "packfile-list.h" |
| 6 | #include "strmap.h" |
| 7 | |
| 8 | /* |
| 9 | * A store that manages packfiles for a given object database. |
| 10 | */ |
| 11 | struct odb_source_packed { |
| 12 | struct odb_source base; |
| 13 | |
| 14 | /* |
| 15 | * The list of packfiles in the order in which they have been most |
| 16 | * recently used. |
| 17 | */ |
| 18 | struct packfile_list packs; |
| 19 | |
| 20 | /* |
| 21 | * Cache of packfiles which are marked as "kept", either because there |
| 22 | * is an on-disk ".keep" file or because they are marked as "kept" in |
| 23 | * memory. |
| 24 | * |
| 25 | * Should not be accessed directly, but via |
| 26 | * `packfile_store_get_kept_pack_cache()`. The list of packs gets |
| 27 | * invalidated when the stored flags and the flags passed to |
| 28 | * `packfile_store_get_kept_pack_cache()` mismatch. |
| 29 | */ |
| 30 | struct { |
| 31 | struct packed_git **packs; |
| 32 | unsigned flags; |
| 33 | } kept_cache; |
| 34 | |
| 35 | /* The multi-pack index that belongs to this specific packfile store. */ |
| 36 | struct multi_pack_index *midx; |
| 37 | |
| 38 | /* |
| 39 | * A map of packfile names to packed_git structs for tracking which |
| 40 | * packs have been loaded already. |
| 41 | */ |
| 42 | struct strmap packs_by_path; |
| 43 | |
| 44 | /* |
| 45 | * Whether packfiles have already been populated with this store's |
| 46 | * packs. |
| 47 | */ |
| 48 | bool initialized; |
| 49 | |
| 50 | /* |
| 51 | * Usually, packfiles will be reordered to the front of the `packs` |
| 52 | * list whenever an object is looked up via them. This has the effect |
| 53 | * that packs that contain a lot of accessed objects will be located |
| 54 | * towards the front. |
| 55 | * |
| 56 | * This is usually desirable, but there are exceptions. One exception |
| 57 | * is when the looking up multiple objects in a loop for each packfile. |
| 58 | * In that case, we may easily end up with an infinite loop as the |
| 59 | * packfiles get reordered to the front repeatedly. |
| 60 | * |
| 61 | * Setting this field to `true` thus disables these reorderings. |
| 62 | */ |
| 63 | bool skip_mru_updates; |
| 64 | }; |
| 65 | |
| 66 | /* |
| 67 | * Allocate and initialize a new empty packfile store for the given object |
| 68 | * database. |
| 69 | */ |
| 70 | struct odb_source_packed *odb_source_packed_new(struct object_database *odb, |
| 71 | const char *path, |
| 72 | bool local); |
| 73 | |
| 74 | /* |
| 75 | * Cast the given object database source to the packed backend. This will cause |
| 76 | * a BUG in case the source doesn't use this backend. |
| 77 | */ |
| 78 | static inline struct odb_source_packed *odb_source_packed_downcast(struct odb_source *source) |
| 79 | { |
| 80 | if (source->type != ODB_SOURCE_PACKED) |
| 81 | BUG("trying to downcast source of type '%s' to '%s'", |
| 82 | odb_source_type_to_name(source->type), |
| 83 | odb_source_type_to_name(ODB_SOURCE_PACKED)); |
| 84 | return container_of(source, struct odb_source_packed, base); |
| 85 | } |
| 86 | |
| 87 | #endif |