Commit 806426565f78ff0ee0ac12e125d59658e3ef34be

Ben Straub 2012-10-16T20:23:10

Convert checkout_* to use progress callback

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);
+}