summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2013-02-05 10:59:58 -0800
committerBen Straub <bs@github.com>2013-02-05 10:59:58 -0800
commitfe95ac1b6750a29d4a132d265ec1d050f49b69e8 (patch)
treed0cf8be4771619b04ab414f8320f3a9c6600bd21 /src
parentde81aee3907e3737ad87e88e14b702f4b3bf12a6 (diff)
downloadlibgit2-fe95ac1b6750a29d4a132d265ec1d050f49b69e8.tar.gz
Allow progress callback to cancel fetch
This works by having the indexer watch the return code of the callback, so will only take effect on object boundaries.
Diffstat (limited to 'src')
-rw-r--r--src/clone.c4
-rw-r--r--src/indexer.c15
-rw-r--r--src/transports/smart_protocol.c2
3 files changed, 12 insertions, 9 deletions
diff --git a/src/clone.c b/src/clone.c
index 333bf2148..c7a24f40a 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -355,8 +355,8 @@ static int setup_remotes_and_fetch(
/* Connect and download everything */
if (!git_remote_connect(origin, GIT_DIRECTION_FETCH)) {
- if (!git_remote_download(origin, options->fetch_progress_cb,
- options->fetch_progress_payload)) {
+ if (!(retcode = git_remote_download(origin, options->fetch_progress_cb,
+ options->fetch_progress_payload))) {
/* Create "origin/foo" branches for all remote branches */
if (!git_remote_update_tips(origin)) {
/* Point HEAD to the requested branch */
diff --git a/src/indexer.c b/src/indexer.c
index 3f6b1076e..08c88ba18 100644
--- a/src/indexer.c
+++ b/src/indexer.c
@@ -394,15 +394,15 @@ on_error:
return -1;
}
-static void do_progress_callback(git_indexer_stream *idx, git_transfer_progress *stats)
+static int do_progress_callback(git_indexer_stream *idx, git_transfer_progress *stats)
{
- if (!idx->progress_cb) return;
- idx->progress_cb(stats, idx->progress_payload);
+ if (!idx->progress_cb) return 0;
+ return idx->progress_cb(stats, idx->progress_payload);
}
int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t size, git_transfer_progress *stats)
{
- int error;
+ int error = -1;
struct git_pack_header hdr;
size_t processed;
git_mwindow_file *mwf = &idx->pack->mwf;
@@ -536,14 +536,17 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz
}
stats->received_objects++;
- do_progress_callback(idx, stats);
+ if (do_progress_callback(idx, stats) < 0) {
+ error = GIT_EUSER;
+ goto on_error;
+ }
}
return 0;
on_error:
git_mwindow_free_all(mwf);
- return -1;
+ return error;
}
static int index_path_stream(git_buf *path, git_indexer_stream *idx, const char *suffix)
diff --git a/src/transports/smart_protocol.c b/src/transports/smart_protocol.c
index 184b21a0b..a68d242bc 100644
--- a/src/transports/smart_protocol.c
+++ b/src/transports/smart_protocol.c
@@ -493,7 +493,7 @@ int git_smart__download_pack(
git__free(pkt);
} else if (pkt->type == GIT_PKT_DATA) {
git_pkt_data *p = (git_pkt_data *) pkt;
- if (writepack->add(writepack, p->data, p->len, stats) < 0)
+ if ((error = writepack->add(writepack, p->data, p->len, stats)) < 0)
goto on_error;
git__free(pkt);