7 #include "sha1-array.h"
10 struct object_directory {
11 struct object_directory *next;
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
20 char loose_objects_subdir_seen[256];
21 struct oid_array loose_objects_cache;
24 * Path to the alternative object store. If this is a relative path,
25 * it is relative to the current working directory.
27 char path[FLEX_ARRAY];
29 void prepare_alt_odb(struct repository *r);
30 char *compute_alternate_path(const char *path, struct strbuf *err);
31 typedef int alt_odb_fn(struct object_directory *, void *);
32 int foreach_alt_odb(alt_odb_fn, void*);
35 * Allocate a "struct alternate_object_database" but do _not_ actually
36 * add it to the list of alternates.
38 struct object_directory *alloc_alt_odb(const char *dir);
41 * Add the directory to the on-disk alternates file; the new entry will also
42 * take effect in the current process.
44 void add_to_alternates_file(const char *dir);
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
51 void add_to_alternates_memory(const char *dir);
54 struct packed_git *next;
56 struct pack_window *windows;
58 const void *index_data;
61 uint32_t num_bad_objects;
62 unsigned char *bad_object_sha1;
66 int index; /* for builtin/pack-objects.c */
67 unsigned pack_local:1,
73 unsigned char sha1[20];
74 struct revindex_entry *revindex;
75 /* something like ".git/objects/pack/xxxxx.pack" */
76 char pack_name[FLEX_ARRAY]; /* more */
79 struct multi_pack_index;
81 struct raw_object_store {
83 * Path to the repository's object store.
84 * Cannot be NULL after initialization.
88 /* Path to extra alternate object database if not NULL */
91 struct object_directory *alt_odb_list;
92 struct object_directory **alt_odb_tail;
95 * Objects that should be substituted by other objects
96 * (see git-replace(1)).
98 struct oidmap *replace_map;
100 struct commit_graph *commit_graph;
101 unsigned commit_graph_attempted : 1; /* if loading has been attempted */
106 * should only be accessed directly by packfile.c and midx.c
108 struct multi_pack_index *multi_pack_index;
113 * should only be accessed directly by packfile.c
116 struct packed_git *packed_git;
117 /* A most-recently-used ordered version of the packed_git list. */
118 struct list_head packed_git_mru;
121 * A linked list containing all packfiles, starting with those
122 * contained in the multi_pack_index.
124 struct packed_git *all_packs;
127 * A fast, rough count of the number of objects in the repository.
128 * These two fields are not meant for direct access. Use
129 * approximate_object_count() instead.
131 unsigned long approximate_object_count;
132 unsigned approximate_object_count_valid : 1;
135 * Whether packed_git has already been populated with this repository's
138 unsigned packed_git_initialized : 1;
141 struct raw_object_store *raw_object_store_new(void);
142 void raw_object_store_clear(struct raw_object_store *o);
145 * Put in `buf` the name of the file in the local object database that
146 * would be used to store a loose object with the specified sha1.
148 const char *loose_object_path(struct repository *r, struct strbuf *buf, const unsigned char *sha1);
150 void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
152 extern void *read_object_file_extended(const struct object_id *oid,
153 enum object_type *type,
154 unsigned long *size, int lookup_replace);
155 static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
157 return read_object_file_extended(oid, type, size, 1);
160 /* Read and unpack an object file into memory, write memory to an object file */
161 int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
163 extern int hash_object_file(const void *buf, unsigned long len,
164 const char *type, struct object_id *oid);
166 extern int write_object_file(const void *buf, unsigned long len,
167 const char *type, struct object_id *oid);
169 extern int hash_object_file_literally(const void *buf, unsigned long len,
170 const char *type, struct object_id *oid,
173 extern int pretend_object_file(void *, unsigned long, enum object_type,
174 struct object_id *oid);
176 extern int force_object_loose(const struct object_id *oid, time_t mtime);
179 * Open the loose object at path, check its hash, and return the contents,
180 * type, and size. If the object is a blob, then "contents" may return NULL,
181 * to allow streaming of large blobs.
183 * Returns 0 on success, negative on error (details may be written to stderr).
185 int read_loose_object(const char *path,
186 const struct object_id *expected_oid,
187 enum object_type *type,
192 * Convenience for sha1_object_info_extended() with a NULL struct
193 * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
194 * nonzero flags to also set other flags.
196 extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
197 static inline int has_sha1_file(const unsigned char *sha1)
199 return has_sha1_file_with_flags(sha1, 0);
202 /* Same as the above, except for struct object_id. */
203 extern int has_object_file(const struct object_id *oid);
204 extern int has_object_file_with_flags(const struct object_id *oid, int flags);
207 * Return true iff an alternate object database has a loose object
208 * with the specified name. This function does not respect replace
211 extern int has_loose_object_nonlocal(const struct object_id *);
213 extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
217 enum object_type *typep;
218 unsigned long *sizep;
220 unsigned char *delta_base_sha1;
221 struct strbuf *type_name;
234 * ... Nothing to expose in this case
237 * ... Nothing to expose in this case
241 struct packed_git *pack;
243 unsigned int is_delta;
249 * Initializer for a "struct object_info" that wants no items. You may
250 * also memset() the memory to all-zeroes.
252 #define OBJECT_INFO_INIT {NULL}
254 /* Invoke lookup_replace_object() on the given hash */
255 #define OBJECT_INFO_LOOKUP_REPLACE 1
256 /* Allow reading from a loose object file of unknown/bogus type */
257 #define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
258 /* Do not check cached storage */
259 #define OBJECT_INFO_SKIP_CACHED 4
260 /* Do not retry packed storage after checking packed and loose storage */
261 #define OBJECT_INFO_QUICK 8
262 /* Do not check loose object */
263 #define OBJECT_INFO_IGNORE_LOOSE 16
265 int oid_object_info_extended(struct repository *r,
266 const struct object_id *,
267 struct object_info *, unsigned flags);
270 * Iterate over the files in the loose-object parts of the object
271 * directory "path", triggering the following callbacks:
273 * - loose_object is called for each loose object we find.
275 * - loose_cruft is called for any files that do not appear to be
276 * loose objects. Note that we only look in the loose object
277 * directories "objects/[0-9a-f]{2}/", so we will not report
278 * "objects/foobar" as cruft.
280 * - loose_subdir is called for each top-level hashed subdirectory
281 * of the object directory (e.g., "$OBJDIR/f0"). It is called
282 * after the objects in the directory are processed.
284 * Any callback that is NULL will be ignored. Callbacks returning non-zero
285 * will end the iteration.
287 * In the "buf" variant, "path" is a strbuf which will also be used as a
288 * scratch buffer, but restored to its original contents before
289 * the function returns.
291 typedef int each_loose_object_fn(const struct object_id *oid,
294 typedef int each_loose_cruft_fn(const char *basename,
297 typedef int each_loose_subdir_fn(unsigned int nr,
300 int for_each_file_in_obj_subdir(unsigned int subdir_nr,
302 each_loose_object_fn obj_cb,
303 each_loose_cruft_fn cruft_cb,
304 each_loose_subdir_fn subdir_cb,
306 int for_each_loose_file_in_objdir(const char *path,
307 each_loose_object_fn obj_cb,
308 each_loose_cruft_fn cruft_cb,
309 each_loose_subdir_fn subdir_cb,
311 int for_each_loose_file_in_objdir_buf(struct strbuf *path,
312 each_loose_object_fn obj_cb,
313 each_loose_cruft_fn cruft_cb,
314 each_loose_subdir_fn subdir_cb,
317 /* Flags for for_each_*_object() below. */
318 enum for_each_object_flags {
319 /* Iterate only over local objects, not alternates. */
320 FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
322 /* Only iterate over packs obtained from the promisor remote. */
323 FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
326 * Visit objects within a pack in packfile order rather than .idx order
328 FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
332 * Iterate over all accessible loose objects without respect to
333 * reachability. By default, this includes both local and alternate objects.
334 * The order in which objects are visited is unspecified.
336 * Any flags specific to packs are ignored.
338 int for_each_loose_object(each_loose_object_fn, void *,
339 enum for_each_object_flags flags);
342 * Iterate over all accessible packed objects without respect to reachability.
343 * By default, this includes both local and alternate packs.
345 * Note that some objects may appear twice if they are found in multiple packs.
346 * Each pack is visited in an unspecified order. By default, objects within a
347 * pack are visited in pack-idx order (i.e., sorted by oid).
349 typedef int each_packed_object_fn(const struct object_id *oid,
350 struct packed_git *pack,
353 int for_each_object_in_pack(struct packed_git *p,
354 each_packed_object_fn, void *data,
355 enum for_each_object_flags flags);
356 int for_each_packed_object(each_packed_object_fn, void *,
357 enum for_each_object_flags flags);
359 #endif /* OBJECT_STORE_H */