Merge branch 'fc/doc-drop-custom-callout-format'
[alt-git.git] / merge-ort-wrappers.c
bloba5507533009abca90617b388f93a7e335049eb16
1 #include "cache.h"
2 #include "gettext.h"
3 #include "hash.h"
4 #include "merge-ort.h"
5 #include "merge-ort-wrappers.h"
6 #include "tree.h"
8 #include "commit.h"
10 static int unclean(struct merge_options *opt, struct tree *head)
12 /* Sanity check on repo state; index must match head */
13 struct strbuf sb = STRBUF_INIT;
15 if (head && repo_index_has_changes(opt->repo, head, &sb)) {
16 error(_("Your local changes to the following files would be overwritten by merge:\n %s"),
17 sb.buf);
18 strbuf_release(&sb);
19 return -1;
22 return 0;
25 int merge_ort_nonrecursive(struct merge_options *opt,
26 struct tree *head,
27 struct tree *merge,
28 struct tree *merge_base)
30 struct merge_result result;
32 if (unclean(opt, head))
33 return -1;
35 if (oideq(&merge_base->object.oid, &merge->object.oid)) {
36 printf_ln(_("Already up to date."));
37 return 1;
40 memset(&result, 0, sizeof(result));
41 merge_incore_nonrecursive(opt, merge_base, head, merge, &result);
42 merge_switch_to_result(opt, head, &result, 1, 1);
44 return result.clean;
47 int merge_ort_recursive(struct merge_options *opt,
48 struct commit *side1,
49 struct commit *side2,
50 struct commit_list *merge_bases,
51 struct commit **result)
53 struct tree *head = repo_get_commit_tree(opt->repo, side1);
54 struct merge_result tmp;
56 if (unclean(opt, head))
57 return -1;
59 memset(&tmp, 0, sizeof(tmp));
60 merge_incore_recursive(opt, merge_bases, side1, side2, &tmp);
61 merge_switch_to_result(opt, head, &tmp, 1, 1);
62 *result = NULL;
64 return tmp.clean;