1#ifndef OBJECT_STORE_H 2#define OBJECT_STORE_H 3 4struct alternate_object_database { 5 struct alternate_object_database *next; 6 7 /* see alt_scratch_buf() */ 8 struct strbuf scratch; 9 size_t base_len; 10 11 /* 12 * Used to store the results of readdir(3) calls when searching 13 * for unique abbreviated hashes. This cache is never 14 * invalidated, thus it's racy and not necessarily accurate. 15 * That's fine for its purpose; don't use it for tasks requiring 16 * greater accuracy! 17 */ 18 char loose_objects_subdir_seen[256]; 19 struct oid_array loose_objects_cache; 20 21 /* 22 * Path to the alternative object store. If this is a relative path, 23 * it is relative to the current working directory. 24 */ 25 char path[FLEX_ARRAY]; 26}; 27#define prepare_alt_odb(r) prepare_alt_odb_##r() 28void prepare_alt_odb_the_repository(void); 29char *compute_alternate_path(const char *path, struct strbuf *err); 30typedef int alt_odb_fn(struct alternate_object_database *, void *); 31int foreach_alt_odb(alt_odb_fn, void*); 32 33/* 34 * Allocate a "struct alternate_object_database" but do _not_ actually 35 * add it to the list of alternates. 36 */ 37struct alternate_object_database *alloc_alt_odb(const char *dir); 38 39/* 40 * Add the directory to the on-disk alternates file; the new entry will also 41 * take effect in the current process. 42 */ 43void add_to_alternates_file(const char *dir); 44 45/* 46 * Add the directory to the in-memory list of alternates (along with any 47 * recursive alternates it points to), but do not modify the on-disk alternates 48 * file. 49 */ 50void add_to_alternates_memory(const char *dir); 51 52/* 53 * Returns a scratch strbuf pre-filled with the alternate object directory, 54 * including a trailing slash, which can be used to access paths in the 55 * alternate. Always use this over direct access to alt->scratch, as it 56 * cleans up any previous use of the scratch buffer. 57 */ 58struct strbuf *alt_scratch_buf(struct alternate_object_database *alt); 59 60struct packed_git { 61 struct packed_git *next; 62 struct list_head mru; 63 struct pack_window *windows; 64 off_t pack_size; 65 const void *index_data; 66 size_t index_size; 67 uint32_t num_objects; 68 uint32_t num_bad_objects; 69 unsigned char *bad_object_sha1; 70 int index_version; 71 time_t mtime; 72 int pack_fd; 73 unsigned pack_local:1, 74 pack_keep:1, 75 freshened:1, 76 do_not_close:1, 77 pack_promisor:1; 78 unsigned char sha1[20]; 79 struct revindex_entry *revindex; 80 /* something like ".git/objects/pack/xxxxx.pack" */ 81 char pack_name[FLEX_ARRAY]; /* more */ 82}; 83 84struct raw_object_store { 85 /* 86 * Path to the repository's object store. 87 * Cannot be NULL after initialization. 88 */ 89 char *objectdir; 90 91 /* Path to extra alternate object database if not NULL */ 92 char *alternate_db; 93 94 struct alternate_object_database *alt_odb_list; 95 struct alternate_object_database **alt_odb_tail; 96 97 /* 98 * private data 99 * 100 * should only be accessed directly by packfile.c 101 */ 102 103 struct packed_git *packed_git; 104 /* A most-recently-used ordered version of the packed_git list. */ 105 struct list_head packed_git_mru; 106 107 /* 108 * A fast, rough count of the number of objects in the repository. 109 * These two fields are not meant for direct access. Use 110 * approximate_object_count() instead. 111 */ 112 unsigned long approximate_object_count; 113 unsigned approximate_object_count_valid : 1; 114 115 /* 116 * Whether packed_git has already been populated with this repository's 117 * packs. 118 */ 119 unsigned packed_git_initialized : 1; 120}; 121 122struct raw_object_store *raw_object_store_new(void); 123void raw_object_store_clear(struct raw_object_store *o); 124 125#endif /* OBJECT_STORE_H */