Commit 397837197d1ce04b8bd4aaa57a7f5f67648dc57f

nulltoken 2012-09-17T20:27:28

checkout: Mimic git_diff_options storage of paths

diff --git a/include/git2/checkout.h b/include/git2/checkout.h
index b15b56a..42d4700 100644
--- a/include/git2/checkout.h
+++ b/include/git2/checkout.h
@@ -39,7 +39,7 @@ typedef struct git_checkout_opts {
 	/* when not NULL, arrays of fnmatch pattern specifying 
 	 * which paths should be taken into account
 	 */
-	git_strarray *paths; 
+	git_strarray paths; 
 } git_checkout_opts;
 
 /**
diff --git a/src/checkout.c b/src/checkout.c
index 30799b6..b20bd57 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -282,10 +282,8 @@ int git_checkout_index(
 
 	diff_opts.flags = GIT_DIFF_INCLUDE_UNTRACKED;
 
-	if (opts && opts->paths) {
-		diff_opts.pathspec.strings = opts->paths->strings;
-		diff_opts.pathspec.count = opts->paths->count;
-	}
+	if (opts && opts->paths.count > 0)
+		diff_opts.pathspec = opts->paths;
 
 	if ((error = git_diff_workdir_to_index(repo, &diff_opts, &diff)) < 0)
 		goto cleanup;
diff --git a/tests-clar/checkout/index.c b/tests-clar/checkout/index.c
index fad10be..d1c59e3 100644
--- a/tests-clar/checkout/index.c
+++ b/tests-clar/checkout/index.c
@@ -102,12 +102,10 @@ void test_checkout_index__can_remove_untracked_files(void)
 
 void test_checkout_index__honor_the_specified_pathspecs(void)
 {
-	git_strarray paths;
 	char *entries[] = { "*.txt" };
 
-	paths.strings = entries;
-	paths.count = 1;
-	g_opts.paths = &paths;
+	g_opts.paths.strings = entries;
+	g_opts.paths.count = 1;
 
 	cl_assert_equal_i(false, git_path_isfile("./testrepo/README"));
 	cl_assert_equal_i(false, git_path_isfile("./testrepo/branch_file.txt"));
diff --git a/tests-clar/checkout/tree.c b/tests-clar/checkout/tree.c
index 5f99043..6d573bf 100644
--- a/tests-clar/checkout/tree.c
+++ b/tests-clar/checkout/tree.c
@@ -32,12 +32,10 @@ void test_checkout_tree__cannot_checkout_a_non_treeish(void)
 
 void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void)
 {
-	git_strarray paths;
 	char *entries[] = { "ab/de/" };
 
-	paths.strings = entries;
-	paths.count = 1;
-	g_opts.paths = &paths;
+	g_opts.paths.strings = entries;
+	g_opts.paths.count = 1;
 
 	cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees"));
 
@@ -51,12 +49,10 @@ void test_checkout_tree__can_checkout_a_subdirectory_from_a_commit(void)
 
 void test_checkout_tree__can_checkout_a_subdirectory_from_a_subtree(void)
 {
-	git_strarray paths;
 	char *entries[] = { "de/" };
 
-	paths.strings = entries;
-	paths.count = 1;
-	g_opts.paths = &paths;
+	g_opts.paths.strings = entries;
+	g_opts.paths.count = 1;
 
 	cl_git_pass(git_revparse_single(&g_object, g_repo, "subtrees:ab"));