summaryrefslogtreecommitdiff
path: root/src/indexer.c
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/indexer.c
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/indexer.c')
-rw-r--r--src/indexer.c15
1 files changed, 9 insertions, 6 deletions
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)