Commit 37b25ac5 by Edward Thomson

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.
parent 2d27ddc0
...@@ -22,6 +22,21 @@ ...@@ -22,6 +22,21 @@
GIT_BEGIN_DECL GIT_BEGIN_DECL
/** /**
* Apply options structure
*
* Initialize with `GIT_APPLY_OPTIONS_INIT`. Alternatively, you can
* use `git_apply_init_options`.
*
* @see git_apply_to_tree, git_apply
*/
typedef struct {
unsigned int version;
} git_apply_options;
#define GIT_APPLY_OPTIONS_VERSION 1
#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
/**
* Apply a `git_diff` to a `git_tree`, and return the resulting image * Apply a `git_diff` to a `git_tree`, and return the resulting image
* as an index. * as an index.
* *
...@@ -29,12 +44,14 @@ GIT_BEGIN_DECL ...@@ -29,12 +44,14 @@ GIT_BEGIN_DECL
* @param repo the repository to apply * @param repo the repository to apply
* @param preimage the tree to apply the diff to * @param preimage the tree to apply the diff to
* @param diff the diff to apply * @param diff the diff to apply
* @param options the options for the apply (or null for defaults)
*/ */
GIT_EXTERN(int) git_apply_to_tree( GIT_EXTERN(int) git_apply_to_tree(
git_index **out, git_index **out,
git_repository *repo, git_repository *repo,
git_tree *preimage, git_tree *preimage,
git_diff *diff); git_diff *diff,
const git_apply_options *options);
typedef enum { typedef enum {
/** /**
...@@ -56,27 +73,20 @@ typedef enum { ...@@ -56,27 +73,20 @@ typedef enum {
GIT_APPLY_LOCATION_BOTH = 2, GIT_APPLY_LOCATION_BOTH = 2,
} git_apply_location_t; } git_apply_location_t;
typedef struct {
unsigned int version;
git_apply_location_t location;
} git_apply_options;
#define GIT_APPLY_OPTIONS_VERSION 1
#define GIT_APPLY_OPTIONS_INIT {GIT_APPLY_OPTIONS_VERSION}
/** /**
* Apply a `git_diff` to the given repository, making changes directly * Apply a `git_diff` to the given repository, making changes directly
* in the working directory, the index, or both. * in the working directory, the index, or both.
* *
* @param repo the repository to apply to * @param repo the repository to apply to
* @param diff the diff to apply * @param diff the diff to apply
* @param location the location to apply (workdir, index or both)
* @param options the options for the apply (or null for defaults) * @param options the options for the apply (or null for defaults)
*/ */
GIT_EXTERN(int) git_apply( GIT_EXTERN(int) git_apply(
git_repository *repo, git_repository *repo,
git_diff *diff, git_diff *diff,
git_apply_options *options); git_apply_location_t location,
const git_apply_options *options);
/** @} */ /** @} */
GIT_END_DECL GIT_END_DECL
......
...@@ -472,10 +472,12 @@ int git_apply_to_tree( ...@@ -472,10 +472,12 @@ int git_apply_to_tree(
git_index **out, git_index **out,
git_repository *repo, git_repository *repo,
git_tree *preimage, git_tree *preimage,
git_diff *diff) git_diff *diff,
const git_apply_options *given_opts)
{ {
git_index *postimage = NULL; git_index *postimage = NULL;
git_reader *pre_reader = NULL; git_reader *pre_reader = NULL;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const git_diff_delta *delta; const git_diff_delta *delta;
size_t i; size_t i;
int error = 0; int error = 0;
...@@ -484,6 +486,9 @@ int git_apply_to_tree( ...@@ -484,6 +486,9 @@ int git_apply_to_tree(
*out = NULL; *out = NULL;
if (given_opts)
memcpy(&opts, given_opts, sizeof(git_apply_options));
if ((error = git_reader_for_tree(&pre_reader, preimage)) < 0) if ((error = git_reader_for_tree(&pre_reader, preimage)) < 0)
goto done; goto done;
...@@ -529,6 +534,7 @@ static int git_apply__to_workdir( ...@@ -529,6 +534,7 @@ static int git_apply__to_workdir(
git_diff *diff, git_diff *diff,
git_index *preimage, git_index *preimage,
git_index *postimage, git_index *postimage,
git_apply_location_t location,
git_apply_options *opts) git_apply_options *opts)
{ {
git_vector paths = GIT_VECTOR_INIT; git_vector paths = GIT_VECTOR_INIT;
...@@ -537,6 +543,8 @@ static int git_apply__to_workdir( ...@@ -537,6 +543,8 @@ static int git_apply__to_workdir(
size_t i; size_t i;
int error; int error;
GIT_UNUSED(opts);
/* /*
* Limit checkout to the paths affected by the diff; this ensures * Limit checkout to the paths affected by the diff; this ensures
* that other modifications in the working directory are unaffected. * that other modifications in the working directory are unaffected.
...@@ -559,7 +567,7 @@ static int git_apply__to_workdir( ...@@ -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_DISABLE_PATHSPEC_MATCH;
checkout_opts.checkout_strategy |= GIT_CHECKOUT_DONT_WRITE_INDEX; 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.checkout_strategy |= GIT_CHECKOUT_DONT_UPDATE_INDEX;
checkout_opts.paths.strings = (char **)paths.contents; checkout_opts.paths.strings = (char **)paths.contents;
...@@ -636,7 +644,8 @@ done: ...@@ -636,7 +644,8 @@ done:
int git_apply( int git_apply(
git_repository *repo, git_repository *repo,
git_diff *diff, 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_indexwriter indexwriter = GIT_INDEXWRITER_INIT;
git_index *index = NULL, *preimage = NULL, *postimage = NULL; git_index *index = NULL, *preimage = NULL, *postimage = NULL;
...@@ -658,7 +667,7 @@ int git_apply( ...@@ -658,7 +667,7 @@ int git_apply(
* in `--cached` or `--index` mode, we apply to the contents already * in `--cached` or `--index` mode, we apply to the contents already
* in the index. * in the index.
*/ */
switch (opts.location) { switch (location) {
case GIT_APPLY_LOCATION_BOTH: case GIT_APPLY_LOCATION_BOTH:
error = git_reader_for_workdir(&pre_reader, repo, true); error = git_reader_for_workdir(&pre_reader, repo, true);
break; break;
...@@ -695,15 +704,15 @@ int git_apply( ...@@ -695,15 +704,15 @@ int git_apply(
goto done; goto done;
} }
switch (opts.location) { switch (location) {
case GIT_APPLY_LOCATION_BOTH: 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; break;
case GIT_APPLY_LOCATION_INDEX: case GIT_APPLY_LOCATION_INDEX:
error = git_apply__to_index(repo, diff, preimage, postimage, &opts); error = git_apply__to_index(repo, diff, preimage, postimage, &opts);
break; break;
case GIT_APPLY_LOCATION_WORKDIR: 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; break;
default: default:
assert(false); assert(false);
...@@ -712,9 +721,6 @@ int git_apply( ...@@ -712,9 +721,6 @@ int git_apply(
if (error < 0) if (error < 0)
goto done; goto done;
if (error < 0)
goto done;
error = git_indexwriter_commit(&indexwriter); error = git_indexwriter_commit(&indexwriter);
done: done:
......
...@@ -30,7 +30,6 @@ void test_apply_both__generated_diff(void) ...@@ -30,7 +30,6 @@ void test_apply_both__generated_diff(void)
git_tree *a_tree, *b_tree; git_tree *a_tree, *b_tree;
git_diff *diff; git_diff *diff;
git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
struct merge_index_entry both_expected[] = { struct merge_index_entry both_expected[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" }, { 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
...@@ -52,9 +51,7 @@ void test_apply_both__generated_diff(void) ...@@ -52,9 +51,7 @@ void test_apply_both__generated_diff(void)
cl_git_pass(git_commit_tree(&b_tree, b_commit)); cl_git_pass(git_commit_tree(&b_tree, b_commit));
cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &diff_opts)); cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &diff_opts));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, both_expected, both_expected_cnt); validate_apply_index(repo, both_expected, both_expected_cnt);
validate_apply_workdir(repo, both_expected, both_expected_cnt); validate_apply_workdir(repo, both_expected, both_expected_cnt);
...@@ -69,7 +66,6 @@ void test_apply_both__generated_diff(void) ...@@ -69,7 +66,6 @@ void test_apply_both__generated_diff(void)
void test_apply_both__parsed_diff(void) void test_apply_both__parsed_diff(void)
{ {
git_diff *diff; git_diff *diff;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
struct merge_index_entry both_expected[] = { struct merge_index_entry both_expected[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" }, { 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
...@@ -84,9 +80,7 @@ void test_apply_both__parsed_diff(void) ...@@ -84,9 +80,7 @@ void test_apply_both__parsed_diff(void)
cl_git_pass(git_diff_from_buffer(&diff, cl_git_pass(git_diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES))); DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, both_expected, both_expected_cnt); validate_apply_index(repo, both_expected, both_expected_cnt);
validate_apply_workdir(repo, both_expected, both_expected_cnt); validate_apply_workdir(repo, both_expected, both_expected_cnt);
...@@ -97,7 +91,6 @@ void test_apply_both__parsed_diff(void) ...@@ -97,7 +91,6 @@ void test_apply_both__parsed_diff(void)
void test_apply_both__removes_file(void) void test_apply_both__removes_file(void)
{ {
git_diff *diff; git_diff *diff;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
struct merge_index_entry both_expected[] = { struct merge_index_entry both_expected[] = {
{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" }, { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
...@@ -111,9 +104,7 @@ void test_apply_both__removes_file(void) ...@@ -111,9 +104,7 @@ void test_apply_both__removes_file(void)
cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE, cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
strlen(DIFF_DELETE_FILE))); strlen(DIFF_DELETE_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, both_expected, both_expected_cnt); validate_apply_index(repo, both_expected, both_expected_cnt);
validate_apply_workdir(repo, both_expected, both_expected_cnt); validate_apply_workdir(repo, both_expected, both_expected_cnt);
...@@ -124,7 +115,6 @@ void test_apply_both__removes_file(void) ...@@ -124,7 +115,6 @@ void test_apply_both__removes_file(void)
void test_apply_both__adds_file(void) void test_apply_both__adds_file(void)
{ {
git_diff *diff; git_diff *diff;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
struct merge_index_entry both_expected[] = { struct merge_index_entry both_expected[] = {
{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" }, { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
...@@ -140,9 +130,7 @@ void test_apply_both__adds_file(void) ...@@ -140,9 +130,7 @@ void test_apply_both__adds_file(void)
cl_git_pass(git_diff_from_buffer(&diff, cl_git_pass(git_diff_from_buffer(&diff,
DIFF_ADD_FILE, strlen(DIFF_ADD_FILE))); DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, both_expected, both_expected_cnt); validate_apply_index(repo, both_expected, both_expected_cnt);
validate_apply_workdir(repo, both_expected, both_expected_cnt); validate_apply_workdir(repo, both_expected, both_expected_cnt);
...@@ -154,7 +142,6 @@ void test_apply_both__application_failure_leaves_index_unmodified(void) ...@@ -154,7 +142,6 @@ void test_apply_both__application_failure_leaves_index_unmodified(void)
{ {
git_diff *diff; git_diff *diff;
git_index *index; git_index *index;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -175,9 +162,7 @@ void test_apply_both__application_failure_leaves_index_unmodified(void) ...@@ -175,9 +162,7 @@ void test_apply_both__application_failure_leaves_index_unmodified(void)
git_index_free(index); git_index_free(index);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_workdir_unchanged(repo); validate_workdir_unchanged(repo);
...@@ -190,7 +175,6 @@ void test_apply_both__index_must_match_workdir(void) ...@@ -190,7 +175,6 @@ void test_apply_both__index_must_match_workdir(void)
git_diff *diff; git_diff *diff;
git_index *index; git_index *index;
git_index_entry idx_entry; git_index_entry idx_entry;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -215,9 +199,7 @@ void test_apply_both__index_must_match_workdir(void) ...@@ -215,9 +199,7 @@ void test_apply_both__index_must_match_workdir(void)
git_index_free(index); git_index_free(index);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, &opts));
git_diff_free(diff); git_diff_free(diff);
} }
...@@ -226,7 +208,6 @@ void test_apply_both__application_failure_leaves_workdir_unmodified(void) ...@@ -226,7 +208,6 @@ void test_apply_both__application_failure_leaves_workdir_unmodified(void)
{ {
git_diff *diff; git_diff *diff;
git_index *index; git_index *index;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -251,9 +232,7 @@ void test_apply_both__application_failure_leaves_workdir_unmodified(void) ...@@ -251,9 +232,7 @@ void test_apply_both__application_failure_leaves_workdir_unmodified(void)
git_index_free(index); git_index_free(index);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, &opts));
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -265,7 +244,6 @@ void test_apply_both__keeps_nonconflicting_changes(void) ...@@ -265,7 +244,6 @@ void test_apply_both__keeps_nonconflicting_changes(void)
git_diff *diff; git_diff *diff;
git_index *index; git_index *index;
git_index_entry idx_entry; git_index_entry idx_entry;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -307,9 +285,7 @@ void test_apply_both__keeps_nonconflicting_changes(void) ...@@ -307,9 +285,7 @@ void test_apply_both__keeps_nonconflicting_changes(void)
cl_git_rewritefile("merge-recursive/gravy.txt", "Hello, world.\n"); cl_git_rewritefile("merge-recursive/gravy.txt", "Hello, world.\n");
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -321,7 +297,6 @@ void test_apply_both__can_apply_nonconflicting_file_changes(void) ...@@ -321,7 +297,6 @@ void test_apply_both__can_apply_nonconflicting_file_changes(void)
{ {
git_diff *diff; git_diff *diff;
git_index *index; git_index *index;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -350,9 +325,7 @@ void test_apply_both__can_apply_nonconflicting_file_changes(void) ...@@ -350,9 +325,7 @@ void test_apply_both__can_apply_nonconflicting_file_changes(void)
git_index_free(index); git_index_free(index);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, both_expected, both_expected_cnt); validate_apply_index(repo, both_expected, both_expected_cnt);
validate_apply_workdir(repo, both_expected, both_expected_cnt); validate_apply_workdir(repo, both_expected, both_expected_cnt);
...@@ -365,7 +338,6 @@ void test_apply_both__honors_crlf_attributes(void) ...@@ -365,7 +338,6 @@ void test_apply_both__honors_crlf_attributes(void)
git_diff *diff; git_diff *diff;
git_oid oid; git_oid oid;
git_commit *commit; git_commit *commit;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -403,9 +375,7 @@ void test_apply_both__honors_crlf_attributes(void) ...@@ -403,9 +375,7 @@ void test_apply_both__honors_crlf_attributes(void)
git_commit_free(commit); git_commit_free(commit);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_BOTH, NULL));
opts.location = GIT_APPLY_LOCATION_BOTH;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
......
...@@ -30,7 +30,6 @@ void test_apply_index__generate_diff(void) ...@@ -30,7 +30,6 @@ void test_apply_index__generate_diff(void)
git_tree *a_tree, *b_tree; git_tree *a_tree, *b_tree;
git_diff *diff; git_diff *diff;
git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT; git_diff_options diff_opts = GIT_DIFF_OPTIONS_INIT;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
struct merge_index_entry index_expected[] = { struct merge_index_entry index_expected[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" }, { 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
...@@ -52,9 +51,7 @@ void test_apply_index__generate_diff(void) ...@@ -52,9 +51,7 @@ void test_apply_index__generate_diff(void)
cl_git_pass(git_commit_tree(&b_tree, b_commit)); cl_git_pass(git_commit_tree(&b_tree, b_commit));
cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &diff_opts)); cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &diff_opts));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_workdir_unchanged(repo); validate_workdir_unchanged(repo);
...@@ -69,7 +66,6 @@ void test_apply_index__generate_diff(void) ...@@ -69,7 +66,6 @@ void test_apply_index__generate_diff(void)
void test_apply_index__parsed_diff(void) void test_apply_index__parsed_diff(void)
{ {
git_diff *diff; git_diff *diff;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
struct merge_index_entry index_expected[] = { struct merge_index_entry index_expected[] = {
{ 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" }, { 0100644, "ffb36e513f5fdf8a6ba850a20142676a2ac4807d", 0, "asparagus.txt" },
...@@ -84,9 +80,7 @@ void test_apply_index__parsed_diff(void) ...@@ -84,9 +80,7 @@ void test_apply_index__parsed_diff(void)
cl_git_pass(git_diff_from_buffer(&diff, cl_git_pass(git_diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES))); DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_workdir_unchanged(repo); validate_workdir_unchanged(repo);
...@@ -97,7 +91,6 @@ void test_apply_index__parsed_diff(void) ...@@ -97,7 +91,6 @@ void test_apply_index__parsed_diff(void)
void test_apply_index__removes_file(void) void test_apply_index__removes_file(void)
{ {
git_diff *diff; git_diff *diff;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
struct merge_index_entry index_expected[] = { struct merge_index_entry index_expected[] = {
{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" }, { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
...@@ -111,9 +104,7 @@ void test_apply_index__removes_file(void) ...@@ -111,9 +104,7 @@ void test_apply_index__removes_file(void)
cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE, cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
strlen(DIFF_DELETE_FILE))); strlen(DIFF_DELETE_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_workdir_unchanged(repo); validate_workdir_unchanged(repo);
...@@ -124,7 +115,6 @@ void test_apply_index__removes_file(void) ...@@ -124,7 +115,6 @@ void test_apply_index__removes_file(void)
void test_apply_index__adds_file(void) void test_apply_index__adds_file(void)
{ {
git_diff *diff; git_diff *diff;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
struct merge_index_entry index_expected[] = { struct merge_index_entry index_expected[] = {
{ 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" }, { 0100644, "f51658077d85f2264fa179b4d0848268cb3475c3", 0, "asparagus.txt" },
...@@ -140,9 +130,7 @@ void test_apply_index__adds_file(void) ...@@ -140,9 +130,7 @@ void test_apply_index__adds_file(void)
cl_git_pass(git_diff_from_buffer(&diff, cl_git_pass(git_diff_from_buffer(&diff,
DIFF_ADD_FILE, strlen(DIFF_ADD_FILE))); DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_workdir_unchanged(repo); validate_workdir_unchanged(repo);
...@@ -153,7 +141,6 @@ void test_apply_index__adds_file(void) ...@@ -153,7 +141,6 @@ void test_apply_index__adds_file(void)
void test_apply_index__modified_workdir_with_unmodified_index_is_ok(void) void test_apply_index__modified_workdir_with_unmodified_index_is_ok(void)
{ {
git_diff *diff; git_diff *diff;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -183,9 +170,7 @@ void test_apply_index__modified_workdir_with_unmodified_index_is_ok(void) ...@@ -183,9 +170,7 @@ void test_apply_index__modified_workdir_with_unmodified_index_is_ok(void)
cl_git_rewritefile("merge-recursive/veal.txt", "Hello, world.\n"); cl_git_rewritefile("merge-recursive/veal.txt", "Hello, world.\n");
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -197,7 +182,6 @@ void test_apply_index__application_failure_leaves_index_unmodified(void) ...@@ -197,7 +182,6 @@ void test_apply_index__application_failure_leaves_index_unmodified(void)
{ {
git_diff *diff; git_diff *diff;
git_index *index; git_index *index;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -218,9 +202,7 @@ void test_apply_index__application_failure_leaves_index_unmodified(void) ...@@ -218,9 +202,7 @@ void test_apply_index__application_failure_leaves_index_unmodified(void)
git_index_free(index); git_index_free(index);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
...@@ -232,7 +214,6 @@ void test_apply_index__keeps_nonconflicting_changes(void) ...@@ -232,7 +214,6 @@ void test_apply_index__keeps_nonconflicting_changes(void)
git_diff *diff; git_diff *diff;
git_index *index; git_index *index;
git_index_entry idx_entry; git_index_entry idx_entry;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -260,9 +241,7 @@ void test_apply_index__keeps_nonconflicting_changes(void) ...@@ -260,9 +241,7 @@ void test_apply_index__keeps_nonconflicting_changes(void)
git_index_free(index); git_index_free(index);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_workdir_unchanged(repo); validate_workdir_unchanged(repo);
...@@ -275,7 +254,6 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void) ...@@ -275,7 +254,6 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void)
git_diff *diff; git_diff *diff;
git_index *index; git_index *index;
git_index_entry idx_entry; git_index_entry idx_entry;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_MODIFY_TWO_FILES; const char *diff_file = DIFF_MODIFY_TWO_FILES;
...@@ -308,9 +286,7 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void) ...@@ -308,9 +286,7 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void)
git_index_free(index); git_index_free(index);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_workdir_unchanged(repo); validate_workdir_unchanged(repo);
...@@ -321,7 +297,6 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void) ...@@ -321,7 +297,6 @@ void test_apply_index__can_apply_nonconflicting_file_changes(void)
void test_apply_index__change_mode(void) void test_apply_index__change_mode(void)
{ {
git_diff *diff; git_diff *diff;
git_apply_options opts = GIT_APPLY_OPTIONS_INIT;
const char *diff_file = DIFF_EXECUTABLE_FILE; const char *diff_file = DIFF_EXECUTABLE_FILE;
...@@ -337,9 +312,7 @@ void test_apply_index__change_mode(void) ...@@ -337,9 +312,7 @@ void test_apply_index__change_mode(void)
sizeof(struct merge_index_entry); sizeof(struct merge_index_entry);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_INDEX, NULL));
opts.location = GIT_APPLY_LOCATION_INDEX;
cl_git_pass(git_apply(repo, diff, &opts));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_workdir_unchanged(repo); validate_workdir_unchanged(repo);
......
...@@ -45,7 +45,7 @@ void test_apply_tree__one(void) ...@@ -45,7 +45,7 @@ void test_apply_tree__one(void)
cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &opts)); cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &opts));
cl_git_pass(git_apply_to_tree(&index, repo, a_tree, diff)); cl_git_pass(git_apply_to_tree(&index, repo, a_tree, diff, NULL));
merge_test_index(index, expected, 6); merge_test_index(index, expected, 6);
git_index_free(index); git_index_free(index);
......
...@@ -50,8 +50,7 @@ void test_apply_workdir__generated_diff(void) ...@@ -50,8 +50,7 @@ void test_apply_workdir__generated_diff(void)
cl_git_pass(git_commit_tree(&b_tree, b_commit)); cl_git_pass(git_commit_tree(&b_tree, b_commit));
cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &opts)); cl_git_pass(git_diff_tree_to_tree(&diff, repo, a_tree, b_tree, &opts));
cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
cl_git_pass(git_apply(repo, diff, NULL));
validate_index_unchanged(repo); validate_index_unchanged(repo);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -80,7 +79,7 @@ void test_apply_workdir__parsed_diff(void) ...@@ -80,7 +79,7 @@ void test_apply_workdir__parsed_diff(void)
cl_git_pass(git_diff_from_buffer(&diff, cl_git_pass(git_diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES))); DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, NULL)); cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_index_unchanged(repo); validate_index_unchanged(repo);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -104,7 +103,7 @@ void test_apply_workdir__removes_file(void) ...@@ -104,7 +103,7 @@ void test_apply_workdir__removes_file(void)
cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE, cl_git_pass(git_diff_from_buffer(&diff, DIFF_DELETE_FILE,
strlen(DIFF_DELETE_FILE))); strlen(DIFF_DELETE_FILE)));
cl_git_pass(git_apply(repo, diff, NULL)); cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_index_unchanged(repo); validate_index_unchanged(repo);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -130,7 +129,7 @@ void test_apply_workdir__adds_file(void) ...@@ -130,7 +129,7 @@ void test_apply_workdir__adds_file(void)
cl_git_pass(git_diff_from_buffer(&diff, cl_git_pass(git_diff_from_buffer(&diff,
DIFF_ADD_FILE, strlen(DIFF_ADD_FILE))); DIFF_ADD_FILE, strlen(DIFF_ADD_FILE)));
cl_git_pass(git_apply(repo, diff, NULL)); cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_index_unchanged(repo); validate_index_unchanged(repo);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -179,7 +178,7 @@ void test_apply_workdir__modified_index_with_unmodified_workdir_is_ok(void) ...@@ -179,7 +178,7 @@ void test_apply_workdir__modified_index_with_unmodified_workdir_is_ok(void)
cl_git_pass(git_index_write(index)); cl_git_pass(git_index_write(index));
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, NULL)); cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_apply_index(repo, index_expected, index_expected_cnt); validate_apply_index(repo, index_expected, index_expected_cnt);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -210,7 +209,7 @@ void test_apply_workdir__application_failure_leaves_workdir_unmodified(void) ...@@ -210,7 +209,7 @@ void test_apply_workdir__application_failure_leaves_workdir_unmodified(void)
"This is a modification.\n"); "This is a modification.\n");
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, NULL)); cl_git_fail_with(GIT_EAPPLYFAIL, git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -236,7 +235,7 @@ void test_apply_workdir__keeps_nonconflicting_changes(void) ...@@ -236,7 +235,7 @@ void test_apply_workdir__keeps_nonconflicting_changes(void)
cl_git_pass(git_diff_from_buffer(&diff, cl_git_pass(git_diff_from_buffer(&diff,
DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES))); DIFF_MODIFY_TWO_FILES, strlen(DIFF_MODIFY_TWO_FILES)));
cl_git_pass(git_apply(repo, diff, NULL)); cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_index_unchanged(repo); validate_index_unchanged(repo);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -270,7 +269,7 @@ void test_apply_workdir__can_apply_nonconflicting_file_changes(void) ...@@ -270,7 +269,7 @@ void test_apply_workdir__can_apply_nonconflicting_file_changes(void)
"This line is added in the workdir.\n"); "This line is added in the workdir.\n");
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, NULL)); cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_index_unchanged(repo); validate_index_unchanged(repo);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
...@@ -297,7 +296,7 @@ void test_apply_workdir__change_mode(void) ...@@ -297,7 +296,7 @@ void test_apply_workdir__change_mode(void)
sizeof(struct merge_index_entry); sizeof(struct merge_index_entry);
cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file))); cl_git_pass(git_diff_from_buffer(&diff, diff_file, strlen(diff_file)));
cl_git_pass(git_apply(repo, diff, NULL)); cl_git_pass(git_apply(repo, diff, GIT_APPLY_LOCATION_WORKDIR, NULL));
validate_index_unchanged(repo); validate_index_unchanged(repo);
validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt); validate_apply_workdir(repo, workdir_expected, workdir_expected_cnt);
......
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