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