diff options
author | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-07-13 12:01:11 +0200 |
---|---|---|
committer | Carlos Martín Nieto <carlos@cmartin.tk> | 2012-08-24 19:01:10 +0200 |
commit | bffa852f89268390d6bc3e6f99f5f0cccdc88f63 (patch) | |
tree | b83249451c776dc386856bd01e318acef801ba43 /src | |
parent | c920e162325d0f9acba46a19c4619e6bfa17707e (diff) | |
download | libgit2-bffa852f89268390d6bc3e6f99f5f0cccdc88f63.tar.gz |
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.
Diffstat (limited to 'src')
-rw-r--r-- | src/fetch.c | 5 | ||||
-rw-r--r-- | src/indexer.c | 12 |
2 files changed, 15 insertions, 2 deletions
diff --git a/src/fetch.c b/src/fetch.c index d96ac7781..eb13701f1 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -324,7 +324,10 @@ int git_fetch__download_pack( goto on_error; *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)) goto on_error; diff --git a/src/indexer.c b/src/indexer.c index 797a58275..30c6469a1 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -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) return -1; + memset(stats, 0, sizeof(git_indexer_stats)); stats->total = (unsigned int)idx->nr_objects; - stats->processed = 0; } /* 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) return error; + stats->received++; continue; } @@ -379,8 +380,17 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz git__free(obj.data); 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; on_error: |