]>
Commit | Line | Data |
---|---|---|
5d4a6003 | 1 | #include "builtin.h" |
c323ac7d | 2 | #include "cache.h" |
a80d72db | 3 | #include "repository.h" |
b2141fc1 | 4 | #include "config.h" |
a74db82e | 5 | #include "attr.h" |
c323ac7d | 6 | #include "object.h" |
8e440259 PE |
7 | #include "blob.h" |
8 | #include "commit.h" | |
9 | #include "tag.h" | |
10 | #include "tree.h" | |
c323ac7d | 11 | #include "delta.h" |
a733cb60 | 12 | #include "pack.h" |
3449f8c4 | 13 | #include "pack-revindex.h" |
c38138cd | 14 | #include "csum-file.h" |
1b0c7174 | 15 | #include "tree-walk.h" |
b5d97e6b JH |
16 | #include "diff.h" |
17 | #include "revision.h" | |
18 | #include "list-objects.h" | |
9535ce73 JH |
19 | #include "list-objects-filter.h" |
20 | #include "list-objects-filter-options.h" | |
2834bc27 | 21 | #include "pack-objects.h" |
96a02f8f | 22 | #include "progress.h" |
f0a24aa5 | 23 | #include "refs.h" |
cf2ba13a | 24 | #include "streaming.h" |
93749194 | 25 | #include "thread-utils.h" |
6b8fda2d | 26 | #include "pack-bitmap.h" |
28b8a730 | 27 | #include "delta-islands.h" |
abcb8655 | 28 | #include "reachable.h" |
fe299ec5 | 29 | #include "oid-array.h" |
dbbcd44f | 30 | #include "strvec.h" |
ec2dd32c | 31 | #include "list.h" |
0317f455 | 32 | #include "packfile.h" |
a80d72db | 33 | #include "object-store.h" |
ed7e5fc3 | 34 | #include "dir.h" |
6a22d521 | 35 | #include "midx.h" |
ae417807 | 36 | #include "trace2.h" |
120ad2b0 | 37 | #include "shallow.h" |
e00549aa | 38 | #include "promisor-remote.h" |
8ecce684 | 39 | |
43fa44fa | 40 | #define IN_PACK(obj) oe_in_pack(&to_pack, obj) |
ac77d0c3 NTND |
41 | #define SIZE(obj) oe_size(&to_pack, obj) |
42 | #define SET_SIZE(obj,size) oe_set_size(&to_pack, obj, size) | |
0aca34e8 | 43 | #define DELTA_SIZE(obj) oe_delta_size(&to_pack, obj) |
898eba5e NTND |
44 | #define DELTA(obj) oe_delta(&to_pack, obj) |
45 | #define DELTA_CHILD(obj) oe_delta_child(&to_pack, obj) | |
46 | #define DELTA_SIBLING(obj) oe_delta_sibling(&to_pack, obj) | |
47 | #define SET_DELTA(obj, val) oe_set_delta(&to_pack, obj, val) | |
6a1e32d5 | 48 | #define SET_DELTA_EXT(obj, oid) oe_set_delta_ext(&to_pack, obj, oid) |
0aca34e8 | 49 | #define SET_DELTA_SIZE(obj, val) oe_set_delta_size(&to_pack, obj, val) |
898eba5e NTND |
50 | #define SET_DELTA_CHILD(obj, val) oe_set_delta_child(&to_pack, obj, val) |
51 | #define SET_DELTA_SIBLING(obj, val) oe_set_delta_sibling(&to_pack, obj, val) | |
43fa44fa | 52 | |
99fb6e04 | 53 | static const char *pack_usage[] = { |
b8c1d275 AH |
54 | N_("git pack-objects --stdout [<options>...] [< <ref-list> | < <object-list>]"), |
55 | N_("git pack-objects [<options>...] <base-name> [< <ref-list> | < <object-list>]"), | |
99fb6e04 NTND |
56 | NULL |
57 | }; | |
c323ac7d | 58 | |
3f9ac8d2 | 59 | /* |
2834bc27 VM |
60 | * Objects we are going to pack are collected in the `to_pack` structure. |
61 | * It contains an array (dynamically expanded) of the object data, and a map | |
62 | * that can resolve SHA1s to their position in the array. | |
3f9ac8d2 | 63 | */ |
2834bc27 VM |
64 | static struct packing_data to_pack; |
65 | ||
79814f42 | 66 | static struct pack_idx_entry **written_list; |
5af05043 | 67 | static uint32_t nr_result, nr_written, nr_seen; |
6a1e32d5 | 68 | static struct bitmap_index *bitmap_git; |
28b8a730 | 69 | static uint32_t write_layer; |
3f9ac8d2 | 70 | |
96f1e58f | 71 | static int non_empty; |
a7de7130 | 72 | static int reuse_delta = 1, reuse_object = 1; |
e5e9714a | 73 | static int keep_unreachable, unpack_unreachable, include_tag; |
dddbad72 | 74 | static timestamp_t unpack_unreachable_expiration; |
e26a8c47 | 75 | static int pack_loose_unreachable; |
96f1e58f | 76 | static int local; |
56dfeb62 | 77 | static int have_non_local_packs; |
96f1e58f | 78 | static int incremental; |
ed7e5fc3 NTND |
79 | static int ignore_packed_keep_on_disk; |
80 | static int ignore_packed_keep_in_core; | |
be6b1914 | 81 | static int allow_ofs_delta; |
ebcfb379 | 82 | static struct pack_idx_option pack_idx_opts; |
d01fb92f | 83 | static const char *base_name; |
024701f1 | 84 | static int progress = 1; |
4812a93a | 85 | static int window = 10; |
568508e7 | 86 | static unsigned long pack_size_limit; |
618e613a | 87 | static int depth = 50; |
43cc2b42 | 88 | static int delta_search_threads; |
df6d6101 | 89 | static int pack_to_stdout; |
4f6d26b1 | 90 | static int sparse; |
6a1e32d5 | 91 | static int thin; |
8d1d8f83 | 92 | static int num_preferred_base; |
dc6a0757 | 93 | static struct progress *progress_state; |
c323ac7d | 94 | |
6b8fda2d VM |
95 | static struct packed_git *reuse_packfile; |
96 | static uint32_t reuse_packfile_objects; | |
bb514de3 | 97 | static struct bitmap *reuse_packfile_bitmap; |
6b8fda2d | 98 | |
645c432d KS |
99 | static int use_bitmap_index_default = 1; |
100 | static int use_bitmap_index = -1; | |
e704fc79 | 101 | static int allow_pack_reuse = 1; |
25575015 JK |
102 | static enum { |
103 | WRITE_BITMAP_FALSE = 0, | |
104 | WRITE_BITMAP_QUIET, | |
105 | WRITE_BITMAP_TRUE, | |
106 | } write_bitmap_index; | |
d4316604 | 107 | static uint16_t write_bitmap_options = BITMAP_OPT_HASH_CACHE; |
6b8fda2d | 108 | |
0c16cd49 JT |
109 | static int exclude_promisor_objects; |
110 | ||
28b8a730 JK |
111 | static int use_delta_islands; |
112 | ||
074b2eea | 113 | static unsigned long delta_cache_size = 0; |
9806f5a7 | 114 | static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE; |
e3dfddb3 | 115 | static unsigned long cache_max_small_delta_size = 1000; |
074b2eea | 116 | |
a97773ce BD |
117 | static unsigned long window_memory_limit = 0; |
118 | ||
9535ce73 JH |
119 | static struct list_objects_filter_options filter_options; |
120 | ||
dd4b732d JT |
121 | static struct string_list uri_protocols = STRING_LIST_INIT_NODUP; |
122 | ||
9535ce73 | 123 | enum missing_action { |
0c16cd49 JT |
124 | MA_ERROR = 0, /* fail if any missing objects are encountered */ |
125 | MA_ALLOW_ANY, /* silently allow ALL missing objects */ | |
126 | MA_ALLOW_PROMISOR, /* silently allow all missing PROMISOR objects */ | |
9535ce73 JH |
127 | }; |
128 | static enum missing_action arg_missing_action; | |
129 | static show_object_fn fn_show_object; | |
130 | ||
dd4b732d JT |
131 | struct configured_exclusion { |
132 | struct oidmap_entry e; | |
133 | char *pack_hash_hex; | |
134 | char *uri; | |
135 | }; | |
136 | static struct oidmap configured_exclusions; | |
137 | ||
138 | static struct oidset excluded_by_config; | |
139 | ||
3f9ac8d2 JH |
140 | /* |
141 | * stats | |
142 | */ | |
7cadf491 SP |
143 | static uint32_t written, written_delta; |
144 | static uint32_t reused, reused_delta; | |
3f9ac8d2 | 145 | |
7cc8f971 VM |
146 | /* |
147 | * Indexed commits | |
148 | */ | |
149 | static struct commit **indexed_commits; | |
150 | static unsigned int indexed_commits_nr; | |
151 | static unsigned int indexed_commits_alloc; | |
152 | ||
153 | static void index_commit_for_bitmap(struct commit *commit) | |
154 | { | |
155 | if (indexed_commits_nr >= indexed_commits_alloc) { | |
156 | indexed_commits_alloc = (indexed_commits_alloc + 32) * 2; | |
2756ca43 | 157 | REALLOC_ARRAY(indexed_commits, indexed_commits_alloc); |
7cc8f971 VM |
158 | } |
159 | ||
160 | indexed_commits[indexed_commits_nr++] = commit; | |
161 | } | |
780e6e73 | 162 | |
3613f9b4 | 163 | static void *get_delta(struct object_entry *entry) |
c323ac7d | 164 | { |
3613f9b4 NP |
165 | unsigned long size, base_size, delta_size; |
166 | void *buf, *base_buf, *delta_buf; | |
21666f1a | 167 | enum object_type type; |
c323ac7d | 168 | |
b4f5aca4 | 169 | buf = read_object_file(&entry->idx.oid, &type, &size); |
3613f9b4 | 170 | if (!buf) |
f616db6a | 171 | die(_("unable to read %s"), oid_to_hex(&entry->idx.oid)); |
898eba5e NTND |
172 | base_buf = read_object_file(&DELTA(entry)->idx.oid, &type, |
173 | &base_size); | |
3613f9b4 | 174 | if (!base_buf) |
e6a492b7 | 175 | die("unable to read %s", |
898eba5e | 176 | oid_to_hex(&DELTA(entry)->idx.oid)); |
3613f9b4 | 177 | delta_buf = diff_delta(base_buf, base_size, |
dcde55bc | 178 | buf, size, &delta_size, 0); |
1a07e59c | 179 | /* |
15beaaa3 | 180 | * We successfully computed this delta once but dropped it for |
1a07e59c NTND |
181 | * memory reasons. Something is very wrong if this time we |
182 | * recompute and create a different delta. | |
183 | */ | |
0aca34e8 | 184 | if (!delta_buf || delta_size != DELTA_SIZE(entry)) |
1a07e59c | 185 | BUG("delta size changed"); |
3613f9b4 NP |
186 | free(buf); |
187 | free(base_buf); | |
c323ac7d LT |
188 | return delta_buf; |
189 | } | |
190 | ||
30ebb40a NP |
191 | static unsigned long do_compress(void **pptr, unsigned long size) |
192 | { | |
ef49a7a0 | 193 | git_zstream stream; |
30ebb40a NP |
194 | void *in, *out; |
195 | unsigned long maxsize; | |
196 | ||
55bb5c91 | 197 | git_deflate_init(&stream, pack_compression_level); |
225a6f10 | 198 | maxsize = git_deflate_bound(&stream, size); |
30ebb40a NP |
199 | |
200 | in = *pptr; | |
201 | out = xmalloc(maxsize); | |
202 | *pptr = out; | |
203 | ||
204 | stream.next_in = in; | |
205 | stream.avail_in = size; | |
206 | stream.next_out = out; | |
207 | stream.avail_out = maxsize; | |
55bb5c91 | 208 | while (git_deflate(&stream, Z_FINISH) == Z_OK) |
30ebb40a | 209 | ; /* nothing */ |
55bb5c91 | 210 | git_deflate_end(&stream); |
30ebb40a NP |
211 | |
212 | free(in); | |
213 | return stream.total_out; | |
214 | } | |
215 | ||
98a3beab | 216 | static unsigned long write_large_blob_data(struct git_istream *st, struct hashfile *f, |
188960b4 | 217 | const struct object_id *oid) |
cf2ba13a NTND |
218 | { |
219 | git_zstream stream; | |
220 | unsigned char ibuf[1024 * 16]; | |
221 | unsigned char obuf[1024 * 16]; | |
222 | unsigned long olen = 0; | |
223 | ||
cf2ba13a NTND |
224 | git_deflate_init(&stream, pack_compression_level); |
225 | ||
226 | for (;;) { | |
227 | ssize_t readlen; | |
228 | int zret = Z_OK; | |
229 | readlen = read_istream(st, ibuf, sizeof(ibuf)); | |
230 | if (readlen == -1) | |
188960b4 | 231 | die(_("unable to read %s"), oid_to_hex(oid)); |
cf2ba13a NTND |
232 | |
233 | stream.next_in = ibuf; | |
234 | stream.avail_in = readlen; | |
235 | while ((stream.avail_in || readlen == 0) && | |
236 | (zret == Z_OK || zret == Z_BUF_ERROR)) { | |
237 | stream.next_out = obuf; | |
238 | stream.avail_out = sizeof(obuf); | |
239 | zret = git_deflate(&stream, readlen ? 0 : Z_FINISH); | |
98a3beab | 240 | hashwrite(f, obuf, stream.next_out - obuf); |
cf2ba13a NTND |
241 | olen += stream.next_out - obuf; |
242 | } | |
243 | if (stream.avail_in) | |
244 | die(_("deflate error (%d)"), zret); | |
245 | if (readlen == 0) { | |
246 | if (zret != Z_STREAM_END) | |
247 | die(_("deflate error (%d)"), zret); | |
248 | break; | |
249 | } | |
250 | } | |
251 | git_deflate_end(&stream); | |
252 | return olen; | |
253 | } | |
254 | ||
780e6e73 NP |
255 | /* |
256 | * we are going to reuse the existing object data as is. make | |
257 | * sure it is not corrupt. | |
258 | */ | |
079afb18 SP |
259 | static int check_pack_inflate(struct packed_git *p, |
260 | struct pack_window **w_curs, | |
6777a59f SP |
261 | off_t offset, |
262 | off_t len, | |
079afb18 SP |
263 | unsigned long expect) |
264 | { | |
ef49a7a0 | 265 | git_zstream stream; |
079afb18 SP |
266 | unsigned char fakebuf[4096], *in; |
267 | int st; | |
268 | ||
269 | memset(&stream, 0, sizeof(stream)); | |
39c68542 | 270 | git_inflate_init(&stream); |
079afb18 SP |
271 | do { |
272 | in = use_pack(p, w_curs, offset, &stream.avail_in); | |
273 | stream.next_in = in; | |
274 | stream.next_out = fakebuf; | |
275 | stream.avail_out = sizeof(fakebuf); | |
39c68542 | 276 | st = git_inflate(&stream, Z_FINISH); |
079afb18 SP |
277 | offset += stream.next_in - in; |
278 | } while (st == Z_OK || st == Z_BUF_ERROR); | |
39c68542 | 279 | git_inflate_end(&stream); |
079afb18 SP |
280 | return (st == Z_STREAM_END && |
281 | stream.total_out == expect && | |
282 | stream.total_in == len) ? 0 : -1; | |
283 | } | |
284 | ||
98a3beab | 285 | static void copy_pack_data(struct hashfile *f, |
079afb18 SP |
286 | struct packed_git *p, |
287 | struct pack_window **w_curs, | |
6777a59f SP |
288 | off_t offset, |
289 | off_t len) | |
079afb18 SP |
290 | { |
291 | unsigned char *in; | |
ef49a7a0 | 292 | unsigned long avail; |
079afb18 SP |
293 | |
294 | while (len) { | |
295 | in = use_pack(p, w_curs, offset, &avail); | |
296 | if (avail > len) | |
ef49a7a0 | 297 | avail = (unsigned long)len; |
98a3beab | 298 | hashwrite(f, in, avail); |
079afb18 SP |
299 | offset += avail; |
300 | len -= avail; | |
301 | } | |
302 | } | |
303 | ||
1b4bb16b | 304 | /* Return 0 if we will bust the pack-size limit */ |
98a3beab | 305 | static unsigned long write_no_reuse_object(struct hashfile *f, struct object_entry *entry, |
c9018b03 | 306 | unsigned long limit, int usable_delta) |
c323ac7d | 307 | { |
c9018b03 | 308 | unsigned long size, datalen; |
2c5e2865 JK |
309 | unsigned char header[MAX_PACK_OBJECT_HEADER], |
310 | dheader[MAX_PACK_OBJECT_HEADER]; | |
6777a59f | 311 | unsigned hdrlen; |
2c5ef824 | 312 | enum object_type type; |
c9018b03 | 313 | void *buf; |
cf2ba13a | 314 | struct git_istream *st = NULL; |
41179100 | 315 | const unsigned hashsz = the_hash_algo->rawsz; |
c9018b03 NTND |
316 | |
317 | if (!usable_delta) { | |
fd9b1bae | 318 | if (oe_type(entry) == OBJ_BLOB && |
ac77d0c3 | 319 | oe_size_greater_than(&to_pack, entry, big_file_threshold) && |
c8123e72 MT |
320 | (st = open_istream(the_repository, &entry->idx.oid, &type, |
321 | &size, NULL)) != NULL) | |
cf2ba13a NTND |
322 | buf = NULL; |
323 | else { | |
b4f5aca4 | 324 | buf = read_object_file(&entry->idx.oid, &type, &size); |
cf2ba13a | 325 | if (!buf) |
e6a492b7 | 326 | die(_("unable to read %s"), |
327 | oid_to_hex(&entry->idx.oid)); | |
cf2ba13a | 328 | } |
c9018b03 NTND |
329 | /* |
330 | * make sure no cached delta data remains from a | |
331 | * previous attempt before a pack split occurred. | |
332 | */ | |
6a83d902 | 333 | FREE_AND_NULL(entry->delta_data); |
c9018b03 NTND |
334 | entry->z_delta_size = 0; |
335 | } else if (entry->delta_data) { | |
0aca34e8 | 336 | size = DELTA_SIZE(entry); |
c9018b03 NTND |
337 | buf = entry->delta_data; |
338 | entry->delta_data = NULL; | |
898eba5e | 339 | type = (allow_ofs_delta && DELTA(entry)->idx.offset) ? |
c9018b03 NTND |
340 | OBJ_OFS_DELTA : OBJ_REF_DELTA; |
341 | } else { | |
342 | buf = get_delta(entry); | |
0aca34e8 | 343 | size = DELTA_SIZE(entry); |
898eba5e | 344 | type = (allow_ofs_delta && DELTA(entry)->idx.offset) ? |
c9018b03 NTND |
345 | OBJ_OFS_DELTA : OBJ_REF_DELTA; |
346 | } | |
347 | ||
cf2ba13a NTND |
348 | if (st) /* large blob case, just assume we don't compress well */ |
349 | datalen = size; | |
350 | else if (entry->z_delta_size) | |
c9018b03 NTND |
351 | datalen = entry->z_delta_size; |
352 | else | |
353 | datalen = do_compress(&buf, size); | |
354 | ||
355 | /* | |
356 | * The object header is a byte of 'type' followed by zero or | |
357 | * more bytes of length. | |
358 | */ | |
7202a6fa JK |
359 | hdrlen = encode_in_pack_object_header(header, sizeof(header), |
360 | type, size); | |
c9018b03 NTND |
361 | |
362 | if (type == OBJ_OFS_DELTA) { | |
363 | /* | |
364 | * Deltas with relative base contain an additional | |
365 | * encoding of the relative offset for the delta | |
366 | * base from this object's position in the pack. | |
367 | */ | |
898eba5e | 368 | off_t ofs = entry->idx.offset - DELTA(entry)->idx.offset; |
c9018b03 NTND |
369 | unsigned pos = sizeof(dheader) - 1; |
370 | dheader[pos] = ofs & 127; | |
371 | while (ofs >>= 7) | |
372 | dheader[--pos] = 128 | (--ofs & 127); | |
41179100 | 373 | if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) { |
cf2ba13a NTND |
374 | if (st) |
375 | close_istream(st); | |
c9018b03 NTND |
376 | free(buf); |
377 | return 0; | |
378 | } | |
98a3beab | 379 | hashwrite(f, header, hdrlen); |
380 | hashwrite(f, dheader + pos, sizeof(dheader) - pos); | |
c9018b03 NTND |
381 | hdrlen += sizeof(dheader) - pos; |
382 | } else if (type == OBJ_REF_DELTA) { | |
383 | /* | |
384 | * Deltas with a base reference contain | |
41179100 | 385 | * additional bytes for the base object ID. |
c9018b03 | 386 | */ |
41179100 | 387 | if (limit && hdrlen + hashsz + datalen + hashsz >= limit) { |
cf2ba13a NTND |
388 | if (st) |
389 | close_istream(st); | |
c9018b03 NTND |
390 | free(buf); |
391 | return 0; | |
392 | } | |
98a3beab | 393 | hashwrite(f, header, hdrlen); |
42c8ce1c | 394 | hashwrite(f, DELTA(entry)->idx.oid.hash, hashsz); |
41179100 | 395 | hdrlen += hashsz; |
c9018b03 | 396 | } else { |
41179100 | 397 | if (limit && hdrlen + datalen + hashsz >= limit) { |
cf2ba13a NTND |
398 | if (st) |
399 | close_istream(st); | |
c9018b03 NTND |
400 | free(buf); |
401 | return 0; | |
402 | } | |
98a3beab | 403 | hashwrite(f, header, hdrlen); |
c9018b03 | 404 | } |
cf2ba13a | 405 | if (st) { |
188960b4 | 406 | datalen = write_large_blob_data(st, f, &entry->idx.oid); |
cf2ba13a NTND |
407 | close_istream(st); |
408 | } else { | |
98a3beab | 409 | hashwrite(f, buf, datalen); |
cf2ba13a NTND |
410 | free(buf); |
411 | } | |
c9018b03 NTND |
412 | |
413 | return hdrlen + datalen; | |
414 | } | |
415 | ||
416 | /* Return 0 if we will bust the pack-size limit */ | |
98a3beab | 417 | static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry, |
af92a645 | 418 | unsigned long limit, int usable_delta) |
c9018b03 | 419 | { |
43fa44fa | 420 | struct packed_git *p = IN_PACK(entry); |
c9018b03 | 421 | struct pack_window *w_curs = NULL; |
952fc687 | 422 | uint32_t pos; |
c9018b03 | 423 | off_t offset; |
fd9b1bae | 424 | enum object_type type = oe_type(entry); |
211c61c6 | 425 | off_t datalen; |
2c5e2865 JK |
426 | unsigned char header[MAX_PACK_OBJECT_HEADER], |
427 | dheader[MAX_PACK_OBJECT_HEADER]; | |
c9018b03 | 428 | unsigned hdrlen; |
41179100 | 429 | const unsigned hashsz = the_hash_algo->rawsz; |
ac77d0c3 | 430 | unsigned long entry_size = SIZE(entry); |
c9018b03 | 431 | |
898eba5e NTND |
432 | if (DELTA(entry)) |
433 | type = (allow_ofs_delta && DELTA(entry)->idx.offset) ? | |
c9018b03 | 434 | OBJ_OFS_DELTA : OBJ_REF_DELTA; |
7202a6fa | 435 | hdrlen = encode_in_pack_object_header(header, sizeof(header), |
ac77d0c3 | 436 | type, entry_size); |
c9018b03 NTND |
437 | |
438 | offset = entry->in_pack_offset; | |
952fc687 TB |
439 | if (offset_to_pack_pos(p, offset, &pos) < 0) |
440 | die(_("write_reuse_object: could not locate %s, expected at " | |
441 | "offset %"PRIuMAX" in pack %s"), | |
442 | oid_to_hex(&entry->idx.oid), (uintmax_t)offset, | |
443 | p->pack_name); | |
444 | datalen = pack_pos_to_offset(p, pos + 1) - offset; | |
c9018b03 | 445 | if (!pack_to_stdout && p->index_version > 1 && |
952fc687 TB |
446 | check_pack_crc(p, &w_curs, offset, datalen, |
447 | pack_pos_to_index(p, pos))) { | |
f616db6a | 448 | error(_("bad packed object CRC for %s"), |
e6a492b7 | 449 | oid_to_hex(&entry->idx.oid)); |
c9018b03 NTND |
450 | unuse_pack(&w_curs); |
451 | return write_no_reuse_object(f, entry, limit, usable_delta); | |
452 | } | |
453 | ||
454 | offset += entry->in_pack_header_size; | |
455 | datalen -= entry->in_pack_header_size; | |
456 | ||
457 | if (!pack_to_stdout && p->index_version == 1 && | |
ac77d0c3 | 458 | check_pack_inflate(p, &w_curs, offset, datalen, entry_size)) { |
f616db6a | 459 | error(_("corrupt packed object for %s"), |
e6a492b7 | 460 | oid_to_hex(&entry->idx.oid)); |
c9018b03 NTND |
461 | unuse_pack(&w_curs); |
462 | return write_no_reuse_object(f, entry, limit, usable_delta); | |
463 | } | |
464 | ||
465 | if (type == OBJ_OFS_DELTA) { | |
898eba5e | 466 | off_t ofs = entry->idx.offset - DELTA(entry)->idx.offset; |
c9018b03 NTND |
467 | unsigned pos = sizeof(dheader) - 1; |
468 | dheader[pos] = ofs & 127; | |
469 | while (ofs >>= 7) | |
470 | dheader[--pos] = 128 | (--ofs & 127); | |
41179100 | 471 | if (limit && hdrlen + sizeof(dheader) - pos + datalen + hashsz >= limit) { |
c9018b03 NTND |
472 | unuse_pack(&w_curs); |
473 | return 0; | |
474 | } | |
98a3beab | 475 | hashwrite(f, header, hdrlen); |
476 | hashwrite(f, dheader + pos, sizeof(dheader) - pos); | |
c9018b03 NTND |
477 | hdrlen += sizeof(dheader) - pos; |
478 | reused_delta++; | |
479 | } else if (type == OBJ_REF_DELTA) { | |
41179100 | 480 | if (limit && hdrlen + hashsz + datalen + hashsz >= limit) { |
c9018b03 NTND |
481 | unuse_pack(&w_curs); |
482 | return 0; | |
483 | } | |
98a3beab | 484 | hashwrite(f, header, hdrlen); |
42c8ce1c | 485 | hashwrite(f, DELTA(entry)->idx.oid.hash, hashsz); |
41179100 | 486 | hdrlen += hashsz; |
c9018b03 NTND |
487 | reused_delta++; |
488 | } else { | |
41179100 | 489 | if (limit && hdrlen + datalen + hashsz >= limit) { |
c9018b03 NTND |
490 | unuse_pack(&w_curs); |
491 | return 0; | |
492 | } | |
98a3beab | 493 | hashwrite(f, header, hdrlen); |
c9018b03 NTND |
494 | } |
495 | copy_pack_data(f, p, &w_curs, offset, datalen); | |
496 | unuse_pack(&w_curs); | |
497 | reused++; | |
498 | return hdrlen + datalen; | |
499 | } | |
500 | ||
501 | /* Return 0 if we will bust the pack-size limit */ | |
98a3beab | 502 | static off_t write_object(struct hashfile *f, |
af92a645 NTND |
503 | struct object_entry *entry, |
504 | off_t write_offset) | |
c9018b03 | 505 | { |
af92a645 NTND |
506 | unsigned long limit; |
507 | off_t len; | |
2c5ef824 | 508 | int usable_delta, to_reuse; |
c323ac7d | 509 | |
78d1e84f NP |
510 | if (!pack_to_stdout) |
511 | crc32_begin(f); | |
512 | ||
a2430dde | 513 | /* apply size limit if limited packsize and not first object */ |
a1e4760f NP |
514 | if (!pack_size_limit || !nr_written) |
515 | limit = 0; | |
516 | else if (pack_size_limit <= write_offset) | |
517 | /* | |
518 | * the earlier object did not fit the limit; avoid | |
519 | * mistaking this with unlimited (i.e. limit = 0). | |
520 | */ | |
521 | limit = 1; | |
522 | else | |
523 | limit = pack_size_limit - write_offset; | |
2c5ef824 | 524 | |
898eba5e | 525 | if (!DELTA(entry)) |
2c5ef824 NP |
526 | usable_delta = 0; /* no delta */ |
527 | else if (!pack_size_limit) | |
528 | usable_delta = 1; /* unlimited packfile */ | |
898eba5e | 529 | else if (DELTA(entry)->idx.offset == (off_t)-1) |
2c5ef824 | 530 | usable_delta = 0; /* base was written to another pack */ |
898eba5e | 531 | else if (DELTA(entry)->idx.offset) |
2c5ef824 NP |
532 | usable_delta = 1; /* base already exists in this pack */ |
533 | else | |
534 | usable_delta = 0; /* base could end up in another pack */ | |
535 | ||
a7de7130 | 536 | if (!reuse_object) |
fa736f72 | 537 | to_reuse = 0; /* explicit */ |
43fa44fa | 538 | else if (!IN_PACK(entry)) |
ab7cd7bb | 539 | to_reuse = 0; /* can't reuse what we don't have */ |
fd9b1bae NTND |
540 | else if (oe_type(entry) == OBJ_REF_DELTA || |
541 | oe_type(entry) == OBJ_OFS_DELTA) | |
17b08f2c DH |
542 | /* check_object() decided it for us ... */ |
543 | to_reuse = usable_delta; | |
544 | /* ... but pack split may override that */ | |
fd9b1bae | 545 | else if (oe_type(entry) != entry->in_pack_type) |
ab7cd7bb | 546 | to_reuse = 0; /* pack has delta which is unusable */ |
898eba5e | 547 | else if (DELTA(entry)) |
ab7cd7bb JH |
548 | to_reuse = 0; /* we want to pack afresh */ |
549 | else | |
550 | to_reuse = 1; /* we have it in-pack undeltified, | |
551 | * and we do not need to deltify it. | |
552 | */ | |
553 | ||
c9018b03 NTND |
554 | if (!to_reuse) |
555 | len = write_no_reuse_object(f, entry, limit, usable_delta); | |
556 | else | |
557 | len = write_reuse_object(f, entry, limit, usable_delta); | |
558 | if (!len) | |
559 | return 0; | |
64bd76b1 | 560 | |
17b08f2c | 561 | if (usable_delta) |
ab7cd7bb | 562 | written_delta++; |
3f9ac8d2 | 563 | written++; |
78d1e84f | 564 | if (!pack_to_stdout) |
aa7e44bf | 565 | entry->idx.crc32 = crc32_end(f); |
c9018b03 | 566 | return len; |
c323ac7d LT |
567 | } |
568 | ||
f63c79db JH |
569 | enum write_one_status { |
570 | WRITE_ONE_SKIP = -1, /* already written */ | |
571 | WRITE_ONE_BREAK = 0, /* writing this will bust the limit; not written */ | |
572 | WRITE_ONE_WRITTEN = 1, /* normal */ | |
573 | WRITE_ONE_RECURSIVE = 2 /* already scheduled to be written */ | |
574 | }; | |
575 | ||
98a3beab | 576 | static enum write_one_status write_one(struct hashfile *f, |
f63c79db JH |
577 | struct object_entry *e, |
578 | off_t *offset) | |
9d5ab962 | 579 | { |
af92a645 | 580 | off_t size; |
f63c79db | 581 | int recursing; |
d7dd0223 | 582 | |
f63c79db JH |
583 | /* |
584 | * we set offset to 1 (which is an impossible value) to mark | |
585 | * the fact that this object is involved in "write its base | |
586 | * first before writing a deltified object" recursion. | |
587 | */ | |
588 | recursing = (e->idx.offset == 1); | |
589 | if (recursing) { | |
f616db6a | 590 | warning(_("recursive delta detected for object %s"), |
e6a492b7 | 591 | oid_to_hex(&e->idx.oid)); |
f63c79db JH |
592 | return WRITE_ONE_RECURSIVE; |
593 | } else if (e->idx.offset || e->preferred_base) { | |
594 | /* offset is non zero if object is written already. */ | |
595 | return WRITE_ONE_SKIP; | |
596 | } | |
d7dd0223 | 597 | |
720c9f7b | 598 | /* if we are deltified, write out base object first. */ |
898eba5e | 599 | if (DELTA(e)) { |
f63c79db | 600 | e->idx.offset = 1; /* now recurse */ |
898eba5e | 601 | switch (write_one(f, DELTA(e), offset)) { |
f63c79db JH |
602 | case WRITE_ONE_RECURSIVE: |
603 | /* we cannot depend on this one */ | |
898eba5e | 604 | SET_DELTA(e, NULL); |
f63c79db JH |
605 | break; |
606 | default: | |
607 | break; | |
608 | case WRITE_ONE_BREAK: | |
609 | e->idx.offset = recursing; | |
610 | return WRITE_ONE_BREAK; | |
611 | } | |
612 | } | |
d7dd0223 | 613 | |
6ed7f25e NP |
614 | e->idx.offset = *offset; |
615 | size = write_object(f, e, *offset); | |
17b08f2c | 616 | if (!size) { |
f63c79db JH |
617 | e->idx.offset = recursing; |
618 | return WRITE_ONE_BREAK; | |
17b08f2c | 619 | } |
79814f42 | 620 | written_list[nr_written++] = &e->idx; |
d7dd0223 NP |
621 | |
622 | /* make sure off_t is sufficiently large not to wrap */ | |
c03c8315 | 623 | if (signed_add_overflows(*offset, size)) |
f616db6a | 624 | die(_("pack too large for current definition of off_t")); |
6ed7f25e | 625 | *offset += size; |
f63c79db | 626 | return WRITE_ONE_WRITTEN; |
9d5ab962 JH |
627 | } |
628 | ||
d155254c | 629 | static int mark_tagged(const char *path, const struct object_id *oid, int flag, |
1b4bb16b JH |
630 | void *cb_data) |
631 | { | |
188960b4 | 632 | struct object_id peeled; |
3a37876b | 633 | struct object_entry *entry = packlist_find(&to_pack, oid); |
1b4bb16b JH |
634 | |
635 | if (entry) | |
636 | entry->tagged = 1; | |
b420d909 | 637 | if (!peel_ref(path, &peeled)) { |
3a37876b | 638 | entry = packlist_find(&to_pack, &peeled); |
1b4bb16b JH |
639 | if (entry) |
640 | entry->tagged = 1; | |
641 | } | |
642 | return 0; | |
643 | } | |
644 | ||
be126818 | 645 | static inline void add_to_write_order(struct object_entry **wo, |
92bef1a1 | 646 | unsigned int *endp, |
1b4bb16b JH |
647 | struct object_entry *e) |
648 | { | |
fe0ac2fb | 649 | if (e->filled || oe_layer(&to_pack, e) != write_layer) |
1b4bb16b JH |
650 | return; |
651 | wo[(*endp)++] = e; | |
652 | e->filled = 1; | |
653 | } | |
654 | ||
655 | static void add_descendants_to_write_order(struct object_entry **wo, | |
92bef1a1 | 656 | unsigned int *endp, |
1b4bb16b JH |
657 | struct object_entry *e) |
658 | { | |
f380872f DM |
659 | int add_to_order = 1; |
660 | while (e) { | |
661 | if (add_to_order) { | |
662 | struct object_entry *s; | |
663 | /* add this node... */ | |
664 | add_to_write_order(wo, endp, e); | |
665 | /* all its siblings... */ | |
898eba5e | 666 | for (s = DELTA_SIBLING(e); s; s = DELTA_SIBLING(s)) { |
f380872f DM |
667 | add_to_write_order(wo, endp, s); |
668 | } | |
669 | } | |
670 | /* drop down a level to add left subtree nodes if possible */ | |
898eba5e | 671 | if (DELTA_CHILD(e)) { |
f380872f | 672 | add_to_order = 1; |
898eba5e | 673 | e = DELTA_CHILD(e); |
f380872f DM |
674 | } else { |
675 | add_to_order = 0; | |
676 | /* our sibling might have some children, it is next */ | |
898eba5e NTND |
677 | if (DELTA_SIBLING(e)) { |
678 | e = DELTA_SIBLING(e); | |
f380872f DM |
679 | continue; |
680 | } | |
681 | /* go back to our parent node */ | |
898eba5e NTND |
682 | e = DELTA(e); |
683 | while (e && !DELTA_SIBLING(e)) { | |
f380872f DM |
684 | /* we're on the right side of a subtree, keep |
685 | * going up until we can go right again */ | |
898eba5e | 686 | e = DELTA(e); |
f380872f DM |
687 | } |
688 | if (!e) { | |
689 | /* done- we hit our original root node */ | |
690 | return; | |
691 | } | |
692 | /* pass it off to sibling at this level */ | |
898eba5e | 693 | e = DELTA_SIBLING(e); |
f380872f DM |
694 | } |
695 | }; | |
1b4bb16b JH |
696 | } |
697 | ||
698 | static void add_family_to_write_order(struct object_entry **wo, | |
92bef1a1 | 699 | unsigned int *endp, |
1b4bb16b JH |
700 | struct object_entry *e) |
701 | { | |
702 | struct object_entry *root; | |
703 | ||
898eba5e | 704 | for (root = e; DELTA(root); root = DELTA(root)) |
1b4bb16b | 705 | ; /* nothing */ |
1b4bb16b JH |
706 | add_descendants_to_write_order(wo, endp, root); |
707 | } | |
708 | ||
f64ba53e | 709 | static void compute_layer_order(struct object_entry **wo, unsigned int *wo_end) |
1b4bb16b | 710 | { |
f64ba53e | 711 | unsigned int i, last_untagged; |
2834bc27 | 712 | struct object_entry *objects = to_pack.objects; |
1b4bb16b | 713 | |
2834bc27 | 714 | for (i = 0; i < to_pack.nr_objects; i++) { |
1b4bb16b JH |
715 | if (objects[i].tagged) |
716 | break; | |
f64ba53e | 717 | add_to_write_order(wo, wo_end, &objects[i]); |
1b4bb16b | 718 | } |
38d4debb | 719 | last_untagged = i; |
1b4bb16b JH |
720 | |
721 | /* | |
722 | * Then fill all the tagged tips. | |
723 | */ | |
2834bc27 | 724 | for (; i < to_pack.nr_objects; i++) { |
1b4bb16b | 725 | if (objects[i].tagged) |
f64ba53e | 726 | add_to_write_order(wo, wo_end, &objects[i]); |
1b4bb16b JH |
727 | } |
728 | ||
729 | /* | |
730 | * And then all remaining commits and tags. | |
731 | */ | |
2834bc27 | 732 | for (i = last_untagged; i < to_pack.nr_objects; i++) { |
fd9b1bae NTND |
733 | if (oe_type(&objects[i]) != OBJ_COMMIT && |
734 | oe_type(&objects[i]) != OBJ_TAG) | |
1b4bb16b | 735 | continue; |
f64ba53e | 736 | add_to_write_order(wo, wo_end, &objects[i]); |
1b4bb16b JH |
737 | } |
738 | ||
739 | /* | |
740 | * And then all the trees. | |
741 | */ | |
2834bc27 | 742 | for (i = last_untagged; i < to_pack.nr_objects; i++) { |
fd9b1bae | 743 | if (oe_type(&objects[i]) != OBJ_TREE) |
1b4bb16b | 744 | continue; |
f64ba53e | 745 | add_to_write_order(wo, wo_end, &objects[i]); |
1b4bb16b JH |
746 | } |
747 | ||
748 | /* | |
749 | * Finally all the rest in really tight order | |
750 | */ | |
2834bc27 | 751 | for (i = last_untagged; i < to_pack.nr_objects; i++) { |
fe0ac2fb | 752 | if (!objects[i].filled && oe_layer(&to_pack, &objects[i]) == write_layer) |
f64ba53e | 753 | add_family_to_write_order(wo, wo_end, &objects[i]); |
38d4debb | 754 | } |
f64ba53e CC |
755 | } |
756 | ||
757 | static struct object_entry **compute_write_order(void) | |
758 | { | |
28b8a730 | 759 | uint32_t max_layers = 1; |
f64ba53e CC |
760 | unsigned int i, wo_end; |
761 | ||
762 | struct object_entry **wo; | |
763 | struct object_entry *objects = to_pack.objects; | |
764 | ||
765 | for (i = 0; i < to_pack.nr_objects; i++) { | |
766 | objects[i].tagged = 0; | |
767 | objects[i].filled = 0; | |
768 | SET_DELTA_CHILD(&objects[i], NULL); | |
769 | SET_DELTA_SIBLING(&objects[i], NULL); | |
770 | } | |
771 | ||
772 | /* | |
773 | * Fully connect delta_child/delta_sibling network. | |
774 | * Make sure delta_sibling is sorted in the original | |
775 | * recency order. | |
776 | */ | |
777 | for (i = to_pack.nr_objects; i > 0;) { | |
778 | struct object_entry *e = &objects[--i]; | |
779 | if (!DELTA(e)) | |
780 | continue; | |
781 | /* Mark me as the first child */ | |
782 | e->delta_sibling_idx = DELTA(e)->delta_child_idx; | |
783 | SET_DELTA_CHILD(DELTA(e), e); | |
38d4debb DM |
784 | } |
785 | ||
f64ba53e CC |
786 | /* |
787 | * Mark objects that are at the tip of tags. | |
788 | */ | |
789 | for_each_tag_ref(mark_tagged, NULL); | |
790 | ||
28b8a730 JK |
791 | if (use_delta_islands) |
792 | max_layers = compute_pack_layers(&to_pack); | |
793 | ||
f64ba53e CC |
794 | ALLOC_ARRAY(wo, to_pack.nr_objects); |
795 | wo_end = 0; | |
796 | ||
28b8a730 JK |
797 | for (; write_layer < max_layers; ++write_layer) |
798 | compute_layer_order(wo, &wo_end); | |
38d4debb | 799 | |
2834bc27 | 800 | if (wo_end != to_pack.nr_objects) |
f616db6a NTND |
801 | die(_("ordered %u objects, expected %"PRIu32), |
802 | wo_end, to_pack.nr_objects); | |
1b4bb16b JH |
803 | |
804 | return wo; | |
805 | } | |
806 | ||
bb514de3 JK |
807 | |
808 | /* | |
809 | * A reused set of objects. All objects in a chunk have the same | |
810 | * relative position in the original packfile and the generated | |
811 | * packfile. | |
812 | */ | |
813 | ||
814 | static struct reused_chunk { | |
815 | /* The offset of the first object of this chunk in the original | |
816 | * packfile. */ | |
817 | off_t original; | |
818 | /* The offset of the first object of this chunk in the generated | |
819 | * packfile minus "original". */ | |
820 | off_t difference; | |
821 | } *reused_chunks; | |
822 | static int reused_chunks_nr; | |
823 | static int reused_chunks_alloc; | |
824 | ||
825 | static void record_reused_object(off_t where, off_t offset) | |
826 | { | |
827 | if (reused_chunks_nr && reused_chunks[reused_chunks_nr-1].difference == offset) | |
828 | return; | |
829 | ||
830 | ALLOC_GROW(reused_chunks, reused_chunks_nr + 1, | |
831 | reused_chunks_alloc); | |
832 | reused_chunks[reused_chunks_nr].original = where; | |
833 | reused_chunks[reused_chunks_nr].difference = offset; | |
834 | reused_chunks_nr++; | |
835 | } | |
836 | ||
837 | /* | |
838 | * Binary search to find the chunk that "where" is in. Note | |
839 | * that we're not looking for an exact match, just the first | |
840 | * chunk that contains it (which implicitly ends at the start | |
841 | * of the next chunk. | |
842 | */ | |
843 | static off_t find_reused_offset(off_t where) | |
6b8fda2d | 844 | { |
bb514de3 JK |
845 | int lo = 0, hi = reused_chunks_nr; |
846 | while (lo < hi) { | |
847 | int mi = lo + ((hi - lo) / 2); | |
848 | if (where == reused_chunks[mi].original) | |
849 | return reused_chunks[mi].difference; | |
850 | if (where < reused_chunks[mi].original) | |
851 | hi = mi; | |
852 | else | |
853 | lo = mi + 1; | |
854 | } | |
6b8fda2d | 855 | |
bb514de3 JK |
856 | /* |
857 | * The first chunk starts at zero, so we can't have gone below | |
858 | * there. | |
859 | */ | |
860 | assert(lo); | |
861 | return reused_chunks[lo-1].difference; | |
862 | } | |
6b8fda2d | 863 | |
bb514de3 JK |
864 | static void write_reused_pack_one(size_t pos, struct hashfile *out, |
865 | struct pack_window **w_curs) | |
6b8fda2d | 866 | { |
bb514de3 JK |
867 | off_t offset, next, cur; |
868 | enum object_type type; | |
869 | unsigned long size; | |
6b8fda2d | 870 | |
66cbd3e2 TB |
871 | offset = pack_pos_to_offset(reuse_packfile, pos); |
872 | next = pack_pos_to_offset(reuse_packfile, pos + 1); | |
6b8fda2d | 873 | |
bb514de3 | 874 | record_reused_object(offset, offset - hashfile_total(out)); |
6b8fda2d | 875 | |
bb514de3 JK |
876 | cur = offset; |
877 | type = unpack_object_header(reuse_packfile, w_curs, &cur, &size); | |
878 | assert(type >= 0); | |
6b8fda2d | 879 | |
bb514de3 JK |
880 | if (type == OBJ_OFS_DELTA) { |
881 | off_t base_offset; | |
882 | off_t fixup; | |
883 | ||
884 | unsigned char header[MAX_PACK_OBJECT_HEADER]; | |
885 | unsigned len; | |
886 | ||
887 | base_offset = get_delta_base(reuse_packfile, w_curs, &cur, type, offset); | |
888 | assert(base_offset != 0); | |
889 | ||
890 | /* Convert to REF_DELTA if we must... */ | |
891 | if (!allow_ofs_delta) { | |
66cbd3e2 | 892 | uint32_t base_pos; |
f66d4e02 JK |
893 | struct object_id base_oid; |
894 | ||
66cbd3e2 TB |
895 | if (offset_to_pack_pos(reuse_packfile, base_offset, &base_pos) < 0) |
896 | die(_("expected object at offset %"PRIuMAX" " | |
897 | "in pack %s"), | |
898 | (uintmax_t)base_offset, | |
899 | reuse_packfile->pack_name); | |
900 | ||
f66d4e02 | 901 | nth_packed_object_id(&base_oid, reuse_packfile, |
66cbd3e2 | 902 | pack_pos_to_index(reuse_packfile, base_pos)); |
bb514de3 JK |
903 | |
904 | len = encode_in_pack_object_header(header, sizeof(header), | |
905 | OBJ_REF_DELTA, size); | |
906 | hashwrite(out, header, len); | |
f8cb64e3 | 907 | hashwrite(out, base_oid.hash, the_hash_algo->rawsz); |
bb514de3 JK |
908 | copy_pack_data(out, reuse_packfile, w_curs, cur, next - cur); |
909 | return; | |
910 | } | |
6b8fda2d | 911 | |
bb514de3 JK |
912 | /* Otherwise see if we need to rewrite the offset... */ |
913 | fixup = find_reused_offset(offset) - | |
914 | find_reused_offset(base_offset); | |
915 | if (fixup) { | |
916 | unsigned char ofs_header[10]; | |
917 | unsigned i, ofs_len; | |
918 | off_t ofs = offset - base_offset - fixup; | |
6b8fda2d | 919 | |
bb514de3 JK |
920 | len = encode_in_pack_object_header(header, sizeof(header), |
921 | OBJ_OFS_DELTA, size); | |
6b8fda2d | 922 | |
bb514de3 JK |
923 | i = sizeof(ofs_header) - 1; |
924 | ofs_header[i] = ofs & 127; | |
925 | while (ofs >>= 7) | |
926 | ofs_header[--i] = 128 | (--ofs & 127); | |
6b8fda2d | 927 | |
bb514de3 | 928 | ofs_len = sizeof(ofs_header) - i; |
6b8fda2d | 929 | |
bb514de3 JK |
930 | hashwrite(out, header, len); |
931 | hashwrite(out, ofs_header + sizeof(ofs_header) - ofs_len, ofs_len); | |
932 | copy_pack_data(out, reuse_packfile, w_curs, cur, next - cur); | |
933 | return; | |
934 | } | |
935 | ||
936 | /* ...otherwise we have no fixup, and can write it verbatim */ | |
937 | } | |
938 | ||
939 | copy_pack_data(out, reuse_packfile, w_curs, offset, next - offset); | |
940 | } | |
941 | ||
942 | static size_t write_reused_pack_verbatim(struct hashfile *out, | |
943 | struct pack_window **w_curs) | |
944 | { | |
945 | size_t pos = 0; | |
946 | ||
947 | while (pos < reuse_packfile_bitmap->word_alloc && | |
948 | reuse_packfile_bitmap->words[pos] == (eword_t)~0) | |
949 | pos++; | |
950 | ||
951 | if (pos) { | |
952 | off_t to_write; | |
953 | ||
954 | written = (pos * BITS_IN_EWORD); | |
6a5c10c4 | 955 | to_write = pack_pos_to_offset(reuse_packfile, written) |
bb514de3 JK |
956 | - sizeof(struct pack_header); |
957 | ||
958 | /* We're recording one chunk, not one object. */ | |
959 | record_reused_object(sizeof(struct pack_header), 0); | |
960 | hashflush(out); | |
961 | copy_pack_data(out, reuse_packfile, w_curs, | |
962 | sizeof(struct pack_header), to_write); | |
657673f1 | 963 | |
657673f1 | 964 | display_progress(progress_state, written); |
6b8fda2d | 965 | } |
bb514de3 JK |
966 | return pos; |
967 | } | |
968 | ||
969 | static void write_reused_pack(struct hashfile *f) | |
970 | { | |
971 | size_t i = 0; | |
972 | uint32_t offset; | |
973 | struct pack_window *w_curs = NULL; | |
974 | ||
975 | if (allow_ofs_delta) | |
976 | i = write_reused_pack_verbatim(f, &w_curs); | |
977 | ||
978 | for (; i < reuse_packfile_bitmap->word_alloc; ++i) { | |
979 | eword_t word = reuse_packfile_bitmap->words[i]; | |
980 | size_t pos = (i * BITS_IN_EWORD); | |
6b8fda2d | 981 | |
bb514de3 JK |
982 | for (offset = 0; offset < BITS_IN_EWORD; ++offset) { |
983 | if ((word >> offset) == 0) | |
984 | break; | |
985 | ||
986 | offset += ewah_bit_ctz64(word >> offset); | |
987 | write_reused_pack_one(pos + offset, f, &w_curs); | |
988 | display_progress(progress_state, ++written); | |
989 | } | |
990 | } | |
6b8fda2d | 991 | |
bb514de3 | 992 | unuse_pack(&w_curs); |
6b8fda2d VM |
993 | } |
994 | ||
dd4b732d JT |
995 | static void write_excluded_by_configs(void) |
996 | { | |
997 | struct oidset_iter iter; | |
998 | const struct object_id *oid; | |
999 | ||
1000 | oidset_iter_init(&excluded_by_config, &iter); | |
1001 | while ((oid = oidset_iter_next(&iter))) { | |
1002 | struct configured_exclusion *ex = | |
1003 | oidmap_get(&configured_exclusions, oid); | |
1004 | ||
1005 | if (!ex) | |
1006 | BUG("configured exclusion wasn't configured"); | |
1007 | write_in_full(1, ex->pack_hash_hex, strlen(ex->pack_hash_hex)); | |
1008 | write_in_full(1, " ", 1); | |
1009 | write_in_full(1, ex->uri, strlen(ex->uri)); | |
1010 | write_in_full(1, "\n", 1); | |
1011 | } | |
1012 | } | |
1013 | ||
9cea46cd EW |
1014 | static const char no_split_warning[] = N_( |
1015 | "disabling bitmap writing, packs are split due to pack.packSizeLimit" | |
1016 | ); | |
1017 | ||
d01fb92f | 1018 | static void write_pack_file(void) |
c323ac7d | 1019 | { |
ebe27b13 | 1020 | uint32_t i = 0, j; |
98a3beab | 1021 | struct hashfile *f; |
6ed7f25e | 1022 | off_t offset; |
ebe27b13 | 1023 | uint32_t nr_remaining = nr_result; |
f746bae8 | 1024 | time_t last_mtime = 0; |
1b4bb16b | 1025 | struct object_entry **write_order; |
81a216a5 | 1026 | |
bcd7954e | 1027 | if (progress > pack_to_stdout) |
754dbc43 | 1028 | progress_state = start_progress(_("Writing objects"), nr_result); |
b32fa95f | 1029 | ALLOC_ARRAY(written_list, to_pack.nr_objects); |
1b4bb16b | 1030 | write_order = compute_write_order(); |
183bdb2c | 1031 | |
ebe27b13 | 1032 | do { |
188960b4 | 1033 | struct object_id oid; |
7ba502c4 | 1034 | char *pack_tmp_name = NULL; |
aa7e44bf | 1035 | |
cdf9db3c | 1036 | if (pack_to_stdout) |
98a3beab | 1037 | f = hashfd_throughput(1, "<stdout>", progress_state); |
cdf9db3c JH |
1038 | else |
1039 | f = create_tmp_packfile(&pack_tmp_name); | |
ebe27b13 | 1040 | |
c0ad4657 | 1041 | offset = write_pack_header(f, nr_remaining); |
6b8fda2d VM |
1042 | |
1043 | if (reuse_packfile) { | |
6b8fda2d | 1044 | assert(pack_to_stdout); |
bb514de3 JK |
1045 | write_reused_pack(f); |
1046 | offset = hashfile_total(f); | |
6b8fda2d VM |
1047 | } |
1048 | ||
ebe27b13 | 1049 | nr_written = 0; |
2834bc27 | 1050 | for (; i < to_pack.nr_objects; i++) { |
1b4bb16b | 1051 | struct object_entry *e = write_order[i]; |
cddec4f8 | 1052 | if (write_one(f, e, &offset) == WRITE_ONE_BREAK) |
720c9f7b NP |
1053 | break; |
1054 | display_progress(progress_state, written); | |
1055 | } | |
c553ca25 | 1056 | |
ebe27b13 DH |
1057 | /* |
1058 | * Did we write the wrong # entries in the header? | |
1059 | * If so, rewrite it like in fast-import | |
1060 | */ | |
54352bb2 | 1061 | if (pack_to_stdout) { |
cfe83216 | 1062 | finalize_hashfile(f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_CLOSE); |
54352bb2 | 1063 | } else if (nr_written == nr_remaining) { |
cfe83216 | 1064 | finalize_hashfile(f, oid.hash, CSUM_HASH_IN_STREAM | CSUM_FSYNC | CSUM_CLOSE); |
ebe27b13 | 1065 | } else { |
f2af9f5e | 1066 | int fd = finalize_hashfile(f, oid.hash, 0); |
188960b4 | 1067 | fixup_pack_header_footer(fd, oid.hash, pack_tmp_name, |
1068 | nr_written, oid.hash, offset); | |
7ba502c4 | 1069 | close(fd); |
9cea46cd | 1070 | if (write_bitmap_index) { |
25575015 JK |
1071 | if (write_bitmap_index != WRITE_BITMAP_QUIET) |
1072 | warning(_(no_split_warning)); | |
9cea46cd EW |
1073 | write_bitmap_index = 0; |
1074 | } | |
ebe27b13 DH |
1075 | } |
1076 | ||
1077 | if (!pack_to_stdout) { | |
f746bae8 | 1078 | struct stat st; |
58892711 | 1079 | struct strbuf tmpname = STRBUF_INIT; |
d01fb92f | 1080 | |
f746bae8 NP |
1081 | /* |
1082 | * Packs are runtime accessed in their mtime | |
1083 | * order since newer packs are more likely to contain | |
1084 | * younger objects. So if we are creating multiple | |
1085 | * packs then we should modify the mtime of later ones | |
1086 | * to preserve this property. | |
1087 | */ | |
0e990530 | 1088 | if (stat(pack_tmp_name, &st) < 0) { |
f616db6a | 1089 | warning_errno(_("failed to stat %s"), pack_tmp_name); |
f746bae8 NP |
1090 | } else if (!last_mtime) { |
1091 | last_mtime = st.st_mtime; | |
1092 | } else { | |
1093 | struct utimbuf utb; | |
1094 | utb.actime = st.st_atime; | |
1095 | utb.modtime = --last_mtime; | |
0e990530 | 1096 | if (utime(pack_tmp_name, &utb) < 0) |
f616db6a | 1097 | warning_errno(_("failed utime() on %s"), pack_tmp_name); |
f746bae8 NP |
1098 | } |
1099 | ||
58892711 | 1100 | strbuf_addf(&tmpname, "%s-", base_name); |
7cc8f971 VM |
1101 | |
1102 | if (write_bitmap_index) { | |
188960b4 | 1103 | bitmap_writer_set_checksum(oid.hash); |
06af3bba NTND |
1104 | bitmap_writer_build_type_index( |
1105 | &to_pack, written_list, nr_written); | |
7cc8f971 VM |
1106 | } |
1107 | ||
58892711 | 1108 | finish_tmp_packfile(&tmpname, pack_tmp_name, |
0e990530 | 1109 | written_list, nr_written, |
188960b4 | 1110 | &pack_idx_opts, oid.hash); |
7cc8f971 VM |
1111 | |
1112 | if (write_bitmap_index) { | |
188960b4 | 1113 | strbuf_addf(&tmpname, "%s.bitmap", oid_to_hex(&oid)); |
7cc8f971 VM |
1114 | |
1115 | stop_progress(&progress_state); | |
1116 | ||
1117 | bitmap_writer_show_progress(progress); | |
7cc8f971 VM |
1118 | bitmap_writer_select_commits(indexed_commits, indexed_commits_nr, -1); |
1119 | bitmap_writer_build(&to_pack); | |
ae4f07fb | 1120 | bitmap_writer_finish(written_list, nr_written, |
58892711 | 1121 | tmpname.buf, write_bitmap_options); |
7cc8f971 VM |
1122 | write_bitmap_index = 0; |
1123 | } | |
1124 | ||
58892711 | 1125 | strbuf_release(&tmpname); |
7ba502c4 | 1126 | free(pack_tmp_name); |
188960b4 | 1127 | puts(oid_to_hex(&oid)); |
ebe27b13 DH |
1128 | } |
1129 | ||
1130 | /* mark written objects as written to previous pack */ | |
1131 | for (j = 0; j < nr_written; j++) { | |
79814f42 | 1132 | written_list[j]->offset = (off_t)-1; |
ebe27b13 DH |
1133 | } |
1134 | nr_remaining -= nr_written; | |
2834bc27 | 1135 | } while (nr_remaining && i < to_pack.nr_objects); |
ebe27b13 DH |
1136 | |
1137 | free(written_list); | |
1b4bb16b | 1138 | free(write_order); |
4d4fcc54 | 1139 | stop_progress(&progress_state); |
67c08ce1 | 1140 | if (written != nr_result) |
f616db6a NTND |
1141 | die(_("wrote %"PRIu32" objects while expecting %"PRIu32), |
1142 | written, nr_result); | |
9ed87902 JT |
1143 | trace2_data_intmax("pack-objects", the_repository, |
1144 | "write_pack_file/wrote", nr_result); | |
c323ac7d LT |
1145 | } |
1146 | ||
a74db82e JH |
1147 | static int no_try_delta(const char *path) |
1148 | { | |
2aef63d3 | 1149 | static struct attr_check *check; |
a74db82e | 1150 | |
2aef63d3 JH |
1151 | if (!check) |
1152 | check = attr_check_initl("delta", NULL); | |
f8adbec9 | 1153 | git_check_attr(the_repository->index, path, check); |
2aef63d3 | 1154 | if (ATTR_FALSE(check->items[0].value)) |
a74db82e JH |
1155 | return 1; |
1156 | return 0; | |
1157 | } | |
1158 | ||
ce2bc424 JK |
1159 | /* |
1160 | * When adding an object, check whether we have already added it | |
1161 | * to our packing list. If so, we can skip. However, if we are | |
1162 | * being asked to excludei t, but the previous mention was to include | |
1163 | * it, make sure to adjust its flags and tweak our numbers accordingly. | |
1164 | * | |
1165 | * As an optimization, we pass out the index position where we would have | |
1166 | * found the item, since that saves us from having to look it up again a | |
1167 | * few lines later when we want to add the new entry. | |
1168 | */ | |
188960b4 | 1169 | static int have_duplicate_entry(const struct object_id *oid, |
3a37876b | 1170 | int exclude) |
c323ac7d | 1171 | { |
c323ac7d | 1172 | struct object_entry *entry; |
29b734e4 | 1173 | |
92fb0db9 JK |
1174 | if (reuse_packfile_bitmap && |
1175 | bitmap_walk_contains(bitmap_git, reuse_packfile_bitmap, oid)) | |
1176 | return 1; | |
1177 | ||
3a37876b | 1178 | entry = packlist_find(&to_pack, oid); |
ce2bc424 | 1179 | if (!entry) |
29b734e4 | 1180 | return 0; |
ce2bc424 JK |
1181 | |
1182 | if (exclude) { | |
1183 | if (!entry->preferred_base) | |
1184 | nr_result--; | |
1185 | entry->preferred_base = 1; | |
29b734e4 | 1186 | } |
c323ac7d | 1187 | |
ce2bc424 JK |
1188 | return 1; |
1189 | } | |
1190 | ||
702d1b95 KS |
1191 | static int want_found_object(int exclude, struct packed_git *p) |
1192 | { | |
1193 | if (exclude) | |
1194 | return 1; | |
1195 | if (incremental) | |
1196 | return 0; | |
1197 | ||
1198 | /* | |
1199 | * When asked to do --local (do not include an object that appears in a | |
1200 | * pack we borrow from elsewhere) or --honor-pack-keep (do not include | |
1201 | * an object that appears in a pack marked with .keep), finding a pack | |
1202 | * that matches the criteria is sufficient for us to decide to omit it. | |
1203 | * However, even if this pack does not satisfy the criteria, we need to | |
1204 | * make sure no copy of this object appears in _any_ pack that makes us | |
1205 | * to omit the object, so we need to check all the packs. | |
1206 | * | |
1207 | * We can however first check whether these options can possible matter; | |
1208 | * if they do not matter we know we want the object in generated pack. | |
1209 | * Otherwise, we signal "-1" at the end to tell the caller that we do | |
1210 | * not know either way, and it needs to check more packs. | |
1211 | */ | |
ed7e5fc3 NTND |
1212 | if (!ignore_packed_keep_on_disk && |
1213 | !ignore_packed_keep_in_core && | |
702d1b95 KS |
1214 | (!local || !have_non_local_packs)) |
1215 | return 1; | |
1216 | ||
1217 | if (local && !p->pack_local) | |
1218 | return 0; | |
ed7e5fc3 NTND |
1219 | if (p->pack_local && |
1220 | ((ignore_packed_keep_on_disk && p->pack_keep) || | |
1221 | (ignore_packed_keep_in_core && p->pack_keep_in_core))) | |
702d1b95 KS |
1222 | return 0; |
1223 | ||
1224 | /* we don't know yet; keep looking for more packs */ | |
1225 | return -1; | |
1226 | } | |
1227 | ||
ce2bc424 JK |
1228 | /* |
1229 | * Check whether we want the object in the pack (e.g., we do not want | |
1230 | * objects found in non-local stores if the "--local" option was used). | |
1231 | * | |
702d1b95 KS |
1232 | * If the caller already knows an existing pack it wants to take the object |
1233 | * from, that is passed in *found_pack and *found_offset; otherwise this | |
1234 | * function finds if there is any pack that has the object and returns the pack | |
1235 | * and its offset in these variables. | |
ce2bc424 | 1236 | */ |
188960b4 | 1237 | static int want_object_in_pack(const struct object_id *oid, |
ce2bc424 JK |
1238 | int exclude, |
1239 | struct packed_git **found_pack, | |
1240 | off_t *found_offset) | |
1241 | { | |
702d1b95 | 1242 | int want; |
8865859d | 1243 | struct list_head *pos; |
6a22d521 | 1244 | struct multi_pack_index *m; |
ce2bc424 | 1245 | |
6862ebbf | 1246 | if (!exclude && local && has_loose_object_nonlocal(oid)) |
daae0625 BC |
1247 | return 0; |
1248 | ||
702d1b95 KS |
1249 | /* |
1250 | * If we already know the pack object lives in, start checks from that | |
1251 | * pack - in the usual case when neither --local was given nor .keep files | |
1252 | * are present we will determine the answer right now. | |
1253 | */ | |
1254 | if (*found_pack) { | |
1255 | want = want_found_object(exclude, *found_pack); | |
1256 | if (want != -1) | |
1257 | return want; | |
1258 | } | |
6a22d521 DS |
1259 | |
1260 | for (m = get_multi_pack_index(the_repository); m; m = m->next) { | |
1261 | struct pack_entry e; | |
64404a24 | 1262 | if (fill_midx_entry(the_repository, oid, &e, m)) { |
6a22d521 DS |
1263 | struct packed_git *p = e.p; |
1264 | off_t offset; | |
1265 | ||
1266 | if (p == *found_pack) | |
1267 | offset = *found_offset; | |
1268 | else | |
1269 | offset = find_pack_entry_one(oid->hash, p); | |
1270 | ||
1271 | if (offset) { | |
1272 | if (!*found_pack) { | |
1273 | if (!is_pack_valid(p)) | |
1274 | continue; | |
1275 | *found_offset = offset; | |
1276 | *found_pack = p; | |
1277 | } | |
1278 | want = want_found_object(exclude, p); | |
1279 | if (want != -1) | |
1280 | return want; | |
1281 | } | |
1282 | } | |
1283 | } | |
1284 | ||
a80d72db | 1285 | list_for_each(pos, get_packed_git_mru(the_repository)) { |
ec2dd32c | 1286 | struct packed_git *p = list_entry(pos, struct packed_git, mru); |
702d1b95 KS |
1287 | off_t offset; |
1288 | ||
1289 | if (p == *found_pack) | |
1290 | offset = *found_offset; | |
1291 | else | |
188960b4 | 1292 | offset = find_pack_entry_one(oid->hash, p); |
702d1b95 | 1293 | |
5c49c116 | 1294 | if (offset) { |
ce2bc424 | 1295 | if (!*found_pack) { |
319b678a | 1296 | if (!is_pack_valid(p)) |
4c080182 | 1297 | continue; |
ce2bc424 JK |
1298 | *found_offset = offset; |
1299 | *found_pack = p; | |
64560374 | 1300 | } |
702d1b95 | 1301 | want = want_found_object(exclude, p); |
e6e24c94 | 1302 | if (!exclude && want > 0) |
a80d72db SB |
1303 | list_move(&p->mru, |
1304 | get_packed_git_mru(the_repository)); | |
702d1b95 KS |
1305 | if (want != -1) |
1306 | return want; | |
64560374 LT |
1307 | } |
1308 | } | |
eb019375 | 1309 | |
dd4b732d JT |
1310 | if (uri_protocols.nr) { |
1311 | struct configured_exclusion *ex = | |
1312 | oidmap_get(&configured_exclusions, oid); | |
1313 | int i; | |
1314 | const char *p; | |
1315 | ||
1316 | if (ex) { | |
1317 | for (i = 0; i < uri_protocols.nr; i++) { | |
1318 | if (skip_prefix(ex->uri, | |
1319 | uri_protocols.items[i].string, | |
1320 | &p) && | |
1321 | *p == ':') { | |
1322 | oidset_insert(&excluded_by_config, oid); | |
1323 | return 0; | |
1324 | } | |
1325 | } | |
1326 | } | |
1327 | } | |
1328 | ||
ce2bc424 JK |
1329 | return 1; |
1330 | } | |
1331 | ||
188960b4 | 1332 | static void create_object_entry(const struct object_id *oid, |
ce2bc424 JK |
1333 | enum object_type type, |
1334 | uint32_t hash, | |
1335 | int exclude, | |
1336 | int no_try_delta, | |
ce2bc424 JK |
1337 | struct packed_git *found_pack, |
1338 | off_t found_offset) | |
1339 | { | |
1340 | struct object_entry *entry; | |
29b734e4 | 1341 | |
3a37876b | 1342 | entry = packlist_alloc(&to_pack, oid); |
27225f2e | 1343 | entry->hash = hash; |
fd9b1bae | 1344 | oe_set_type(entry, type); |
29b734e4 NP |
1345 | if (exclude) |
1346 | entry->preferred_base = 1; | |
81a216a5 NP |
1347 | else |
1348 | nr_result++; | |
29b734e4 | 1349 | if (found_pack) { |
43fa44fa | 1350 | oe_set_in_pack(&to_pack, entry, found_pack); |
29b734e4 NP |
1351 | entry->in_pack_offset = found_offset; |
1352 | } | |
7a979d99 | 1353 | |
ce2bc424 JK |
1354 | entry->no_try_delta = no_try_delta; |
1355 | } | |
29b734e4 | 1356 | |
373c67da JK |
1357 | static const char no_closure_warning[] = N_( |
1358 | "disabling bitmap writing, as some objects are not being packed" | |
1359 | ); | |
1360 | ||
188960b4 | 1361 | static int add_object_entry(const struct object_id *oid, enum object_type type, |
ce2bc424 JK |
1362 | const char *name, int exclude) |
1363 | { | |
702d1b95 KS |
1364 | struct packed_git *found_pack = NULL; |
1365 | off_t found_offset = 0; | |
7a979d99 | 1366 | |
5af05043 NTND |
1367 | display_progress(progress_state, ++nr_seen); |
1368 | ||
3a37876b | 1369 | if (have_duplicate_entry(oid, exclude)) |
ce2bc424 | 1370 | return 0; |
a74db82e | 1371 | |
188960b4 | 1372 | if (!want_object_in_pack(oid, exclude, &found_pack, &found_offset)) { |
373c67da JK |
1373 | /* The pack is missing an object, so it will not have closure */ |
1374 | if (write_bitmap_index) { | |
25575015 JK |
1375 | if (write_bitmap_index != WRITE_BITMAP_QUIET) |
1376 | warning(_(no_closure_warning)); | |
373c67da JK |
1377 | write_bitmap_index = 0; |
1378 | } | |
ce2bc424 | 1379 | return 0; |
373c67da | 1380 | } |
29b734e4 | 1381 | |
188960b4 | 1382 | create_object_entry(oid, type, pack_name_hash(name), |
ce2bc424 | 1383 | exclude, name && no_try_delta(name), |
3a37876b | 1384 | found_pack, found_offset); |
29b734e4 | 1385 | return 1; |
c323ac7d LT |
1386 | } |
1387 | ||
20664967 | 1388 | static int add_object_entry_from_bitmap(const struct object_id *oid, |
6b8fda2d VM |
1389 | enum object_type type, |
1390 | int flags, uint32_t name_hash, | |
1391 | struct packed_git *pack, off_t offset) | |
1392 | { | |
5af05043 NTND |
1393 | display_progress(progress_state, ++nr_seen); |
1394 | ||
3a37876b | 1395 | if (have_duplicate_entry(oid, 0)) |
6b8fda2d VM |
1396 | return 0; |
1397 | ||
188960b4 | 1398 | if (!want_object_in_pack(oid, 0, &pack, &offset)) |
702d1b95 KS |
1399 | return 0; |
1400 | ||
3a37876b | 1401 | create_object_entry(oid, type, name_hash, 0, 0, pack, offset); |
29b734e4 | 1402 | return 1; |
c323ac7d LT |
1403 | } |
1404 | ||
5379a5c5 | 1405 | struct pbase_tree_cache { |
188960b4 | 1406 | struct object_id oid; |
5379a5c5 JH |
1407 | int ref; |
1408 | int temporary; | |
1409 | void *tree_data; | |
1410 | unsigned long tree_size; | |
1411 | }; | |
1412 | ||
1413 | static struct pbase_tree_cache *(pbase_tree_cache[256]); | |
188960b4 | 1414 | static int pbase_tree_cache_ix(const struct object_id *oid) |
5379a5c5 | 1415 | { |
188960b4 | 1416 | return oid->hash[0] % ARRAY_SIZE(pbase_tree_cache); |
5379a5c5 JH |
1417 | } |
1418 | static int pbase_tree_cache_ix_incr(int ix) | |
1419 | { | |
1420 | return (ix+1) % ARRAY_SIZE(pbase_tree_cache); | |
1421 | } | |
1422 | ||
1423 | static struct pbase_tree { | |
1424 | struct pbase_tree *next; | |
1425 | /* This is a phony "cache" entry; we are not | |
01689909 | 1426 | * going to evict it or find it through _get() |
5379a5c5 JH |
1427 | * mechanism -- this is for the toplevel node that |
1428 | * would almost always change with any commit. | |
1429 | */ | |
1430 | struct pbase_tree_cache pcache; | |
1431 | } *pbase_tree; | |
1432 | ||
188960b4 | 1433 | static struct pbase_tree_cache *pbase_tree_get(const struct object_id *oid) |
5379a5c5 JH |
1434 | { |
1435 | struct pbase_tree_cache *ent, *nent; | |
1436 | void *data; | |
1437 | unsigned long size; | |
21666f1a | 1438 | enum object_type type; |
5379a5c5 | 1439 | int neigh; |
188960b4 | 1440 | int my_ix = pbase_tree_cache_ix(oid); |
5379a5c5 JH |
1441 | int available_ix = -1; |
1442 | ||
1443 | /* pbase-tree-cache acts as a limited hashtable. | |
1444 | * your object will be found at your index or within a few | |
1445 | * slots after that slot if it is cached. | |
1446 | */ | |
1447 | for (neigh = 0; neigh < 8; neigh++) { | |
1448 | ent = pbase_tree_cache[my_ix]; | |
4a7e27e9 | 1449 | if (ent && oideq(&ent->oid, oid)) { |
5379a5c5 JH |
1450 | ent->ref++; |
1451 | return ent; | |
1452 | } | |
1453 | else if (((available_ix < 0) && (!ent || !ent->ref)) || | |
1454 | ((0 <= available_ix) && | |
1455 | (!ent && pbase_tree_cache[available_ix]))) | |
1456 | available_ix = my_ix; | |
1457 | if (!ent) | |
1458 | break; | |
1459 | my_ix = pbase_tree_cache_ix_incr(my_ix); | |
1460 | } | |
1461 | ||
1462 | /* Did not find one. Either we got a bogus request or | |
1463 | * we need to read and perhaps cache. | |
1464 | */ | |
b4f5aca4 | 1465 | data = read_object_file(oid, &type, &size); |
5379a5c5 JH |
1466 | if (!data) |
1467 | return NULL; | |
21666f1a | 1468 | if (type != OBJ_TREE) { |
5379a5c5 JH |
1469 | free(data); |
1470 | return NULL; | |
1471 | } | |
1472 | ||
1473 | /* We need to either cache or return a throwaway copy */ | |
1474 | ||
1475 | if (available_ix < 0) | |
1476 | ent = NULL; | |
1477 | else { | |
1478 | ent = pbase_tree_cache[available_ix]; | |
1479 | my_ix = available_ix; | |
1480 | } | |
1481 | ||
1482 | if (!ent) { | |
1483 | nent = xmalloc(sizeof(*nent)); | |
1484 | nent->temporary = (available_ix < 0); | |
1485 | } | |
1486 | else { | |
1487 | /* evict and reuse */ | |
1488 | free(ent->tree_data); | |
1489 | nent = ent; | |
1490 | } | |
188960b4 | 1491 | oidcpy(&nent->oid, oid); |
5379a5c5 JH |
1492 | nent->tree_data = data; |
1493 | nent->tree_size = size; | |
1494 | nent->ref = 1; | |
1495 | if (!nent->temporary) | |
1496 | pbase_tree_cache[my_ix] = nent; | |
1497 | return nent; | |
1498 | } | |
1499 | ||
1500 | static void pbase_tree_put(struct pbase_tree_cache *cache) | |
1501 | { | |
1502 | if (!cache->temporary) { | |
1503 | cache->ref--; | |
1504 | return; | |
1505 | } | |
1506 | free(cache->tree_data); | |
1507 | free(cache); | |
1508 | } | |
1509 | ||
1510 | static int name_cmp_len(const char *name) | |
1511 | { | |
1512 | int i; | |
1513 | for (i = 0; name[i] && name[i] != '\n' && name[i] != '/'; i++) | |
1514 | ; | |
1515 | return i; | |
1516 | } | |
1517 | ||
1518 | static void add_pbase_object(struct tree_desc *tree, | |
5379a5c5 | 1519 | const char *name, |
ce0bd642 LT |
1520 | int cmplen, |
1521 | const char *fullname) | |
3f9ac8d2 | 1522 | { |
4c068a98 | 1523 | struct name_entry entry; |
8a5a8d6c | 1524 | int cmp; |
4c068a98 LT |
1525 | |
1526 | while (tree_entry(tree,&entry)) { | |
1211be6b LT |
1527 | if (S_ISGITLINK(entry.mode)) |
1528 | continue; | |
0de16337 | 1529 | cmp = tree_entry_len(&entry) != cmplen ? 1 : |
8a5a8d6c NP |
1530 | memcmp(name, entry.path, cmplen); |
1531 | if (cmp > 0) | |
7a979d99 | 1532 | continue; |
8a5a8d6c NP |
1533 | if (cmp < 0) |
1534 | return; | |
5379a5c5 | 1535 | if (name[cmplen] != '/') { |
ea82b2a0 | 1536 | add_object_entry(&entry.oid, |
4d1012c3 | 1537 | object_type(entry.mode), |
bc32fed5 | 1538 | fullname, 1); |
5379a5c5 JH |
1539 | return; |
1540 | } | |
8a5a8d6c | 1541 | if (S_ISDIR(entry.mode)) { |
7a979d99 | 1542 | struct tree_desc sub; |
5379a5c5 JH |
1543 | struct pbase_tree_cache *tree; |
1544 | const char *down = name+cmplen+1; | |
1545 | int downlen = name_cmp_len(down); | |
1546 | ||
ea82b2a0 | 1547 | tree = pbase_tree_get(&entry.oid); |
5379a5c5 JH |
1548 | if (!tree) |
1549 | return; | |
6fda5e51 | 1550 | init_tree_desc(&sub, tree->tree_data, tree->tree_size); |
5379a5c5 | 1551 | |
ce0bd642 | 1552 | add_pbase_object(&sub, down, downlen, fullname); |
5379a5c5 JH |
1553 | pbase_tree_put(tree); |
1554 | } | |
1555 | } | |
1556 | } | |
1d6b38cc | 1557 | |
5379a5c5 JH |
1558 | static unsigned *done_pbase_paths; |
1559 | static int done_pbase_paths_num; | |
1560 | static int done_pbase_paths_alloc; | |
1561 | static int done_pbase_path_pos(unsigned hash) | |
1562 | { | |
1563 | int lo = 0; | |
1564 | int hi = done_pbase_paths_num; | |
1565 | while (lo < hi) { | |
19716b21 | 1566 | int mi = lo + (hi - lo) / 2; |
5379a5c5 JH |
1567 | if (done_pbase_paths[mi] == hash) |
1568 | return mi; | |
1569 | if (done_pbase_paths[mi] < hash) | |
1570 | hi = mi; | |
1571 | else | |
1572 | lo = mi + 1; | |
1573 | } | |
1574 | return -lo-1; | |
1575 | } | |
1576 | ||
1577 | static int check_pbase_path(unsigned hash) | |
1578 | { | |
c7b07805 | 1579 | int pos = done_pbase_path_pos(hash); |
5379a5c5 JH |
1580 | if (0 <= pos) |
1581 | return 1; | |
1582 | pos = -pos - 1; | |
25e19407 DD |
1583 | ALLOC_GROW(done_pbase_paths, |
1584 | done_pbase_paths_num + 1, | |
1585 | done_pbase_paths_alloc); | |
5379a5c5 JH |
1586 | done_pbase_paths_num++; |
1587 | if (pos < done_pbase_paths_num) | |
f331ab9d RS |
1588 | MOVE_ARRAY(done_pbase_paths + pos + 1, done_pbase_paths + pos, |
1589 | done_pbase_paths_num - pos - 1); | |
5379a5c5 JH |
1590 | done_pbase_paths[pos] = hash; |
1591 | return 0; | |
1592 | } | |
1593 | ||
bc32fed5 | 1594 | static void add_preferred_base_object(const char *name) |
5379a5c5 JH |
1595 | { |
1596 | struct pbase_tree *it; | |
8a5a8d6c | 1597 | int cmplen; |
68fb36eb | 1598 | unsigned hash = pack_name_hash(name); |
5379a5c5 | 1599 | |
8a5a8d6c | 1600 | if (!num_preferred_base || check_pbase_path(hash)) |
5379a5c5 JH |
1601 | return; |
1602 | ||
8a5a8d6c | 1603 | cmplen = name_cmp_len(name); |
5379a5c5 JH |
1604 | for (it = pbase_tree; it; it = it->next) { |
1605 | if (cmplen == 0) { | |
188960b4 | 1606 | add_object_entry(&it->pcache.oid, OBJ_TREE, NULL, 1); |
5379a5c5 JH |
1607 | } |
1608 | else { | |
1609 | struct tree_desc tree; | |
6fda5e51 | 1610 | init_tree_desc(&tree, it->pcache.tree_data, it->pcache.tree_size); |
ce0bd642 | 1611 | add_pbase_object(&tree, name, cmplen, name); |
7a979d99 | 1612 | } |
3f9ac8d2 | 1613 | } |
3f9ac8d2 JH |
1614 | } |
1615 | ||
188960b4 | 1616 | static void add_preferred_base(struct object_id *oid) |
3f9ac8d2 | 1617 | { |
5379a5c5 JH |
1618 | struct pbase_tree *it; |
1619 | void *data; | |
1620 | unsigned long size; | |
188960b4 | 1621 | struct object_id tree_oid; |
1d6b38cc | 1622 | |
8d1d8f83 JH |
1623 | if (window <= num_preferred_base++) |
1624 | return; | |
1625 | ||
d3b4705a NTND |
1626 | data = read_object_with_reference(the_repository, oid, |
1627 | tree_type, &size, &tree_oid); | |
5379a5c5 | 1628 | if (!data) |
7a979d99 | 1629 | return; |
5379a5c5 JH |
1630 | |
1631 | for (it = pbase_tree; it; it = it->next) { | |
4a7e27e9 | 1632 | if (oideq(&it->pcache.oid, &tree_oid)) { |
5379a5c5 JH |
1633 | free(data); |
1634 | return; | |
1635 | } | |
1636 | } | |
1637 | ||
1638 | it = xcalloc(1, sizeof(*it)); | |
1639 | it->next = pbase_tree; | |
1640 | pbase_tree = it; | |
1641 | ||
188960b4 | 1642 | oidcpy(&it->pcache.oid, &tree_oid); |
5379a5c5 JH |
1643 | it->pcache.tree_data = data; |
1644 | it->pcache.tree_size = size; | |
3f9ac8d2 JH |
1645 | } |
1646 | ||
0ef95f72 NP |
1647 | static void cleanup_preferred_base(void) |
1648 | { | |
1649 | struct pbase_tree *it; | |
1650 | unsigned i; | |
1651 | ||
1652 | it = pbase_tree; | |
1653 | pbase_tree = NULL; | |
1654 | while (it) { | |
095b3b2c BW |
1655 | struct pbase_tree *tmp = it; |
1656 | it = tmp->next; | |
1657 | free(tmp->pcache.tree_data); | |
1658 | free(tmp); | |
0ef95f72 NP |
1659 | } |
1660 | ||
1661 | for (i = 0; i < ARRAY_SIZE(pbase_tree_cache); i++) { | |
1662 | if (!pbase_tree_cache[i]) | |
1663 | continue; | |
1664 | free(pbase_tree_cache[i]->tree_data); | |
6a83d902 | 1665 | FREE_AND_NULL(pbase_tree_cache[i]); |
0ef95f72 NP |
1666 | } |
1667 | ||
6a83d902 | 1668 | FREE_AND_NULL(done_pbase_paths); |
0ef95f72 NP |
1669 | done_pbase_paths_num = done_pbase_paths_alloc = 0; |
1670 | } | |
1671 | ||
2fa233a5 JK |
1672 | /* |
1673 | * Return 1 iff the object specified by "delta" can be sent | |
1674 | * literally as a delta against the base in "base_sha1". If | |
1675 | * so, then *base_out will point to the entry in our packing | |
1676 | * list, or NULL if we must use the external-base list. | |
1677 | * | |
1678 | * Depth value does not matter - find_deltas() will | |
1679 | * never consider reused delta as the base object to | |
1680 | * deltify other objects against, in order to avoid | |
1681 | * circular deltas. | |
1682 | */ | |
3f83fd5e | 1683 | static int can_reuse_delta(const struct object_id *base_oid, |
2fa233a5 JK |
1684 | struct object_entry *delta, |
1685 | struct object_entry **base_out) | |
1686 | { | |
1687 | struct object_entry *base; | |
3df28cae | 1688 | |
2fa233a5 JK |
1689 | /* |
1690 | * First see if we're already sending the base (or it's explicitly in | |
1691 | * our "excluded" list). | |
1692 | */ | |
3f83fd5e | 1693 | base = packlist_find(&to_pack, base_oid); |
2fa233a5 JK |
1694 | if (base) { |
1695 | if (!in_same_island(&delta->idx.oid, &base->idx.oid)) | |
1696 | return 0; | |
1697 | *base_out = base; | |
1698 | return 1; | |
1699 | } | |
1700 | ||
1701 | /* | |
1702 | * Otherwise, reachability bitmaps may tell us if the receiver has it, | |
1703 | * even if it was buried too deep in history to make it into the | |
1704 | * packing list. | |
1705 | */ | |
3f83fd5e | 1706 | if (thin && bitmap_has_oid_in_uninteresting(bitmap_git, base_oid)) { |
2fa233a5 | 1707 | if (use_delta_islands) { |
3f83fd5e | 1708 | if (!in_same_island(&delta->idx.oid, base_oid)) |
2fa233a5 JK |
1709 | return 0; |
1710 | } | |
1711 | *base_out = NULL; | |
1712 | return 1; | |
1713 | } | |
1714 | ||
1715 | return 0; | |
1716 | } | |
1717 | ||
e00549aa JT |
1718 | static void prefetch_to_pack(uint32_t object_index_start) { |
1719 | struct oid_array to_fetch = OID_ARRAY_INIT; | |
1720 | uint32_t i; | |
1721 | ||
1722 | for (i = object_index_start; i < to_pack.nr_objects; i++) { | |
1723 | struct object_entry *entry = to_pack.objects + i; | |
1724 | ||
1725 | if (!oid_object_info_extended(the_repository, | |
1726 | &entry->idx.oid, | |
1727 | NULL, | |
1728 | OBJECT_INFO_FOR_PREFETCH)) | |
1729 | continue; | |
1730 | oid_array_append(&to_fetch, &entry->idx.oid); | |
1731 | } | |
1732 | promisor_remote_get_direct(the_repository, | |
1733 | to_fetch.oid, to_fetch.nr); | |
1734 | oid_array_clear(&to_fetch); | |
1735 | } | |
1736 | ||
1737 | static void check_object(struct object_entry *entry, uint32_t object_index) | |
c323ac7d | 1738 | { |
ac77d0c3 | 1739 | unsigned long canonical_size; |
8d5cf957 JT |
1740 | enum object_type type; |
1741 | struct object_info oi = {.typep = &type, .sizep = &canonical_size}; | |
ac77d0c3 | 1742 | |
43fa44fa NTND |
1743 | if (IN_PACK(entry)) { |
1744 | struct packed_git *p = IN_PACK(entry); | |
03e79c88 | 1745 | struct pack_window *w_curs = NULL; |
3f83fd5e JK |
1746 | int have_base = 0; |
1747 | struct object_id base_ref; | |
5c49c116 NP |
1748 | struct object_entry *base_entry; |
1749 | unsigned long used, used_0; | |
ef49a7a0 | 1750 | unsigned long avail; |
5c49c116 NP |
1751 | off_t ofs; |
1752 | unsigned char *buf, c; | |
fd9b1bae | 1753 | enum object_type type; |
27a7d067 | 1754 | unsigned long in_pack_size; |
780e6e73 | 1755 | |
6777a59f | 1756 | buf = use_pack(p, &w_curs, entry->in_pack_offset, &avail); |
ab7cd7bb | 1757 | |
5c49c116 | 1758 | /* |
fa736f72 NP |
1759 | * We want in_pack_type even if we do not reuse delta |
1760 | * since non-delta representations could still be reused. | |
ab7cd7bb | 1761 | */ |
09ded04b | 1762 | used = unpack_object_header_buffer(buf, avail, |
fd9b1bae | 1763 | &type, |
27a7d067 | 1764 | &in_pack_size); |
03d66015 NP |
1765 | if (used == 0) |
1766 | goto give_up; | |
ab7cd7bb | 1767 | |
fd9b1bae NTND |
1768 | if (type < 0) |
1769 | BUG("invalid type %d", type); | |
1770 | entry->in_pack_type = type; | |
1771 | ||
5c49c116 NP |
1772 | /* |
1773 | * Determine if this is a delta and if so whether we can | |
1774 | * reuse it or not. Otherwise let's find out as cheaply as | |
1775 | * possible what the actual type and size for this object is. | |
3f9ac8d2 | 1776 | */ |
5c49c116 NP |
1777 | switch (entry->in_pack_type) { |
1778 | default: | |
1779 | /* Not a delta hence we've already got all we need. */ | |
fd9b1bae | 1780 | oe_set_type(entry, entry->in_pack_type); |
ac77d0c3 | 1781 | SET_SIZE(entry, in_pack_size); |
5c49c116 | 1782 | entry->in_pack_header_size = used; |
fd9b1bae | 1783 | if (oe_type(entry) < OBJ_COMMIT || oe_type(entry) > OBJ_BLOB) |
03d66015 | 1784 | goto give_up; |
5c49c116 NP |
1785 | unuse_pack(&w_curs); |
1786 | return; | |
1787 | case OBJ_REF_DELTA: | |
3f83fd5e JK |
1788 | if (reuse_delta && !entry->preferred_base) { |
1789 | oidread(&base_ref, | |
1790 | use_pack(p, &w_curs, | |
1791 | entry->in_pack_offset + used, | |
1792 | NULL)); | |
1793 | have_base = 1; | |
1794 | } | |
41179100 | 1795 | entry->in_pack_header_size = used + the_hash_algo->rawsz; |
5c49c116 NP |
1796 | break; |
1797 | case OBJ_OFS_DELTA: | |
1798 | buf = use_pack(p, &w_curs, | |
1799 | entry->in_pack_offset + used, NULL); | |
1800 | used_0 = 0; | |
1801 | c = buf[used_0++]; | |
1802 | ofs = c & 127; | |
1803 | while (c & 128) { | |
1804 | ofs += 1; | |
03d66015 | 1805 | if (!ofs || MSB(ofs, 7)) { |
f616db6a | 1806 | error(_("delta base offset overflow in pack for %s"), |
e6a492b7 | 1807 | oid_to_hex(&entry->idx.oid)); |
03d66015 NP |
1808 | goto give_up; |
1809 | } | |
5c49c116 NP |
1810 | c = buf[used_0++]; |
1811 | ofs = (ofs << 7) + (c & 127); | |
780e6e73 | 1812 | } |
5c49c116 | 1813 | ofs = entry->in_pack_offset - ofs; |
03d66015 | 1814 | if (ofs <= 0 || ofs >= entry->in_pack_offset) { |
f616db6a | 1815 | error(_("delta base offset out of bound for %s"), |
e6a492b7 | 1816 | oid_to_hex(&entry->idx.oid)); |
03d66015 NP |
1817 | goto give_up; |
1818 | } | |
a7de7130 | 1819 | if (reuse_delta && !entry->preferred_base) { |
eb3fd99e TB |
1820 | uint32_t pos; |
1821 | if (offset_to_pack_pos(p, ofs, &pos) < 0) | |
08698b1e | 1822 | goto give_up; |
eb3fd99e TB |
1823 | if (!nth_packed_object_id(&base_ref, p, |
1824 | pack_pos_to_index(p, pos))) | |
3f83fd5e | 1825 | have_base = 1; |
3449f8c4 | 1826 | } |
5c49c116 NP |
1827 | entry->in_pack_header_size = used + used_0; |
1828 | break; | |
780e6e73 | 1829 | } |
780e6e73 | 1830 | |
3f83fd5e JK |
1831 | if (have_base && |
1832 | can_reuse_delta(&base_ref, entry, &base_entry)) { | |
fd9b1bae | 1833 | oe_set_type(entry, entry->in_pack_type); |
ac77d0c3 | 1834 | SET_SIZE(entry, in_pack_size); /* delta size */ |
0aca34e8 | 1835 | SET_DELTA_SIZE(entry, in_pack_size); |
6a1e32d5 JK |
1836 | |
1837 | if (base_entry) { | |
1838 | SET_DELTA(entry, base_entry); | |
1839 | entry->delta_sibling_idx = base_entry->delta_child_idx; | |
1840 | SET_DELTA_CHILD(base_entry, entry); | |
1841 | } else { | |
a93c141d | 1842 | SET_DELTA_EXT(entry, &base_ref); |
6a1e32d5 JK |
1843 | } |
1844 | ||
5c49c116 NP |
1845 | unuse_pack(&w_curs); |
1846 | return; | |
1847 | } | |
ab7cd7bb | 1848 | |
fd9b1bae | 1849 | if (oe_type(entry)) { |
27a7d067 NTND |
1850 | off_t delta_pos; |
1851 | ||
5c49c116 NP |
1852 | /* |
1853 | * This must be a delta and we already know what the | |
1854 | * final object type is. Let's extract the actual | |
1855 | * object size from the delta header. | |
1856 | */ | |
27a7d067 | 1857 | delta_pos = entry->in_pack_offset + entry->in_pack_header_size; |
ac77d0c3 NTND |
1858 | canonical_size = get_size_from_delta(p, &w_curs, delta_pos); |
1859 | if (canonical_size == 0) | |
03d66015 | 1860 | goto give_up; |
ac77d0c3 | 1861 | SET_SIZE(entry, canonical_size); |
5c49c116 | 1862 | unuse_pack(&w_curs); |
3f9ac8d2 JH |
1863 | return; |
1864 | } | |
5c49c116 NP |
1865 | |
1866 | /* | |
1867 | * No choice but to fall back to the recursive delta walk | |
c93206b4 | 1868 | * with oid_object_info() to find about the object type |
5c49c116 NP |
1869 | * at this point... |
1870 | */ | |
03d66015 | 1871 | give_up: |
5c49c116 | 1872 | unuse_pack(&w_curs); |
36e4d74a | 1873 | } |
3f9ac8d2 | 1874 | |
8d5cf957 | 1875 | if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi, |
e00549aa JT |
1876 | OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) { |
1877 | if (has_promisor_remote()) { | |
1878 | prefetch_to_pack(object_index); | |
1879 | if (oid_object_info_extended(the_repository, &entry->idx.oid, &oi, | |
1880 | OBJECT_INFO_SKIP_FETCH_OBJECT | OBJECT_INFO_LOOKUP_REPLACE) < 0) | |
1881 | type = -1; | |
1882 | } else { | |
1883 | type = -1; | |
1884 | } | |
1885 | } | |
8d5cf957 | 1886 | oe_set_type(entry, type); |
ac77d0c3 NTND |
1887 | if (entry->type_valid) { |
1888 | SET_SIZE(entry, canonical_size); | |
1889 | } else { | |
1890 | /* | |
1891 | * Bad object type is checked in prepare_pack(). This is | |
1892 | * to permit a missing preferred base object to be ignored | |
1893 | * as a preferred base. Doing so can result in a larger | |
1894 | * pack file, but the transfer will still take place. | |
1895 | */ | |
1896 | } | |
3f9ac8d2 JH |
1897 | } |
1898 | ||
5c49c116 NP |
1899 | static int pack_offset_sort(const void *_a, const void *_b) |
1900 | { | |
1901 | const struct object_entry *a = *(struct object_entry **)_a; | |
1902 | const struct object_entry *b = *(struct object_entry **)_b; | |
43fa44fa NTND |
1903 | const struct packed_git *a_in_pack = IN_PACK(a); |
1904 | const struct packed_git *b_in_pack = IN_PACK(b); | |
5c49c116 NP |
1905 | |
1906 | /* avoid filesystem trashing with loose objects */ | |
43fa44fa | 1907 | if (!a_in_pack && !b_in_pack) |
e6a492b7 | 1908 | return oidcmp(&a->idx.oid, &b->idx.oid); |
5c49c116 | 1909 | |
43fa44fa | 1910 | if (a_in_pack < b_in_pack) |
5c49c116 | 1911 | return -1; |
43fa44fa | 1912 | if (a_in_pack > b_in_pack) |
5c49c116 NP |
1913 | return 1; |
1914 | return a->in_pack_offset < b->in_pack_offset ? -1 : | |
1915 | (a->in_pack_offset > b->in_pack_offset); | |
1916 | } | |
1917 | ||
4cf2143e JK |
1918 | /* |
1919 | * Drop an on-disk delta we were planning to reuse. Naively, this would | |
1920 | * just involve blanking out the "delta" field, but we have to deal | |
1921 | * with some extra book-keeping: | |
1922 | * | |
1923 | * 1. Removing ourselves from the delta_sibling linked list. | |
1924 | * | |
1925 | * 2. Updating our size/type to the non-delta representation. These were | |
1926 | * either not recorded initially (size) or overwritten with the delta type | |
1927 | * (type) when check_object() decided to reuse the delta. | |
7dbabbbe JK |
1928 | * |
1929 | * 3. Resetting our delta depth, as we are now a base object. | |
4cf2143e JK |
1930 | */ |
1931 | static void drop_reused_delta(struct object_entry *entry) | |
1932 | { | |
898eba5e | 1933 | unsigned *idx = &to_pack.objects[entry->delta_idx - 1].delta_child_idx; |
4cf2143e | 1934 | struct object_info oi = OBJECT_INFO_INIT; |
fd9b1bae | 1935 | enum object_type type; |
ac77d0c3 | 1936 | unsigned long size; |
4cf2143e | 1937 | |
898eba5e NTND |
1938 | while (*idx) { |
1939 | struct object_entry *oe = &to_pack.objects[*idx - 1]; | |
4cf2143e | 1940 | |
898eba5e NTND |
1941 | if (oe == entry) |
1942 | *idx = oe->delta_sibling_idx; | |
4cf2143e | 1943 | else |
898eba5e | 1944 | idx = &oe->delta_sibling_idx; |
4cf2143e | 1945 | } |
898eba5e | 1946 | SET_DELTA(entry, NULL); |
7dbabbbe | 1947 | entry->depth = 0; |
4cf2143e | 1948 | |
ac77d0c3 | 1949 | oi.sizep = &size; |
fd9b1bae | 1950 | oi.typep = &type; |
ad635e82 | 1951 | if (packed_object_info(the_repository, IN_PACK(entry), entry->in_pack_offset, &oi) < 0) { |
4cf2143e JK |
1952 | /* |
1953 | * We failed to get the info from this pack for some reason; | |
c93206b4 | 1954 | * fall back to oid_object_info, which may find another copy. |
fd9b1bae | 1955 | * And if that fails, the error will be recorded in oe_type(entry) |
4cf2143e JK |
1956 | * and dealt with in prepare_pack(). |
1957 | */ | |
ad635e82 JH |
1958 | oe_set_type(entry, |
1959 | oid_object_info(the_repository, &entry->idx.oid, &size)); | |
fd9b1bae NTND |
1960 | } else { |
1961 | oe_set_type(entry, type); | |
4cf2143e | 1962 | } |
ac77d0c3 | 1963 | SET_SIZE(entry, size); |
4cf2143e JK |
1964 | } |
1965 | ||
1966 | /* | |
1967 | * Follow the chain of deltas from this entry onward, throwing away any links | |
1968 | * that cause us to hit a cycle (as determined by the DFS state flags in | |
1969 | * the entries). | |
7dbabbbe JK |
1970 | * |
1971 | * We also detect too-long reused chains that would violate our --depth | |
1972 | * limit. | |
4cf2143e JK |
1973 | */ |
1974 | static void break_delta_chains(struct object_entry *entry) | |
1975 | { | |
42b766d7 JK |
1976 | /* |
1977 | * The actual depth of each object we will write is stored as an int, | |
1978 | * as it cannot exceed our int "depth" limit. But before we break | |
1979 | * changes based no that limit, we may potentially go as deep as the | |
1980 | * number of objects, which is elsewhere bounded to a uint32_t. | |
1981 | */ | |
1982 | uint32_t total_depth; | |
1983 | struct object_entry *cur, *next; | |
1984 | ||
1985 | for (cur = entry, total_depth = 0; | |
1986 | cur; | |
898eba5e | 1987 | cur = DELTA(cur), total_depth++) { |
42b766d7 JK |
1988 | if (cur->dfs_state == DFS_DONE) { |
1989 | /* | |
1990 | * We've already seen this object and know it isn't | |
1991 | * part of a cycle. We do need to append its depth | |
1992 | * to our count. | |
1993 | */ | |
1994 | total_depth += cur->depth; | |
1995 | break; | |
1996 | } | |
4cf2143e | 1997 | |
4cf2143e | 1998 | /* |
42b766d7 JK |
1999 | * We break cycles before looping, so an ACTIVE state (or any |
2000 | * other cruft which made its way into the state variable) | |
2001 | * is a bug. | |
4cf2143e | 2002 | */ |
42b766d7 | 2003 | if (cur->dfs_state != DFS_NONE) |
033abf97 | 2004 | BUG("confusing delta dfs state in first pass: %d", |
42b766d7 | 2005 | cur->dfs_state); |
4cf2143e | 2006 | |
4cf2143e | 2007 | /* |
42b766d7 JK |
2008 | * Now we know this is the first time we've seen the object. If |
2009 | * it's not a delta, we're done traversing, but we'll mark it | |
2010 | * done to save time on future traversals. | |
4cf2143e | 2011 | */ |
898eba5e | 2012 | if (!DELTA(cur)) { |
42b766d7 JK |
2013 | cur->dfs_state = DFS_DONE; |
2014 | break; | |
2015 | } | |
4cf2143e | 2016 | |
4cf2143e | 2017 | /* |
42b766d7 JK |
2018 | * Mark ourselves as active and see if the next step causes |
2019 | * us to cycle to another active object. It's important to do | |
2020 | * this _before_ we loop, because it impacts where we make the | |
2021 | * cut, and thus how our total_depth counter works. | |
2022 | * E.g., We may see a partial loop like: | |
2023 | * | |
2024 | * A -> B -> C -> D -> B | |
2025 | * | |
2026 | * Cutting B->C breaks the cycle. But now the depth of A is | |
2027 | * only 1, and our total_depth counter is at 3. The size of the | |
2028 | * error is always one less than the size of the cycle we | |
2029 | * broke. Commits C and D were "lost" from A's chain. | |
2030 | * | |
2031 | * If we instead cut D->B, then the depth of A is correct at 3. | |
2032 | * We keep all commits in the chain that we examined. | |
4cf2143e | 2033 | */ |
42b766d7 | 2034 | cur->dfs_state = DFS_ACTIVE; |
898eba5e | 2035 | if (DELTA(cur)->dfs_state == DFS_ACTIVE) { |
42b766d7 JK |
2036 | drop_reused_delta(cur); |
2037 | cur->dfs_state = DFS_DONE; | |
2038 | break; | |
7dbabbbe | 2039 | } |
42b766d7 | 2040 | } |
7dbabbbe | 2041 | |
42b766d7 JK |
2042 | /* |
2043 | * And now that we've gone all the way to the bottom of the chain, we | |
2044 | * need to clear the active flags and set the depth fields as | |
2045 | * appropriate. Unlike the loop above, which can quit when it drops a | |
2046 | * delta, we need to keep going to look for more depth cuts. So we need | |
2047 | * an extra "next" pointer to keep going after we reset cur->delta. | |
2048 | */ | |
2049 | for (cur = entry; cur; cur = next) { | |
898eba5e | 2050 | next = DELTA(cur); |
4cf2143e | 2051 | |
42b766d7 JK |
2052 | /* |
2053 | * We should have a chain of zero or more ACTIVE states down to | |
2054 | * a final DONE. We can quit after the DONE, because either it | |
2055 | * has no bases, or we've already handled them in a previous | |
2056 | * call. | |
2057 | */ | |
2058 | if (cur->dfs_state == DFS_DONE) | |
2059 | break; | |
2060 | else if (cur->dfs_state != DFS_ACTIVE) | |
033abf97 | 2061 | BUG("confusing delta dfs state in second pass: %d", |
42b766d7 | 2062 | cur->dfs_state); |
4cf2143e | 2063 | |
4cf2143e | 2064 | /* |
42b766d7 JK |
2065 | * If the total_depth is more than depth, then we need to snip |
2066 | * the chain into two or more smaller chains that don't exceed | |
2067 | * the maximum depth. Most of the resulting chains will contain | |
2068 | * (depth + 1) entries (i.e., depth deltas plus one base), and | |
2069 | * the last chain (i.e., the one containing entry) will contain | |
2070 | * whatever entries are left over, namely | |
2071 | * (total_depth % (depth + 1)) of them. | |
2072 | * | |
2073 | * Since we are iterating towards decreasing depth, we need to | |
2074 | * decrement total_depth as we go, and we need to write to the | |
2075 | * entry what its final depth will be after all of the | |
2076 | * snipping. Since we're snipping into chains of length (depth | |
2077 | * + 1) entries, the final depth of an entry will be its | |
2078 | * original depth modulo (depth + 1). Any time we encounter an | |
2079 | * entry whose final depth is supposed to be zero, we snip it | |
2080 | * from its delta base, thereby making it so. | |
4cf2143e | 2081 | */ |
42b766d7 JK |
2082 | cur->depth = (total_depth--) % (depth + 1); |
2083 | if (!cur->depth) | |
2084 | drop_reused_delta(cur); | |
2085 | ||
2086 | cur->dfs_state = DFS_DONE; | |
4cf2143e JK |
2087 | } |
2088 | } | |
2089 | ||
c323ac7d LT |
2090 | static void get_object_details(void) |
2091 | { | |
7cadf491 | 2092 | uint32_t i; |
5c49c116 NP |
2093 | struct object_entry **sorted_by_offset; |
2094 | ||
5af05043 NTND |
2095 | if (progress) |
2096 | progress_state = start_progress(_("Counting objects"), | |
2097 | to_pack.nr_objects); | |
2098 | ||
2834bc27 VM |
2099 | sorted_by_offset = xcalloc(to_pack.nr_objects, sizeof(struct object_entry *)); |
2100 | for (i = 0; i < to_pack.nr_objects; i++) | |
2101 | sorted_by_offset[i] = to_pack.objects + i; | |
9ed0d8d6 | 2102 | QSORT(sorted_by_offset, to_pack.nr_objects, pack_offset_sort); |
c323ac7d | 2103 | |
2834bc27 | 2104 | for (i = 0; i < to_pack.nr_objects; i++) { |
15366280 | 2105 | struct object_entry *entry = sorted_by_offset[i]; |
e00549aa | 2106 | check_object(entry, i); |
ac77d0c3 NTND |
2107 | if (entry->type_valid && |
2108 | oe_size_greater_than(&to_pack, entry, big_file_threshold)) | |
15366280 | 2109 | entry->no_try_delta = 1; |
5af05043 | 2110 | display_progress(progress_state, i + 1); |
15366280 | 2111 | } |
5af05043 | 2112 | stop_progress(&progress_state); |
3449f8c4 | 2113 | |
4cf2143e JK |
2114 | /* |
2115 | * This must happen in a second pass, since we rely on the delta | |
2116 | * information for the whole list being completed. | |
2117 | */ | |
2118 | for (i = 0; i < to_pack.nr_objects; i++) | |
2119 | break_delta_chains(&to_pack.objects[i]); | |
2120 | ||
5c49c116 | 2121 | free(sorted_by_offset); |
c323ac7d LT |
2122 | } |
2123 | ||
b904166c NP |
2124 | /* |
2125 | * We search for deltas in a list sorted by type, by filename hash, and then | |
2126 | * by size, so that we see progressively smaller and smaller files. | |
2127 | * That's because we prefer deltas to be from the bigger file | |
2128 | * to the smaller -- deletes are potentially cheaper, but perhaps | |
2129 | * more importantly, the bigger file is likely the more recent | |
2130 | * one. The deepest deltas are therefore the oldest objects which are | |
2131 | * less susceptible to be accessed often. | |
2132 | */ | |
9668cf59 | 2133 | static int type_size_sort(const void *_a, const void *_b) |
c323ac7d | 2134 | { |
9668cf59 NP |
2135 | const struct object_entry *a = *(struct object_entry **)_a; |
2136 | const struct object_entry *b = *(struct object_entry **)_b; | |
33de80b1 SL |
2137 | const enum object_type a_type = oe_type(a); |
2138 | const enum object_type b_type = oe_type(b); | |
2139 | const unsigned long a_size = SIZE(a); | |
2140 | const unsigned long b_size = SIZE(b); | |
9668cf59 | 2141 | |
fd9b1bae | 2142 | if (a_type > b_type) |
27225f2e | 2143 | return -1; |
fd9b1bae | 2144 | if (a_type < b_type) |
27225f2e | 2145 | return 1; |
b904166c | 2146 | if (a->hash > b->hash) |
7a979d99 | 2147 | return -1; |
b904166c | 2148 | if (a->hash < b->hash) |
7a979d99 | 2149 | return 1; |
b904166c | 2150 | if (a->preferred_base > b->preferred_base) |
c323ac7d | 2151 | return -1; |
b904166c NP |
2152 | if (a->preferred_base < b->preferred_base) |
2153 | return 1; | |
28b8a730 | 2154 | if (use_delta_islands) { |
33de80b1 | 2155 | const int island_cmp = island_delta_cmp(&a->idx.oid, &b->idx.oid); |
28b8a730 JK |
2156 | if (island_cmp) |
2157 | return island_cmp; | |
2158 | } | |
ac77d0c3 | 2159 | if (a_size > b_size) |
b904166c | 2160 | return -1; |
ac77d0c3 | 2161 | if (a_size < b_size) |
c323ac7d | 2162 | return 1; |
b904166c | 2163 | return a < b ? -1 : (a > b); /* newest first */ |
c323ac7d LT |
2164 | } |
2165 | ||
2166 | struct unpacked { | |
2167 | struct object_entry *entry; | |
2168 | void *data; | |
f6c7081a | 2169 | struct delta_index *index; |
5a235b5e | 2170 | unsigned depth; |
c323ac7d LT |
2171 | }; |
2172 | ||
d250626c NP |
2173 | static int delta_cacheable(unsigned long src_size, unsigned long trg_size, |
2174 | unsigned long delta_size) | |
074b2eea MK |
2175 | { |
2176 | if (max_delta_cache_size && delta_cache_size + delta_size > max_delta_cache_size) | |
2177 | return 0; | |
2178 | ||
e3dfddb3 MK |
2179 | if (delta_size < cache_max_small_delta_size) |
2180 | return 1; | |
2181 | ||
074b2eea MK |
2182 | /* cache delta, if objects are large enough compared to delta size */ |
2183 | if ((src_size >> 20) + (trg_size >> 21) > (delta_size >> 10)) | |
2184 | return 1; | |
2185 | ||
2186 | return 0; | |
2187 | } | |
2188 | ||
ffbd51cc | 2189 | /* Protect delta_cache_size */ |
44626dc7 | 2190 | static pthread_mutex_t cache_mutex; |
3c701839 NP |
2191 | #define cache_lock() pthread_mutex_lock(&cache_mutex) |
2192 | #define cache_unlock() pthread_mutex_unlock(&cache_mutex) | |
2193 | ||
ffbd51cc NTND |
2194 | /* |
2195 | * Protect object list partitioning (e.g. struct thread_param) and | |
2196 | * progress_state | |
2197 | */ | |
44626dc7 | 2198 | static pthread_mutex_t progress_mutex; |
8ecce684 NP |
2199 | #define progress_lock() pthread_mutex_lock(&progress_mutex) |
2200 | #define progress_unlock() pthread_mutex_unlock(&progress_mutex) | |
2201 | ||
ffbd51cc NTND |
2202 | /* |
2203 | * Access to struct object_entry is unprotected since each thread owns | |
2204 | * a portion of the main object list. Just don't access object entries | |
2205 | * ahead in the list because they can be stolen and would need | |
2206 | * progress_mutex for protection. | |
2207 | */ | |
8ecce684 | 2208 | |
ac77d0c3 NTND |
2209 | /* |
2210 | * Return the size of the object without doing any delta | |
2211 | * reconstruction (so non-deltas are true object sizes, but deltas | |
2212 | * return the size of the delta data). | |
2213 | */ | |
2214 | unsigned long oe_get_size_slow(struct packing_data *pack, | |
2215 | const struct object_entry *e) | |
2216 | { | |
2217 | struct packed_git *p; | |
2218 | struct pack_window *w_curs; | |
2219 | unsigned char *buf; | |
2220 | enum object_type type; | |
2221 | unsigned long used, avail, size; | |
2222 | ||
2223 | if (e->type_ != OBJ_OFS_DELTA && e->type_ != OBJ_REF_DELTA) { | |
edb673cf | 2224 | packing_data_lock(&to_pack); |
ad635e82 | 2225 | if (oid_object_info(the_repository, &e->idx.oid, &size) < 0) |
ac77d0c3 NTND |
2226 | die(_("unable to get size of %s"), |
2227 | oid_to_hex(&e->idx.oid)); | |
edb673cf | 2228 | packing_data_unlock(&to_pack); |
ac77d0c3 NTND |
2229 | return size; |
2230 | } | |
2231 | ||
2232 | p = oe_in_pack(pack, e); | |
2233 | if (!p) | |
2234 | BUG("when e->type is a delta, it must belong to a pack"); | |
2235 | ||
edb673cf | 2236 | packing_data_lock(&to_pack); |
ac77d0c3 NTND |
2237 | w_curs = NULL; |
2238 | buf = use_pack(p, &w_curs, e->in_pack_offset, &avail); | |
2239 | used = unpack_object_header_buffer(buf, avail, &type, &size); | |
2240 | if (used == 0) | |
2241 | die(_("unable to parse object header of %s"), | |
2242 | oid_to_hex(&e->idx.oid)); | |
2243 | ||
2244 | unuse_pack(&w_curs); | |
edb673cf | 2245 | packing_data_unlock(&to_pack); |
ac77d0c3 NTND |
2246 | return size; |
2247 | } | |
2248 | ||
f6c7081a | 2249 | static int try_delta(struct unpacked *trg, struct unpacked *src, |
ef0316fc | 2250 | unsigned max_depth, unsigned long *mem_usage) |
c323ac7d | 2251 | { |
f6c7081a NP |
2252 | struct object_entry *trg_entry = trg->entry; |
2253 | struct object_entry *src_entry = src->entry; | |
560b25a8 | 2254 | unsigned long trg_size, src_size, delta_size, sizediff, max_size, sz; |
c83f032e | 2255 | unsigned ref_depth; |
21666f1a | 2256 | enum object_type type; |
c323ac7d LT |
2257 | void *delta_buf; |
2258 | ||
2259 | /* Don't bother doing diffs between different types */ | |
fd9b1bae | 2260 | if (oe_type(trg_entry) != oe_type(src_entry)) |
c323ac7d LT |
2261 | return -1; |
2262 | ||
51d1e83f | 2263 | /* |
15f07e06 JK |
2264 | * We do not bother to try a delta that we discarded on an |
2265 | * earlier try, but only when reusing delta data. Note that | |
2266 | * src_entry that is marked as the preferred_base should always | |
2267 | * be considered, as even if we produce a suboptimal delta against | |
2268 | * it, we will still save the transfer cost, as we already know | |
2269 | * the other side has it and we won't send src_entry at all. | |
51d1e83f | 2270 | */ |
43fa44fa NTND |
2271 | if (reuse_delta && IN_PACK(trg_entry) && |
2272 | IN_PACK(trg_entry) == IN_PACK(src_entry) && | |
15f07e06 | 2273 | !src_entry->preferred_base && |
e9195b58 JH |
2274 | trg_entry->in_pack_type != OBJ_REF_DELTA && |
2275 | trg_entry->in_pack_type != OBJ_OFS_DELTA) | |
51d1e83f LT |
2276 | return 0; |
2277 | ||
898b14ce | 2278 | /* Let's not bust the allowed depth. */ |
5a235b5e | 2279 | if (src->depth >= max_depth) |
d116a45a | 2280 | return 0; |
c323ac7d | 2281 | |
c3b06a69 | 2282 | /* Now some size filtering heuristics. */ |
ac77d0c3 | 2283 | trg_size = SIZE(trg_entry); |
898eba5e | 2284 | if (!DELTA(trg_entry)) { |
41179100 | 2285 | max_size = trg_size/2 - the_hash_algo->rawsz; |
c83f032e NP |
2286 | ref_depth = 1; |
2287 | } else { | |
0aca34e8 | 2288 | max_size = DELTA_SIZE(trg_entry); |
5a235b5e | 2289 | ref_depth = trg->depth; |
c83f032e | 2290 | } |
720fe22d | 2291 | max_size = (uint64_t)max_size * (max_depth - src->depth) / |
c83f032e | 2292 | (max_depth - ref_depth + 1); |
c3b06a69 NP |
2293 | if (max_size == 0) |
2294 | return 0; | |
ac77d0c3 | 2295 | src_size = SIZE(src_entry); |
560b25a8 | 2296 | sizediff = src_size < trg_size ? trg_size - src_size : 0; |
27225f2e | 2297 | if (sizediff >= max_size) |
f527cb8c | 2298 | return 0; |
a1dab41a BD |
2299 | if (trg_size < src_size / 32) |
2300 | return 0; | |
f6c7081a | 2301 | |
28b8a730 JK |
2302 | if (!in_same_island(&trg->entry->idx.oid, &src->entry->idx.oid)) |
2303 | return 0; | |
2304 | ||
560b25a8 NP |
2305 | /* Load data if not already done */ |
2306 | if (!trg->data) { | |
edb673cf | 2307 | packing_data_lock(&to_pack); |
b4f5aca4 | 2308 | trg->data = read_object_file(&trg_entry->idx.oid, &type, &sz); |
edb673cf | 2309 | packing_data_unlock(&to_pack); |
2e3404c3 | 2310 | if (!trg->data) |
f616db6a | 2311 | die(_("object %s cannot be read"), |
e6a492b7 | 2312 | oid_to_hex(&trg_entry->idx.oid)); |
560b25a8 | 2313 | if (sz != trg_size) |
ca473cef TB |
2314 | die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"), |
2315 | oid_to_hex(&trg_entry->idx.oid), (uintmax_t)sz, | |
2316 | (uintmax_t)trg_size); | |
ef0316fc | 2317 | *mem_usage += sz; |
560b25a8 NP |
2318 | } |
2319 | if (!src->data) { | |
edb673cf | 2320 | packing_data_lock(&to_pack); |
b4f5aca4 | 2321 | src->data = read_object_file(&src_entry->idx.oid, &type, &sz); |
edb673cf | 2322 | packing_data_unlock(&to_pack); |
71064a95 NP |
2323 | if (!src->data) { |
2324 | if (src_entry->preferred_base) { | |
2325 | static int warned = 0; | |
2326 | if (!warned++) | |
f616db6a | 2327 | warning(_("object %s cannot be read"), |
e6a492b7 | 2328 | oid_to_hex(&src_entry->idx.oid)); |
71064a95 NP |
2329 | /* |
2330 | * Those objects are not included in the | |
2331 | * resulting pack. Be resilient and ignore | |
2332 | * them if they can't be read, in case the | |
2333 | * pack could be created nevertheless. | |
2334 | */ | |
2335 | return 0; | |
2336 | } | |
f616db6a | 2337 | die(_("object %s cannot be read"), |
e6a492b7 | 2338 | oid_to_hex(&src_entry->idx.oid)); |
71064a95 | 2339 | } |
560b25a8 | 2340 | if (sz != src_size) |
ca473cef TB |
2341 | die(_("object %s inconsistent object length (%"PRIuMAX" vs %"PRIuMAX")"), |
2342 | oid_to_hex(&src_entry->idx.oid), (uintmax_t)sz, | |
2343 | (uintmax_t)src_size); | |
ef0316fc | 2344 | *mem_usage += sz; |
560b25a8 NP |
2345 | } |
2346 | if (!src->index) { | |
2347 | src->index = create_delta_index(src->data, src_size); | |
a588d88a MK |
2348 | if (!src->index) { |
2349 | static int warned = 0; | |
2350 | if (!warned++) | |
f616db6a | 2351 | warning(_("suboptimal pack - out of memory")); |
a588d88a MK |
2352 | return 0; |
2353 | } | |
ef0316fc | 2354 | *mem_usage += sizeof_delta_index(src->index); |
560b25a8 NP |
2355 | } |
2356 | ||
2357 | delta_buf = create_delta(src->index, trg->data, trg_size, &delta_size, max_size); | |
c323ac7d | 2358 | if (!delta_buf) |
75c42d8c | 2359 | return 0; |
f6c7081a | 2360 | |
898eba5e | 2361 | if (DELTA(trg_entry)) { |
848d732c | 2362 | /* Prefer only shallower same-sized deltas. */ |
0aca34e8 | 2363 | if (delta_size == DELTA_SIZE(trg_entry) && |
5a235b5e | 2364 | src->depth + 1 >= trg->depth) { |
848d732c BD |
2365 | free(delta_buf); |
2366 | return 0; | |
2367 | } | |
074b2eea | 2368 | } |
9e2d57a0 | 2369 | |
3c701839 NP |
2370 | /* |
2371 | * Handle memory allocation outside of the cache | |
2372 | * accounting lock. Compiler will optimize the strangeness | |
7eb151d6 | 2373 | * away when NO_PTHREADS is defined. |
3c701839 | 2374 | */ |
8e0f7003 | 2375 | free(trg_entry->delta_data); |
3c701839 | 2376 | cache_lock(); |
9e2d57a0 | 2377 | if (trg_entry->delta_data) { |
0aca34e8 | 2378 | delta_cache_size -= DELTA_SIZE(trg_entry); |
9e2d57a0 NP |
2379 | trg_entry->delta_data = NULL; |
2380 | } | |
d250626c | 2381 | if (delta_cacheable(src_size, trg_size, delta_size)) { |
b7a28f78 | 2382 | delta_cache_size += delta_size; |
3c701839 NP |
2383 | cache_unlock(); |
2384 | trg_entry->delta_data = xrealloc(delta_buf, delta_size); | |
2385 | } else { | |
2386 | cache_unlock(); | |
074b2eea | 2387 | free(delta_buf); |
3c701839 NP |
2388 | } |
2389 | ||
898eba5e | 2390 | SET_DELTA(trg_entry, src_entry); |
0aca34e8 | 2391 | SET_DELTA_SIZE(trg_entry, delta_size); |
b7a28f78 NP |
2392 | trg->depth = src->depth + 1; |
2393 | ||
f6c7081a | 2394 | return 1; |
c323ac7d LT |
2395 | } |
2396 | ||
898b14ce | 2397 | static unsigned int check_delta_limit(struct object_entry *me, unsigned int n) |
b2504a0d | 2398 | { |
898eba5e | 2399 | struct object_entry *child = DELTA_CHILD(me); |
898b14ce NP |
2400 | unsigned int m = n; |
2401 | while (child) { | |
33de80b1 | 2402 | const unsigned int c = check_delta_limit(child, n + 1); |
898b14ce NP |
2403 | if (m < c) |
2404 | m = c; | |
898eba5e | 2405 | child = DELTA_SIBLING(child); |
898b14ce NP |
2406 | } |
2407 | return m; | |
b2504a0d NP |
2408 | } |
2409 | ||
75ad235c | 2410 | static unsigned long free_unpacked(struct unpacked *n) |
a97773ce | 2411 | { |
ef0316fc | 2412 | unsigned long freed_mem = sizeof_delta_index(n->index); |
a97773ce BD |
2413 | free_delta_index(n->index); |
2414 | n->index = NULL; | |
2415 | if (n->data) { | |
ac77d0c3 | 2416 | freed_mem += SIZE(n->entry); |
6a83d902 | 2417 | FREE_AND_NULL(n->data); |
a97773ce BD |
2418 | } |
2419 | n->entry = NULL; | |
7d7baa5e | 2420 | n->depth = 0; |
ef0316fc | 2421 | return freed_mem; |
a97773ce BD |
2422 | } |
2423 | ||
384b32c0 | 2424 | static void find_deltas(struct object_entry **list, unsigned *list_size, |
e334977d | 2425 | int window, int depth, unsigned *processed) |
c323ac7d | 2426 | { |
384b32c0 | 2427 | uint32_t i, idx = 0, count = 0; |
7cadf491 | 2428 | struct unpacked *array; |
ef0316fc | 2429 | unsigned long mem_usage = 0; |
c323ac7d | 2430 | |
19d4b416 | 2431 | array = xcalloc(window, sizeof(struct unpacked)); |
21fcd1bd | 2432 | |
384b32c0 | 2433 | for (;;) { |
421b488a | 2434 | struct object_entry *entry; |
c323ac7d | 2435 | struct unpacked *n = array + idx; |
ef0316fc | 2436 | int j, max_depth, best_base = -1; |
c323ac7d | 2437 | |
384b32c0 NP |
2438 | progress_lock(); |
2439 | if (!*list_size) { | |
2440 | progress_unlock(); | |
2441 | break; | |
2442 | } | |
421b488a | 2443 | entry = *list++; |
384b32c0 NP |
2444 | (*list_size)--; |
2445 | if (!entry->preferred_base) { | |
2446 | (*processed)++; | |
2447 | display_progress(progress_state, *processed); | |
2448 | } | |
2449 | progress_unlock(); | |
2450 | ||
ef0316fc | 2451 | mem_usage -= free_unpacked(n); |
c323ac7d | 2452 | n->entry = entry; |
ab7cd7bb | 2453 | |
a97773ce | 2454 | while (window_memory_limit && |
ef0316fc | 2455 | mem_usage > window_memory_limit && |
a97773ce | 2456 | count > 1) { |
33de80b1 | 2457 | const uint32_t tail = (idx + window - count) % window; |
75ad235c | 2458 | mem_usage -= free_unpacked(array + tail); |
a97773ce BD |
2459 | count--; |
2460 | } | |
2461 | ||
75d39853 NP |
2462 | /* We do not compute delta to *create* objects we are not |
2463 | * going to pack. | |
2464 | */ | |
2465 | if (entry->preferred_base) | |
2466 | goto next; | |
2467 | ||
898b14ce NP |
2468 | /* |
2469 | * If the current object is at pack edge, take the depth the | |
2470 | * objects that depend on the current object into account | |
2471 | * otherwise they would become too deep. | |
2472 | */ | |
2473 | max_depth = depth; | |
898eba5e | 2474 | if (DELTA_CHILD(entry)) { |
898b14ce NP |
2475 | max_depth -= check_delta_limit(entry, 0); |
2476 | if (max_depth <= 0) | |
2477 | goto next; | |
2478 | } | |
2479 | ||
78817c15 LT |
2480 | j = window; |
2481 | while (--j > 0) { | |
77639870 | 2482 | int ret; |
7cadf491 | 2483 | uint32_t other_idx = idx + j; |
c323ac7d | 2484 | struct unpacked *m; |
78817c15 LT |
2485 | if (other_idx >= window) |
2486 | other_idx -= window; | |
c323ac7d LT |
2487 | m = array + other_idx; |
2488 | if (!m->entry) | |
2489 | break; | |
ef0316fc | 2490 | ret = try_delta(n, m, max_depth, &mem_usage); |
77639870 | 2491 | if (ret < 0) |
c323ac7d | 2492 | break; |
77639870 JH |
2493 | else if (ret > 0) |
2494 | best_base = other_idx; | |
c323ac7d | 2495 | } |
898b14ce | 2496 | |
ed4a9031 NP |
2497 | /* |
2498 | * If we decided to cache the delta data, then it is best | |
2499 | * to compress it right away. First because we have to do | |
2500 | * it anyway, and doing it here while we're threaded will | |
2501 | * save a lot of time in the non threaded write phase, | |
2502 | * as well as allow for caching more deltas within | |
2503 | * the same cache size limit. | |
2504 | * ... | |
2505 | * But only if not writing to stdout, since in that case | |
2506 | * the network is most likely throttling writes anyway, | |
2507 | * and therefore it is best to go to the write phase ASAP | |
2508 | * instead, as we can afford spending more time compressing | |
2509 | * between writes at that moment. | |
2510 | */ | |
2511 | if (entry->delta_data && !pack_to_stdout) { | |
0cb3c142 NTND |
2512 | unsigned long size; |
2513 | ||
0aca34e8 | 2514 | size = do_compress(&entry->delta_data, DELTA_SIZE(entry)); |
0cb3c142 NTND |
2515 | if (size < (1U << OE_Z_DELTA_BITS)) { |
2516 | entry->z_delta_size = size; | |
2517 | cache_lock(); | |
0aca34e8 | 2518 | delta_cache_size -= DELTA_SIZE(entry); |
0cb3c142 NTND |
2519 | delta_cache_size += entry->z_delta_size; |
2520 | cache_unlock(); | |
2521 | } else { | |
2522 | FREE_AND_NULL(entry->delta_data); | |
2523 | entry->z_delta_size = 0; | |
2524 | } | |
ed4a9031 NP |
2525 | } |
2526 | ||
70ca1a3f JH |
2527 | /* if we made n a delta, and if n is already at max |
2528 | * depth, leaving it in the window is pointless. we | |
2529 | * should evict it first. | |
70ca1a3f | 2530 | */ |
898eba5e | 2531 | if (DELTA(entry) && max_depth <= n->depth) |
70ca1a3f | 2532 | continue; |
ff45715c | 2533 | |
77639870 JH |
2534 | /* |
2535 | * Move the best delta base up in the window, after the | |
2536 | * currently deltified object, to keep it longer. It will | |
2537 | * be the first base object to be attempted next. | |
2538 | */ | |
898eba5e | 2539 | if (DELTA(entry)) { |
77639870 JH |
2540 | struct unpacked swap = array[best_base]; |
2541 | int dist = (window + idx - best_base) % window; | |
2542 | int dst = best_base; | |
2543 | while (dist--) { | |
2544 | int src = (dst + 1) % window; | |
2545 | array[dst] = array[src]; | |
2546 | dst = src; | |
2547 | } | |
2548 | array[dst] = swap; | |
2549 | } | |
2550 | ||
898b14ce | 2551 | next: |
521a4f4c | 2552 | idx++; |
a97773ce BD |
2553 | if (count + 1 < window) |
2554 | count++; | |
521a4f4c LT |
2555 | if (idx >= window) |
2556 | idx = 0; | |
384b32c0 | 2557 | } |
adee7bdf | 2558 | |
f6c7081a | 2559 | for (i = 0; i < window; ++i) { |
ff45715c | 2560 | free_delta_index(array[i].index); |
adee7bdf | 2561 | free(array[i].data); |
f6c7081a | 2562 | } |
adee7bdf | 2563 | free(array); |
c323ac7d LT |
2564 | } |
2565 | ||
50f22ada | 2566 | /* |
ffbd51cc NTND |
2567 | * The main object list is split into smaller lists, each is handed to |
2568 | * one worker. | |
2569 | * | |
50f22ada JS |
2570 | * The main thread waits on the condition that (at least) one of the workers |
2571 | * has stopped working (which is indicated in the .working member of | |
2572 | * struct thread_params). | |
ffbd51cc | 2573 | * |
50f22ada JS |
2574 | * When a work thread has completed its work, it sets .working to 0 and |
2575 | * signals the main thread and waits on the condition that .data_ready | |
2576 | * becomes 1. | |
ffbd51cc NTND |
2577 | * |
2578 | * The main thread steals half of the work from the worker that has | |
2579 | * most work left to hand it to the idle worker. | |
50f22ada JS |
2580 | */ |
2581 | ||
8ecce684 NP |
2582 | struct thread_params { |
2583 | pthread_t thread; | |
2584 | struct object_entry **list; | |
2585 | unsigned list_size; | |
384b32c0 | 2586 | unsigned remaining; |
8ecce684 NP |
2587 | int window; |
2588 | int depth; | |
50f22ada JS |
2589 | int working; |
2590 | int data_ready; | |
2591 | pthread_mutex_t mutex; | |
2592 | pthread_cond_t cond; | |
8ecce684 NP |
2593 | unsigned *processed; |
2594 | }; | |
2595 | ||
44626dc7 AH |
2596 | static pthread_cond_t progress_cond; |
2597 | ||
2598 | /* | |
2599 | * Mutex and conditional variable can't be statically-initialized on Windows. | |
2600 | */ | |
2601 | static void init_threaded_search(void) | |
2602 | { | |
44626dc7 AH |
2603 | pthread_mutex_init(&cache_mutex, NULL); |
2604 | pthread_mutex_init(&progress_mutex, NULL); | |
2605 | pthread_cond_init(&progress_cond, NULL); | |
2606 | } | |
2607 | ||
2608 | static void cleanup_threaded_search(void) | |
2609 | { | |
2610 | pthread_cond_destroy(&progress_cond); | |
44626dc7 AH |
2611 | pthread_mutex_destroy(&cache_mutex); |
2612 | pthread_mutex_destroy(&progress_mutex); | |
2613 | } | |
c2a33679 | 2614 | |
8ecce684 NP |
2615 | static void *threaded_find_deltas(void *arg) |
2616 | { | |
c2a33679 NP |
2617 | struct thread_params *me = arg; |
2618 | ||
0c2ad00b | 2619 | progress_lock(); |
50f22ada | 2620 | while (me->remaining) { |
0c2ad00b MÅ |
2621 | progress_unlock(); |
2622 | ||
384b32c0 | 2623 | find_deltas(me->list, &me->remaining, |
c2a33679 | 2624 | me->window, me->depth, me->processed); |
50f22ada JS |
2625 | |
2626 | progress_lock(); | |
2627 | me->working = 0; | |
2628 | pthread_cond_signal(&progress_cond); | |
2629 | progress_unlock(); | |
2630 | ||
2631 | /* | |
2632 | * We must not set ->data_ready before we wait on the | |
2633 | * condition because the main thread may have set it to 1 | |
2634 | * before we get here. In order to be sure that new | |
2635 | * work is available if we see 1 in ->data_ready, it | |
2636 | * was initialized to 0 before this thread was spawned | |
2637 | * and we reset it to 0 right away. | |
2638 | */ | |
2639 | pthread_mutex_lock(&me->mutex); | |
2640 | while (!me->data_ready) | |
2641 | pthread_cond_wait(&me->cond, &me->mutex); | |
2642 | me->data_ready = 0; | |
2643 | pthread_mutex_unlock(&me->mutex); | |
0c2ad00b MÅ |
2644 | |
2645 | progress_lock(); | |
c2a33679 | 2646 | } |
0c2ad00b | 2647 | progress_unlock(); |
50f22ada JS |
2648 | /* leave ->working 1 so that this doesn't get more work assigned */ |
2649 | return NULL; | |
8ecce684 NP |
2650 | } |
2651 | ||
8ecce684 NP |
2652 | static void ll_find_deltas(struct object_entry **list, unsigned list_size, |
2653 | int window, int depth, unsigned *processed) | |
2654 | { | |
dcda3614 | 2655 | struct thread_params *p; |
384b32c0 | 2656 | int i, ret, active_threads = 0; |
c2a33679 | 2657 | |
44626dc7 AH |
2658 | init_threaded_search(); |
2659 | ||
367f4a43 | 2660 | if (delta_search_threads <= 1) { |
384b32c0 | 2661 | find_deltas(list, &list_size, window, depth, processed); |
44626dc7 | 2662 | cleanup_threaded_search(); |
367f4a43 NP |
2663 | return; |
2664 | } | |
43cc2b42 | 2665 | if (progress > pack_to_stdout) |
f616db6a | 2666 | fprintf_ln(stderr, _("Delta compression using up to %d threads"), |
1a07e59c | 2667 | delta_search_threads); |
dcda3614 | 2668 | p = xcalloc(delta_search_threads, sizeof(*p)); |
367f4a43 | 2669 | |
50f22ada | 2670 | /* Partition the work amongst work threads. */ |
367f4a43 | 2671 | for (i = 0; i < delta_search_threads; i++) { |
50f22ada JS |
2672 | unsigned sub_size = list_size / (delta_search_threads - i); |
2673 | ||
bf874896 NP |
2674 | /* don't use too small segments or no deltas will be found */ |
2675 | if (sub_size < 2*window && i+1 < delta_search_threads) | |
2676 | sub_size = 0; | |
2677 | ||
8ecce684 NP |
2678 | p[i].window = window; |
2679 | p[i].depth = depth; | |
2680 | p[i].processed = processed; | |
50f22ada JS |
2681 | p[i].working = 1; |
2682 | p[i].data_ready = 0; | |
c2a33679 | 2683 | |
59921b4b | 2684 | /* try to split chunks on "path" boundaries */ |
6fc74703 NP |
2685 | while (sub_size && sub_size < list_size && |
2686 | list[sub_size]->hash && | |
384b32c0 NP |
2687 | list[sub_size]->hash == list[sub_size-1]->hash) |
2688 | sub_size++; | |
2689 | ||
50f22ada JS |
2690 | p[i].list = list; |
2691 | p[i].list_size = sub_size; | |
2692 | p[i].remaining = sub_size; | |
59921b4b | 2693 | |
384b32c0 NP |
2694 | list += sub_size; |
2695 | list_size -= sub_size; | |
2696 | } | |
2697 | ||
50f22ada JS |
2698 | /* Start work threads. */ |
2699 | for (i = 0; i < delta_search_threads; i++) { | |
2700 | if (!p[i].list_size) | |
2701 | continue; | |
68e6a4f8 JS |
2702 | pthread_mutex_init(&p[i].mutex, NULL); |
2703 | pthread_cond_init(&p[i].cond, NULL); | |
50f22ada JS |
2704 | ret = pthread_create(&p[i].thread, NULL, |
2705 | threaded_find_deltas, &p[i]); | |
2706 | if (ret) | |
f616db6a | 2707 | die(_("unable to create thread: %s"), strerror(ret)); |
50f22ada JS |
2708 | active_threads++; |
2709 | } | |
2710 | ||
384b32c0 NP |
2711 | /* |
2712 | * Now let's wait for work completion. Each time a thread is done | |
2713 | * with its work, we steal half of the remaining work from the | |
2714 | * thread with the largest number of unprocessed objects and give | |
2715 | * it to that newly idle thread. This ensure good load balancing | |
2716 | * until the remaining object list segments are simply too short | |
2717 | * to be worth splitting anymore. | |
2718 | */ | |
50f22ada JS |
2719 | while (active_threads) { |
2720 | struct thread_params *target = NULL; | |
384b32c0 NP |
2721 | struct thread_params *victim = NULL; |
2722 | unsigned sub_size = 0; | |
384b32c0 NP |
2723 | |
2724 | progress_lock(); | |
50f22ada JS |
2725 | for (;;) { |
2726 | for (i = 0; !target && i < delta_search_threads; i++) | |
2727 | if (!p[i].working) | |
2728 | target = &p[i]; | |
2729 | if (target) | |
2730 | break; | |
2731 | pthread_cond_wait(&progress_cond, &progress_mutex); | |
2732 | } | |
2733 | ||
384b32c0 NP |
2734 | for (i = 0; i < delta_search_threads; i++) |
2735 | if (p[i].remaining > 2*window && | |
2736 | (!victim || victim->remaining < p[i].remaining)) | |
2737 | victim = &p[i]; | |
2738 | if (victim) { | |
2739 | sub_size = victim->remaining / 2; | |
2740 | list = victim->list + victim->list_size - sub_size; | |
2741 | while (sub_size && list[0]->hash && | |
2742 | list[0]->hash == list[-1]->hash) { | |
2743 | list++; | |
2744 | sub_size--; | |
2745 | } | |
eb9688ff NP |
2746 | if (!sub_size) { |
2747 | /* | |
2748 | * It is possible for some "paths" to have | |
2749 | * so many objects that no hash boundary | |
2750 | * might be found. Let's just steal the | |
2751 | * exact half in that case. | |
2752 | */ | |
2753 | sub_size = victim->remaining / 2; | |
2754 | list -= sub_size; | |
2755 | } | |
384b32c0 NP |
2756 | target->list = list; |
2757 | victim->list_size -= sub_size; | |
2758 | victim->remaining -= sub_size; | |
2759 | } | |
384b32c0 NP |
2760 | target->list_size = sub_size; |
2761 | target->remaining = sub_size; | |
50f22ada JS |
2762 | target->working = 1; |
2763 | progress_unlock(); | |
2764 | ||
2765 | pthread_mutex_lock(&target->mutex); | |
2766 | target->data_ready = 1; | |
2767 | pthread_cond_signal(&target->cond); | |
2768 | pthread_mutex_unlock(&target->mutex); | |
c2a33679 | 2769 | |
384b32c0 | 2770 | if (!sub_size) { |
b81d9af7 | 2771 | pthread_join(target->thread, NULL); |
50f22ada JS |
2772 | pthread_cond_destroy(&target->cond); |
2773 | pthread_mutex_destroy(&target->mutex); | |
384b32c0 | 2774 | active_threads--; |
c2a33679 | 2775 | } |
50f22ada | 2776 | } |
44626dc7 | 2777 | cleanup_threaded_search(); |
dcda3614 | 2778 | free(p); |
8ecce684 NP |
2779 | } |
2780 | ||
ff483026 JK |
2781 | static int obj_is_packed(const struct object_id *oid) |
2782 | { | |
a14aebea | 2783 | return packlist_find(&to_pack, oid) || |
92fb0db9 JK |
2784 | (reuse_packfile_bitmap && |
2785 | bitmap_walk_contains(bitmap_git, reuse_packfile_bitmap, oid)); | |
ff483026 JK |
2786 | } |
2787 | ||
b773ddea JK |
2788 | static void add_tag_chain(const struct object_id *oid) |
2789 | { | |
2790 | struct tag *tag; | |
2791 | ||
2792 | /* | |
2793 | * We catch duplicates already in add_object_entry(), but we'd | |
2794 | * prefer to do this extra check to avoid having to parse the | |
2795 | * tag at all if we already know that it's being packed (e.g., if | |
2796 | * it was included via bitmaps, we would not have parsed it | |
2797 | * previously). | |
2798 | */ | |
ff483026 | 2799 | if (obj_is_packed(oid)) |
b773ddea JK |
2800 | return; |
2801 | ||
ce71efb7 | 2802 | tag = lookup_tag(the_repository, oid); |
b773ddea JK |
2803 | while (1) { |
2804 | if (!tag || parse_tag(tag) || !tag->tagged) | |
f616db6a | 2805 | die(_("unable to pack objects reachable from tag %s"), |
b773ddea JK |
2806 | oid_to_hex(oid)); |
2807 | ||
188960b4 | 2808 | add_object_entry(&tag->object.oid, OBJ_TAG, NULL, 0); |
b773ddea JK |
2809 | |
2810 | if (tag->tagged->type != OBJ_TAG) | |
2811 | return; | |
2812 | ||
2813 | tag = (struct tag *)tag->tagged; | |
2814 | } | |
2815 | } | |
2816 | ||
d155254c | 2817 | static int add_ref_tag(const char *path, const struct object_id *oid, int flag, void *cb_data) |
f0a24aa5 | 2818 | { |
d155254c | 2819 | struct object_id peeled; |
f0a24aa5 | 2820 | |
59556548 | 2821 | if (starts_with(path, "refs/tags/") && /* is a tag? */ |
b420d909 | 2822 | !peel_ref(path, &peeled) && /* peelable? */ |
ff483026 | 2823 | obj_is_packed(&peeled)) /* object packed? */ |
b773ddea | 2824 | add_tag_chain(oid); |
f0a24aa5 SP |
2825 | return 0; |
2826 | } | |
2827 | ||
f3123c4a JH |
2828 | static void prepare_pack(int window, int depth) |
2829 | { | |
9668cf59 | 2830 | struct object_entry **delta_list; |
6e1c2344 RJ |
2831 | uint32_t i, nr_deltas; |
2832 | unsigned n; | |
9668cf59 | 2833 | |
28b8a730 | 2834 | if (use_delta_islands) |
385cb64f | 2835 | resolve_tree_islands(the_repository, progress, &to_pack); |
28b8a730 | 2836 | |
3f9ac8d2 | 2837 | get_object_details(); |
9668cf59 | 2838 | |
0e8189e2 NP |
2839 | /* |
2840 | * If we're locally repacking then we need to be doubly careful | |
2841 | * from now on in order to make sure no stealth corruption gets | |
2842 | * propagated to the new pack. Clients receiving streamed packs | |
2843 | * should validate everything they get anyway so no need to incur | |
2844 | * the additional cost here in that case. | |
2845 | */ | |
2846 | if (!pack_to_stdout) | |
2847 | do_check_packed_object_crc = 1; | |
2848 | ||
2834bc27 | 2849 | if (!to_pack.nr_objects || !window || !depth) |
9668cf59 NP |
2850 | return; |
2851 | ||
b32fa95f | 2852 | ALLOC_ARRAY(delta_list, to_pack.nr_objects); |
75d39853 NP |
2853 | nr_deltas = n = 0; |
2854 | ||
2834bc27 VM |
2855 | for (i = 0; i < to_pack.nr_objects; i++) { |
2856 | struct object_entry *entry = to_pack.objects + i; | |
75d39853 | 2857 | |
898eba5e | 2858 | if (DELTA(entry)) |
75d39853 | 2859 | /* This happens if we decided to reuse existing |
a7de7130 | 2860 | * delta from a pack. "reuse_delta &&" is implied. |
75d39853 NP |
2861 | */ |
2862 | continue; | |
2863 | ||
ac77d0c3 NTND |
2864 | if (!entry->type_valid || |
2865 | oe_size_less_than(&to_pack, entry, 50)) | |
75d39853 NP |
2866 | continue; |
2867 | ||
2868 | if (entry->no_try_delta) | |
2869 | continue; | |
2870 | ||
6d6f9cdd | 2871 | if (!entry->preferred_base) { |
75d39853 | 2872 | nr_deltas++; |
fd9b1bae | 2873 | if (oe_type(entry) < 0) |
f616db6a | 2874 | die(_("unable to get type of object %s"), |
e6a492b7 | 2875 | oid_to_hex(&entry->idx.oid)); |
eede9f42 | 2876 | } else { |
fd9b1bae | 2877 | if (oe_type(entry) < 0) { |
eede9f42 NP |
2878 | /* |
2879 | * This object is not found, but we | |
2880 | * don't have to include it anyway. | |
2881 | */ | |
2882 | continue; | |
2883 | } | |
6d6f9cdd | 2884 | } |
75d39853 NP |
2885 | |
2886 | delta_list[n++] = entry; | |
2887 | } | |
2888 | ||
2f8b8947 | 2889 | if (nr_deltas && n > 1) { |
e334977d | 2890 | unsigned nr_done = 0; |
bb514de3 | 2891 | |
e334977d | 2892 | if (progress) |
754dbc43 | 2893 | progress_state = start_progress(_("Compressing objects"), |
dc6a0757 | 2894 | nr_deltas); |
9ed0d8d6 | 2895 | QSORT(delta_list, n, type_size_sort); |
8ecce684 | 2896 | ll_find_deltas(delta_list, n, window+1, depth, &nr_done); |
4d4fcc54 | 2897 | stop_progress(&progress_state); |
e334977d | 2898 | if (nr_done != nr_deltas) |
f616db6a | 2899 | die(_("inconsistency with delta count")); |
75d39853 | 2900 | } |
9668cf59 | 2901 | free(delta_list); |
f3123c4a JH |
2902 | } |
2903 | ||
ef90d6d4 | 2904 | static int git_pack_config(const char *k, const char *v, void *cb) |
4812a93a | 2905 | { |
eeefa7c9 | 2906 | if (!strcmp(k, "pack.window")) { |
4812a93a JK |
2907 | window = git_config_int(k, v); |
2908 | return 0; | |
2909 | } | |
a97773ce BD |
2910 | if (!strcmp(k, "pack.windowmemory")) { |
2911 | window_memory_limit = git_config_ulong(k, v); | |
2912 | return 0; | |
2913 | } | |
2914 | if (!strcmp(k, "pack.depth")) { | |
842aaf93 TT |
2915 | depth = git_config_int(k, v); |
2916 | return 0; | |
2917 | } | |
074b2eea MK |
2918 | if (!strcmp(k, "pack.deltacachesize")) { |
2919 | max_delta_cache_size = git_config_int(k, v); | |
2920 | return 0; | |
2921 | } | |
e3dfddb3 MK |
2922 | if (!strcmp(k, "pack.deltacachelimit")) { |
2923 | cache_max_small_delta_size = git_config_int(k, v); | |
2924 | return 0; | |
2925 | } | |
ae4f07fb VM |
2926 | if (!strcmp(k, "pack.writebitmaphashcache")) { |
2927 | if (git_config_bool(k, v)) | |
2928 | write_bitmap_options |= BITMAP_OPT_HASH_CACHE; | |
2929 | else | |
2930 | write_bitmap_options &= ~BITMAP_OPT_HASH_CACHE; | |
2931 | } | |
6b8fda2d | 2932 | if (!strcmp(k, "pack.usebitmaps")) { |
645c432d | 2933 | use_bitmap_index_default = git_config_bool(k, v); |
6b8fda2d VM |
2934 | return 0; |
2935 | } | |
e704fc79 JK |
2936 | if (!strcmp(k, "pack.allowpackreuse")) { |
2937 | allow_pack_reuse = git_config_bool(k, v); | |
2938 | return 0; | |
2939 | } | |
693b86ff NP |
2940 | if (!strcmp(k, "pack.threads")) { |
2941 | delta_search_threads = git_config_int(k, v); | |
833e3df1 | 2942 | if (delta_search_threads < 0) |
f616db6a | 2943 | die(_("invalid number of threads specified (%d)"), |
693b86ff | 2944 | delta_search_threads); |
9c897c5c | 2945 | if (!HAVE_THREADS && delta_search_threads != 1) { |
f616db6a | 2946 | warning(_("no threads support, ignoring %s"), k); |
2e96d815 ÆAB |
2947 | delta_search_threads = 0; |
2948 | } | |
693b86ff NP |
2949 | return 0; |
2950 | } | |
4d00bda2 | 2951 | if (!strcmp(k, "pack.indexversion")) { |
ebcfb379 JH |
2952 | pack_idx_opts.version = git_config_int(k, v); |
2953 | if (pack_idx_opts.version > 2) | |
f616db6a | 2954 | die(_("bad pack.indexversion=%"PRIu32), |
ebcfb379 | 2955 | pack_idx_opts.version); |
4d00bda2 NP |
2956 | return 0; |
2957 | } | |
c9773343 TB |
2958 | if (!strcmp(k, "pack.writereverseindex")) { |
2959 | if (git_config_bool(k, v)) | |
2960 | pack_idx_opts.flags |= WRITE_REV; | |
2961 | else | |
2962 | pack_idx_opts.flags &= ~WRITE_REV; | |
2963 | return 0; | |
2964 | } | |
dd4b732d JT |
2965 | if (!strcmp(k, "uploadpack.blobpackfileuri")) { |
2966 | struct configured_exclusion *ex = xmalloc(sizeof(*ex)); | |
2967 | const char *oid_end, *pack_end; | |
2968 | /* | |
2969 | * Stores the pack hash. This is not a true object ID, but is | |
2970 | * of the same form. | |
2971 | */ | |
2972 | struct object_id pack_hash; | |
2973 | ||
2974 | if (parse_oid_hex(v, &ex->e.oid, &oid_end) || | |
2975 | *oid_end != ' ' || | |
2976 | parse_oid_hex(oid_end + 1, &pack_hash, &pack_end) || | |
2977 | *pack_end != ' ') | |
2978 | die(_("value of uploadpack.blobpackfileuri must be " | |
2979 | "of the form '<object-hash> <pack-hash> <uri>' (got '%s')"), v); | |
2980 | if (oidmap_get(&configured_exclusions, &ex->e.oid)) | |
2981 | die(_("object already configured in another " | |
2982 | "uploadpack.blobpackfileuri (got '%s')"), v); | |
2983 | ex->pack_hash_hex = xcalloc(1, pack_end - oid_end); | |
2984 | memcpy(ex->pack_hash_hex, oid_end + 1, pack_end - oid_end - 1); | |
2985 | ex->uri = xstrdup(pack_end + 1); | |
2986 | oidmap_put(&configured_exclusions, ex); | |
2987 | } | |
ef90d6d4 | 2988 | return git_default_config(k, v, cb); |
4812a93a JK |
2989 | } |
2990 | ||
b5d97e6b | 2991 | static void read_object_list_from_stdin(void) |
c323ac7d | 2992 | { |
188960b4 | 2993 | char line[GIT_MAX_HEXSZ + 1 + PATH_MAX + 2]; |
2994 | struct object_id oid; | |
2995 | const char *p; | |
b2504a0d | 2996 | |
da93d12b | 2997 | for (;;) { |
da93d12b LT |
2998 | if (!fgets(line, sizeof(line), stdin)) { |
2999 | if (feof(stdin)) | |
3000 | break; | |
3001 | if (!ferror(stdin)) | |
1a07e59c | 3002 | die("BUG: fgets returned NULL, not EOF, not error!"); |
687dd75c | 3003 | if (errno != EINTR) |
d824cbba | 3004 | die_errno("fgets"); |
687dd75c JH |
3005 | clearerr(stdin); |
3006 | continue; | |
da93d12b | 3007 | } |
7a979d99 | 3008 | if (line[0] == '-') { |
188960b4 | 3009 | if (get_oid_hex(line+1, &oid)) |
f616db6a | 3010 | die(_("expected edge object ID, got garbage:\n %s"), |
b5d97e6b | 3011 | line); |
188960b4 | 3012 | add_preferred_base(&oid); |
7a979d99 | 3013 | continue; |
21fcd1bd | 3014 | } |
188960b4 | 3015 | if (parse_oid_hex(line, &oid, &p)) |
f616db6a | 3016 | die(_("expected object ID, got garbage:\n %s"), line); |
b5d97e6b | 3017 | |
188960b4 | 3018 | add_preferred_base_object(p + 1); |
fd9b1bae | 3019 | add_object_entry(&oid, OBJ_NONE, p + 1, 0); |
c323ac7d | 3020 | } |
b5d97e6b JH |
3021 | } |
3022 | ||
95308d64 | 3023 | /* Remember to update object flag allocation in object.h */ |
08cdfb13 JH |
3024 | #define OBJECT_ADDED (1u<<20) |
3025 | ||
11c211fa | 3026 | static void show_commit(struct commit *commit, void *data) |
b5d97e6b | 3027 | { |
188960b4 | 3028 | add_object_entry(&commit->object.oid, OBJ_COMMIT, NULL, 0); |
08cdfb13 | 3029 | commit->object.flags |= OBJECT_ADDED; |
7cc8f971 VM |
3030 | |
3031 | if (write_bitmap_index) | |
3032 | index_commit_for_bitmap(commit); | |
28b8a730 JK |
3033 | |
3034 | if (use_delta_islands) | |
3035 | propagate_island_marks(commit); | |
b5d97e6b JH |
3036 | } |
3037 | ||
de1e67d0 | 3038 | static void show_object(struct object *obj, const char *name, void *data) |
b5d97e6b | 3039 | { |
8d2dfc49 | 3040 | add_preferred_base_object(name); |
188960b4 | 3041 | add_object_entry(&obj->oid, obj->type, name, 0); |
8d2dfc49 | 3042 | obj->flags |= OBJECT_ADDED; |
28b8a730 JK |
3043 | |
3044 | if (use_delta_islands) { | |
3045 | const char *p; | |
39490536 | 3046 | unsigned depth; |
28b8a730 JK |
3047 | struct object_entry *ent; |
3048 | ||
39490536 JK |
3049 | /* the empty string is a root tree, which is depth 0 */ |
3050 | depth = *name ? 1 : 0; | |
28b8a730 JK |
3051 | for (p = strchr(name, '/'); p; p = strchr(p + 1, '/')) |
3052 | depth++; | |
3053 | ||
3a37876b | 3054 | ent = packlist_find(&to_pack, &obj->oid); |
108f5303 CC |
3055 | if (ent && depth > oe_tree_depth(&to_pack, ent)) |
3056 | oe_set_tree_depth(&to_pack, ent, depth); | |
28b8a730 | 3057 | } |
b5d97e6b JH |
3058 | } |
3059 | ||
9535ce73 JH |
3060 | static void show_object__ma_allow_any(struct object *obj, const char *name, void *data) |
3061 | { | |
3062 | assert(arg_missing_action == MA_ALLOW_ANY); | |
3063 | ||
3064 | /* | |
3065 | * Quietly ignore ALL missing objects. This avoids problems with | |
3066 | * staging them now and getting an odd error later. | |
3067 | */ | |
ee47243d | 3068 | if (!has_object(the_repository, &obj->oid, 0)) |
9535ce73 JH |
3069 | return; |
3070 | ||
3071 | show_object(obj, name, data); | |
3072 | } | |
3073 | ||
0c16cd49 JT |
3074 | static void show_object__ma_allow_promisor(struct object *obj, const char *name, void *data) |
3075 | { | |
3076 | assert(arg_missing_action == MA_ALLOW_PROMISOR); | |
3077 | ||
3078 | /* | |
3079 | * Quietly ignore EXPECTED missing objects. This avoids problems with | |
3080 | * staging them now and getting an odd error later. | |
3081 | */ | |
ee47243d | 3082 | if (!has_object(the_repository, &obj->oid, 0) && is_promisor_object(&obj->oid)) |
0c16cd49 JT |
3083 | return; |
3084 | ||
3085 | show_object(obj, name, data); | |
3086 | } | |
3087 | ||
9535ce73 JH |
3088 | static int option_parse_missing_action(const struct option *opt, |
3089 | const char *arg, int unset) | |
3090 | { | |
3091 | assert(arg); | |
3092 | assert(!unset); | |
3093 | ||
3094 | if (!strcmp(arg, "error")) { | |
3095 | arg_missing_action = MA_ERROR; | |
3096 | fn_show_object = show_object; | |
3097 | return 0; | |
3098 | } | |
3099 | ||
3100 | if (!strcmp(arg, "allow-any")) { | |
3101 | arg_missing_action = MA_ALLOW_ANY; | |
0c16cd49 | 3102 | fetch_if_missing = 0; |
9535ce73 JH |
3103 | fn_show_object = show_object__ma_allow_any; |
3104 | return 0; | |
3105 | } | |
3106 | ||
0c16cd49 JT |
3107 | if (!strcmp(arg, "allow-promisor")) { |
3108 | arg_missing_action = MA_ALLOW_PROMISOR; | |
3109 | fetch_if_missing = 0; | |
3110 | fn_show_object = show_object__ma_allow_promisor; | |
3111 | return 0; | |
3112 | } | |
3113 | ||
9535ce73 JH |
3114 | die(_("invalid value for --missing")); |
3115 | return 0; | |
3116 | } | |
3117 | ||
8d1d8f83 JH |
3118 | static void show_edge(struct commit *commit) |
3119 | { | |
188960b4 | 3120 | add_preferred_base(&commit->object.oid); |
8d1d8f83 JH |
3121 | } |
3122 | ||
08cdfb13 JH |
3123 | struct in_pack_object { |
3124 | off_t offset; | |
3125 | struct object *object; | |
3126 | }; | |
3127 | ||
3128 | struct in_pack { | |
071bcaab RJ |
3129 | unsigned int alloc; |
3130 | unsigned int nr; | |
08cdfb13 JH |
3131 | struct in_pack_object *array; |
3132 | }; | |
3133 | ||
3134 | static void mark_in_pack_object(struct object *object, struct packed_git *p, struct in_pack *in_pack) | |
3135 | { | |
ed1c9977 | 3136 | in_pack->array[in_pack->nr].offset = find_pack_entry_one(object->oid.hash, p); |
08cdfb13 JH |
3137 | in_pack->array[in_pack->nr].object = object; |
3138 | in_pack->nr++; | |
3139 | } | |
3140 | ||
3141 | /* | |
3142 | * Compare the objects in the offset order, in order to emulate the | |
f18d244a | 3143 | * "git rev-list --objects" output that produced the pack originally. |
08cdfb13 JH |
3144 | */ |
3145 | static int ofscmp(const void *a_, const void *b_) | |
3146 | { | |
3147 | struct in_pack_object *a = (struct in_pack_object *)a_; | |
3148 | struct in_pack_object *b = (struct in_pack_object *)b_; | |
3149 | ||
3150 | if (a->offset < b->offset) | |
3151 | return -1; | |
3152 | else if (a->offset > b->offset) | |
3153 | return 1; | |
3154 | else | |
f2fd0760 | 3155 | return oidcmp(&a->object->oid, &b->object->oid); |
08cdfb13 JH |
3156 | } |
3157 | ||
7a2a7216 | 3158 | static void add_objects_in_unpacked_packs(void) |
08cdfb13 JH |
3159 | { |
3160 | struct packed_git *p; | |
3161 | struct in_pack in_pack; | |
3162 | uint32_t i; | |
3163 | ||
3164 | memset(&in_pack, 0, sizeof(in_pack)); | |
3165 | ||
454ea2e4 | 3166 | for (p = get_all_packs(the_repository); p; p = p->next) { |
188960b4 | 3167 | struct object_id oid; |
08cdfb13 JH |
3168 | struct object *o; |
3169 | ||
ed7e5fc3 | 3170 | if (!p->pack_local || p->pack_keep || p->pack_keep_in_core) |
08cdfb13 JH |
3171 | continue; |
3172 | if (open_pack_index(p)) | |
f616db6a | 3173 | die(_("cannot open pack index")); |
08cdfb13 JH |
3174 | |
3175 | ALLOC_GROW(in_pack.array, | |
3176 | in_pack.nr + p->num_objects, | |
3177 | in_pack.alloc); | |
3178 | ||
3179 | for (i = 0; i < p->num_objects; i++) { | |
0763671b | 3180 | nth_packed_object_id(&oid, p, i); |
0ebbcf70 | 3181 | o = lookup_unknown_object(&oid); |
08cdfb13 JH |
3182 | if (!(o->flags & OBJECT_ADDED)) |
3183 | mark_in_pack_object(o, p, &in_pack); | |
3184 | o->flags |= OBJECT_ADDED; | |
3185 | } | |
3186 | } | |
3187 | ||
3188 | if (in_pack.nr) { | |
9ed0d8d6 | 3189 | QSORT(in_pack.array, in_pack.nr, ofscmp); |
08cdfb13 JH |
3190 | for (i = 0; i < in_pack.nr; i++) { |
3191 | struct object *o = in_pack.array[i].object; | |
188960b4 | 3192 | add_object_entry(&o->oid, o->type, "", 0); |
08cdfb13 JH |
3193 | } |
3194 | } | |
3195 | free(in_pack.array); | |
3196 | } | |
3197 | ||
76c1d9a0 | 3198 | static int add_loose_object(const struct object_id *oid, const char *path, |
e26a8c47 JK |
3199 | void *data) |
3200 | { | |
0df8e965 | 3201 | enum object_type type = oid_object_info(the_repository, oid, NULL); |
e26a8c47 JK |
3202 | |
3203 | if (type < 0) { | |
f616db6a | 3204 | warning(_("loose object at %s could not be examined"), path); |
e26a8c47 JK |
3205 | return 0; |
3206 | } | |
3207 | ||
188960b4 | 3208 | add_object_entry(oid, type, "", 0); |
e26a8c47 JK |
3209 | return 0; |
3210 | } | |
3211 | ||
3212 | /* | |
3213 | * We actually don't even have to worry about reachability here. | |
3214 | * add_object_entry will weed out duplicates, so we just add every | |
3215 | * loose object we find. | |
3216 | */ | |
3217 | static void add_unreachable_loose_objects(void) | |
3218 | { | |
3219 | for_each_loose_file_in_objdir(get_object_directory(), | |
3220 | add_loose_object, | |
3221 | NULL, NULL, NULL); | |
3222 | } | |
3223 | ||
188960b4 | 3224 | static int has_sha1_pack_kept_or_nonlocal(const struct object_id *oid) |
094085e3 BC |
3225 | { |
3226 | static struct packed_git *last_found = (void *)1; | |
3227 | struct packed_git *p; | |
3228 | ||
a80d72db | 3229 | p = (last_found != (void *)1) ? last_found : |
454ea2e4 | 3230 | get_all_packs(the_repository); |
094085e3 BC |
3231 | |
3232 | while (p) { | |
ed7e5fc3 NTND |
3233 | if ((!p->pack_local || p->pack_keep || |
3234 | p->pack_keep_in_core) && | |
188960b4 | 3235 | find_pack_entry_one(oid->hash, p)) { |
094085e3 BC |
3236 | last_found = p; |
3237 | return 1; | |
3238 | } | |
3239 | if (p == last_found) | |
454ea2e4 | 3240 | p = get_all_packs(the_repository); |
094085e3 BC |
3241 | else |
3242 | p = p->next; | |
3243 | if (p == last_found) | |
3244 | p = p->next; | |
3245 | } | |
3246 | return 0; | |
3247 | } | |
3248 | ||
abcb8655 JK |
3249 | /* |
3250 | * Store a list of sha1s that are should not be discarded | |
3251 | * because they are either written too recently, or are | |
3252 | * reachable from another object that was. | |
3253 | * | |
3254 | * This is filled by get_object_list. | |
3255 | */ | |
910650d2 | 3256 | static struct oid_array recent_objects; |
abcb8655 | 3257 | |
4ce3621a | 3258 | static int loosened_object_can_be_discarded(const struct object_id *oid, |
dddbad72 | 3259 | timestamp_t mtime) |
d0d46abc JK |
3260 | { |
3261 | if (!unpack_unreachable_expiration) | |
3262 | return 0; | |
3263 | if (mtime > unpack_unreachable_expiration) | |
3264 | return 0; | |
910650d2 | 3265 | if (oid_array_lookup(&recent_objects, oid) >= 0) |
abcb8655 | 3266 | return 0; |
d0d46abc JK |
3267 | return 1; |
3268 | } | |
3269 | ||
7a2a7216 | 3270 | static void loosen_unused_packed_objects(void) |
ca11b212 NP |
3271 | { |
3272 | struct packed_git *p; | |
3273 | uint32_t i; | |
4ce3621a | 3274 | struct object_id oid; |
ca11b212 | 3275 | |
454ea2e4 | 3276 | for (p = get_all_packs(the_repository); p; p = p->next) { |
ed7e5fc3 | 3277 | if (!p->pack_local || p->pack_keep || p->pack_keep_in_core) |
ca11b212 NP |
3278 | continue; |
3279 | ||
3280 | if (open_pack_index(p)) | |
f616db6a | 3281 | die(_("cannot open pack index")); |
ca11b212 NP |
3282 | |
3283 | for (i = 0; i < p->num_objects; i++) { | |
0763671b | 3284 | nth_packed_object_id(&oid, p, i); |
3a37876b | 3285 | if (!packlist_find(&to_pack, &oid) && |
188960b4 | 3286 | !has_sha1_pack_kept_or_nonlocal(&oid) && |
4ce3621a | 3287 | !loosened_object_can_be_discarded(&oid, p->mtime)) |
4bdb70a4 | 3288 | if (force_object_loose(&oid, p->mtime)) |
f616db6a | 3289 | die(_("unable to force loose object")); |
ca11b212 NP |
3290 | } |
3291 | } | |
3292 | } | |
3293 | ||
69e4b342 | 3294 | /* |
645c432d KS |
3295 | * This tracks any options which pack-reuse code expects to be on, or which a |
3296 | * reader of the pack might not understand, and which would therefore prevent | |
3297 | * blind reuse of what we have on disk. | |
69e4b342 JK |
3298 | */ |
3299 | static int pack_options_allow_reuse(void) | |
3300 | { | |
e704fc79 JK |
3301 | return allow_pack_reuse && |
3302 | pack_to_stdout && | |
ed7e5fc3 NTND |
3303 | !ignore_packed_keep_on_disk && |
3304 | !ignore_packed_keep_in_core && | |
9df4a607 JK |
3305 | (!local || !have_non_local_packs) && |
3306 | !incremental; | |
69e4b342 JK |
3307 | } |
3308 | ||
6b8fda2d VM |
3309 | static int get_object_list_from_bitmap(struct rev_info *revs) |
3310 | { | |
3ab3185f | 3311 | if (!(bitmap_git = prepare_bitmap_walk(revs, &filter_options))) |
6b8fda2d VM |
3312 | return -1; |
3313 | ||
69e4b342 JK |
3314 | if (pack_options_allow_reuse() && |
3315 | !reuse_partial_packfile_from_bitmap( | |
3ae5fa07 | 3316 | bitmap_git, |
6b8fda2d VM |
3317 | &reuse_packfile, |
3318 | &reuse_packfile_objects, | |
bb514de3 | 3319 | &reuse_packfile_bitmap)) { |
6b8fda2d VM |
3320 | assert(reuse_packfile_objects); |
3321 | nr_result += reuse_packfile_objects; | |
78d2214e | 3322 | display_progress(progress_state, nr_result); |
6b8fda2d VM |
3323 | } |
3324 | ||
4eb707eb JK |
3325 | traverse_bitmap_commit_list(bitmap_git, revs, |
3326 | &add_object_entry_from_bitmap); | |
6b8fda2d VM |
3327 | return 0; |
3328 | } | |
3329 | ||
abcb8655 | 3330 | static void record_recent_object(struct object *obj, |
de1e67d0 | 3331 | const char *name, |
abcb8655 JK |
3332 | void *data) |
3333 | { | |
910650d2 | 3334 | oid_array_append(&recent_objects, &obj->oid); |
abcb8655 JK |
3335 | } |
3336 | ||
3337 | static void record_recent_commit(struct commit *commit, void *data) | |
3338 | { | |
910650d2 | 3339 | oid_array_append(&recent_objects, &commit->object.oid); |
abcb8655 JK |
3340 | } |
3341 | ||
8d1d8f83 | 3342 | static void get_object_list(int ac, const char **av) |
b5d97e6b JH |
3343 | { |
3344 | struct rev_info revs; | |
bbcde41a MD |
3345 | struct setup_revision_opt s_r_opt = { |
3346 | .allow_exclude_promisor_objects = 1, | |
3347 | }; | |
b5d97e6b | 3348 | char line[1000]; |
b5d97e6b | 3349 | int flags = 0; |
a4544b31 | 3350 | int save_warning; |
b5d97e6b | 3351 | |
2abf3503 | 3352 | repo_init_revisions(the_repository, &revs, NULL); |
b5d97e6b | 3353 | save_commit_buffer = 0; |
bbcde41a | 3354 | setup_revisions(ac, av, &revs, &s_r_opt); |
b5d97e6b | 3355 | |
b790e0f6 | 3356 | /* make sure shallows are read */ |
c8813487 | 3357 | is_repository_shallow(the_repository); |
b790e0f6 | 3358 | |
a4544b31 DS |
3359 | save_warning = warn_on_object_refname_ambiguity; |
3360 | warn_on_object_refname_ambiguity = 0; | |
3361 | ||
b5d97e6b JH |
3362 | while (fgets(line, sizeof(line), stdin) != NULL) { |
3363 | int len = strlen(line); | |
872c930d | 3364 | if (len && line[len - 1] == '\n') |
b5d97e6b JH |
3365 | line[--len] = 0; |
3366 | if (!len) | |
3367 | break; | |
3368 | if (*line == '-') { | |
3369 | if (!strcmp(line, "--not")) { | |
3370 | flags ^= UNINTERESTING; | |
7cc8f971 | 3371 | write_bitmap_index = 0; |
b5d97e6b JH |
3372 | continue; |
3373 | } | |
b790e0f6 | 3374 | if (starts_with(line, "--shallow ")) { |
e92b848c | 3375 | struct object_id oid; |
3376 | if (get_oid_hex(line + 10, &oid)) | |
4279000d | 3377 | die("not an object name '%s'", line + 10); |
19143f13 | 3378 | register_shallow(the_repository, &oid); |
f7f91086 | 3379 | use_bitmap_index = 0; |
b790e0f6 NTND |
3380 | continue; |
3381 | } | |
f616db6a | 3382 | die(_("not a rev '%s'"), line); |
b5d97e6b | 3383 | } |
8e676e8b | 3384 | if (handle_revision_arg(line, &revs, flags, REVARG_CANNOT_BE_FILENAME)) |
f616db6a | 3385 | die(_("bad revision '%s'"), line); |
b5d97e6b JH |
3386 | } |
3387 | ||
a4544b31 DS |
3388 | warn_on_object_refname_ambiguity = save_warning; |
3389 | ||
6b8fda2d VM |
3390 | if (use_bitmap_index && !get_object_list_from_bitmap(&revs)) |
3391 | return; | |
3392 | ||
28b8a730 | 3393 | if (use_delta_islands) |
bdbdf42f | 3394 | load_delta_islands(the_repository, progress); |
28b8a730 | 3395 | |
3d51e1b5 | 3396 | if (prepare_revision_walk(&revs)) |
f616db6a | 3397 | die(_("revision walk setup failed")); |
4f6d26b1 | 3398 | mark_edges_uninteresting(&revs, show_edge, sparse); |
9535ce73 JH |
3399 | |
3400 | if (!fn_show_object) | |
3401 | fn_show_object = show_object; | |
3402 | traverse_commit_list_filtered(&filter_options, &revs, | |
3403 | show_commit, fn_show_object, NULL, | |
3404 | NULL); | |
08cdfb13 | 3405 | |
abcb8655 JK |
3406 | if (unpack_unreachable_expiration) { |
3407 | revs.ignore_missing_links = 1; | |
3408 | if (add_unseen_recent_objects_to_traversal(&revs, | |
3409 | unpack_unreachable_expiration)) | |
f616db6a | 3410 | die(_("unable to add recent objects")); |
abcb8655 | 3411 | if (prepare_revision_walk(&revs)) |
f616db6a | 3412 | die(_("revision walk setup failed")); |
abcb8655 JK |
3413 | traverse_commit_list(&revs, record_recent_commit, |
3414 | record_recent_object, NULL); | |
3415 | } | |
3416 | ||
08cdfb13 | 3417 | if (keep_unreachable) |
7a2a7216 | 3418 | add_objects_in_unpacked_packs(); |
e26a8c47 JK |
3419 | if (pack_loose_unreachable) |
3420 | add_unreachable_loose_objects(); | |
ca11b212 | 3421 | if (unpack_unreachable) |
7a2a7216 | 3422 | loosen_unused_packed_objects(); |
abcb8655 | 3423 | |
910650d2 | 3424 | oid_array_clear(&recent_objects); |
b5d97e6b JH |
3425 | } |
3426 | ||
ed7e5fc3 NTND |
3427 | static void add_extra_kept_packs(const struct string_list *names) |
3428 | { | |
3429 | struct packed_git *p; | |
3430 | ||
3431 | if (!names->nr) | |
3432 | return; | |
3433 | ||
454ea2e4 | 3434 | for (p = get_all_packs(the_repository); p; p = p->next) { |
ed7e5fc3 NTND |
3435 | const char *name = basename(p->pack_name); |
3436 | int i; | |
3437 | ||
3438 | if (!p->pack_local) | |
3439 | continue; | |
3440 | ||
3441 | for (i = 0; i < names->nr; i++) | |
3442 | if (!fspathcmp(name, names->items[i].string)) | |
3443 | break; | |
3444 | ||
3445 | if (i < names->nr) { | |
3446 | p->pack_keep_in_core = 1; | |
3447 | ignore_packed_keep_in_core = 1; | |
3448 | continue; | |
3449 | } | |
3450 | } | |
3451 | } | |
3452 | ||
99fb6e04 NTND |
3453 | static int option_parse_index_version(const struct option *opt, |
3454 | const char *arg, int unset) | |
3455 | { | |
3456 | char *c; | |
3457 | const char *val = arg; | |
517fe807 JK |
3458 | |
3459 | BUG_ON_OPT_NEG(unset); | |
3460 | ||
99fb6e04 NTND |
3461 | pack_idx_opts.version = strtoul(val, &c, 10); |
3462 | if (pack_idx_opts.version > 2) | |
3463 | die(_("unsupported index version %s"), val); | |
3464 | if (*c == ',' && c[1]) | |
3465 | pack_idx_opts.off32_limit = strtoul(c+1, &c, 0); | |
3466 | if (*c || pack_idx_opts.off32_limit & 0x80000000) | |
3467 | die(_("bad index version '%s'"), val); | |
3468 | return 0; | |
3469 | } | |
3470 | ||
7e52f566 JK |
3471 | static int option_parse_unpack_unreachable(const struct option *opt, |
3472 | const char *arg, int unset) | |
3473 | { | |
3474 | if (unset) { | |
3475 | unpack_unreachable = 0; | |
3476 | unpack_unreachable_expiration = 0; | |
3477 | } | |
3478 | else { | |
3479 | unpack_unreachable = 1; | |
3480 | if (arg) | |
3481 | unpack_unreachable_expiration = approxidate(arg); | |
3482 | } | |
3483 | return 0; | |
3484 | } | |
3485 | ||
b5d97e6b JH |
3486 | int cmd_pack_objects(int argc, const char **argv, const char *prefix) |
3487 | { | |
b5d97e6b | 3488 | int use_internal_rev_list = 0; |
2dacf26d | 3489 | int shallow = 0; |
4f366275 | 3490 | int all_progress_implied = 0; |
22f9b7f3 | 3491 | struct strvec rp = STRVEC_INIT; |
99fb6e04 | 3492 | int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0; |
c90f9e13 | 3493 | int rev_list_index = 0; |
ed7e5fc3 | 3494 | struct string_list keep_pack_list = STRING_LIST_INIT_NODUP; |
99fb6e04 NTND |
3495 | struct option pack_objects_options[] = { |
3496 | OPT_SET_INT('q', "quiet", &progress, | |
4c688120 | 3497 | N_("do not show progress meter"), 0), |
99fb6e04 | 3498 | OPT_SET_INT(0, "progress", &progress, |
4c688120 | 3499 | N_("show progress meter"), 1), |
99fb6e04 | 3500 | OPT_SET_INT(0, "all-progress", &progress, |
4c688120 | 3501 | N_("show progress meter during object writing phase"), 2), |
99fb6e04 NTND |
3502 | OPT_BOOL(0, "all-progress-implied", |
3503 | &all_progress_implied, | |
4c688120 | 3504 | N_("similar to --all-progress when progress meter is shown")), |
203c8533 | 3505 | OPT_CALLBACK_F(0, "index-version", NULL, N_("<version>[,<offset>]"), |
4c688120 | 3506 | N_("write the pack index file in the specified idx format version"), |
203c8533 | 3507 | PARSE_OPT_NONEG, option_parse_index_version), |
2a514ed8 CB |
3508 | OPT_MAGNITUDE(0, "max-pack-size", &pack_size_limit, |
3509 | N_("maximum size of each output pack file")), | |
99fb6e04 | 3510 | OPT_BOOL(0, "local", &local, |
4c688120 | 3511 | N_("ignore borrowed objects from alternate object store")), |
99fb6e04 | 3512 | OPT_BOOL(0, "incremental", &incremental, |
4c688120 | 3513 | N_("ignore packed objects")), |
99fb6e04 | 3514 | OPT_INTEGER(0, "window", &window, |
4c688120 | 3515 | N_("limit pack window by objects")), |
2a514ed8 CB |
3516 | OPT_MAGNITUDE(0, "window-memory", &window_memory_limit, |
3517 | N_("limit pack window by memory in addition to object limit")), | |
99fb6e04 | 3518 | OPT_INTEGER(0, "depth", &depth, |
4c688120 | 3519 | N_("maximum length of delta chain allowed in the resulting pack")), |
99fb6e04 | 3520 | OPT_BOOL(0, "reuse-delta", &reuse_delta, |
4c688120 | 3521 | N_("reuse existing deltas")), |
99fb6e04 | 3522 | OPT_BOOL(0, "reuse-object", &reuse_object, |
4c688120 | 3523 | N_("reuse existing objects")), |
99fb6e04 | 3524 | OPT_BOOL(0, "delta-base-offset", &allow_ofs_delta, |
4c688120 | 3525 | N_("use OFS_DELTA objects")), |
99fb6e04 | 3526 | OPT_INTEGER(0, "threads", &delta_search_threads, |
4c688120 | 3527 | N_("use threads when searching for best delta matches")), |
99fb6e04 | 3528 | OPT_BOOL(0, "non-empty", &non_empty, |
4c688120 | 3529 | N_("do not create an empty pack output")), |
99fb6e04 | 3530 | OPT_BOOL(0, "revs", &use_internal_rev_list, |
4c688120 | 3531 | N_("read revision arguments from standard input")), |
3e4a67b4 NTND |
3532 | OPT_SET_INT_F(0, "unpacked", &rev_list_unpacked, |
3533 | N_("limit the objects to those that are not yet packed"), | |
3534 | 1, PARSE_OPT_NONEG), | |
3535 | OPT_SET_INT_F(0, "all", &rev_list_all, | |
3536 | N_("include objects reachable from any reference"), | |
3537 | 1, PARSE_OPT_NONEG), | |
3538 | OPT_SET_INT_F(0, "reflog", &rev_list_reflog, | |
3539 | N_("include objects referred by reflog entries"), | |
3540 | 1, PARSE_OPT_NONEG), | |
3541 | OPT_SET_INT_F(0, "indexed-objects", &rev_list_index, | |
3542 | N_("include objects referred to by the index"), | |
3543 | 1, PARSE_OPT_NONEG), | |
99fb6e04 | 3544 | OPT_BOOL(0, "stdout", &pack_to_stdout, |
4c688120 | 3545 | N_("output pack to stdout")), |
99fb6e04 | 3546 | OPT_BOOL(0, "include-tag", &include_tag, |
4c688120 | 3547 | N_("include tag objects that refer to objects to be packed")), |
99fb6e04 | 3548 | OPT_BOOL(0, "keep-unreachable", &keep_unreachable, |
4c688120 | 3549 | N_("keep unreachable objects")), |
e26a8c47 JK |
3550 | OPT_BOOL(0, "pack-loose-unreachable", &pack_loose_unreachable, |
3551 | N_("pack loose unreachable objects")), | |
203c8533 | 3552 | OPT_CALLBACK_F(0, "unpack-unreachable", NULL, N_("time"), |
4c688120 | 3553 | N_("unpack unreachable objects newer than <time>"), |
203c8533 | 3554 | PARSE_OPT_OPTARG, option_parse_unpack_unreachable), |
4f6d26b1 DS |
3555 | OPT_BOOL(0, "sparse", &sparse, |
3556 | N_("use the sparse reachability algorithm")), | |
99fb6e04 | 3557 | OPT_BOOL(0, "thin", &thin, |
4c688120 | 3558 | N_("create thin packs")), |
2dacf26d | 3559 | OPT_BOOL(0, "shallow", &shallow, |
3560 | N_("create packs suitable for shallow fetches")), | |
ed7e5fc3 | 3561 | OPT_BOOL(0, "honor-pack-keep", &ignore_packed_keep_on_disk, |
4c688120 | 3562 | N_("ignore packs that have companion .keep file")), |
ed7e5fc3 NTND |
3563 | OPT_STRING_LIST(0, "keep-pack", &keep_pack_list, N_("name"), |
3564 | N_("ignore this pack")), | |
99fb6e04 | 3565 | OPT_INTEGER(0, "compression", &pack_compression_level, |
4c688120 | 3566 | N_("pack compression level")), |
99fb6e04 | 3567 | OPT_SET_INT(0, "keep-true-parents", &grafts_replace_parents, |
4c688120 | 3568 | N_("do not hide commits by grafts"), 0), |
6b8fda2d VM |
3569 | OPT_BOOL(0, "use-bitmap-index", &use_bitmap_index, |
3570 | N_("use a bitmap index if available to speed up counting objects")), | |
25575015 JK |
3571 | OPT_SET_INT(0, "write-bitmap-index", &write_bitmap_index, |
3572 | N_("write a bitmap index together with the pack index"), | |
3573 | WRITE_BITMAP_TRUE), | |
3574 | OPT_SET_INT_F(0, "write-bitmap-index-quiet", | |
3575 | &write_bitmap_index, | |
3576 | N_("write a bitmap index if possible"), | |
3577 | WRITE_BITMAP_QUIET, PARSE_OPT_HIDDEN), | |
9535ce73 | 3578 | OPT_PARSE_LIST_OBJECTS_FILTER(&filter_options), |
203c8533 | 3579 | OPT_CALLBACK_F(0, "missing", NULL, N_("action"), |
9535ce73 | 3580 | N_("handling for missing objects"), PARSE_OPT_NONEG, |
203c8533 | 3581 | option_parse_missing_action), |
0c16cd49 JT |
3582 | OPT_BOOL(0, "exclude-promisor-objects", &exclude_promisor_objects, |
3583 | N_("do not pack objects in promisor packfiles")), | |
28b8a730 JK |
3584 | OPT_BOOL(0, "delta-islands", &use_delta_islands, |
3585 | N_("respect islands during delta compression")), | |
dd4b732d JT |
3586 | OPT_STRING_LIST(0, "uri-protocol", &uri_protocols, |
3587 | N_("protocol"), | |
3588 | N_("exclude any configured uploadpack.blobpackfileuri with this protocol")), | |
99fb6e04 NTND |
3589 | OPT_END(), |
3590 | }; | |
8d1d8f83 | 3591 | |
0c6804ab NTND |
3592 | if (DFS_NUM_STATES > (1 << OE_DFS_STATE_BITS)) |
3593 | BUG("too many dfs states, increase OE_DFS_STATE_BITS"); | |
3594 | ||
6ebd1caf | 3595 | read_replace_refs = 0; |
dae556bd | 3596 | |
2d657ab9 | 3597 | sparse = git_env_bool("GIT_TEST_PACK_SPARSE", -1); |
7211b9e7 | 3598 | prepare_repo_settings(the_repository); |
2d657ab9 | 3599 | if (sparse < 0) |
7211b9e7 DS |
3600 | sparse = the_repository->settings.pack_use_sparse; |
3601 | ||
ebcfb379 | 3602 | reset_pack_idx_option(&pack_idx_opts); |
ef90d6d4 | 3603 | git_config(git_pack_config, NULL); |
e8c58f89 TB |
3604 | if (git_env_bool(GIT_TEST_WRITE_REV_INDEX, 0)) |
3605 | pack_idx_opts.flags |= WRITE_REV; | |
b5d97e6b JH |
3606 | |
3607 | progress = isatty(2); | |
99fb6e04 NTND |
3608 | argc = parse_options(argc, argv, prefix, pack_objects_options, |
3609 | pack_usage, 0); | |
b5d97e6b | 3610 | |
99fb6e04 NTND |
3611 | if (argc) { |
3612 | base_name = argv[0]; | |
3613 | argc--; | |
b5d97e6b | 3614 | } |
99fb6e04 NTND |
3615 | if (pack_to_stdout != !base_name || argc) |
3616 | usage_with_options(pack_usage, pack_objects_options); | |
b5d97e6b | 3617 | |
b5c0cbd8 NTND |
3618 | if (depth >= (1 << OE_DEPTH_BITS)) { |
3619 | warning(_("delta chain depth %d is too deep, forcing %d"), | |
3620 | depth, (1 << OE_DEPTH_BITS) - 1); | |
3621 | depth = (1 << OE_DEPTH_BITS) - 1; | |
3622 | } | |
0cb3c142 NTND |
3623 | if (cache_max_small_delta_size >= (1U << OE_Z_DELTA_BITS)) { |
3624 | warning(_("pack.deltaCacheLimit is too high, forcing %d"), | |
3625 | (1U << OE_Z_DELTA_BITS) - 1); | |
3626 | cache_max_small_delta_size = (1U << OE_Z_DELTA_BITS) - 1; | |
3627 | } | |
b5c0cbd8 | 3628 | |
22f9b7f3 | 3629 | strvec_push(&rp, "pack-objects"); |
99fb6e04 NTND |
3630 | if (thin) { |
3631 | use_internal_rev_list = 1; | |
22f9b7f3 | 3632 | strvec_push(&rp, shallow |
2dacf26d | 3633 | ? "--objects-edge-aggressive" |
3634 | : "--objects-edge"); | |
99fb6e04 | 3635 | } else |
22f9b7f3 | 3636 | strvec_push(&rp, "--objects"); |
b5d97e6b | 3637 | |
99fb6e04 NTND |
3638 | if (rev_list_all) { |
3639 | use_internal_rev_list = 1; | |
22f9b7f3 | 3640 | strvec_push(&rp, "--all"); |
99fb6e04 NTND |
3641 | } |
3642 | if (rev_list_reflog) { | |
3643 | use_internal_rev_list = 1; | |
22f9b7f3 | 3644 | strvec_push(&rp, "--reflog"); |
99fb6e04 | 3645 | } |
c90f9e13 JK |
3646 | if (rev_list_index) { |
3647 | use_internal_rev_list = 1; | |
22f9b7f3 | 3648 | strvec_push(&rp, "--indexed-objects"); |
99fb6e04 NTND |
3649 | } |
3650 | if (rev_list_unpacked) { | |
3651 | use_internal_rev_list = 1; | |
22f9b7f3 | 3652 | strvec_push(&rp, "--unpacked"); |
99fb6e04 | 3653 | } |
b5d97e6b | 3654 | |
0c16cd49 JT |
3655 | if (exclude_promisor_objects) { |
3656 | use_internal_rev_list = 1; | |
3657 | fetch_if_missing = 0; | |
22f9b7f3 | 3658 | strvec_push(&rp, "--exclude-promisor-objects"); |
0c16cd49 | 3659 | } |
58bd77b6 NTND |
3660 | if (unpack_unreachable || keep_unreachable || pack_loose_unreachable) |
3661 | use_internal_rev_list = 1; | |
0c16cd49 | 3662 | |
99fb6e04 NTND |
3663 | if (!reuse_object) |
3664 | reuse_delta = 0; | |
3665 | if (pack_compression_level == -1) | |
3666 | pack_compression_level = Z_DEFAULT_COMPRESSION; | |
3667 | else if (pack_compression_level < 0 || pack_compression_level > Z_BEST_COMPRESSION) | |
f616db6a | 3668 | die(_("bad pack compression level %d"), pack_compression_level); |
0c45d258 JH |
3669 | |
3670 | if (!delta_search_threads) /* --threads=0 means autodetect */ | |
3671 | delta_search_threads = online_cpus(); | |
3672 | ||
9c897c5c | 3673 | if (!HAVE_THREADS && delta_search_threads != 1) |
f616db6a | 3674 | warning(_("no threads support, ignoring --threads")); |
2b84b5a8 JS |
3675 | if (!pack_to_stdout && !pack_size_limit) |
3676 | pack_size_limit = pack_size_limit_cfg; | |
01c12a23 | 3677 | if (pack_to_stdout && pack_size_limit) |
f616db6a | 3678 | die(_("--max-pack-size cannot be used to build a pack for transfer")); |
07cf0f24 | 3679 | if (pack_size_limit && pack_size_limit < 1024*1024) { |
f616db6a | 3680 | warning(_("minimum pack size limit is 1 MiB")); |
07cf0f24 NP |
3681 | pack_size_limit = 1024*1024; |
3682 | } | |
01c12a23 | 3683 | |
8d1d8f83 | 3684 | if (!pack_to_stdout && thin) |
f616db6a | 3685 | die(_("--thin cannot be used to build an indexable pack")); |
b5d97e6b | 3686 | |
ca11b212 | 3687 | if (keep_unreachable && unpack_unreachable) |
f616db6a | 3688 | die(_("--keep-unreachable and --unpack-unreachable are incompatible")); |
b1e757f3 JK |
3689 | if (!rev_list_all || !rev_list_reflog || !rev_list_index) |
3690 | unpack_unreachable_expiration = 0; | |
ca11b212 | 3691 | |
9535ce73 JH |
3692 | if (filter_options.choice) { |
3693 | if (!pack_to_stdout) | |
f616db6a | 3694 | die(_("cannot use --filter without --stdout")); |
9535ce73 JH |
3695 | } |
3696 | ||
645c432d KS |
3697 | /* |
3698 | * "soft" reasons not to use bitmaps - for on-disk repack by default we want | |
3699 | * | |
3700 | * - to produce good pack (with bitmap index not-yet-packed objects are | |
3701 | * packed in suboptimal order). | |
3702 | * | |
3703 | * - to use more robust pack-generation codepath (avoiding possible | |
3704 | * bugs in bitmap code and possible bitmap index corruption). | |
3705 | */ | |
3706 | if (!pack_to_stdout) | |
3707 | use_bitmap_index_default = 0; | |
3708 | ||
3709 | if (use_bitmap_index < 0) | |
3710 | use_bitmap_index = use_bitmap_index_default; | |
3711 | ||
3712 | /* "hard" reasons not to use bitmaps; these just won't work at all */ | |
c8813487 | 3713 | if (!use_internal_rev_list || (!pack_to_stdout && write_bitmap_index) || is_repository_shallow(the_repository)) |
6b8fda2d VM |
3714 | use_bitmap_index = 0; |
3715 | ||
7cc8f971 VM |
3716 | if (pack_to_stdout || !rev_list_all) |
3717 | write_bitmap_index = 0; | |
3718 | ||
28b8a730 | 3719 | if (use_delta_islands) |
22f9b7f3 | 3720 | strvec_push(&rp, "--topo-order"); |
28b8a730 | 3721 | |
4f366275 NP |
3722 | if (progress && all_progress_implied) |
3723 | progress = 2; | |
3724 | ||
ed7e5fc3 NTND |
3725 | add_extra_kept_packs(&keep_pack_list); |
3726 | if (ignore_packed_keep_on_disk) { | |
56dfeb62 | 3727 | struct packed_git *p; |
454ea2e4 | 3728 | for (p = get_all_packs(the_repository); p; p = p->next) |
56dfeb62 JK |
3729 | if (p->pack_local && p->pack_keep) |
3730 | break; | |
3731 | if (!p) /* no keep-able packs found */ | |
ed7e5fc3 | 3732 | ignore_packed_keep_on_disk = 0; |
56dfeb62 JK |
3733 | } |
3734 | if (local) { | |
3735 | /* | |
ed7e5fc3 NTND |
3736 | * unlike ignore_packed_keep_on_disk above, we do not |
3737 | * want to unset "local" based on looking at packs, as | |
3738 | * it also covers non-local objects | |
56dfeb62 JK |
3739 | */ |
3740 | struct packed_git *p; | |
454ea2e4 | 3741 | for (p = get_all_packs(the_repository); p; p = p->next) { |
56dfeb62 JK |
3742 | if (!p->pack_local) { |
3743 | have_non_local_packs = 1; | |
3744 | break; | |
3745 | } | |
3746 | } | |
3747 | } | |
b5d97e6b | 3748 | |
ae417807 DS |
3749 | trace2_region_enter("pack-objects", "enumerate-objects", |
3750 | the_repository); | |
7c141127 | 3751 | prepare_packing_data(the_repository, &to_pack); |
43fa44fa | 3752 | |
13aaf148 | 3753 | if (progress) |
5af05043 | 3754 | progress_state = start_progress(_("Enumerating objects"), 0); |
b5d97e6b JH |
3755 | if (!use_internal_rev_list) |
3756 | read_object_list_from_stdin(); | |
8d1d8f83 | 3757 | else { |
d70a9eb6 | 3758 | get_object_list(rp.nr, rp.v); |
22f9b7f3 | 3759 | strvec_clear(&rp); |
8d1d8f83 | 3760 | } |
0ef95f72 | 3761 | cleanup_preferred_base(); |
d155254c MH |
3762 | if (include_tag && nr_result) |
3763 | for_each_ref(add_ref_tag, NULL); | |
4d4fcc54 | 3764 | stop_progress(&progress_state); |
ae417807 DS |
3765 | trace2_region_leave("pack-objects", "enumerate-objects", |
3766 | the_repository); | |
96a02f8f | 3767 | |
f0b0af1b | 3768 | if (non_empty && !nr_result) |
1c4a2912 | 3769 | return 0; |
ae417807 DS |
3770 | if (nr_result) { |
3771 | trace2_region_enter("pack-objects", "prepare-pack", | |
3772 | the_repository); | |
f7ae6a93 | 3773 | prepare_pack(window, depth); |
ae417807 DS |
3774 | trace2_region_leave("pack-objects", "prepare-pack", |
3775 | the_repository); | |
3776 | } | |
3777 | ||
3778 | trace2_region_enter("pack-objects", "write-pack-file", the_repository); | |
dd4b732d | 3779 | write_excluded_by_configs(); |
d01fb92f | 3780 | write_pack_file(); |
ae417807 DS |
3781 | trace2_region_leave("pack-objects", "write-pack-file", the_repository); |
3782 | ||
ab7cd7bb | 3783 | if (progress) |
f616db6a NTND |
3784 | fprintf_ln(stderr, |
3785 | _("Total %"PRIu32" (delta %"PRIu32")," | |
bab28d9f JK |
3786 | " reused %"PRIu32" (delta %"PRIu32")," |
3787 | " pack-reused %"PRIu32), | |
3788 | written, written_delta, reused, reused_delta, | |
3789 | reuse_packfile_objects); | |
c323ac7d LT |
3790 | return 0; |
3791 | } |