From 397837197d1ce04b8bd4aaa57a7f5f67648dc57f Mon Sep 17 00:00:00 2001 From: nulltoken Date: Mon, 17 Sep 2012 20:27:28 +0200 Subject: [PATCH] checkout: Mimic git_diff_options storage of paths --- include/git2/checkout.h | 2 +- src/checkout.c | 6 ++---- tests-clar/checkout/index.c | 6 ++---- tests-clar/checkout/tree.c | 12 ++++-------- 4 files changed, 9 insertions(+), 17 deletions(-) diff --git a/include/git2/checkout.h b/include/git2/checkout.h index b15b56a33..42d47003d 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 30799b608..b20bd57e8 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 fad10be51..d1c59e38c 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 5f99043f9..6d573bfd7 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"));