Skip to content

Commit 47b1e89

Browse files
newrengitster
authored andcommitted
merge-ort-wrappers: new convience wrappers to mimic the old merge API
There are a few differences between the new API in merge-ort and the old API in merge-recursive. While the new API is more flexible, it might feel like more work at times than the old API. merge-ort-wrappers creates two convenience wrappers taking the exact same arguments as the old merge_trees() and merge_recursive() functions and implements them via the new API. This makes converting existing callsites easier, and serves to highlight some of the differences in the API. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 17e5574 commit 47b1e89

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -922,6 +922,7 @@ LIB_OBJS += match-trees.o
922922
LIB_OBJS += mem-pool.o
923923
LIB_OBJS += merge-blobs.o
924924
LIB_OBJS += merge-ort.o
925+
LIB_OBJS += merge-ort-wrappers.o
925926
LIB_OBJS += merge-recursive.o
926927
LIB_OBJS += merge.o
927928
LIB_OBJS += mergesort.o

merge-ort-wrappers.c

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#include "cache.h"
2+
#include "merge-ort.h"
3+
#include "merge-ort-wrappers.h"
4+
5+
#include "commit.h"
6+
7+
static int unclean(struct merge_options *opt, struct tree *head)
8+
{
9+
/* Sanity check on repo state; index must match head */
10+
struct strbuf sb = STRBUF_INIT;
11+
12+
if (head && repo_index_has_changes(opt->repo, head, &sb)) {
13+
fprintf(stderr, _("Your local changes to the following files would be overwritten by merge:\n %s"),
14+
sb.buf);
15+
strbuf_release(&sb);
16+
return -1;
17+
}
18+
19+
return 0;
20+
}
21+
22+
int merge_ort_nonrecursive(struct merge_options *opt,
23+
struct tree *head,
24+
struct tree *merge,
25+
struct tree *merge_base)
26+
{
27+
struct merge_result result;
28+
29+
if (unclean(opt, head))
30+
return -1;
31+
32+
if (oideq(&merge_base->object.oid, &merge->object.oid)) {
33+
printf(_("Already up to date!"));
34+
return 1;
35+
}
36+
37+
memset(&result, 0, sizeof(result));
38+
merge_incore_nonrecursive(opt, merge_base, head, merge, &result);
39+
merge_switch_to_result(opt, head, &result, 1, 1);
40+
41+
return result.clean;
42+
}
43+
44+
int merge_ort_recursive(struct merge_options *opt,
45+
struct commit *side1,
46+
struct commit *side2,
47+
struct commit_list *merge_bases,
48+
struct commit **result)
49+
{
50+
struct tree *head = repo_get_commit_tree(opt->repo, side1);
51+
struct merge_result tmp;
52+
53+
if (unclean(opt, head))
54+
return -1;
55+
56+
memset(&tmp, 0, sizeof(tmp));
57+
merge_incore_recursive(opt, merge_bases, side1, side2, &tmp);
58+
merge_switch_to_result(opt, head, &tmp, 1, 1);
59+
*result = NULL;
60+
61+
return tmp.clean;
62+
}

merge-ort-wrappers.h

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#ifndef MERGE_ORT_WRAPPERS_H
2+
#define MERGE_ORT_WRAPPERS_H
3+
4+
#include "merge-recursive.h"
5+
6+
/*
7+
* rename-detecting three-way merge, no recursion.
8+
* Wrapper mimicking the old merge_trees() function.
9+
*/
10+
int merge_ort_nonrecursive(struct merge_options *opt,
11+
struct tree *head,
12+
struct tree *merge,
13+
struct tree *common);
14+
15+
/*
16+
* rename-detecting three-way merge with recursive ancestor consolidation.
17+
* Wrapper mimicking the old merge_recursive() function.
18+
*/
19+
int merge_ort_recursive(struct merge_options *opt,
20+
struct commit *h1,
21+
struct commit *h2,
22+
struct commit_list *ancestors,
23+
struct commit **result);
24+
25+
#endif

0 commit comments

Comments
 (0)