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.
30 void prepare_alt_odb(struct repository *r);
31 char *compute_alternate_path(const char *path, struct strbuf *err);
32 typedef int alt_odb_fn(struct object_directory *, void *);
33 int foreach_alt_odb(alt_odb_fn, void*);
36 * Add the directory to the on-disk alternates file; the new entry will also
37 * take effect in the current process.
39 void add_to_alternates_file(const char *dir);
42 * Add the directory to the in-memory list of alternates (along with any
43 * recursive alternates it points to), but do not modify the on-disk alternates
46 void add_to_alternates_memory(const char *dir);
49 struct packed_git *next;
51 struct pack_window *windows;
53 const void *index_data;
56 uint32_t num_bad_objects;
57 unsigned char *bad_object_sha1;
61 int index; /* for builtin/pack-objects.c */
62 unsigned pack_local:1,
68 unsigned char sha1[20];
69 struct revindex_entry *revindex;
70 /* something like ".git/objects/pack/xxxxx.pack" */
71 char pack_name[FLEX_ARRAY]; /* more */
74 struct multi_pack_index;
76 struct raw_object_store {
78 * Set of all object directories; the main directory is first (and
79 * cannot be NULL after initialization). Subsequent directories are
82 struct object_directory *odb;
83 struct object_directory **odb_tail;
84 int loaded_alternates;
87 * A list of alternate object directories loaded from the environment;
88 * this should not generally need to be accessed directly, but will
89 * populate the "odb" list when prepare_alt_odb() is run.
94 * Objects that should be substituted by other objects
95 * (see git-replace(1)).
97 struct oidmap *replace_map;
99 struct commit_graph *commit_graph;
100 unsigned commit_graph_attempted : 1; /* if loading has been attempted */
105 * should only be accessed directly by packfile.c and midx.c
107 struct multi_pack_index *multi_pack_index;
112 * should only be accessed directly by packfile.c
115 struct packed_git *packed_git;
116 /* A most-recently-used ordered version of the packed_git list. */
117 struct list_head packed_git_mru;
120 * A linked list containing all packfiles, starting with those
121 * contained in the multi_pack_index.
123 struct packed_git *all_packs;
126 * A fast, rough count of the number of objects in the repository.
127 * These two fields are not meant for direct access. Use
128 * approximate_object_count() instead.
130 unsigned long approximate_object_count;
131 unsigned approximate_object_count_valid : 1;
134 * Whether packed_git has already been populated with this repository's
137 unsigned packed_git_initialized : 1;
140 struct raw_object_store *raw_object_store_new(void);
141 void raw_object_store_clear(struct raw_object_store *o);
144 * Put in `buf` the name of the file in the local object database that
145 * would be used to store a loose object with the specified sha1.
147 const char *loose_object_path(struct repository *r, struct strbuf *buf, const unsigned char *sha1);
149 void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsigned long *size);
151 extern void *read_object_file_extended(const struct object_id *oid,
152 enum object_type *type,
153 unsigned long *size, int lookup_replace);
154 static inline void *read_object_file(const struct object_id *oid, enum object_type *type, unsigned long *size)
156 return read_object_file_extended(oid, type, size, 1);
159 /* Read and unpack an object file into memory, write memory to an object file */
160 int oid_object_info(struct repository *r, const struct object_id *, unsigned long *);
162 extern int hash_object_file(const void *buf, unsigned long len,
163 const char *type, struct object_id *oid);
165 extern int write_object_file(const void *buf, unsigned long len,
166 const char *type, struct object_id *oid);
168 extern int hash_object_file_literally(const void *buf, unsigned long len,
169 const char *type, struct object_id *oid,
172 extern int pretend_object_file(void *, unsigned long, enum object_type,
173 struct object_id *oid);
175 extern int force_object_loose(const struct object_id *oid, time_t mtime);
178 * Open the loose object at path, check its hash, and return the contents,
179 * type, and size. If the object is a blob, then "contents" may return NULL,
180 * to allow streaming of large blobs.
182 * Returns 0 on success, negative on error (details may be written to stderr).
184 int read_loose_object(const char *path,
185 const struct object_id *expected_oid,
186 enum object_type *type,
191 * Convenience for sha1_object_info_extended() with a NULL struct
192 * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
193 * nonzero flags to also set other flags.
195 extern int has_sha1_file_with_flags(const unsigned char *sha1, int flags);
196 static inline int has_sha1_file(const unsigned char *sha1)
198 return has_sha1_file_with_flags(sha1, 0);
201 /* Same as the above, except for struct object_id. */
202 extern int has_object_file(const struct object_id *oid);
203 extern int has_object_file_with_flags(const struct object_id *oid, int flags);
206 * Return true iff an alternate object database has a loose object
207 * with the specified name. This function does not respect replace
210 extern int has_loose_object_nonlocal(const struct object_id *);
212 extern void assert_oid_type(const struct object_id *oid, enum object_type expect);
216 enum object_type *typep;
217 unsigned long *sizep;
219 unsigned char *delta_base_sha1;
220 struct strbuf *type_name;
233 * ... Nothing to expose in this case
236 * ... Nothing to expose in this case
240 struct packed_git *pack;
242 unsigned int is_delta;
248 * Initializer for a "struct object_info" that wants no items. You may
249 * also memset() the memory to all-zeroes.
251 #define OBJECT_INFO_INIT {NULL}
253 /* Invoke lookup_replace_object() on the given hash */
254 #define OBJECT_INFO_LOOKUP_REPLACE 1
255 /* Allow reading from a loose object file of unknown/bogus type */
256 #define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
257 /* Do not check cached storage */
258 #define OBJECT_INFO_SKIP_CACHED 4
259 /* Do not retry packed storage after checking packed and loose storage */
260 #define OBJECT_INFO_QUICK 8
261 /* Do not check loose object */
262 #define OBJECT_INFO_IGNORE_LOOSE 16
264 int oid_object_info_extended(struct repository *r,
265 const struct object_id *,
266 struct object_info *, unsigned flags);
269 * Iterate over the files in the loose-object parts of the object
270 * directory "path", triggering the following callbacks:
272 * - loose_object is called for each loose object we find.
274 * - loose_cruft is called for any files that do not appear to be
275 * loose objects. Note that we only look in the loose object
276 * directories "objects/[0-9a-f]{2}/", so we will not report
277 * "objects/foobar" as cruft.
279 * - loose_subdir is called for each top-level hashed subdirectory
280 * of the object directory (e.g., "$OBJDIR/f0"). It is called
281 * after the objects in the directory are processed.
283 * Any callback that is NULL will be ignored. Callbacks returning non-zero
284 * will end the iteration.
286 * In the "buf" variant, "path" is a strbuf which will also be used as a
287 * scratch buffer, but restored to its original contents before
288 * the function returns.
290 typedef int each_loose_object_fn(const struct object_id *oid,
293 typedef int each_loose_cruft_fn(const char *basename,
296 typedef int each_loose_subdir_fn(unsigned int nr,
299 int for_each_file_in_obj_subdir(unsigned int subdir_nr,
301 each_loose_object_fn obj_cb,
302 each_loose_cruft_fn cruft_cb,
303 each_loose_subdir_fn subdir_cb,
305 int for_each_loose_file_in_objdir(const char *path,
306 each_loose_object_fn obj_cb,
307 each_loose_cruft_fn cruft_cb,
308 each_loose_subdir_fn subdir_cb,
310 int for_each_loose_file_in_objdir_buf(struct strbuf *path,
311 each_loose_object_fn obj_cb,
312 each_loose_cruft_fn cruft_cb,
313 each_loose_subdir_fn subdir_cb,
316 /* Flags for for_each_*_object() below. */
317 enum for_each_object_flags {
318 /* Iterate only over local objects, not alternates. */
319 FOR_EACH_OBJECT_LOCAL_ONLY = (1<<0),
321 /* Only iterate over packs obtained from the promisor remote. */
322 FOR_EACH_OBJECT_PROMISOR_ONLY = (1<<1),
325 * Visit objects within a pack in packfile order rather than .idx order
327 FOR_EACH_OBJECT_PACK_ORDER = (1<<2),
331 * Iterate over all accessible loose objects without respect to
332 * reachability. By default, this includes both local and alternate objects.
333 * The order in which objects are visited is unspecified.
335 * Any flags specific to packs are ignored.
337 int for_each_loose_object(each_loose_object_fn, void *,
338 enum for_each_object_flags flags);
341 * Iterate over all accessible packed objects without respect to reachability.
342 * By default, this includes both local and alternate packs.
344 * Note that some objects may appear twice if they are found in multiple packs.
345 * Each pack is visited in an unspecified order. By default, objects within a
346 * pack are visited in pack-idx order (i.e., sorted by oid).
348 typedef int each_packed_object_fn(const struct object_id *oid,
349 struct packed_git *pack,
352 int for_each_object_in_pack(struct packed_git *p,
353 each_packed_object_fn, void *data,
354 enum for_each_object_flags flags);
355 int for_each_packed_object(each_packed_object_fn, void *,
356 enum for_each_object_flags flags);
358 #endif /* OBJECT_STORE_H */