summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBen Straub <bs@github.com>2012-11-29 15:05:04 -0800
committerBen Straub <bs@github.com>2012-11-30 13:12:14 -0800
commit2f8d30becb4801d869188d2d46ca1512843e8698 (patch)
tree603ee4d64529de316e1c83914705e83d46b38cad /src
parent691776213947e59a3928aab09e97a64b65e990ab (diff)
downloadlibgit2-2f8d30becb4801d869188d2d46ca1512843e8698.tar.gz
Deploy GIT_DIFF_OPTIONS_INIT
Diffstat (limited to 'src')
-rw-r--r--src/checkout.c2
-rw-r--r--src/diff.c7
-rw-r--r--src/diff.h14
-rw-r--r--src/diff_output.c3
-rw-r--r--src/stash.c4
-rw-r--r--src/status.c3
-rw-r--r--src/submodule.c3
7 files changed, 26 insertions, 10 deletions
diff --git a/src/checkout.c b/src/checkout.c
index 2a7ad70be..06407bb30 100644
--- a/src/checkout.c
+++ b/src/checkout.c
@@ -622,7 +622,7 @@ int git_checkout_index(
git_checkout_opts *opts)
{
git_diff_list *diff = NULL;
- git_diff_options diff_opts = {0};
+ git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
git_checkout_opts checkout_opts;
checkout_diff_data data;
git_buf workdir = GIT_BUF_INIT;
diff --git a/src/diff.c b/src/diff.c
index 86f76f9c0..722acbead 100644
--- a/src/diff.c
+++ b/src/diff.c
@@ -755,14 +755,15 @@ fail:
return error;
}
-
#define DIFF_FROM_ITERATORS(MAKE_FIRST, MAKE_SECOND) do { \
git_iterator *a = NULL, *b = NULL; \
char *pfx = opts ? git_pathspec_prefix(&opts->pathspec) : NULL; \
- if (!(error = MAKE_FIRST) && !(error = MAKE_SECOND)) \
+ if (!git_diff__opts_has_valid_version(opts)) \
+ error = -1; \
+ else if (!(error = MAKE_FIRST) && !(error = MAKE_SECOND)) \
error = diff_from_iterators(diff, repo, a, b, opts); \
git__free(pfx); git_iterator_free(a); git_iterator_free(b); \
- } while (0)
+} while (0)
int git_diff_tree_to_tree(
git_diff_list **diff,
diff --git a/src/diff.h b/src/diff.h
index 1e3be7593..1f45af1cd 100644
--- a/src/diff.h
+++ b/src/diff.h
@@ -61,5 +61,19 @@ extern bool git_diff_delta__should_skip(
extern int git_diff__oid_for_file(
git_repository *, const char *, uint16_t, git_off_t, git_oid *);
+
+GIT_INLINE(bool) git_diff__opts_has_valid_version(const git_diff_options *opts)
+{
+ if (!opts)
+ return true;
+
+ if (opts->version > 0 && opts->version <= GIT_DIFF_OPTIONS_VERSION)
+ return true;
+
+ giterr_set(GITERR_INVALID, "Invalid version %d in git_diff_options", opts->version);
+ return false;
+}
+
+
#endif
diff --git a/src/diff_output.c b/src/diff_output.c
index e137fd0f2..6316bfa1e 100644
--- a/src/diff_output.c
+++ b/src/diff_output.c
@@ -1266,6 +1266,9 @@ int git_diff_blobs(
git_diff_delta delta;
git_diff_patch patch;
+ if (!git_diff__opts_has_valid_version(options))
+ return -1;
+
if (options && (options->flags & GIT_DIFF_REVERSE)) {
git_blob *swap = old_blob;
old_blob = new_blob;
diff --git a/src/stash.c b/src/stash.c
index edd8c55db..261d3b199 100644
--- a/src/stash.c
+++ b/src/stash.c
@@ -229,7 +229,7 @@ static int build_untracked_tree(
{
git_tree *i_tree = NULL;
git_diff_list *diff = NULL;
- git_diff_options opts = {0};
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
struct cb_data data = {0};
int error = -1;
@@ -315,7 +315,7 @@ static int build_workdir_tree(
git_repository *repo = git_index_owner(index);
git_tree *b_tree = NULL;
git_diff_list *diff = NULL, *diff2 = NULL;
- git_diff_options opts = {0};
+ git_diff_options opts = GIT_DIFF_OPTIONS_INIT;
struct cb_data data = {0};
int error = -1;
diff --git a/src/status.c b/src/status.c
index c7dea2c71..ca500c5cb 100644
--- a/src/status.c
+++ b/src/status.c
@@ -108,7 +108,7 @@ int git_status_foreach_ext(
void *payload)
{
int err = 0;
- git_diff_options diffopt;
+ git_diff_options diffopt = GIT_DIFF_OPTIONS_INIT;
git_diff_list *idx2head = NULL, *wd2idx = NULL;
git_tree *head = NULL;
git_status_show_t show =
@@ -126,7 +126,6 @@ int git_status_foreach_ext(
!(err == GIT_ENOTFOUND || err == GIT_EORPHANEDHEAD))
return err;
- memset(&diffopt, 0, sizeof(diffopt));
memcpy(&diffopt.pathspec, &opts->pathspec, sizeof(diffopt.pathspec));
diffopt.flags = GIT_DIFF_INCLUDE_TYPECHANGE;
diff --git a/src/submodule.c b/src/submodule.c
index c117255d4..7ac666c73 100644
--- a/src/submodule.c
+++ b/src/submodule.c
@@ -1439,7 +1439,7 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm)
if (sm_repo != NULL) {
git_tree *sm_head;
- git_diff_options opt;
+ git_diff_options opt = GIT_DIFF_OPTIONS_INIT;
git_diff_list *diff;
/* the diffs below could be optimized with an early termination
@@ -1452,7 +1452,6 @@ static int submodule_wd_status(unsigned int *status, git_submodule *sm)
if ((error = git_repository_head_tree(&sm_head, sm_repo)) < 0)
return error;
- memset(&opt, 0, sizeof(opt));
if (sm->ignore == GIT_SUBMODULE_IGNORE_NONE)
opt.flags |= GIT_DIFF_INCLUDE_UNTRACKED;