make pack-objects a bit more resilient to repo corruption
Right now, packing valid objects could fail when creating a thin pack simply because a pack edge object used as a preferred base is corrupted. Since preferred base objects are not strictly needed to produce a valid pack, let's not consider the inability to read them as a fatal error. Delta compression may well be attempted against other objects in the search window. To avoid warning storms (we are in the inner loop of the delta search window) a warning is emitted only on the first occurrence. Signed-off-by: Nicolas Pitre <nico@fluxnic.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Nicolas Pitre committed
Oct 22, 2010 at 16:26 UTC
71064a956b25ef519eab340e364d0bc0e786bd11
1 file changed
+15
-1
builtin/pack-objects.c
+15
-1
@@ -1298,9 +1298,23 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
1298
read_lock();
1299
src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz);
1300
read_unlock();
1301
- if (!src->data)
1301
+ if (!src->data) {
1302
+ if (src_entry->preferred_base) {
1303
+ static int warned = 0;
1304
+ if (!warned++)
1305
+ warning("object %s cannot be read",
1306
+ sha1_to_hex(src_entry->idx.sha1));
1307
+ /*
1308
+ * Those objects are not included in the
1309
+ * resulting pack. Be resilient and ignore
1310
+ * them if they can't be read, in case the
1311
+ * pack could be created nevertheless.
1312
+ */
1313
+ return 0;
1314
+ }
1315
die("object %s cannot be read",
1316
sha1_to_hex(src_entry->idx.sha1));
1317
+ }
1318
if (sz != src_size)
1319
die("object %s inconsistent object length (%lu vs %lu)",
1320
sha1_to_hex(src_entry->idx.sha1), sz, src_size);