Commit 80642656 by Ben Straub

Convert checkout_* to use progress callback

parent 2c8bbb27
...@@ -86,22 +86,19 @@ typedef struct git_checkout_opts { ...@@ -86,22 +86,19 @@ typedef struct git_checkout_opts {
* *
* @param repo repository to check out (must be non-bare) * @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL) * @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 * @return 0 on success, GIT_EORPHANEDHEAD when HEAD points to a non existing
* branch, GIT_ERROR otherwise (use giterr_last for information * branch, GIT_ERROR otherwise (use giterr_last for information
* about the error) * about the error)
*/ */
GIT_EXTERN(int) git_checkout_head( GIT_EXTERN(int) git_checkout_head(
git_repository *repo, git_repository *repo,
git_checkout_opts *opts, git_checkout_opts *opts);
git_indexer_stats *stats);
/** /**
* Updates files in the working tree to match the content of the index. * Updates files in the working tree to match the content of the index.
* *
* @param repo repository to check out (must be non-bare) * @param repo repository to check out (must be non-bare)
* @param opts specifies checkout options (may be NULL) * @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 * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
* about the error) * about the error)
*/ */
...@@ -117,15 +114,13 @@ GIT_EXTERN(int) git_checkout_index( ...@@ -117,15 +114,13 @@ GIT_EXTERN(int) git_checkout_index(
* @param treeish a commit, tag or tree which content will be used to update * @param treeish a commit, tag or tree which content will be used to update
* the working directory * the working directory
* @param opts specifies checkout options (may be NULL) * @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 * @return 0 on success, GIT_ERROR otherwise (use giterr_last for information
* about the error) * about the error)
*/ */
GIT_EXTERN(int) git_checkout_tree( GIT_EXTERN(int) git_checkout_tree(
git_repository *repo, git_repository *repo,
git_object *treeish, git_object *treeish,
git_checkout_opts *opts, git_checkout_opts *opts);
git_indexer_stats *stats);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
...@@ -387,8 +387,7 @@ cleanup: ...@@ -387,8 +387,7 @@ cleanup:
int git_checkout_tree( int git_checkout_tree(
git_repository *repo, git_repository *repo,
git_object *treeish, git_object *treeish,
git_checkout_opts *opts, git_checkout_opts *opts)
git_indexer_stats *stats)
{ {
git_index *index = NULL; git_index *index = NULL;
git_tree *tree = NULL; git_tree *tree = NULL;
...@@ -421,8 +420,7 @@ cleanup: ...@@ -421,8 +420,7 @@ cleanup:
int git_checkout_head( int git_checkout_head(
git_repository *repo, git_repository *repo,
git_checkout_opts *opts, git_checkout_opts *opts)
git_indexer_stats *stats)
{ {
git_reference *head; git_reference *head;
int error; int error;
...@@ -436,7 +434,7 @@ int git_checkout_head( ...@@ -436,7 +434,7 @@ int git_checkout_head(
if ((error = git_reference_peel(&tree, head, GIT_OBJ_TREE)) < 0) if ((error = git_reference_peel(&tree, head, GIT_OBJ_TREE)) < 0)
goto cleanup; goto cleanup;
error = git_checkout_tree(repo, tree, opts, stats); error = git_checkout_tree(repo, tree, opts);
cleanup: cleanup:
git_reference_free(head); git_reference_free(head);
......
...@@ -333,7 +333,7 @@ static int clone_internal( ...@@ -333,7 +333,7 @@ static int clone_internal(
} }
if (!retcode && should_checkout(repo, is_bare, checkout_opts)) 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; return retcode;
} }
......
...@@ -27,7 +27,7 @@ void test_checkout_tree__cannot_checkout_a_non_treeish(void) ...@@ -27,7 +27,7 @@ void test_checkout_tree__cannot_checkout_a_non_treeish(void)
/* blob */ /* blob */
cl_git_pass(git_revparse_single(&g_object, g_repo, "a71586c1dfe8a71c6cbf6c129f404c5642ff31bd")); 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) 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) ...@@ -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_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/2.txt"));
cl_assert_equal_i(true, git_path_isfile("./testrepo/ab/de/fgh/1.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) ...@@ -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_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/2.txt"));
cl_assert_equal_i(true, git_path_isfile("./testrepo/de/fgh/1.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);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment