Convert checkout_* to use progress callback
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index d0190c2..9032c6b 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -86,22 +86,19 @@ typedef struct git_checkout_opts {
*
* @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL)
- * @param stats structure through which progress information is reported
* @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
* branch, GIT_ERROR otherwise (use giterr_last for information
* about the error)
*/
GIT_EXTERN(int) git_checkout_head(
git_repository *repo,
- git_checkout_opts *opts,
- git_indexer_stats *stats);
+ git_checkout_opts *opts);
/**
* Updates files in the working tree to match the content of the index.
*
* @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL)
- * @param stats structure through which progress information is reported
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
* about the error)
*/
@@ -117,15 +114,13 @@ GIT_EXTERN(int) git_checkout_index(
* @param treeish a commit, tag or tree which content will be used to update
* the working directory
* @param opts specifies checkout options (may be NULL)
- * @param stats structure through which progress information is reported
* @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
* about the error)
*/
GIT_EXTERN(int) git_checkout_tree(
git_repository *repo,
git_object *treeish,
- git_checkout_opts *opts,
- git_indexer_stats *stats);
+ git_checkout_opts *opts);
/** @} */
GIT_END_DECL
diff --git a/src/checkout.c b/src/checkout.c
index 222eb26..ef4ab8d 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -387,8 +387,7 @@ cleanup:
int git_checkout_tree(
git_repository *repo,
git_object *treeish,
- git_checkout_opts *opts,
- git_indexer_stats *stats)
+ git_checkout_opts *opts)
{
git_index *index = NULL;
git_tree *tree = NULL;
@@ -421,8 +420,7 @@ cleanup:
int git_checkout_head(
git_repository *repo,
- git_checkout_opts *opts,
- git_indexer_stats *stats)
+ git_checkout_opts *opts)
{
git_reference *head;
int error;
@@ -436,7 +434,7 @@ int git_checkout_head(
if ((error = git_reference_peel(&tree, head, GIT_OBJ_TREE)) < 0)
goto cleanup;
- error = git_checkout_tree(repo, tree, opts, stats);
+ error = git_checkout_tree(repo, tree, opts);
cleanup:
git_reference_free(head);
diff --git a/src/clone.c b/src/clone.c
index 0039b14..b84cd8d 100644
--- a/src/clone.c
+++ b/src/clone.c
@@ -333,7 +333,7 @@ static int clone_internal(
}
if (!retcode && should_checkout(repo, is_bare, checkout_opts))
- retcode = git_checkout_head(*out, checkout_opts, checkout_stats);
+ retcode = git_checkout_head(*out, checkout_opts);
return retcode;
}
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
index 6d573bf..c698959 100644
--- a/tests-clar/checkout/tree.c
+++ b/tests-clar/checkout/tree.c
@@ -27,7 +27,7 @@ void test_checkout_tree__cannot_checkout_a_non_treeish(void)
/* blob */
cl_git_pass(git_revparse_single(&g_object, g_repo, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd"));
- cl_git_fail(git_checkout_tree(g_repo, g_object, NULL, NULL));
+ cl_git_fail(git_checkout_tree(g_repo, g_object, NULL));
}
void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void)
@@ -41,7 +41,7 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void)
cl_assert_equal_i(false, git_path_isdir("./testrepo/ab/"));
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts, NULL));
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/2.txt"));
cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.txt"));
@@ -58,8 +58,26 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void)
cl_assert_equal_i(false, git_path_isdir("./testrepo/de/"));
- cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts, NULL));
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
cl_assert_equal_i(true, git_path_isfile("./testrepo/de/2.txt"));
cl_assert_equal_i(true, git_path_isfile("./testrepo/de/fgh/1.txt"));
}
+
+static void progress(const char *path, float progress, void *payload)
+{
+ GIT_UNUSED(path); GIT_UNUSED(progress);
+ int *count = (int*)payload;
+ (*count)++;
+}
+
+void test_checkout_tree__calls_progress_callback(void)
+{
+ int count = 0;
+ g_opts.progress_cb = progress;
+ g_opts.progress_payload = &count;
+
+ cl_git_pass(git_revparse_single(&g_object, g_repo, "master"));
+ cl_git_pass(git_checkout_tree(g_repo, g_object, &g_opts));
+ cl_assert_equal_i(count, 4);
+}