Skip to content

Commit 71064a9

Browse files
npitregitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a90438 commit 71064a9

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

builtin/pack-objects.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1298,9 +1298,23 @@ static int try_delta(struct unpacked *trg, struct unpacked *src,
12981298
read_lock();
12991299
src->data = read_sha1_file(src_entry->idx.sha1, &type, &sz);
13001300
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+
}
13021315
die("object %s cannot be read",
13031316
sha1_to_hex(src_entry->idx.sha1));
1317+
}
13041318
if (sz != src_size)
13051319
die("object %s inconsistent object length (%lu vs %lu)",
13061320
sha1_to_hex(src_entry->idx.sha1), sz, src_size);

0 commit comments

Comments
 (0)