7 #include "sha1-array.h"
10 struct alternate_object_database
{
11 struct alternate_object_database
*next
;
13 /* see alt_scratch_buf() */
14 struct strbuf scratch
;
18 * Used to store the results of readdir(3) calls when searching
19 * for unique abbreviated hashes. This cache is never
20 * invalidated, thus it's racy and not necessarily accurate.
21 * That's fine for its purpose; don't use it for tasks requiring
24 char loose_objects_subdir_seen
[256];
25 struct oid_array loose_objects_cache
;
28 * Path to the alternative object store. If this is a relative path,
29 * it is relative to the current working directory.
31 char path
[FLEX_ARRAY
];
33 void prepare_alt_odb(struct repository
*r
);
34 char *compute_alternate_path(const char *path
, struct strbuf
*err
);
35 typedef int alt_odb_fn(struct alternate_object_database
*, void *);
36 int foreach_alt_odb(alt_odb_fn
, void*);
39 * Allocate a "struct alternate_object_database" but do _not_ actually
40 * add it to the list of alternates.
42 struct alternate_object_database
*alloc_alt_odb(const char *dir
);
45 * Add the directory to the on-disk alternates file; the new entry will also
46 * take effect in the current process.
48 void add_to_alternates_file(const char *dir
);
51 * Add the directory to the in-memory list of alternates (along with any
52 * recursive alternates it points to), but do not modify the on-disk alternates
55 void add_to_alternates_memory(const char *dir
);
58 * Returns a scratch strbuf pre-filled with the alternate object directory,
59 * including a trailing slash, which can be used to access paths in the
60 * alternate. Always use this over direct access to alt->scratch, as it
61 * cleans up any previous use of the scratch buffer.
63 struct strbuf
*alt_scratch_buf(struct alternate_object_database
*alt
);
66 struct packed_git
*next
;
68 struct pack_window
*windows
;
70 const void *index_data
;
73 uint32_t num_bad_objects
;
74 unsigned char *bad_object_sha1
;
78 int index
; /* for builtin/pack-objects.c */
79 unsigned pack_local
:1,
85 unsigned char sha1
[20];
86 struct revindex_entry
*revindex
;
87 /* something like ".git/objects/pack/xxxxx.pack" */
88 char pack_name
[FLEX_ARRAY
]; /* more */
91 struct raw_object_store
{
93 * Path to the repository's object store.
94 * Cannot be NULL after initialization.
98 /* Path to extra alternate object database if not NULL */
101 struct alternate_object_database
*alt_odb_list
;
102 struct alternate_object_database
**alt_odb_tail
;
105 * Objects that should be substituted by other objects
106 * (see git-replace(1)).
108 struct oidmap
*replace_map
;
110 struct commit_graph
*commit_graph
;
111 unsigned commit_graph_attempted
: 1; /* if loading has been attempted */
116 * should only be accessed directly by packfile.c
119 struct packed_git
*packed_git
;
120 /* A most-recently-used ordered version of the packed_git list. */
121 struct list_head packed_git_mru
;
124 * A fast, rough count of the number of objects in the repository.
125 * These two fields are not meant for direct access. Use
126 * approximate_object_count() instead.
128 unsigned long approximate_object_count
;
129 unsigned approximate_object_count_valid
: 1;
132 * Whether packed_git has already been populated with this repository's
135 unsigned packed_git_initialized
: 1;
138 struct raw_object_store
*raw_object_store_new(void);
139 void raw_object_store_clear(struct raw_object_store
*o
);
142 * Put in `buf` the name of the file in the local object database that
143 * would be used to store a loose object with the specified sha1.
145 void sha1_file_name(struct repository
*r
, struct strbuf
*buf
, const unsigned char *sha1
);
147 void *map_sha1_file(struct repository
*r
, const unsigned char *sha1
, unsigned long *size
);
149 extern void *read_object_file_extended(const struct object_id
*oid
,
150 enum object_type
*type
,
151 unsigned long *size
, int lookup_replace
);
152 static inline void *read_object_file(const struct object_id
*oid
, enum object_type
*type
, unsigned long *size
)
154 return read_object_file_extended(oid
, type
, size
, 1);
157 /* Read and unpack an object file into memory, write memory to an object file */
158 int oid_object_info(struct repository
*r
, const struct object_id
*, unsigned long *);
160 extern int hash_object_file(const void *buf
, unsigned long len
,
161 const char *type
, struct object_id
*oid
);
163 extern int write_object_file(const void *buf
, unsigned long len
,
164 const char *type
, struct object_id
*oid
);
166 extern int hash_object_file_literally(const void *buf
, unsigned long len
,
167 const char *type
, struct object_id
*oid
,
170 extern int pretend_object_file(void *, unsigned long, enum object_type
,
171 struct object_id
*oid
);
173 extern int force_object_loose(const struct object_id
*oid
, time_t mtime
);
176 * Open the loose object at path, check its hash, and return the contents,
177 * type, and size. If the object is a blob, then "contents" may return NULL,
178 * to allow streaming of large blobs.
180 * Returns 0 on success, negative on error (details may be written to stderr).
182 int read_loose_object(const char *path
,
183 const struct object_id
*expected_oid
,
184 enum object_type
*type
,
189 * Convenience for sha1_object_info_extended() with a NULL struct
190 * object_info. OBJECT_INFO_SKIP_CACHED is automatically set; pass
191 * nonzero flags to also set other flags.
193 extern int has_sha1_file_with_flags(const unsigned char *sha1
, int flags
);
194 static inline int has_sha1_file(const unsigned char *sha1
)
196 return has_sha1_file_with_flags(sha1
, 0);
199 /* Same as the above, except for struct object_id. */
200 extern int has_object_file(const struct object_id
*oid
);
201 extern int has_object_file_with_flags(const struct object_id
*oid
, int flags
);
204 * Return true iff an alternate object database has a loose object
205 * with the specified name. This function does not respect replace
208 extern int has_loose_object_nonlocal(const struct object_id
*);
210 extern void assert_oid_type(const struct object_id
*oid
, enum object_type expect
);
214 enum object_type
*typep
;
215 unsigned long *sizep
;
217 unsigned char *delta_base_sha1
;
218 struct strbuf
*type_name
;
231 * ... Nothing to expose in this case
234 * ... Nothing to expose in this case
238 struct packed_git
*pack
;
240 unsigned int is_delta
;
246 * Initializer for a "struct object_info" that wants no items. You may
247 * also memset() the memory to all-zeroes.
249 #define OBJECT_INFO_INIT {NULL}
251 /* Invoke lookup_replace_object() on the given hash */
252 #define OBJECT_INFO_LOOKUP_REPLACE 1
253 /* Allow reading from a loose object file of unknown/bogus type */
254 #define OBJECT_INFO_ALLOW_UNKNOWN_TYPE 2
255 /* Do not check cached storage */
256 #define OBJECT_INFO_SKIP_CACHED 4
257 /* Do not retry packed storage after checking packed and loose storage */
258 #define OBJECT_INFO_QUICK 8
259 /* Do not check loose object */
260 #define OBJECT_INFO_IGNORE_LOOSE 16
262 int oid_object_info_extended(struct repository
*r
,
263 const struct object_id
*,
264 struct object_info
*, unsigned flags
);
266 #endif /* OBJECT_STORE_H */