diff --git a/TAGS b/TAGS new file mode 100644 index 00000000000..1f87aa5a8e7 --- /dev/null +++ b/TAGS @@ -0,0 +1,6971 @@ + +build/CMakeFiles/CompilerIdC/CMakeCCompilerId.c,3808 +# define ID_VOID_MAIN9,224 +# define COMPILER_ID 13,302 +# define COMPILER_VERSION_MAJOR 15,362 +# define COMPILER_VERSION_MINOR 16,420 +# define COMPILER_VERSION_PATCH 17,482 +# define COMPILER_VERSION_TWEAK 20,633 +# define COMPILER_ID 24,733 +# define COMPILER_VERSION_MAJOR 25,762 +# define COMPILER_VERSION_MINOR 26,815 +# define COMPILER_VERSION_PATCH 27,868 +# define COMPILER_ID 30,989 +# define COMPILER_VERSION_MAJOR 31,1024 +# define COMPILER_VERSION_MINOR 32,1096 +# define COMPILER_VERSION_PATCH 33,1168 +# define COMPILER_ID 36,1269 +# define COMPILER_VERSION_MAJOR 38,1329 +# define COMPILER_VERSION_MINOR 39,1382 +# define COMPILER_ID 42,1467 +# define COMPILER_VERSION_MAJOR 44,1524 +# define COMPILER_VERSION_MINOR 45,1579 +# define COMPILER_ID 48,1661 +# define COMPILER_VERSION_MAJOR 51,1746 +# define COMPILER_VERSION_MINOR 52,1799 +# define COMPILER_VERSION_PATCH 53,1858 +# define COMPILER_VERSION_MAJOR 56,1951 +# define COMPILER_VERSION_MINOR 57,2003 +# define COMPILER_VERSION_PATCH 58,2061 +# define COMPILER_ID 62,2151 +# define COMPILER_VERSION_MAJOR 64,2202 +# define COMPILER_VERSION_MINOR 65,2253 +# define COMPILER_VERSION_PATCH 66,2308 +# define COMPILER_ID 69,2386 +# define COMPILER_ID 73,2472 +# define COMPILER_ID 76,2529 +# define COMPILER_ID 78,2565 +# define COMPILER_VERSION_MAJOR 81,2633 +# define COMPILER_VERSION_MINOR 82,2684 +# define COMPILER_VERSION_PATCH 83,2739 +# define COMPILER_ID 87,2824 +# define COMPILER_VERSION_MAJOR 88,2851 +# define COMPILER_VERSION_MINOR 89,2897 +# define COMPILER_VERSION_PATCH 91,2983 +# define COMPILER_ID 95,3079 +# define COMPILER_ID 98,3135 +# define COMPILER_ID 101,3203 +# define COMPILER_ID 104,3259 +# define COMPILER_ID 107,3321 +# define COMPILER_ID 110,3373 +# define COMPILER_VERSION_MAJOR 111,3400 +# define COMPILER_VERSION_MINOR 112,3446 +# define COMPILER_VERSION_PATCH 114,3532 +# define COMPILER_ID 118,3623 +# define COMPILER_VERSION_MAJOR 120,3675 +# define COMPILER_VERSION_MINOR 121,3727 +# define COMPILER_VERSION_PATCH 125,3866 +# define COMPILER_VERSION_PATCH 128,3971 +# define COMPILER_VERSION_TWEAK 132,4074 +# define COMPILER_ID 138,4298 +# define COMPILER_ID 149,4606 +# define COMPILER_ID 152,4702 +# define COMPILER_VERSION_MAJOR 155,4805 +# define COMPILER_VERSION_MINOR 156,4869 +# define COMPILER_VERSION_PATCH 157,4937 +# define COMPILER_VERSION_MAJOR 160,5044 +# define COMPILER_VERSION_MINOR 161,5104 +# define COMPILER_VERSION_PATCH 162,5168 +# define COMPILER_ID 169,5430 +# define COMPILER_ID 172,5503 +# define COMPILER_ID 175,5559 +char const* info_compiler 183,5858 +# define PLATFORM_ID 187,6029 +# define PLATFORM_ID 190,6085 +# define PLATFORM_ID 193,6143 +# define PLATFORM_ID 196,6198 +# define PLATFORM_ID 199,6291 +# define PLATFORM_ID 202,6372 +# define PLATFORM_ID 205,6451 +# define PLATFORM_ID 208,6531 +# define PLATFORM_ID 211,6600 +# define PLATFORM_ID 214,6726 +# define PLATFORM_ID 217,6812 +# define PLATFORM_ID 220,6884 +# define PLATFORM_ID 223,6978 +# define PLATFORM_ID 229,7157 +# define PLATFORM_ID 232,7232 +# define PLATFORM_ID 235,7324 +# define PLATFORM_ID 238,7401 +# define PLATFORM_ID 241,7499 +# define PLATFORM_ID 244,7556 +# define PLATFORM_ID 247,7613 +# define PLATFORM_ID 250,7683 +# define PLATFORM_ID 253,7755 +# define PLATFORM_ID 256,7845 +# define PLATFORM_ID 259,7943 +# define PLATFORM_ID 262,8036 +# define PLATFORM_ID 265,8095 +# define ARCHITECTURE_ID 276,8438 +# define ARCHITECTURE_ID 279,8516 +# define ARCHITECTURE_ID 282,8574 +# define ARCHITECTURE_ID 285,8641 +# define ARCHITECTURE_ID 289,8685 +#define DEC(293,8772 +#define HEX(304,9121 +char const info_version[info_version316,9483 +char const* info_platform 336,10143 +char const* info_arch 337,10211 +void main(344,10378 +int main(346,10399 + +build/Makefile,17 +SUFFIXES 15,456 + +build/xcode/CMakeFiles/CompilerIdC/CMakeCCompilerId.c,3808 +# define ID_VOID_MAIN9,224 +# define COMPILER_ID 13,302 +# define COMPILER_VERSION_MAJOR 15,362 +# define COMPILER_VERSION_MINOR 16,420 +# define COMPILER_VERSION_PATCH 17,482 +# define COMPILER_VERSION_TWEAK 20,633 +# define COMPILER_ID 24,733 +# define COMPILER_VERSION_MAJOR 25,762 +# define COMPILER_VERSION_MINOR 26,815 +# define COMPILER_VERSION_PATCH 27,868 +# define COMPILER_ID 30,989 +# define COMPILER_VERSION_MAJOR 31,1024 +# define COMPILER_VERSION_MINOR 32,1096 +# define COMPILER_VERSION_PATCH 33,1168 +# define COMPILER_ID 36,1269 +# define COMPILER_VERSION_MAJOR 38,1329 +# define COMPILER_VERSION_MINOR 39,1382 +# define COMPILER_ID 42,1467 +# define COMPILER_VERSION_MAJOR 44,1524 +# define COMPILER_VERSION_MINOR 45,1579 +# define COMPILER_ID 48,1661 +# define COMPILER_VERSION_MAJOR 51,1746 +# define COMPILER_VERSION_MINOR 52,1799 +# define COMPILER_VERSION_PATCH 53,1858 +# define COMPILER_VERSION_MAJOR 56,1951 +# define COMPILER_VERSION_MINOR 57,2003 +# define COMPILER_VERSION_PATCH 58,2061 +# define COMPILER_ID 62,2151 +# define COMPILER_VERSION_MAJOR 64,2202 +# define COMPILER_VERSION_MINOR 65,2253 +# define COMPILER_VERSION_PATCH 66,2308 +# define COMPILER_ID 69,2386 +# define COMPILER_ID 73,2472 +# define COMPILER_ID 76,2529 +# define COMPILER_ID 78,2565 +# define COMPILER_VERSION_MAJOR 81,2633 +# define COMPILER_VERSION_MINOR 82,2684 +# define COMPILER_VERSION_PATCH 83,2739 +# define COMPILER_ID 87,2824 +# define COMPILER_VERSION_MAJOR 88,2851 +# define COMPILER_VERSION_MINOR 89,2897 +# define COMPILER_VERSION_PATCH 91,2983 +# define COMPILER_ID 95,3079 +# define COMPILER_ID 98,3135 +# define COMPILER_ID 101,3203 +# define COMPILER_ID 104,3259 +# define COMPILER_ID 107,3321 +# define COMPILER_ID 110,3373 +# define COMPILER_VERSION_MAJOR 111,3400 +# define COMPILER_VERSION_MINOR 112,3446 +# define COMPILER_VERSION_PATCH 114,3532 +# define COMPILER_ID 118,3623 +# define COMPILER_VERSION_MAJOR 120,3675 +# define COMPILER_VERSION_MINOR 121,3727 +# define COMPILER_VERSION_PATCH 125,3866 +# define COMPILER_VERSION_PATCH 128,3971 +# define COMPILER_VERSION_TWEAK 132,4074 +# define COMPILER_ID 138,4298 +# define COMPILER_ID 149,4606 +# define COMPILER_ID 152,4702 +# define COMPILER_VERSION_MAJOR 155,4805 +# define COMPILER_VERSION_MINOR 156,4869 +# define COMPILER_VERSION_PATCH 157,4937 +# define COMPILER_VERSION_MAJOR 160,5044 +# define COMPILER_VERSION_MINOR 161,5104 +# define COMPILER_VERSION_PATCH 162,5168 +# define COMPILER_ID 169,5430 +# define COMPILER_ID 172,5503 +# define COMPILER_ID 175,5559 +char const* info_compiler 183,5858 +# define PLATFORM_ID 187,6029 +# define PLATFORM_ID 190,6085 +# define PLATFORM_ID 193,6143 +# define PLATFORM_ID 196,6198 +# define PLATFORM_ID 199,6291 +# define PLATFORM_ID 202,6372 +# define PLATFORM_ID 205,6451 +# define PLATFORM_ID 208,6531 +# define PLATFORM_ID 211,6600 +# define PLATFORM_ID 214,6726 +# define PLATFORM_ID 217,6812 +# define PLATFORM_ID 220,6884 +# define PLATFORM_ID 223,6978 +# define PLATFORM_ID 229,7157 +# define PLATFORM_ID 232,7232 +# define PLATFORM_ID 235,7324 +# define PLATFORM_ID 238,7401 +# define PLATFORM_ID 241,7499 +# define PLATFORM_ID 244,7556 +# define PLATFORM_ID 247,7613 +# define PLATFORM_ID 250,7683 +# define PLATFORM_ID 253,7755 +# define PLATFORM_ID 256,7845 +# define PLATFORM_ID 259,7943 +# define PLATFORM_ID 262,8036 +# define PLATFORM_ID 265,8095 +# define ARCHITECTURE_ID 276,8438 +# define ARCHITECTURE_ID 279,8516 +# define ARCHITECTURE_ID 282,8574 +# define ARCHITECTURE_ID 285,8641 +# define ARCHITECTURE_ID 289,8685 +#define DEC(293,8772 +#define HEX(304,9121 +char const info_version[info_version316,9483 +char const* info_platform 336,10143 +char const* info_arch 337,10211 +void main(344,10378 +int main(346,10399 + +build/xcode/libgit2.xcodeproj/project.xcworkspace/contents.xcworkspacedata,19 + struct dl_data { - git_indexer_stats fetch_stats; - git_indexer_stats checkout_stats; + git_progress_multistage progress; git_checkout_opts opts; + int ret; int finished; const char *url; @@ -23,15 +23,41 @@ static void *clone_thread(void *ptr) git_repository *repo = NULL; // Kick off the clone - data->ret = git_clone(&repo, data->url, data->path, - &data->fetch_stats, &data->checkout_stats, - &data->opts); + data->ret = git_clone(&repo, data->url, data->path, &data->progress, &data->opts); if (repo) git_repository_free(repo); data->finished = 1; pthread_exit(&data->ret); } +void print_progress(git_progress_multistage *msp) +{ + size_t composite_percentage = 0; + int i; + + printf("Progress: "); + for (i=0; i < msp->count; i++) { + git_progress r = msp->stages[i]; + size_t percentage; + + if (i != 0) printf(" / "); + + percentage = r.total == 0 + ? 0 + : 100 * r.current / r.total; + composite_percentage += percentage; + + /*printf(" %zu/%zu", r.current, r.total);*/ + if (r.total == 0) + printf("---%%"); + else + printf("%3zu%%", percentage); + } + printf(" ==> "); + /*printf("%zu/%zu ", t_num, t_den);*/ + printf("(%3zu%%)\n", msp->count == 0 ? 0 : composite_percentage / msp->count); +} + int do_clone(git_repository *repo, int argc, char **argv) { struct dl_data data = {0}; @@ -55,13 +81,9 @@ int do_clone(git_repository *repo, int argc, char **argv) // Watch for progress information do { usleep(10000); - printf("Fetch %d/%d – Checkout %d/%d\n", - data.fetch_stats.processed, data.fetch_stats.total, - data.checkout_stats.processed, data.checkout_stats.total); + print_progress(&data.progress); } while (!data.finished); - printf("Fetch %d/%d – Checkout %d/%d\n", - data.fetch_stats.processed, data.fetch_stats.total, - data.checkout_stats.processed, data.checkout_stats.total); + print_progress(&data.progress); return data.ret; } diff --git a/examples/network/fetch.c b/examples/network/fetch.c index fa941b97adf..36ccf40b091 100644 --- a/examples/network/fetch.c +++ b/examples/network/fetch.c @@ -107,7 +107,7 @@ int fetch(git_repository *repo, int argc, char **argv) usleep(10000); if (stats.total > 0) - printf("Received %d/%d objects (%d) in %d bytes\r", + printf("Received %u/%u objects (%u) in %lld bytes\r", stats.received, stats.total, stats.processed, bytes); } while (!data.finished); @@ -115,7 +115,7 @@ int fetch(git_repository *repo, int argc, char **argv) goto on_error; pthread_join(worker, NULL); - printf("\rReceived %d/%d objects in %zu bytes\n", stats.processed, stats.total, bytes); + printf("\rReceived %u/%u objects in %lld bytes\n", stats.processed, stats.total, bytes); // Disconnect the underlying connection to prevent from idling. git_remote_disconnect(remote); diff --git a/include/git2/checkout.h b/include/git2/checkout.h index ac31b3462d3..5891b4b85a3 100644 --- a/include/git2/checkout.h +++ b/include/git2/checkout.h @@ -44,7 +44,7 @@ typedef struct git_checkout_opts { */ GIT_EXTERN(int) git_checkout_head(git_repository *repo, git_checkout_opts *opts, - git_indexer_stats *stats); + git_progress *progress); @@ -58,7 +58,7 @@ GIT_EXTERN(int) git_checkout_head(git_repository *repo, */ GIT_EXTERN(int) git_checkout_reference(git_reference *ref, git_checkout_opts *opts, - git_indexer_stats *stats); + git_progress *progress); /** @} */ diff --git a/include/git2/clone.h b/include/git2/clone.h index 40292ed59f6..027e82c2d04 100644 --- a/include/git2/clone.h +++ b/include/git2/clone.h @@ -36,8 +36,7 @@ GIT_BEGIN_DECL GIT_EXTERN(int) git_clone(git_repository **out, const char *origin_url, const char *workdir_path, - git_indexer_stats *fetch_stats, - git_indexer_stats *checkout_stats, + git_progress_multistage *progress, git_checkout_opts *checkout_opts); /** @@ -52,7 +51,7 @@ GIT_EXTERN(int) git_clone(git_repository **out, GIT_EXTERN(int) git_clone_bare(git_repository **out, const char *origin_url, const char *dest_path, - git_indexer_stats *fetch_stats); + git_progress_multistage *progress); /** @} */ GIT_END_DECL diff --git a/include/git2/common.h b/include/git2/common.h index 0af37e81f36..d4626051a99 100644 --- a/include/git2/common.h +++ b/include/git2/common.h @@ -90,6 +90,21 @@ typedef struct { size_t count; } git_strarray; +#define GIT_PROGRESS_STAGE_TRANSFER 0 +#define GIT_PROGRESS_STAGE_INDEX 1 +#define GIT_PROGRESS_STAGE_CHECKOUT 2 + +typedef struct git_progress { + size_t current; + size_t total; +} git_progress; + +typedef struct git_progress_multistage { + size_t count; + git_progress stages[8]; + int stage_types[8]; +} git_progress_multistage; + GIT_EXTERN(void) git_strarray_free(git_strarray *array); GIT_EXTERN(int) git_strarray_copy(git_strarray *tgt, const git_strarray *src); diff --git a/include/git2/index.h b/include/git2/index.h index 062932e1aa4..6ba528fd81f 100644 --- a/include/git2/index.h +++ b/include/git2/index.h @@ -346,7 +346,7 @@ GIT_EXTERN(int) git_index_entry_stage(const git_index_entry *entry); * @param stats structure that receives the total node count (may be NULL) * @return 0 or an error code */ -GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree, git_indexer_stats *stats); +GIT_EXTERN(int) git_index_read_tree(git_index *index, git_tree *tree, size_t *total); /** @} */ GIT_END_DECL diff --git a/include/git2/indexer.h b/include/git2/indexer.h index 87f48fe277c..fdb01f54ad2 100644 --- a/include/git2/indexer.h +++ b/include/git2/indexer.h @@ -20,6 +20,8 @@ typedef struct git_indexer_stats { unsigned int total; unsigned int processed; unsigned int received; + git_progress *transfer_progress; + git_progress *index_progress; } git_indexer_stats; diff --git a/src/checkout.c b/src/checkout.c index 88df2128db4..1210e841ce3 100644 --- a/src/checkout.c +++ b/src/checkout.c @@ -27,7 +27,7 @@ GIT_BEGIN_DECL typedef struct tree_walk_data { - git_indexer_stats *stats; + git_progress *progress; git_checkout_opts *opts; git_repository *repo; git_odb *odb; @@ -145,15 +145,15 @@ static int checkout_walker(const char *path, const git_tree_entry *entry, void * } git_buf_free(&fnbuf); - data->stats->processed++; + data->progress->current++; return retcode; } -int git_checkout_head(git_repository *repo, git_checkout_opts *opts, git_indexer_stats *stats) +int git_checkout_head(git_repository *repo, git_checkout_opts *opts, git_progress *progress) { int retcode = GIT_ERROR; - git_indexer_stats dummy_stats; + git_progress dummy_progress; git_checkout_opts default_opts = {0}; git_tree *tree; tree_walk_data payload; @@ -161,7 +161,7 @@ int git_checkout_head(git_repository *repo, git_checkout_opts *opts, git_indexer assert(repo); if (!opts) opts = &default_opts; - if (!stats) stats = &dummy_stats; + if (!progress) progress = &dummy_progress; /* Default options */ if (!opts->existing_file_action) @@ -186,8 +186,8 @@ int git_checkout_head(git_repository *repo, git_checkout_opts *opts, git_indexer } } - stats->total = stats->processed = 0; - payload.stats = stats; + progress->current = progress->total = 0; + payload.progress = progress; payload.opts = opts; payload.repo = repo; if (git_repository_odb(&payload.odb, repo) < 0) return GIT_ERROR; @@ -195,7 +195,7 @@ int git_checkout_head(git_repository *repo, git_checkout_opts *opts, git_indexer if (!git_repository_head_tree(&tree, repo)) { git_index *idx; if (!(retcode = git_repository_index(&idx, repo))) { - if (!(retcode = git_index_read_tree(idx, tree, stats))) { + if (!(retcode = git_index_read_tree(idx, tree, &progress->total))) { git_index_write(idx); retcode = git_tree_walk(tree, checkout_walker, GIT_TREEWALK_POST, &payload); } @@ -211,7 +211,7 @@ int git_checkout_head(git_repository *repo, git_checkout_opts *opts, git_indexer int git_checkout_reference(git_reference *ref, git_checkout_opts *opts, - git_indexer_stats *stats) + git_progress *progress) { git_repository *repo= git_reference_owner(ref); git_reference *head = NULL; @@ -221,7 +221,7 @@ int git_checkout_reference(git_reference *ref, git_reference_name(ref), true)) < 0) return retcode; - retcode = git_checkout_head(git_reference_owner(ref), opts, stats); + retcode = git_checkout_head(git_reference_owner(ref), opts, progress); git_reference_free(head); return retcode; diff --git a/src/clone.c b/src/clone.c index 33953d7a09a..978727bea6f 100644 --- a/src/clone.c +++ b/src/clone.c @@ -146,20 +146,26 @@ static int update_head_to_remote(git_repository *repo, git_remote *remote) static int setup_remotes_and_fetch(git_repository *repo, const char *origin_url, - git_indexer_stats *fetch_stats) + git_progress_multistage *progress) { int retcode = GIT_ERROR; git_remote *origin = NULL; git_off_t bytes = 0; - git_indexer_stats dummy_stats; + git_indexer_stats dummy_stats = {0}; + git_progress_multistage dummy_progress = {0}; - if (!fetch_stats) fetch_stats = &dummy_stats; + if (!progress) progress = &dummy_progress; + + /* Set up indexer stats to update multistage progress directly */ + dummy_stats.transfer_progress = &progress->stages[0]; + dummy_stats.index_progress = &progress->stages[1]; /* Create the "origin" remote */ if (!git_remote_add(&origin, repo, "origin", origin_url)) { + /* Connect and download everything */ if (!git_remote_connect(origin, GIT_DIR_FETCH)) { - if (!git_remote_download(origin, &bytes, fetch_stats)) { + if (!git_remote_download(origin, &bytes, &dummy_stats)) { /* 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 */ @@ -193,21 +199,26 @@ static bool path_is_okay(const char *path) static int clone_internal(git_repository **out, const char *origin_url, const char *path, - git_indexer_stats *fetch_stats, + git_progress_multistage *progress, int is_bare) { int retcode = GIT_ERROR; git_repository *repo = NULL; - git_indexer_stats dummy_stats; + git_progress_multistage dummy_progress = {0}; - if (!fetch_stats) fetch_stats = &dummy_stats; + if (!progress) progress = &dummy_progress; if (!path_is_okay(path)) { return GIT_ERROR; } + progress->count = 3; + progress->stage_types[0] = GIT_PROGRESS_STAGE_TRANSFER; + progress->stage_types[1] = GIT_PROGRESS_STAGE_INDEX; + progress->stage_types[2] = GIT_PROGRESS_STAGE_CHECKOUT; + if (!(retcode = git_repository_init(&repo, path, is_bare))) { - if ((retcode = setup_remotes_and_fetch(repo, origin_url, fetch_stats)) < 0) { + if ((retcode = setup_remotes_and_fetch(repo, origin_url, progress)) < 0) { /* Failed to fetch; clean up */ git_repository_free(repo); git_futils_rmdir_r(path, GIT_DIRREMOVAL_FILES_AND_DIRS); @@ -223,26 +234,25 @@ static int clone_internal(git_repository **out, int git_clone_bare(git_repository **out, const char *origin_url, const char *dest_path, - git_indexer_stats *fetch_stats) + git_progress_multistage *progress) { assert(out && origin_url && dest_path); - return clone_internal(out, origin_url, dest_path, fetch_stats, 1); + return clone_internal(out, origin_url, dest_path, progress, 1); } int git_clone(git_repository **out, const char *origin_url, const char *workdir_path, - git_indexer_stats *fetch_stats, - git_indexer_stats *checkout_stats, + git_progress_multistage *progress, git_checkout_opts *checkout_opts) { int retcode = GIT_ERROR; assert(out && origin_url && workdir_path); - if (!(retcode = clone_internal(out, origin_url, workdir_path, fetch_stats, 0))) { - retcode = git_checkout_head(*out, checkout_opts, checkout_stats); + if (!(retcode = clone_internal(out, origin_url, workdir_path, progress, 0))) { + retcode = git_checkout_head(*out, checkout_opts, &progress->stages[2]); } return retcode; diff --git a/src/fetch.c b/src/fetch.c index 278ba3c50f1..eb808395a22 100644 --- a/src/fetch.c +++ b/src/fetch.c @@ -332,7 +332,12 @@ int git_fetch__download_pack( goto on_error; git_buf_free(&path); - memset(stats, 0, sizeof(git_indexer_stats)); + stats->processed = stats->received = stats->total = 0; + if (stats->transfer_progress) + stats->transfer_progress->current = stats->transfer_progress->total = 0; + if (stats->index_progress) + stats->index_progress->current = stats->index_progress->total = 0; + *bytes = 0; /* diff --git a/src/index.c b/src/index.c index a1042b72331..86445ac0b79 100644 --- a/src/index.c +++ b/src/index.c @@ -988,7 +988,7 @@ int git_index_entry_stage(const git_index_entry *entry) typedef struct read_tree_data { git_index *index; - git_indexer_stats *stats; + size_t *total; } read_tree_data; static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *data) @@ -997,7 +997,7 @@ static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *da git_index_entry *entry = NULL; git_buf path = GIT_BUF_INIT; - rtd->stats->total++; + (*rtd->total)++; if (git_tree_entry__is_tree(tentry)) return 0; @@ -1021,14 +1021,14 @@ static int read_tree_cb(const char *root, const git_tree_entry *tentry, void *da return 0; } -int git_index_read_tree(git_index *index, git_tree *tree, git_indexer_stats *stats) +int git_index_read_tree(git_index *index, git_tree *tree, size_t *total) { - git_indexer_stats dummy_stats; + size_t dummy_total = 0; read_tree_data rtd = {index, NULL}; - if (!stats) stats = &dummy_stats; - stats->total = 0; - rtd.stats = stats; + if (!total) total = &dummy_total; + *total = 0; + rtd.total = total; git_index_clear(index); diff --git a/src/indexer.c b/src/indexer.c index 85ffb161f1a..5df03574a69 100644 --- a/src/indexer.c +++ b/src/indexer.c @@ -10,6 +10,7 @@ #include "git2/indexer.h" #include "git2/object.h" #include "git2/oid.h" +#include "git2/common.h" #include "common.h" #include "pack.h" @@ -277,11 +278,18 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz { int error; struct git_pack_header hdr; - size_t processed; + size_t processed; git_mwindow_file *mwf = &idx->pack->mwf; + git_progress *transfer_progress, *index_progress; + git_progress dummy_progress1 = {0}, dummy_progress2 = {0}; assert(idx && data && stats); + transfer_progress = stats->transfer_progress; + index_progress = stats->index_progress; + if (!transfer_progress) transfer_progress = &dummy_progress1; + if (!index_progress) index_progress = &dummy_progress2; + processed = stats->processed; if (git_filebuf_write(&idx->pack_file, data, size) < 0) @@ -324,8 +332,10 @@ 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 = stats->received = stats->total = 0; + transfer_progress->current = index_progress->current = 0; + transfer_progress->total = index_progress->total = stats->total = + (unsigned int)idx->nr_objects; } /* Now that we have data in the pack, let's try to parse it */ @@ -362,6 +372,7 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz return error; stats->received++; + transfer_progress->current++; continue; } @@ -381,6 +392,8 @@ int git_indexer_stream_add(git_indexer_stream *idx, const void *data, size_t siz stats->processed = (unsigned int)++processed; stats->received++; + index_progress->current = processed; + transfer_progress->current = stats->received; } return 0; @@ -429,6 +442,7 @@ static int resolve_deltas(git_indexer_stream *idx, git_indexer_stats *stats) git__free(obj.data); stats->processed++; + if (stats->index_progress) stats->index_progress->current++; } return 0; @@ -794,16 +808,22 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats) int error; struct entry *entry; unsigned int left, processed; + git_progress *progress; + git_progress dummy_rational; assert(idx && stats); + progress = stats->index_progress; + if (!progress) progress = &dummy_rational; + mwf = &idx->pack->mwf; error = git_mwindow_file_register(mwf); if (error < 0) return error; stats->total = (unsigned int)idx->nr_objects; - stats->processed = processed = 0; + progress->current = stats->processed = processed = 0; + progress->total = stats->total; while (processed < idx->nr_objects) { git_rawobj obj; @@ -873,7 +893,7 @@ int git_indexer_run(git_indexer *idx, git_indexer_stats *stats) git__free(obj.data); - stats->processed = ++processed; + progress->current = stats->processed = ++processed; } cleanup: diff --git a/tests-clar/clone/clone.c b/tests-clar/clone/clone.c index 4cca15ffe03..51a049b84c9 100644 --- a/tests-clar/clone/clone.c +++ b/tests-clar/clone/clone.c @@ -67,7 +67,7 @@ static void build_local_file_url(git_buf *out, const char *fixture) void test_clone_clone__bad_url(void) { /* Clone should clean up the mess if the URL isn't a git repository */ - cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", NULL, NULL, NULL)); + cl_git_fail(git_clone(&g_repo, "not_a_repo", "./foo", NULL, NULL)); cl_assert(!git_path_exists("./foo")); cl_git_fail(git_clone_bare(&g_repo, "not_a_repo", "./foo.git", NULL)); cl_assert(!git_path_exists("./foo.git")); @@ -80,7 +80,7 @@ void test_clone_clone__local(void) build_local_file_url(&src, cl_fixture("testrepo.git")); #if DO_LOCAL_TEST - cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local", NULL, NULL, NULL)); + cl_git_pass(git_clone(&g_repo, git_buf_cstr(&src), "./local", NULL, NULL)); git_repository_free(g_repo); git_futils_rmdir_r("./local", GIT_DIRREMOVAL_FILES_AND_DIRS); cl_git_pass(git_clone_bare(&g_repo, git_buf_cstr(&src), "./local.git", NULL)); @@ -96,7 +96,7 @@ void test_clone_clone__network_full(void) #if DO_LIVE_NETWORK_TESTS git_remote *origin; - cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL, NULL, NULL)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./test2", NULL, NULL)); cl_assert(!git_repository_is_bare(g_repo)); cl_git_pass(git_remote_load(&origin, g_repo, "origin")); git_futils_rmdir_r("./test2", GIT_DIRREMOVAL_FILES_AND_DIRS); @@ -121,19 +121,19 @@ void test_clone_clone__already_exists(void) #if DO_LIVE_NETWORK_TESTS /* Should pass with existing-but-empty dir */ p_mkdir("./foo", GIT_DIR_MODE); - cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); + cl_git_pass(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL)); git_repository_free(g_repo); g_repo = NULL; git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); #endif /* Should fail with a file */ cl_git_mkfile("./foo", "Bar!"); - cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); + cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL)); git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); /* Should fail with existing-and-nonempty dir */ p_mkdir("./foo", GIT_DIR_MODE); cl_git_mkfile("./foo/bar", "Baz!"); - cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL, NULL)); + cl_git_fail(git_clone(&g_repo, LIVE_REPO_URL, "./foo", NULL, NULL)); git_futils_rmdir_r("./foo", GIT_DIRREMOVAL_FILES_AND_DIRS); }