summaryrefslogtreecommitdiff
path: root/src/status.c
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2012-11-29 20:12:59 -0800
committerBen Straub <bs@github.com>2012-11-30 13:12:15 -0800
commit79cfa20d60cfdaf578da59cfb4d17551cf1b6256 (patch)
tree128cdc157ae65579ebf11346d3dc8a35832fdb57 /src/status.c
parentb4d136527c2210f1abbcc53ab7290ad38029ab3c (diff)
downloadlibgit2-79cfa20d60cfdaf578da59cfb4d17551cf1b6256.tar.gz
Deploy GIT_STATUS_OPTIONS_INIT
Diffstat (limited to 'src/status.c')
-rw-r--r--src/status.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/status.c b/src/status.c
index ca500c5cb..f23f40e6d 100644
--- a/src/status.c
+++ b/src/status.c
@@ -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 |