mirror of
https://git.proxmox.com/git/libgit2
synced 2025-06-19 22:44:42 +00:00
indexer: recognize and mark when all of the packfile has been downloaded
We can't always rely on the network telling us when the download is finished. Recognize it from the indexer itself.
This commit is contained in:
parent
c920e16232
commit
bffa852f89
@ -96,7 +96,7 @@ int fetch(git_repository *repo, int argc, char **argv)
|
|||||||
// the download rate.
|
// the download rate.
|
||||||
do {
|
do {
|
||||||
usleep(10000);
|
usleep(10000);
|
||||||
printf("\rReceived %d/%d objects in %zu bytes", stats.processed, stats.total, bytes);
|
printf("\rReceived %d/%d objects (%d) in %d bytes", stats.received, stats.total, stats.processed, bytes);
|
||||||
} while (!data.finished);
|
} while (!data.finished);
|
||||||
|
|
||||||
if (data.ret < 0)
|
if (data.ret < 0)
|
||||||
|
@ -19,6 +19,8 @@ GIT_BEGIN_DECL
|
|||||||
typedef struct git_indexer_stats {
|
typedef struct git_indexer_stats {
|
||||||
unsigned int total;
|
unsigned int total;
|
||||||
unsigned int processed;
|
unsigned int processed;
|
||||||
|
unsigned int received;
|
||||||
|
unsigned int data_received;
|
||||||
} git_indexer_stats;
|
} git_indexer_stats;
|
||||||
|
|
||||||
|
|
||||||
|
@ -324,7 +324,10 @@ int git_fetch__download_pack(
|
|||||||
goto on_error;
|
goto on_error;
|
||||||
|
|
||||||
*bytes += recvd;
|
*bytes += recvd;
|
||||||
} while(recvd > 0);
|
} while(recvd > 0 && !stats->data_received);
|
||||||
|
|
||||||
|
if (!stats->data_received)
|
||||||
|
giterr_set(GITERR_NET, "Early EOF while downloading packfile");
|
||||||
|
|
||||||
if (git_indexer_stream_finalize(idx, stats))
|
if (git_indexer_stream_finalize(idx, stats))
|
||||||
goto on_error;
|
goto on_error;
|
||||||
|
@ -324,8 +324,8 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
|
|||||||
if (git_vector_init(&idx->deltas, (unsigned int)(idx->nr_objects / 2), NULL) < 0)
|
if (git_vector_init(&idx->deltas, (unsigned int)(idx->nr_objects / 2), NULL) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
memset(stats, 0, sizeof(git_indexer_stats));
|
||||||
stats->total = (unsigned int)idx->nr_objects;
|
stats->total = (unsigned int)idx->nr_objects;
|
||||||
stats->processed = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Now that we have data in the pack, let's try to parse it */
|
/* Now that we have data in the pack, let's try to parse it */
|
||||||
@ -361,6 +361,7 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
|
|||||||
if (error < 0)
|
if (error < 0)
|
||||||
return error;
|
return error;
|
||||||
|
|
||||||
|
stats->received++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -379,8 +380,17 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
|
|||||||
git__free(obj.data);
|
git__free(obj.data);
|
||||||
|
|
||||||
stats->processed = (unsigned int)++processed;
|
stats->processed = (unsigned int)++processed;
|
||||||
|
stats->received++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If we've received all of the objects and our packfile is
|
||||||
|
* one hash beyond the end of the last object, all of the
|
||||||
|
* packfile is here.
|
||||||
|
*/
|
||||||
|
if (stats->received == idx->nr_objects && idx->pack->mwf.size >= idx->off + 20)
|
||||||
|
stats->data_received = 1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
on_error:
|
on_error:
|
||||||
|
Loading…
Reference in New Issue
Block a user