summaryrefslogtreecommitdiffstats
path: root/merge-ort-wrappers.c
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 09:49:36 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 09:49:36 +0000
commit5ec6074f0633939fd17d94111d10c6c6b062978c (patch)
treebfaa17b5a64abc66c918e9c70969e519d9e1df8e /merge-ort-wrappers.c
parentInitial commit. (diff)
downloadgit-upstream.tar.xz
git-upstream.zip
Adding upstream version 1:2.30.2.upstream/1%2.30.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'merge-ort-wrappers.c')
-rw-r--r--merge-ort-wrappers.c62
1 files changed, 62 insertions, 0 deletions
diff --git a/merge-ort-wrappers.c b/merge-ort-wrappers.c
new file mode 100644
index 0000000..7eec25f
--- /dev/null
+++ b/merge-ort-wrappers.c
@@ -0,0 +1,62 @@
+#include "cache.h"
+#include "merge-ort.h"
+#include "merge-ort-wrappers.h"
+
+#include "commit.h"
+
+static int unclean(struct merge_options *opt, struct tree *head)
+{
+ /* Sanity check on repo state; index must match head */
+ struct strbuf sb = STRBUF_INIT;
+
+ if (head && repo_index_has_changes(opt->repo, head, &sb)) {
+ fprintf(stderr, _("Your local changes to the following files would be overwritten by merge:\n %s"),
+ sb.buf);
+ strbuf_release(&sb);
+ return -1;
+ }
+
+ return 0;
+}
+
+int merge_ort_nonrecursive(struct merge_options *opt,
+ struct tree *head,
+ struct tree *merge,
+ struct tree *merge_base)
+{
+ struct merge_result result;
+
+ if (unclean(opt, head))
+ return -1;
+
+ if (oideq(&merge_base->object.oid, &merge->object.oid)) {
+ printf(_("Already up to date!"));
+ return 1;
+ }
+
+ memset(&result, 0, sizeof(result));
+ merge_incore_nonrecursive(opt, merge_base, head, merge, &result);
+ merge_switch_to_result(opt, head, &result, 1, 1);
+
+ return result.clean;
+}
+
+int merge_ort_recursive(struct merge_options *opt,
+ struct commit *side1,
+ struct commit *side2,
+ struct commit_list *merge_bases,
+ struct commit **result)
+{
+ struct tree *head = repo_get_commit_tree(opt->repo, side1);
+ struct merge_result tmp;
+
+ if (unclean(opt, head))
+ return -1;
+
+ memset(&tmp, 0, sizeof(tmp));
+ merge_incore_recursive(opt, merge_bases, side1, side2, &tmp);
+ merge_switch_to_result(opt, head, &tmp, 1, 1);
+ *result = NULL;
+
+ return tmp.clean;
+}