} git_indexer_stats;
+/**
+ * Type for progress callbacks during indexing
+ */
+typedef void (*git_indexer_progress_callback)(const git_indexer_stats *stats, void *payload);
+
typedef struct git_indexer git_indexer;
typedef struct git_indexer_stream git_indexer_stream;
*
* @param out where to store the indexer instance
* @param path to the directory where the packfile should be stored
+ * @param progress_cb function to call with progress information
+ * @param progress_payload payload for the progress callback
*/
-GIT_EXTERN(int) git_indexer_stream_new(git_indexer_stream **out, const char *path);
+GIT_EXTERN(int) git_indexer_stream_new(
+ git_indexer_stream **out,
+ const char *path,
+ git_indexer_progress_callback progress_cb,
+ void *progress_callback_payload);
/**
* Add data to the indexer
*
* @param remote the remote to download from
* @param filename where to store the temporary filename
+ * @param progress_cb function to call with progress information
+ * @param progress_payload payload for the progress callback
* @return 0 or an error code
*/
-GIT_EXTERN(int) git_remote_download(git_remote *remote, git_off_t *bytes);
+GIT_EXTERN(int) git_remote_download(
+ git_remote *remote,
+ git_off_t *bytes,
+ git_indexer_progress_callback progress_cb,
+ void *progress_payload);
/**
* Check whether the remote is connected
if (!git_remote_add(&origin, repo, GIT_REMOTE_ORIGIN, origin_url)) {
/* Connect and download everything */
if (!git_remote_connect(origin, GIT_DIR_FETCH)) {
- if (!git_remote_download(origin, &bytes)) {
+ if (!git_remote_download(origin, &bytes, NULL, NULL)) {
/* Create "origin/foo" branches for all remote branches */
if (!git_remote_update_tips(origin)) {
/* Point HEAD to the same ref as the remote's head */
return error;
}
-int git_fetch_download_pack(git_remote *remote, git_off_t *bytes)
+int git_fetch_download_pack(
+ git_remote *remote,
+ git_off_t *bytes,
+ git_indexer_progress_callback progress_cb,
+ void *progress_payload)
{
git_transport *t = remote->transport;
if (t->own_logic)
return t->download_pack(t, remote->repo, bytes, &remote->stats);
- return git_fetch__download_pack(t, remote->repo, bytes, &remote->stats);
+ return git_fetch__download_pack(t, remote->repo, bytes, &remote->stats,
+ progress_cb, progress_payload);
}
git_transport *t,
git_repository *repo,
git_off_t *bytes,
- git_indexer_stats *stats)
+ git_indexer_stats *stats,
+ git_indexer_progress_callback progress_cb,
+ void *progress_payload)
{
git_buf path = GIT_BUF_INIT;
gitno_buffer *buf = &t->buffer;
if (git_buf_joinpath(&path, git_repository_path(repo), "objects/pack") < 0)
return -1;
- if (git_indexer_stream_new(&idx, git_buf_cstr(&path)) < 0)
+ if (git_indexer_stream_new(&idx, git_buf_cstr(&path), progress_cb, progress_payload) < 0)
goto on_error;
git_buf_free(&path);
#include "netops.h"
int git_fetch_negotiate(git_remote *remote);
-int git_fetch_download_pack(git_remote *remote, git_off_t *bytes);
-int git_fetch__download_pack(git_transport *t, git_repository *repo, git_off_t *bytes, git_indexer_stats *stats);
+int git_fetch_download_pack(
+ git_remote *remote,
+ git_off_t *bytes,
+ git_indexer_progress_callback progress_cb,
+ void *progress_payload);
+
+int git_fetch__download_pack(
+ git_transport *t,
+ git_repository *repo,
+ git_off_t *bytes,
+ git_indexer_stats *stats,
+ git_indexer_progress_callback progress_cb,
+ void *progress_payload);
+
int git_fetch_setup_walk(git_revwalk **out, git_repository *repo);
#endif
git_vector deltas;
unsigned int fanout[256];
git_oid hash;
+ git_indexer_progress_callback progress_cb;
+ void *progress_payload;
};
struct delta_info {
return git_oid_cmp(&ea->sha1, &eb->sha1);
}
-int git_indexer_stream_new(git_indexer_stream **out, const char *prefix)
+int git_indexer_stream_new(
+ git_indexer_stream **out,
+ const char *prefix,
+ git_indexer_progress_callback progress_cb,
+ void *progress_payload)
{
git_indexer_stream *idx;
git_buf path = GIT_BUF_INIT;
idx = git__calloc(1, sizeof(git_indexer_stream));
GITERR_CHECK_ALLOC(idx);
+ idx->progress_cb = progress_cb;
+ idx->progress_payload = progress_payload;
error = git_buf_joinpath(&path, prefix, suff);
if (error < 0)
return -1;
}
+static void do_progress_callback(git_indexer_stream *idx, git_indexer_stats *stats)
+{
+ if (!idx->progress_cb) return;
+ idx->progress_cb(stats, idx->progress_payload);
+}
+
int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t size, git_indexer_stats *stats)
{
int error;
memset(stats, 0, sizeof(git_indexer_stats));
stats->total = (unsigned int)idx->nr_objects;
+ do_progress_callback(idx, stats);
}
/* Now that we have data in the pack, let's try to parse it */
return error;
stats->received++;
+ do_progress_callback(idx, stats);
continue;
}
stats->processed = (unsigned int)++processed;
stats->received++;
+ do_progress_callback(idx, stats);
}
return 0;
return 0;
}
-int git_remote_download(git_remote *remote, git_off_t *bytes)
+int git_remote_download(
+ git_remote *remote,
+ git_off_t *bytes,
+ git_indexer_progress_callback progress_cb,
+ void *progress_payload)
{
int error;
if ((error = git_fetch_negotiate(remote)) < 0)
return error;
- return git_fetch_download_pack(remote, bytes);
+ return git_fetch_download_pack(remote, bytes, progress_cb, progress_payload);
}
int git_remote_update_tips(git_remote *remote)
return 0;
}
+static void progress(const git_indexer_stats *stats, void *payload)
+{
+ GIT_UNUSED(stats);
+ bool *was_called = (bool*)payload;
+ *was_called = true;
+}
+
static void do_fetch(const char *url, int flag, int n)
{
git_remote *remote;
git_off_t bytes;
git_remote_callbacks callbacks;
+ bool progress_was_called = false;
memset(&callbacks, 0, sizeof(git_remote_callbacks));
callbacks.update_tips = update_tips;
git_remote_set_callbacks(remote, &callbacks);
git_remote_set_autotag(remote, flag);
cl_git_pass(git_remote_connect(remote, GIT_DIR_FETCH));
- cl_git_pass(git_remote_download(remote, &bytes));
+ cl_git_pass(git_remote_download(remote, &bytes, progress, &progress_was_called));
git_remote_disconnect(remote);
cl_git_pass(git_remote_update_tips(remote));
cl_assert_equal_i(counter, n);
+ cl_assert_equal_i(progress_was_called, true);
git_remote_free(remote);
}