summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2018-07-08 16:12:58 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2018-11-05 15:53:58 +0000
commit37b25ac57f78dc72e6bf4e516e24dc5010098cee (patch)
tree4d87b64b67f8332cf7d16d661e3bcbea7af0e224 /src
parent2d27ddc02e22a3cffbfafcb42e6eac04baf7256f (diff)
downloadlibgit2-37b25ac57f78dc72e6bf4e516e24dc5010098cee.tar.gz
apply: move location to an argument, not the opts
Move the location option to an argument, out of the options structure. This allows the options structure to be re-used for functions that don't need to know the location, since it's implicit in their functionality. For example, `git_apply_tree` should not take a location, but is expected to take all the other options.
Diffstat (limited to 'src')
-rw-r--r--src/apply.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/src/apply.c b/src/apply.c
index d098f962e..e6c2ae15b 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -472,10 +472,12 @@ int git_apply_to_tree(
git_index **out,
git_repository *repo,
git_tree *preimage,
- git_diff *diff)
+ git_diff *diff,
+ const git_apply_options *given_opts)
{
git_index *postimage = NULL;
git_reader *pre_reader = NULL;
+ git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const git_diff_delta *delta;
size_t i;
int error = 0;
@@ -484,6 +486,9 @@ int git_apply_to_tree(
*out = NULL;
+ if (given_opts)
+ memcpy(&opts, given_opts, sizeof(git_apply_options));
+
if ((error = git_reader_for_tree(&pre_reader, preimage)) < 0)
goto done;
@@ -529,6 +534,7 @@ static int git_apply__to_workdir(
git_diff *diff,
git_index *preimage,
git_index *postimage,
+ git_apply_location_t location,
git_apply_options *opts)
{
git_vector paths = GIT_VECTOR_INIT;
@@ -537,6 +543,8 @@ static int git_apply__to_workdir(
size_t i;
int error;
+ GIT_UNUSED(opts);
+
/*
* Limit checkout to the paths affected by the diff; this ensures
* that other modifications in the working directory are unaffected.
@@ -559,7 +567,7 @@ static int git_apply__to_workdir(
checkout_opts.checkout_strategy |= GIT_CHECKOUT_DISABLE_PATHSPEC_MATCH;
checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_WRITE_INDEX;
- if (opts->location == GIT_APPLY_LOCATION_WORKDIR)
+ if (location == GIT_APPLY_LOCATION_WORKDIR)
checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_UPDATE_INDEX;
checkout_opts.paths.strings = (char **)paths.contents;
@@ -636,7 +644,8 @@ done:
int git_apply(
git_repository *repo,
git_diff *diff,
- git_apply_options *given_opts)
+ git_apply_location_t location,
+ const git_apply_options *given_opts)
{
git_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
git_index *index = NULL, *preimage = NULL, *postimage = NULL;
@@ -658,7 +667,7 @@ int git_apply(
* in `--cached` or `--index` mode, we apply to the contents already
* in the index.
*/
- switch (opts.location) {
+ switch (location) {
case GIT_APPLY_LOCATION_BOTH:
error = git_reader_for_workdir(&pre_reader, repo, true);
break;
@@ -695,15 +704,15 @@ int git_apply(
goto done;
}
- switch (opts.location) {
+ switch (location) {
case GIT_APPLY_LOCATION_BOTH:
- error = git_apply__to_workdir(repo, diff, preimage, postimage, &opts);
+ error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts);
break;
case GIT_APPLY_LOCATION_INDEX:
error = git_apply__to_index(repo, diff, preimage, postimage, &opts);
break;
case GIT_APPLY_LOCATION_WORKDIR:
- error = git_apply__to_workdir(repo, diff, preimage, postimage, &opts);
+ error = git_apply__to_workdir(repo, diff, preimage, postimage, location, &opts);
break;
default:
assert(false);
@@ -712,9 +721,6 @@ int git_apply(
if (error < 0)
goto done;
- if (error < 0)
- goto done;
-
error = git_indexwriter_commit(&indexwriter);
done: