mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-09 05:28:34 +00:00
indexer: do multiple passes over the delta list
Though unusual, a packfile may contain a delta whose base is a delta that comes later. In order index such a packfile, we must not give up on the first failure to resolve a delta, but keep it around. If there is a pass which makes no progress, this indicates that the packfile is broken, so fail accordingly.
This commit is contained in:
parent
71e33d2649
commit
cf0582b43c
@ -594,20 +594,38 @@ static int resolve_deltas(git_indexer_stream *idx, git_transfer_progress *stats)
|
||||
{
|
||||
unsigned int i;
|
||||
struct delta_info *delta;
|
||||
int progressed = 0;
|
||||
|
||||
git_vector_foreach(&idx->deltas, i, delta) {
|
||||
git_rawobj obj;
|
||||
while (idx->deltas.length > 0) {
|
||||
progressed = 0;
|
||||
git_vector_foreach(&idx->deltas, i, delta) {
|
||||
git_rawobj obj;
|
||||
|
||||
idx->off = delta->delta_off;
|
||||
if (git_packfile_unpack(&obj, idx->pack, &idx->off) < 0)
|
||||
idx->off = delta->delta_off;
|
||||
if (git_packfile_unpack(&obj, idx->pack, &idx->off) < 0)
|
||||
continue;
|
||||
|
||||
if (hash_and_save(idx, &obj, delta->delta_off) < 0)
|
||||
continue;
|
||||
|
||||
git__free(obj.data);
|
||||
stats->indexed_objects++;
|
||||
progressed = 1;
|
||||
do_progress_callback(idx, stats);
|
||||
|
||||
/*
|
||||
* Remove this delta from the list and
|
||||
* decrease i so we don't skip over the next
|
||||
* delta.
|
||||
*/
|
||||
git_vector_remove(&idx->deltas, i);
|
||||
i--;
|
||||
}
|
||||
|
||||
if (!progressed) {
|
||||
giterr_set(GITERR_INDEXER, "the packfile is missing bases");
|
||||
return -1;
|
||||
|
||||
if (hash_and_save(idx, &obj, delta->delta_off) < 0)
|
||||
return -1;
|
||||
|
||||
git__free(obj.data);
|
||||
stats->indexed_objects++;
|
||||
do_progress_callback(idx, stats);
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
40
tests-clar/pack/indexer.c
Normal file
40
tests-clar/pack/indexer.c
Normal file
@ -0,0 +1,40 @@
|
||||
#include "clar_libgit2.h"
|
||||
#include "fileops.h"
|
||||
#include "hash.h"
|
||||
#include "iterator.h"
|
||||
#include "vector.h"
|
||||
#include "posix.h"
|
||||
|
||||
/*
|
||||
* This is a packfile with three objects. The second is a delta which
|
||||
* depends on the third, which is also a delta.
|
||||
*/
|
||||
unsigned char out_of_order_pack[] = {
|
||||
0x50, 0x41, 0x43, 0x4b, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x03,
|
||||
0x32, 0x78, 0x9c, 0x63, 0x67, 0x00, 0x00, 0x00, 0x10, 0x00, 0x08, 0x76,
|
||||
0xe6, 0x8f, 0xe8, 0x12, 0x9b, 0x54, 0x6b, 0x10, 0x1a, 0xee, 0x95, 0x10,
|
||||
0xc5, 0x32, 0x8e, 0x7f, 0x21, 0xca, 0x1d, 0x18, 0x78, 0x9c, 0x63, 0x62,
|
||||
0x66, 0x4e, 0xcb, 0xcf, 0x07, 0x00, 0x02, 0xac, 0x01, 0x4d, 0x75, 0x01,
|
||||
0xd7, 0x71, 0x36, 0x66, 0xf4, 0xde, 0x82, 0x27, 0x76, 0xc7, 0x62, 0x2c,
|
||||
0x10, 0xf1, 0xb0, 0x7d, 0xe2, 0x80, 0xdc, 0x78, 0x9c, 0x63, 0x62, 0x62,
|
||||
0x62, 0xb7, 0x03, 0x00, 0x00, 0x69, 0x00, 0x4c, 0xde, 0x7d, 0xaa, 0xe4,
|
||||
0x19, 0x87, 0x58, 0x80, 0x61, 0x09, 0x9a, 0x33, 0xca, 0x7a, 0x31, 0x92,
|
||||
0x6f, 0xae, 0x66, 0x75
|
||||
};
|
||||
unsigned int out_of_order_pack_len = 112;
|
||||
|
||||
void test_pack_indexer__out_of_order(void)
|
||||
{
|
||||
git_indexer_stream *idx;
|
||||
git_transfer_progress stats;
|
||||
|
||||
cl_git_pass(git_indexer_stream_new(&idx, ".", NULL, NULL, NULL));
|
||||
cl_git_pass(git_indexer_stream_add(idx, out_of_order_pack, out_of_order_pack_len, &stats));
|
||||
cl_git_pass(git_indexer_stream_finalize(idx, &stats));
|
||||
|
||||
cl_assert_equal_i(stats.total_objects, 3);
|
||||
cl_assert_equal_i(stats.received_objects, 3);
|
||||
cl_assert_equal_i(stats.indexed_objects, 3);
|
||||
|
||||
git_indexer_stream_free(idx);
|
||||
}
|
Loading…
Reference in New Issue
Block a user