#include "clar_libgit2.h"
-#include "fileops.h"
+#include "futils.h"
#include "refs.h"
#include "tree.h"
#include "merge_helpers.h"
#include "merge.h"
+#include "index.h"
#include "git2/merge.h"
#include "git2/sys/index.h"
+#include "git2/annotated_commit.h"
int merge_trees_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
- git_merge_tree_opts *opts)
+ git_merge_options *opts)
{
git_commit *our_commit, *their_commit, *ancestor_commit = NULL;
git_tree *our_tree, *their_tree, *ancestor_tree = NULL;
git_oid our_oid, their_oid, ancestor_oid;
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
int error;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
cl_git_pass(git_commit_tree(&our_tree, our_commit));
cl_git_pass(git_commit_tree(&their_tree, their_commit));
- cl_git_pass(git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, opts));
+ error = git_merge_trees(index, repo, ancestor_tree, our_tree, their_tree, opts);
- git_buf_free(&branch_buf);
+ git_str_dispose(&branch_buf);
git_tree_free(our_tree);
git_tree_free(their_tree);
git_tree_free(ancestor_tree);
git_commit_free(their_commit);
git_commit_free(ancestor_commit);
- return 0;
+ return error;
}
int merge_commits_from_branches(
git_index **index, git_repository *repo,
const char *ours_name, const char *theirs_name,
- git_merge_tree_opts *opts)
+ git_merge_options *opts)
{
git_commit *our_commit, *their_commit;
git_oid our_oid, their_oid;
- git_buf branch_buf = GIT_BUF_INIT;
+ git_str branch_buf = GIT_STR_INIT;
+ int error;
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, ours_name);
cl_git_pass(git_reference_name_to_id(&our_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&our_commit, repo, &our_oid));
- git_buf_clear(&branch_buf);
- git_buf_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
+ git_str_clear(&branch_buf);
+ git_str_printf(&branch_buf, "%s%s", GIT_REFS_HEADS_DIR, theirs_name);
cl_git_pass(git_reference_name_to_id(&their_oid, repo, branch_buf.ptr));
cl_git_pass(git_commit_lookup(&their_commit, repo, &their_oid));
- cl_git_pass(git_merge_commits(index, repo, our_commit, their_commit, opts));
+ error = git_merge_commits(index, repo, our_commit, their_commit, opts);
- git_buf_free(&branch_buf);
+ git_str_dispose(&branch_buf);
git_commit_free(our_commit);
git_commit_free(their_commit);
- return 0;
+ return error;
}
-int merge_branches(git_merge_result **result, git_repository *repo, const char *ours_branch, const char *theirs_branch, git_merge_opts *opts)
+int merge_branches(git_repository *repo,
+ const char *ours_branch, const char *theirs_branch,
+ git_merge_options *merge_opts, git_checkout_options *checkout_opts)
{
git_reference *head_ref, *theirs_ref;
- git_merge_head *theirs_head;
- git_checkout_opts head_checkout_opts = GIT_CHECKOUT_OPTS_INIT;
+ git_annotated_commit *theirs_head;
+ git_checkout_options head_checkout_opts = GIT_CHECKOUT_OPTIONS_INIT;
head_checkout_opts.checkout_strategy = GIT_CHECKOUT_FORCE;
- cl_git_pass(git_reference_symbolic_create(&head_ref, repo, "HEAD", ours_branch, 1));
+ cl_git_pass(git_reference_symbolic_create(&head_ref, repo, "HEAD", ours_branch, 1, NULL));
cl_git_pass(git_checkout_head(repo, &head_checkout_opts));
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_annotated_commit_from_ref(&theirs_head, repo, theirs_ref));
- cl_git_pass(git_merge(result, repo, (const git_merge_head **)&theirs_head, 1, opts));
+ cl_git_pass(git_merge(repo, (const git_annotated_commit **)&theirs_head, 1, merge_opts, checkout_opts));
git_reference_free(head_ref);
git_reference_free(theirs_ref);
- git_merge_head_free(theirs_head);
+ git_annotated_commit_free(theirs_head);
return 0;
}
size_t i;
const git_index_entry *index_entry;
- printf ("\nINDEX [%d]:\n", (int)index_entries->length);
+ printf ("\nINDEX [%"PRIuZ"]:\n", index_entries->length);
for (i = 0; i < index_entries->length; i++) {
index_entry = index_entries->contents[i];
printf("%o ", index_entry->mode);
- printf("%s ", git_oid_allocfmt(&index_entry->oid));
+ printf("%s ", git_oid_allocfmt(&index_entry->id));
printf("%d ", git_index_entry_stage(index_entry));
printf("%s ", index_entry->path);
printf("\n");
test_oid = 0;
if (actual->mode != expected->mode ||
- (test_oid && git_oid_cmp(&actual->oid, &expected_oid) != 0) ||
+ (test_oid && git_oid_cmp(&actual->id, &expected_oid) != 0) ||
git_index_entry_stage(actual) != expected->stage)
return 0;
const git_index_entry *index_entry;
/*
- dump_index_entries(&index->entries);
+ merge__dump_index_entries(&index->entries);
*/
if (git_index_entrycount(index) != expected_len)
return 1;
}
-int dircount(void *payload, git_buf *pathbuf)
+static int dircount(void *payload, git_str *pathbuf)
{
- int *entries = payload;
- size_t len = git_buf_len(pathbuf);
+ size_t *entries = payload;
+ size_t len = git_str_len(pathbuf);
- if (len < 5 || strcmp(pathbuf->ptr + (git_buf_len(pathbuf) - 5), "/.git") != 0)
+ if (len < 5 || strcmp(pathbuf->ptr + (git_str_len(pathbuf) - 5), "/.git") != 0)
(*entries)++;
return 0;
{
size_t actual_len = 0, i;
git_oid actual_oid, expected_oid;
- git_buf wd = GIT_BUF_INIT;
+ git_str wd = GIT_STR_INIT;
- git_buf_puts(&wd, repo->workdir);
- git_path_direach(&wd, 0, dircount, &actual_len);
+ git_str_puts(&wd, repo->workdir);
+ git_fs_path_direach(&wd, 0, dircount, &actual_len);
if (actual_len != expected_len)
return 0;
for (i = 0; i < expected_len; i++) {
- git_blob_create_fromworkdir(&actual_oid, repo, expected[i].path);
+ git_blob_create_from_workdir(&actual_oid, repo, expected[i].path);
git_oid_fromstr(&expected_oid, expected[i].oid_str);
if (git_oid_cmp(&actual_oid, &expected_oid) != 0)
return 0;
}
- git_buf_free(&wd);
+ git_str_dispose(&wd);
return 1;
}