dir.h: move DTYPE defines from cache.h
[git.git] / merge-ort-wrappers.c
blobc00dfbab1cde5fc39916e243aca2ba67b1be62f8
1 #include "cache.h"
2 #include "gettext.h"
3 #include "merge-ort.h"
4 #include "merge-ort-wrappers.h"
6 #include "commit.h"
8 static int unclean(struct merge_options *opt, struct tree *head)
10 /* Sanity check on repo state; index must match head */
11 struct strbuf sb = STRBUF_INIT;
13 if (head && repo_index_has_changes(opt->repo, head, &sb)) {
14 error(_("Your local changes to the following files would be overwritten by merge:\n %s"),
15 sb.buf);
16 strbuf_release(&sb);
17 return -1;
20 return 0;
23 int merge_ort_nonrecursive(struct merge_options *opt,
24 struct tree *head,
25 struct tree *merge,
26 struct tree *merge_base)
28 struct merge_result result;
30 if (unclean(opt, head))
31 return -1;
33 if (oideq(&merge_base->object.oid, &merge->object.oid)) {
34 printf_ln(_("Already up to date."));
35 return 1;
38 memset(&result, 0, sizeof(result));
39 merge_incore_nonrecursive(opt, merge_base, head, merge, &result);
40 merge_switch_to_result(opt, head, &result, 1, 1);
42 return result.clean;
45 int merge_ort_recursive(struct merge_options *opt,
46 struct commit *side1,
47 struct commit *side2,
48 struct commit_list *merge_bases,
49 struct commit **result)
51 struct tree *head = repo_get_commit_tree(opt->repo, side1);
52 struct merge_result tmp;
54 if (unclean(opt, head))
55 return -1;
57 memset(&tmp, 0, sizeof(tmp));
58 merge_incore_recursive(opt, merge_bases, side1, side2, &tmp);
59 merge_switch_to_result(opt, head, &tmp, 1, 1);
60 *result = NULL;
62 return tmp.clean;