checkout: Mimic git_diff_options storage of paths
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
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"));