Commit 79cfa20d by Ben Straub

Deploy GIT_STATUS_OPTIONS_INIT

parent b4d13652
...@@ -471,9 +471,8 @@ static int ensure_there_are_changes_to_stash( ...@@ -471,9 +471,8 @@ static int ensure_there_are_changes_to_stash(
bool include_ignored_files) bool include_ignored_files)
{ {
int error; int error;
git_status_options opts; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
memset(&opts, 0, sizeof(opts));
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
if (include_untracked_files) if (include_untracked_files)
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
......
...@@ -101,6 +101,18 @@ static int status_invoke_cb( ...@@ -101,6 +101,18 @@ static int status_invoke_cb(
return usercb->cb(path, status, usercb->payload); return usercb->cb(path, status, usercb->payload);
} }
static bool options_have_valid_version(const git_status_options *opts)
{
if (!opts)
return true;
if (opts->version > 0 && opts->version <= GIT_REMOTE_CALLBACKS_VERSION)
return true;
giterr_set(GITERR_INVALID, "Invalid version %d for git_repository_init_options", opts->version);
return false;
}
int git_status_foreach_ext( int git_status_foreach_ext(
git_repository *repo, git_repository *repo,
const git_status_options *opts, const git_status_options *opts,
...@@ -117,6 +129,9 @@ int git_status_foreach_ext( ...@@ -117,6 +129,9 @@ int git_status_foreach_ext(
assert(show <= GIT_STATUS_SHOW_INDEX_THEN_WORKDIR); assert(show <= GIT_STATUS_SHOW_INDEX_THEN_WORKDIR);
if (!options_have_valid_version(opts))
return -1;
if (show != GIT_STATUS_SHOW_INDEX_ONLY && if (show != GIT_STATUS_SHOW_INDEX_ONLY &&
(err = git_repository__ensure_not_bare(repo, "status")) < 0) (err = git_repository__ensure_not_bare(repo, "status")) < 0)
return err; return err;
...@@ -180,9 +195,8 @@ int git_status_foreach( ...@@ -180,9 +195,8 @@ int git_status_foreach(
git_status_cb callback, git_status_cb callback,
void *payload) void *payload)
{ {
git_status_options opts; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
memset(&opts, 0, sizeof(opts));
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED | opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_UNTRACKED |
...@@ -223,16 +237,14 @@ int git_status_file( ...@@ -223,16 +237,14 @@ int git_status_file(
const char *path) const char *path)
{ {
int error; int error;
git_status_options opts; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
struct status_file_info sfi; struct status_file_info sfi = {0};
assert(status_flags && repo && path); assert(status_flags && repo && path);
memset(&sfi, 0, sizeof(sfi));
if ((sfi.expected = git__strdup(path)) == NULL) if ((sfi.expected = git__strdup(path)) == NULL)
return -1; return -1;
memset(&opts, 0, sizeof(opts));
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR; opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED | opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNTRACKED | GIT_STATUS_OPT_INCLUDE_UNTRACKED |
......
...@@ -180,9 +180,6 @@ void test_status_ignore__subdirectories(void) ...@@ -180,9 +180,6 @@ void test_status_ignore__subdirectories(void)
{ {
status_entry_single st; status_entry_single st;
int ignored; int ignored;
git_status_options opts;
GIT_UNUSED(opts);
g_repo = cl_git_sandbox_init("empty_standard_repo"); g_repo = cl_git_sandbox_init("empty_standard_repo");
...@@ -216,11 +213,6 @@ void test_status_ignore__subdirectories(void) ...@@ -216,11 +213,6 @@ void test_status_ignore__subdirectories(void)
cl_git_mkfile( cl_git_mkfile(
"empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!"); "empty_standard_repo/test/ignore_me/file", "I'm going to be ignored!");
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
memset(&st, 0, sizeof(st)); memset(&st, 0, sizeof(st));
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st)); cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
cl_assert_equal_i(2, st.count); cl_assert_equal_i(2, st.count);
......
...@@ -111,7 +111,7 @@ void test_status_worktree__swap_subdir_and_file(void) ...@@ -111,7 +111,7 @@ void test_status_worktree__swap_subdir_and_file(void)
status_entry_counts counts; status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status"); git_repository *repo = cl_git_sandbox_init("status");
git_index *index; git_index *index;
git_status_options opts; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
bool ignore_case; bool ignore_case;
cl_git_pass(git_repository_index(&index, repo)); cl_git_pass(git_repository_index(&index, repo));
...@@ -133,7 +133,6 @@ void test_status_worktree__swap_subdir_and_file(void) ...@@ -133,7 +133,6 @@ void test_status_worktree__swap_subdir_and_file(void)
counts.expected_paths = ignore_case ? entry_paths3_icase : entry_paths3; counts.expected_paths = ignore_case ? entry_paths3_icase : entry_paths3;
counts.expected_statuses = ignore_case ? entry_statuses3_icase : entry_statuses3; counts.expected_statuses = ignore_case ? entry_statuses3_icase : entry_statuses3;
memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_INCLUDE_IGNORED; GIT_STATUS_OPT_INCLUDE_IGNORED;
...@@ -150,7 +149,7 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void) ...@@ -150,7 +149,7 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
{ {
status_entry_counts counts; status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status"); git_repository *repo = cl_git_sandbox_init("status");
git_status_options opts; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
/* first alter the contents of the worktree */ /* first alter the contents of the worktree */
cl_git_pass(p_rename("status/current_file", "status/swap")); cl_git_pass(p_rename("status/current_file", "status/swap"));
...@@ -167,7 +166,6 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void) ...@@ -167,7 +166,6 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
counts.expected_paths = entry_paths4; counts.expected_paths = entry_paths4;
counts.expected_statuses = entry_statuses4; counts.expected_statuses = entry_statuses4;
memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS; GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
/* TODO: set pathspec to "current_file" eventually */ /* TODO: set pathspec to "current_file" eventually */
...@@ -691,7 +689,7 @@ void test_status_worktree__filemode_changes(void) ...@@ -691,7 +689,7 @@ void test_status_worktree__filemode_changes(void)
{ {
git_repository *repo = cl_git_sandbox_init("filemodes"); git_repository *repo = cl_git_sandbox_init("filemodes");
status_entry_counts counts; status_entry_counts counts;
git_status_options opts; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
git_config *cfg; git_config *cfg;
/* overwrite stored filemode with platform appropriate value */ /* overwrite stored filemode with platform appropriate value */
...@@ -708,7 +706,6 @@ void test_status_worktree__filemode_changes(void) ...@@ -708,7 +706,6 @@ void test_status_worktree__filemode_changes(void)
filemode_statuses[i] = GIT_STATUS_CURRENT; filemode_statuses[i] = GIT_STATUS_CURRENT;
} }
memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_INCLUDE_IGNORED | GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNMODIFIED; GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
...@@ -746,7 +743,7 @@ static int cb_status__expected_path(const char *p, unsigned int s, void *payload ...@@ -746,7 +743,7 @@ static int cb_status__expected_path(const char *p, unsigned int s, void *payload
void test_status_worktree__disable_pathspec_match(void) void test_status_worktree__disable_pathspec_match(void)
{ {
git_repository *repo; git_repository *repo;
git_status_options opts; git_status_options opts = GIT_STATUS_OPTIONS_INIT;
char *file_with_bracket = "LICENSE[1].md", char *file_with_bracket = "LICENSE[1].md",
*imaginary_file_with_bracket = "LICENSE[1-2].md"; *imaginary_file_with_bracket = "LICENSE[1-2].md";
...@@ -754,7 +751,6 @@ void test_status_worktree__disable_pathspec_match(void) ...@@ -754,7 +751,6 @@ void test_status_worktree__disable_pathspec_match(void)
cl_git_mkfile("pathspec/LICENSE[1].md", "screaming bracket\n"); cl_git_mkfile("pathspec/LICENSE[1].md", "screaming bracket\n");
cl_git_mkfile("pathspec/LICENSE1.md", "no bracket\n"); cl_git_mkfile("pathspec/LICENSE1.md", "no bracket\n");
memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED | opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH; GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
opts.pathspec.count = 1; opts.pathspec.count = 1;
......
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