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 we are OK
15 * sacrificing accuracy due to races for speed. That includes
16 * our search for unique abbreviated hashes. Don't use it for tasks
17 * requiring greater accuracy!
19 * Be sure to call odb_load_loose_cache() before using.
21 char loose_objects_subdir_seen
[256];
22 struct oid_array loose_objects_cache
;
25 * Path to the alternative object store. If this is a relative path,
26 * it is relative to the current working directory.
31 void prepare_alt_odb(struct repository
*r
);
32 char *compute_alternate_path(const char *path
, struct strbuf
*err
);
33 typedef int alt_odb_fn(struct object_directory
*, void *);
34 int foreach_alt_odb(alt_odb_fn
, void*);
37 * Add the directory to the on-disk alternates file; the new entry will also
38 * take effect in the current process.
40 void add_to_alternates_file(const char *dir
);
43 * Add the directory to the in-memory list of alternates (along with any
44 * recursive alternates it points to), but do not modify the on-disk alternates
47 void add_to_alternates_memory(const char *dir
);
50 * Populate an odb's loose object cache for one particular subdirectory (i.e.,
51 * the one that corresponds to the first byte of objects you're interested in,
52 * from 0 to 255 inclusive).
54 void odb_load_loose_cache(struct object_directory
*odb
, int subdir_nr
);
57 struct packed_git
*next
;
59 struct pack_window
*windows
;
61 const void *index_data
;
64 uint32_t num_bad_objects
;
65 unsigned char *bad_object_sha1
;
69 int index
; /* for builtin/pack-objects.c */
70 unsigned pack_local
:1,
76 unsigned char sha1
[20];
77 struct revindex_entry
*revindex
;
78 /* something like ".git/objects/pack/xxxxx.pack" */
79 char pack_name
[FLEX_ARRAY
]; /* more */
82 struct multi_pack_index
;
84 struct raw_object_store
{
86 * Set of all object directories; the main directory is first (and
87 * cannot be NULL after initialization). Subsequent directories are
90 struct object_directory
*odb
;
91 struct object_directory
**odb_tail
;
92 int loaded_alternates
;
95 * A list of alternate object directories loaded from the environment;
96 * this should not generally need to be accessed directly, but will
97 * populate the "odb" list when prepare_alt_odb() is run.
102 * Objects that should be substituted by other objects
103 * (see git-replace(1)).
105 struct oidmap
*replace_map
;
107 struct commit_graph
*commit_graph
;
108 unsigned commit_graph_attempted
: 1; /* if loading has been attempted */
113 * should only be accessed directly by packfile.c and midx.c
115 struct multi_pack_index
*multi_pack_index
;
120 * should only be accessed directly by packfile.c
123 struct packed_git
*packed_git
;
124 /* A most-recently-used ordered version of the packed_git list. */
125 struct list_head packed_git_mru
;
128 * A linked list containing all packfiles, starting with those
129 * contained in the multi_pack_index.
131 struct packed_git
*all_packs
;
134 * A fast, rough count of the number of objects in the repository.
135 * These two fields are not meant for direct access. Use
136 * approximate_object_count() instead.
138 unsigned long approximate_object_count
;
139 unsigned approximate_object_count_valid
: 1;
142 * Whether packed_git has already been populated with this repository's
145 unsigned packed_git_initialized
: 1;
148 struct raw_object_store
*raw_object_store_new(void);
149 void raw_object_store_clear(struct raw_object_store
*o
);
152 * Put in `buf` the name of the file in the local object database that
153 * would be used to store a loose object with the specified sha1.
155 const char *loose_object_path(struct repository
*r
, struct strbuf
*buf
, const unsigned char *sha1
);
157 void *map_sha1_file(struct repository
*r
, const unsigned char *sha1
, unsigned long *size
);
159 extern void *read_object_file_extended(const struct object_id
*oid
,
160 enum object_type
*type
,
161 unsigned long *size
, int lookup_replace
);
162 static inline void *read_object_file(const struct object_id
*oid
, enum object_type
*type
, unsigned long *size
)
164 return read_object_file_extended(oid
, type
, size
, 1);
167 /* Read and unpack an object file into memory, write memory to an object file */
168 int oid_object_info(struct repository
*r
, const struct object_id
*, unsigned long *);
170 extern int hash_object_file(const void *buf
, unsigned long len
,
171 const char *type
, struct object_id
*oid
);
173 extern int write_object_file(const void *buf
, unsigned long len
,
174 const char *type
, struct object_id
*oid
);
176 extern int hash_object_file_literally(const void *buf
, unsigned long len
,
177 const char *type
, struct object_id
*oid
,
180 extern int pretend_object_file(void *, unsigned long, enum object_type
,
181 struct object_id
*oid
);
183 extern int force_object_loose(const struct object_id
*oid
, time_t mtime
);
186 * Open the loose object at path, check its hash, and return the contents,
187 * type, and size. If the object is a blob, then "contents" may return NULL,
188 * to allow streaming of large blobs.
190 * Returns 0 on success, negative on error (details may be written to stderr).
192 int read_loose_object(const char *path
,
193 const struct object_id
*expected_oid
,
194 enum object_type
*type
,
199 * Convenience for sha1_object_info_extended() with a NULL struct
200 * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
201 * nonzero flags to also set other flags.
203 extern int has_sha1_file_with_flags(const unsigned char *sha1
, int flags
);
204 static inline int has_sha1_file(const unsigned char *sha1
)
206 return has_sha1_file_with_flags(sha1
, 0);
209 /* Same as the above, except for struct object_id. */
210 extern int has_object_file(const struct object_id
*oid
);
211 extern int has_object_file_with_flags(const struct object_id
*oid
, int flags
);
214 * Return true iff an alternate object database has a loose object
215 * with the specified name. This function does not respect replace
218 extern int has_loose_object_nonlocal(const struct object_id
*);
220 extern void assert_oid_type(const struct object_id
*oid
, enum object_type expect
);
224 enum object_type
*typep
;
225 unsigned long *sizep
;
227 unsigned char *delta_base_sha1
;
228 struct strbuf
*type_name
;
241 * ... Nothing to expose in this case
244 * ... Nothing to expose in this case
248 struct packed_git
*pack
;
250 unsigned int is_delta
;
256 * Initializer for a "struct object_info" that wants no items. You may
257 * also memset() the memory to all-zeroes.
259 #define OBJECT_INFO_INIT {NULL}
261 /* Invoke lookup_replace_object() on the given hash */
262 #define OBJECT_INFO_LOOKUP_REPLACE 1
263 /* Allow reading from a loose object file of unknown/bogus type */
264 #define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
265 /* Do not check cached storage */
266 #define OBJECT_INFO_SKIP_CACHED 4
267 /* Do not retry packed storage after checking packed and loose storage */
268 #define OBJECT_INFO_QUICK 8
269 /* Do not check loose object */
270 #define OBJECT_INFO_IGNORE_LOOSE 16
272 int oid_object_info_extended(struct repository
*r
,
273 const struct object_id
*,
274 struct object_info
*, unsigned flags
);
277 * Iterate over the files in the loose-object parts of the object
278 * directory "path", triggering the following callbacks:
280 * - loose_object is called for each loose object we find.
282 * - loose_cruft is called for any files that do not appear to be
283 * loose objects. Note that we only look in the loose object
284 * directories "objects/[0-9a-f]{2}/", so we will not report
285 * "objects/foobar" as cruft.
287 * - loose_subdir is called for each top-level hashed subdirectory
288 * of the object directory (e.g., "$OBJDIR/f0"). It is called
289 * after the objects in the directory are processed.
291 * Any callback that is NULL will be ignored. Callbacks returning non-zero
292 * will end the iteration.
294 * In the "buf" variant, "path" is a strbuf which will also be used as a
295 * scratch buffer, but restored to its original contents before
296 * the function returns.
298 typedef int each_loose_object_fn(const struct object_id
*oid
,
301 typedef int each_loose_cruft_fn(const char *basename
,
304 typedef int each_loose_subdir_fn(unsigned int nr
,
307 int for_each_file_in_obj_subdir(unsigned int subdir_nr
,
309 each_loose_object_fn obj_cb
,
310 each_loose_cruft_fn cruft_cb
,
311 each_loose_subdir_fn subdir_cb
,
313 int for_each_loose_file_in_objdir(const char *path
,
314 each_loose_object_fn obj_cb
,
315 each_loose_cruft_fn cruft_cb
,
316 each_loose_subdir_fn subdir_cb
,
318 int for_each_loose_file_in_objdir_buf(struct strbuf
*path
,
319 each_loose_object_fn obj_cb
,
320 each_loose_cruft_fn cruft_cb
,
321 each_loose_subdir_fn subdir_cb
,
324 /* Flags for for_each_*_object() below. */
325 enum for_each_object_flags
{
326 /* Iterate only over local objects, not alternates. */
327 FOR_EACH_OBJECT_LOCAL_ONLY
= (1<<0),
329 /* Only iterate over packs obtained from the promisor remote. */
330 FOR_EACH_OBJECT_PROMISOR_ONLY
= (1<<1),
333 * Visit objects within a pack in packfile order rather than .idx order
335 FOR_EACH_OBJECT_PACK_ORDER
= (1<<2),
339 * Iterate over all accessible loose objects without respect to
340 * reachability. By default, this includes both local and alternate objects.
341 * The order in which objects are visited is unspecified.
343 * Any flags specific to packs are ignored.
345 int for_each_loose_object(each_loose_object_fn
, void *,
346 enum for_each_object_flags flags
);
349 * Iterate over all accessible packed objects without respect to reachability.
350 * By default, this includes both local and alternate packs.
352 * Note that some objects may appear twice if they are found in multiple packs.
353 * Each pack is visited in an unspecified order. By default, objects within a
354 * pack are visited in pack-idx order (i.e., sorted by oid).
356 typedef int each_packed_object_fn(const struct object_id
*oid
,
357 struct packed_git
*pack
,
360 int for_each_object_in_pack(struct packed_git
*p
,
361 each_packed_object_fn
, void *data
,
362 enum for_each_object_flags flags
);
363 int for_each_packed_object(each_packed_object_fn
, void *,
364 enum for_each_object_flags flags
);
366 #endif /* OBJECT_STORE_H */