1#ifndef OBJECT_STORE_H 2#define OBJECT_STORE_H 3 4#include"oidmap.h" 5 6struct alternate_object_database { 7struct alternate_object_database *next; 8 9/* see alt_scratch_buf() */ 10struct strbuf scratch; 11size_t base_len; 12 13/* 14 * Used to store the results of readdir(3) calls when searching 15 * for unique abbreviated hashes. This cache is never 16 * invalidated, thus it's racy and not necessarily accurate. 17 * That's fine for its purpose; don't use it for tasks requiring 18 * greater accuracy! 19 */ 20char loose_objects_subdir_seen[256]; 21struct oid_array loose_objects_cache; 22 23/* 24 * Path to the alternative object store. If this is a relative path, 25 * it is relative to the current working directory. 26 */ 27char path[FLEX_ARRAY]; 28}; 29voidprepare_alt_odb(struct repository *r); 30char*compute_alternate_path(const char*path,struct strbuf *err); 31typedefintalt_odb_fn(struct alternate_object_database *,void*); 32intforeach_alt_odb(alt_odb_fn,void*); 33 34/* 35 * Allocate a "struct alternate_object_database" but do _not_ actually 36 * add it to the list of alternates. 37 */ 38struct alternate_object_database *alloc_alt_odb(const char*dir); 39 40/* 41 * Add the directory to the on-disk alternates file; the new entry will also 42 * take effect in the current process. 43 */ 44voidadd_to_alternates_file(const char*dir); 45 46/* 47 * Add the directory to the in-memory list of alternates (along with any 48 * recursive alternates it points to), but do not modify the on-disk alternates 49 * file. 50 */ 51voidadd_to_alternates_memory(const char*dir); 52 53/* 54 * Returns a scratch strbuf pre-filled with the alternate object directory, 55 * including a trailing slash, which can be used to access paths in the 56 * alternate. Always use this over direct access to alt->scratch, as it 57 * cleans up any previous use of the scratch buffer. 58 */ 59struct strbuf *alt_scratch_buf(struct alternate_object_database *alt); 60 61struct packed_git { 62struct packed_git *next; 63struct list_head mru; 64struct pack_window *windows; 65 off_t pack_size; 66const void*index_data; 67size_t index_size; 68uint32_t num_objects; 69uint32_t num_bad_objects; 70unsigned char*bad_object_sha1; 71int index_version; 72time_t mtime; 73int pack_fd; 74int index;/* for builtin/pack-objects.c */ 75unsigned pack_local:1, 76 pack_keep:1, 77 pack_keep_in_core:1, 78 freshened:1, 79 do_not_close:1, 80 pack_promisor:1; 81unsigned char sha1[20]; 82struct revindex_entry *revindex; 83/* something like ".git/objects/pack/xxxxx.pack" */ 84char pack_name[FLEX_ARRAY];/* more */ 85}; 86 87struct raw_object_store { 88/* 89 * Path to the repository's object store. 90 * Cannot be NULL after initialization. 91 */ 92char*objectdir; 93 94/* Path to extra alternate object database if not NULL */ 95char*alternate_db; 96 97struct alternate_object_database *alt_odb_list; 98struct alternate_object_database **alt_odb_tail; 99 100/* 101 * Objects that should be substituted by other objects 102 * (see git-replace(1)). 103 */ 104struct oidmap *replace_map; 105 106/* 107 * private data 108 * 109 * should only be accessed directly by packfile.c 110 */ 111 112struct packed_git *packed_git; 113/* A most-recently-used ordered version of the packed_git list. */ 114struct list_head packed_git_mru; 115 116/* 117 * A fast, rough count of the number of objects in the repository. 118 * These two fields are not meant for direct access. Use 119 * approximate_object_count() instead. 120 */ 121unsigned long approximate_object_count; 122unsigned approximate_object_count_valid :1; 123 124/* 125 * Whether packed_git has already been populated with this repository's 126 * packs. 127 */ 128unsigned packed_git_initialized :1; 129}; 130 131struct raw_object_store *raw_object_store_new(void); 132voidraw_object_store_clear(struct raw_object_store *o); 133 134/* 135 * Put in `buf` the name of the file in the local object database that 136 * would be used to store a loose object with the specified sha1. 137 */ 138voidsha1_file_name(struct repository *r,struct strbuf *buf,const unsigned char*sha1); 139 140void*map_sha1_file(struct repository *r,const unsigned char*sha1,unsigned long*size); 141 142externvoid*read_object_file_extended(const struct object_id *oid, 143enum object_type *type, 144unsigned long*size,int lookup_replace); 145staticinlinevoid*read_object_file(const struct object_id *oid,enum object_type *type,unsigned long*size) 146{ 147returnread_object_file_extended(oid, type, size,1); 148} 149 150/* Read and unpack an object file into memory, write memory to an object file */ 151intoid_object_info(struct repository *r,const struct object_id *,unsigned long*); 152 153externinthash_object_file(const void*buf,unsigned long len, 154const char*type,struct object_id *oid); 155 156externintwrite_object_file(const void*buf,unsigned long len, 157const char*type,struct object_id *oid); 158 159externinthash_object_file_literally(const void*buf,unsigned long len, 160const char*type,struct object_id *oid, 161unsigned flags); 162 163externintpretend_object_file(void*,unsigned long,enum object_type, 164struct object_id *oid); 165 166externintforce_object_loose(const struct object_id *oid,time_t mtime); 167 168/* 169 * Open the loose object at path, check its hash, and return the contents, 170 * type, and size. If the object is a blob, then "contents" may return NULL, 171 * to allow streaming of large blobs. 172 * 173 * Returns 0 on success, negative on error (details may be written to stderr). 174 */ 175intread_loose_object(const char*path, 176const struct object_id *expected_oid, 177enum object_type *type, 178unsigned long*size, 179void**contents); 180 181/* 182 * Convenience for sha1_object_info_extended() with a NULL struct 183 * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass 184 * nonzero flags to also set other flags. 185 */ 186externinthas_sha1_file_with_flags(const unsigned char*sha1,int flags); 187staticinlineinthas_sha1_file(const unsigned char*sha1) 188{ 189returnhas_sha1_file_with_flags(sha1,0); 190} 191 192/* Same as the above, except for struct object_id. */ 193externinthas_object_file(const struct object_id *oid); 194externinthas_object_file_with_flags(const struct object_id *oid,int flags); 195 196/* 197 * Return true iff an alternate object database has a loose object 198 * with the specified name. This function does not respect replace 199 * references. 200 */ 201externinthas_loose_object_nonlocal(const struct object_id *); 202 203externvoidassert_oid_type(const struct object_id *oid,enum object_type expect); 204 205struct object_info { 206/* Request */ 207enum object_type *typep; 208unsigned long*sizep; 209 off_t *disk_sizep; 210unsigned char*delta_base_sha1; 211struct strbuf *type_name; 212void**contentp; 213 214/* Response */ 215enum{ 216 OI_CACHED, 217 OI_LOOSE, 218 OI_PACKED, 219 OI_DBCACHED 220} whence; 221union{ 222/* 223 * struct { 224 * ... Nothing to expose in this case 225 * } cached; 226 * struct { 227 * ... Nothing to expose in this case 228 * } loose; 229 */ 230struct{ 231struct packed_git *pack; 232 off_t offset; 233unsigned int is_delta; 234} packed; 235} u; 236}; 237 238/* 239 * Initializer for a "struct object_info" that wants no items. You may 240 * also memset() the memory to all-zeroes. 241 */ 242#define OBJECT_INFO_INIT {NULL} 243 244/* Invoke lookup_replace_object() on the given hash */ 245#define OBJECT_INFO_LOOKUP_REPLACE 1 246/* Allow reading from a loose object file of unknown/bogus type */ 247#define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2 248/* Do not check cached storage */ 249#define OBJECT_INFO_SKIP_CACHED 4 250/* Do not retry packed storage after checking packed and loose storage */ 251#define OBJECT_INFO_QUICK 8 252/* Do not check loose object */ 253#define OBJECT_INFO_IGNORE_LOOSE 16 254 255intoid_object_info_extended(struct repository *r, 256const struct object_id *, 257struct object_info *,unsigned flags); 258 259#endif/* OBJECT_STORE_H */