Commit d9fdee6e by Edward Thomson

Remove `git_merge_result` as it's now unnecessary

parent 5aa2ac6d
......@@ -472,27 +472,11 @@ GIT_EXTERN(int) git_merge_commits(
const git_merge_options *opts);
/**
* Merges the given commit(s) into HEAD and either returns immediately
* if there was no merge to perform (the specified commits have already
* been merged or would produce a fast-forward) or performs the merge
* and writes the results into the working directory.
* Merges the given commit(s) into HEAD, writing the results into the working
* directory. Any changes are staged for commit and any conflicts are written
* to the index. Callers should inspect the repository's index after this
* completes, resolve any conflicts and prepare a commit.
*
* Callers should inspect the `git_merge_result`:
*
* If `git_merge_result_is_uptodate` is true, there is no work to perform.
*
* If `git_merge_result_is_fastforward` is true, the caller should update
* any necessary references to the commit ID returned by
* `git_merge_result_fastforward_id` and check that out in order to complete
* the fast-forward.
*
* Otherwise, callers should inspect the resulting index, resolve any
* conflicts and prepare a commit.
*
* The resultant `git_merge_result` should be free with
* `git_merge_result_free`.
*
* @param out the results of the merge
* @param repo the repository to merge
* @param merge_heads the heads to merge into
* @param merge_heads_len the number of heads to merge
......@@ -501,52 +485,12 @@ GIT_EXTERN(int) git_merge_commits(
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge(
git_merge_result **out,
git_repository *repo,
const git_merge_head **their_heads,
size_t their_heads_len,
const git_merge_options *merge_opts,
const git_checkout_options *checkout_opts);
/**
* Returns true if a merge is "up-to-date", meaning that the commit(s)
* that were provided to `git_merge` are already included in `HEAD`
* and there is no work to do.
*
* @return true if the merge is up-to-date, false otherwise
*/
GIT_EXTERN(int) git_merge_result_is_uptodate(git_merge_result *merge_result);
/**
* Returns true if a merge is eligible to be "fast-forwarded", meaning that
* the commit that was provided to `git_merge` need not be merged, it can
* simply be checked out, because the current `HEAD` is the merge base of
* itself and the given commit. To perform the fast-forward, the caller
* should check out the results of `git_merge_result_fastforward_id`.
*
* This will never be true if `GIT_MERGE_NO_FASTFORWARD` is supplied as
* a merge option.
*
* @return true if the merge is fast-forwardable, false otherwise
*/
GIT_EXTERN(int) git_merge_result_is_fastforward(git_merge_result *merge_result);
/**
* Gets the fast-forward OID if the merge was a fastforward.
*
* @param out pointer to populate with the OID of the fast-forward
* @param merge_result the results of the merge
* @return 0 on success or error code
*/
GIT_EXTERN(int) git_merge_result_fastforward_id(git_oid *out, git_merge_result *merge_result);
/**
* Frees a `git_merge_result`.
*
* @param result merge result to free
*/
GIT_EXTERN(void) git_merge_result_free(git_merge_result *merge_result);
/** @} */
GIT_END_DECL
#endif
......@@ -2548,14 +2548,12 @@ done:
}
int git_merge(
git_merge_result **out,
git_repository *repo,
const git_merge_head **their_heads,
size_t their_heads_len,
const git_merge_options *merge_opts,
const git_checkout_options *given_checkout_opts)
{
git_merge_result *result;
git_reference *our_ref = NULL;
git_checkout_options checkout_opts;
git_merge_head *ancestor_head = NULL, *our_head = NULL;
......@@ -2564,18 +2562,13 @@ int git_merge(
size_t i;
int error = 0;
assert(out && repo && their_heads);
*out = NULL;
assert(repo && their_heads);
if (their_heads_len != 1) {
giterr_set(GITERR_MERGE, "Can only merge a single branch");
return -1;
}
result = git__calloc(1, sizeof(git_merge_result));
GITERR_CHECK_ALLOC(result);
their_trees = git__calloc(their_heads_len, sizeof(git_tree *));
GITERR_CHECK_ALLOC(their_trees);
......@@ -2610,16 +2603,12 @@ int git_merge(
(error = git_checkout_index(repo, index_repo, &checkout_opts)) < 0)
goto on_error;
result->index = index_new;
*out = result;
goto done;
on_error:
merge_state_cleanup(repo);
git_index_free(index_new);
git__free(result);
done:
git_index_free(index_repo);
......@@ -2640,41 +2629,6 @@ done:
return error;
}
/* Merge result data */
int git_merge_result_is_uptodate(git_merge_result *merge_result)
{
assert(merge_result);
return merge_result->is_uptodate;
}
int git_merge_result_is_fastforward(git_merge_result *merge_result)
{
assert(merge_result);
return merge_result->is_fastforward;
}
int git_merge_result_fastforward_id(git_oid *out, git_merge_result *merge_result)
{
assert(out && merge_result);
git_oid_cpy(out, &merge_result->fastforward_oid);
return 0;
}
void git_merge_result_free(git_merge_result *merge_result)
{
if (merge_result == NULL)
return;
git_index_free(merge_result->index);
merge_result->index = NULL;
git__free(merge_result);
}
/* Merge heads are the input to merge */
static int merge_head_init(
......
......@@ -120,16 +120,6 @@ struct git_merge_head {
git_commit *commit;
};
/** Internal structure for merge results */
struct git_merge_result {
bool is_uptodate;
bool is_fastforward;
git_oid fastforward_oid;
git_index *index;
};
int git_merge__bases_many(
git_commit_list **out,
git_revwalk *walk,
......
......@@ -79,7 +79,7 @@ int merge_commits_from_branches(
return 0;
}
int merge_branches(git_merge_result **result, git_repository *repo,
int merge_branches(git_repository *repo,
const char *ours_branch, const char *theirs_branch,
git_merge_options *merge_opts, git_checkout_options *checkout_opts)
{
......@@ -95,7 +95,7 @@ int merge_branches(git_merge_result **result, git_repository *repo,
cl_git_pass(git_reference_lookup(&theirs_ref, repo, theirs_branch));
cl_git_pass(git_merge_head_from_ref(&theirs_head, repo, theirs_ref));
cl_git_pass(git_merge(result, repo, (const git_merge_head **)&theirs_head, 1, merge_opts, checkout_opts));
cl_git_pass(git_merge(repo, (const git_merge_head **)&theirs_head, 1, merge_opts, checkout_opts));
git_reference_free(head_ref);
git_reference_free(theirs_ref);
......
......@@ -92,7 +92,7 @@ int merge_commits_from_branches(
const char *ours_name, const char *theirs_name,
git_merge_options *opts);
int merge_branches(git_merge_result **result, git_repository *repo,
int merge_branches(git_repository *repo,
const char *ours_branch, const char *theirs_branch,
git_merge_options *merge_opts, git_checkout_options *checkout_opts);
......
......@@ -86,7 +86,7 @@ static void set_core_autocrlf_to(git_repository *repo, bool value)
git_config_free(cfg);
}
static int merge_branch(git_merge_result **result, int merge_file_favor, int checkout_strategy)
static int merge_branch(int merge_file_favor, int checkout_strategy)
{
git_oid their_oids[1];
git_merge_head *their_heads[1];
......@@ -99,7 +99,7 @@ static int merge_branch(git_merge_result **result, int merge_file_favor, int che
merge_opts.file_favor = merge_file_favor;
checkout_opts.checkout_strategy = checkout_strategy;
error = git_merge(result, repo, (const git_merge_head **)their_heads, 1, &merge_opts, &checkout_opts);
error = git_merge(repo, (const git_merge_head **)their_heads, 1, &merge_opts, &checkout_opts);
git_merge_head_free(their_heads[0]);
......@@ -177,7 +177,6 @@ static void stage_content(char *content[])
{
git_reference *head;
git_object *head_object;
git_merge_result *result = NULL;
git_buf path = GIT_BUF_INIT;
char *filename, *text;
size_t i;
......@@ -198,7 +197,6 @@ static void stage_content(char *content[])
cl_git_pass(git_index_add_bypath(repo_index, filename));
}
git_merge_result_free(result);
git_object_free(head_object);
git_reference_free(head);
git_buf_free(&path);
......@@ -208,7 +206,6 @@ static int merge_dirty_files(char *dirty_files[])
{
git_reference *head;
git_object *head_object;
git_merge_result *result = NULL;
int error;
cl_git_pass(git_repository_head(&head, repo));
......@@ -217,9 +214,8 @@ static int merge_dirty_files(char *dirty_files[])
write_files(dirty_files);
error = merge_branch(&result, 0, 0);
error = merge_branch(0, 0);
git_merge_result_free(result);
git_object_free(head_object);
git_reference_free(head);
......@@ -230,7 +226,6 @@ static int merge_differently_filtered_files(char *files[])
{
git_reference *head;
git_object *head_object;
git_merge_result *result = NULL;
int error;
cl_git_pass(git_repository_head(&head, repo));
......@@ -242,9 +237,8 @@ static int merge_differently_filtered_files(char *files[])
cl_git_pass(git_index_write(repo_index));
error = merge_branch(&result, 0, 0);
error = merge_branch(0, 0);
git_merge_result_free(result);
git_object_free(head_object);
git_reference_free(head);
......@@ -253,16 +247,8 @@ static int merge_differently_filtered_files(char *files[])
static int merge_staged_files(char *staged_files[])
{
git_merge_result *result = NULL;
int error;
stage_random_files(staged_files);
error = merge_branch(&result, 0, 0);
git_merge_result_free(result);
return error;
return merge_branch(0, 0);
}
void test_merge_workdir_dirty__unaffected_dirty_files_allowed(void)
......@@ -297,7 +283,6 @@ void test_merge_workdir_dirty__staged_files_in_index_disallowed(void)
void test_merge_workdir_dirty__identical_staged_files_allowed(void)
{
git_merge_result *result;
char **content;
size_t i;
......@@ -307,9 +292,7 @@ void test_merge_workdir_dirty__identical_staged_files_allowed(void)
stage_content(content);
git_index_write(repo_index);
cl_git_pass(merge_branch(&result, 0, 0));
git_merge_result_free(result);
cl_git_pass(merge_branch(0, 0));
}
}
......
......@@ -34,7 +34,6 @@ void test_merge_workdir_renames__cleanup(void)
void test_merge_workdir_renames__renames(void)
{
git_merge_result *result;
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
struct merge_index_entry merge_index_entries[] = {
......@@ -67,16 +66,13 @@ void test_merge_workdir_renames__renames(void)
merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
merge_opts.rename_threshold = 50;
cl_git_pass(merge_branches(&result, repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, NULL));
cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, NULL));
cl_assert(merge_test_workdir(repo, merge_index_entries, 24));
git_merge_result_free(result);
}
void test_merge_workdir_renames__ours(void)
{
git_index *index;
git_merge_result *result;
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
......@@ -107,18 +103,16 @@ void test_merge_workdir_renames__ours(void)
merge_opts.rename_threshold = 50;
checkout_opts.checkout_strategy = GIT_CHECKOUT_SAFE | GIT_CHECKOUT_USE_OURS;
cl_git_pass(merge_branches(&result, repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, &checkout_opts));
cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, &checkout_opts));
cl_git_pass(git_repository_index(&index, repo));
cl_git_pass(git_index_write(index));
cl_assert(merge_test_workdir(repo, merge_index_entries, 20));
git_merge_result_free(result);
git_index_free(index);
}
void test_merge_workdir_renames__similar(void)
{
git_merge_result *result;
git_merge_options merge_opts = GIT_MERGE_OPTIONS_INIT;
/*
......@@ -156,9 +150,7 @@ void test_merge_workdir_renames__similar(void)
merge_opts.flags |= GIT_MERGE_TREE_FIND_RENAMES;
merge_opts.rename_threshold = 50;
cl_git_pass(merge_branches(&result, repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, NULL));
cl_git_pass(merge_branches(repo, GIT_REFS_HEADS_DIR BRANCH_RENAME_OURS, GIT_REFS_HEADS_DIR BRANCH_RENAME_THEIRS, &merge_opts, NULL));
cl_assert(merge_test_workdir(repo, merge_index_entries, 24));
git_merge_result_free(result);
}
......@@ -970,7 +970,6 @@ void test_merge_workdir_setup__retained_after_success(void)
git_oid our_oid;
git_reference *octo1_ref;
git_merge_head *our_head, *their_heads[1];
git_merge_result *result;
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_merge_head_from_id(&our_head, repo, &our_oid));
......@@ -979,7 +978,7 @@ void test_merge_workdir_setup__retained_after_success(void)
cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, octo1_ref));
cl_git_pass(git_merge(&result, repo, (const git_merge_head **)&their_heads[0], 1, NULL, NULL));
cl_git_pass(git_merge(repo, (const git_merge_head **)&their_heads[0], 1, NULL, NULL));
cl_assert(test_file_contents(GIT_MERGE_HEAD_FILE, OCTO1_OID "\n"));
cl_assert(test_file_contents(GIT_ORIG_HEAD_FILE, ORIG_HEAD "\n"));
......@@ -990,7 +989,6 @@ void test_merge_workdir_setup__retained_after_success(void)
git_merge_head_free(our_head);
git_merge_head_free(their_heads[0]);
git_merge_result_free(result);
}
void test_merge_workdir_setup__removed_after_failure(void)
......@@ -998,7 +996,6 @@ void test_merge_workdir_setup__removed_after_failure(void)
git_oid our_oid;
git_reference *octo1_ref;
git_merge_head *our_head, *their_heads[1];
git_merge_result *result;
cl_git_pass(git_oid_fromstr(&our_oid, ORIG_HEAD));
cl_git_pass(git_merge_head_from_id(&our_head, repo, &our_oid));
......@@ -1010,7 +1007,7 @@ void test_merge_workdir_setup__removed_after_failure(void)
"Conflicting file!\n\nMerge will fail!\n");
cl_git_fail(git_merge(
&result, repo, (const git_merge_head **)&their_heads[0], 1, NULL, NULL));
repo, (const git_merge_head **)&their_heads[0], 1, NULL, NULL));
cl_assert(!git_path_exists("merge-resolve/" GIT_MERGE_HEAD_FILE));
cl_assert(!git_path_exists("merge-resolve/" GIT_ORIG_HEAD_FILE));
......@@ -1021,5 +1018,4 @@ void test_merge_workdir_setup__removed_after_failure(void)
git_merge_head_free(our_head);
git_merge_head_free(their_heads[0]);
git_merge_result_free(result);
}
......@@ -31,7 +31,6 @@ void test_merge_workdir_submodules__automerge(void)
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_merge_head *their_head;
git_merge_result *result;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
......@@ -50,13 +49,12 @@ void test_merge_workdir_submodules__automerge(void)
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge(&result, repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_merge(repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 6));
git_index_free(index);
git_merge_result_free(result);
git_merge_head_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
......@@ -68,7 +66,6 @@ void test_merge_workdir_submodules__take_changed(void)
git_reference *our_ref, *their_ref;
git_commit *our_commit;
git_merge_head *their_head;
git_merge_result *result;
git_index *index;
struct merge_index_entry merge_index_entries[] = {
......@@ -85,13 +82,12 @@ void test_merge_workdir_submodules__take_changed(void)
cl_git_pass(git_reference_lookup(&their_ref, repo, "refs/heads/" SUBMODULE_OTHER2_BRANCH));
cl_git_pass(git_merge_head_from_ref(&their_head, repo, their_ref));
cl_git_pass(git_merge(&result, repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_merge(repo, (const git_merge_head **)&their_head, 1, NULL, NULL));
cl_git_pass(git_repository_index(&index, repo));
cl_assert(merge_test_index(index, merge_index_entries, 4));
git_index_free(index);
git_merge_result_free(result);
git_merge_head_free(their_head);
git_commit_free(our_commit);
git_reference_free(their_ref);
......
......@@ -34,7 +34,6 @@ static int merge_trivial(const char *ours, const char *theirs)
git_checkout_options checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
git_reference *our_ref, *their_ref;
git_merge_head *their_heads[1];
git_merge_result *result;
checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
......@@ -48,13 +47,12 @@ static int merge_trivial(const char *ours, const char *theirs)
cl_git_pass(git_reference_lookup(&their_ref, repo, branch_buf.ptr));
cl_git_pass(git_merge_head_from_ref(&their_heads[0], repo, their_ref));
cl_git_pass(git_merge(&result, repo, (const git_merge_head **)their_heads, 1, NULL, NULL));
cl_git_pass(git_merge(repo, (const git_merge_head **)their_heads, 1, NULL, NULL));
git_buf_free(&branch_buf);
git_reference_free(our_ref);
git_reference_free(their_ref);
git_merge_head_free(their_heads[0]);
git_merge_result_free(result);
return 0;
}
......
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