Deploy GIT_STATUS_OPTIONS_INIT

This commit is contained in:
Ben Straub 2012-11-29 20:12:59 -08:00
parent b4d136527c
commit 79cfa20d60
4 changed files with 23 additions and 24 deletions

View File

@ -471,9 +471,8 @@ static int ensure_there_are_changes_to_stash(
bool include_ignored_files)
{
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;
if (include_untracked_files)
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |

View File

@ -101,6 +101,18 @@ static int status_invoke_cb(
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(
git_repository *repo,
const git_status_options *opts,
@ -117,6 +129,9 @@ int git_status_foreach_ext(
assert(show <= GIT_STATUS_SHOW_INDEX_THEN_WORKDIR);
if (!options_have_valid_version(opts))
return -1;
if (show != GIT_STATUS_SHOW_INDEX_ONLY &&
(err = git_repository__ensure_not_bare(repo, "status")) < 0)
return err;
@ -180,9 +195,8 @@ int git_status_foreach(
git_status_cb callback,
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.flags = GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNTRACKED |
@ -223,16 +237,14 @@ int git_status_file(
const char *path)
{
int error;
git_status_options opts;
struct status_file_info sfi;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
struct status_file_info sfi = {0};
assert(status_flags && repo && path);
memset(&sfi, 0, sizeof(sfi));
if ((sfi.expected = git__strdup(path)) == NULL)
return -1;
memset(&opts, 0, sizeof(opts));
opts.show = GIT_STATUS_SHOW_INDEX_AND_WORKDIR;
opts.flags = GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNTRACKED |

View File

@ -180,9 +180,6 @@ void test_status_ignore__subdirectories(void)
{
status_entry_single st;
int ignored;
git_status_options opts;
GIT_UNUSED(opts);
g_repo = cl_git_sandbox_init("empty_standard_repo");
@ -216,11 +213,6 @@ void test_status_ignore__subdirectories(void)
cl_git_mkfile(
"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));
cl_git_pass(git_status_foreach(g_repo, cb_status__single, &st));
cl_assert_equal_i(2, st.count);

View File

@ -111,7 +111,7 @@ void test_status_worktree__swap_subdir_and_file(void)
status_entry_counts counts;
git_repository *repo = cl_git_sandbox_init("status");
git_index *index;
git_status_options opts;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
bool ignore_case;
cl_git_pass(git_repository_index(&index, repo));
@ -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_statuses = ignore_case ? entry_statuses3_icase : entry_statuses3;
memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_INCLUDE_IGNORED;
@ -150,7 +149,7 @@ void test_status_worktree__swap_subdir_with_recurse_and_pathspec(void)
{
status_entry_counts counts;
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 */
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)
counts.expected_paths = entry_paths4;
counts.expected_statuses = entry_statuses4;
memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_RECURSE_UNTRACKED_DIRS;
/* TODO: set pathspec to "current_file" eventually */
@ -691,7 +689,7 @@ void test_status_worktree__filemode_changes(void)
{
git_repository *repo = cl_git_sandbox_init("filemodes");
status_entry_counts counts;
git_status_options opts;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
git_config *cfg;
/* overwrite stored filemode with platform appropriate value */
@ -708,7 +706,6 @@ void test_status_worktree__filemode_changes(void)
filemode_statuses[i] = GIT_STATUS_CURRENT;
}
memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_INCLUDE_IGNORED |
GIT_STATUS_OPT_INCLUDE_UNMODIFIED;
@ -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)
{
git_repository *repo;
git_status_options opts;
git_status_options opts = GIT_STATUS_OPTIONS_INIT;
char *file_with_bracket = "LICENSE[1].md",
*imaginary_file_with_bracket = "LICENSE[1-2].md";
@ -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/LICENSE1.md", "no bracket\n");
memset(&opts, 0, sizeof(opts));
opts.flags = GIT_STATUS_OPT_INCLUDE_UNTRACKED |
GIT_STATUS_OPT_DISABLE_PATHSPEC_MATCH;
opts.pathspec.count = 1;