Skip to content

Commit 17e5574

Browse files
newrengitster
authored andcommitted
merge-ort: barebones API of new merge strategy with empty implementation
This is the beginning of a new merge strategy. While there are some API differences, and the implementation has some differences in behavior, it is essentially meant as an eventual drop-in replacement for merge-recursive.c. However, it is being built to exist side-by-side with merge-recursive so that we have plenty of time to find out how those differences pan out in the real world while people can still fall back to merge-recursive. (Also, I intend to avoid modifying merge-recursive during this process, to keep it stable.) The primary difference noticable here is that the updating of the working tree and index is not done simultaneously with the merge algorithm, but is a separate post-processing step. The new API is designed so that one can do repeated merges (e.g. during a rebase or cherry-pick) and only update the index and working tree one time at the end instead of updating it with every intermediate result. Also, one can perform a merge between two branches, neither of which match the index or the working tree, without clobbering the index or working tree. The next three commits will demonstrate various uses of this new API. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2e67335 commit 17e5574

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,7 @@ LIB_OBJS += mailmap.o
921921
LIB_OBJS += match-trees.o
922922
LIB_OBJS += mem-pool.o
923923
LIB_OBJS += merge-blobs.o
924+
LIB_OBJS += merge-ort.o
924925
LIB_OBJS += merge-recursive.o
925926
LIB_OBJS += merge.o
926927
LIB_OBJS += mergesort.o

merge-ort.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* "Ostensibly Recursive's Twin" merge strategy, or "ort" for short. Meant
3+
* as a drop-in replacement for the "recursive" merge strategy, allowing one
4+
* to replace
5+
*
6+
* git merge [-s recursive]
7+
*
8+
* with
9+
*
10+
* git merge -s ort
11+
*
12+
* Note: git's parser allows the space between '-s' and its argument to be
13+
* missing. (Should I have backronymed "ham", "alsa", "kip", "nap, "alvo",
14+
* "cale", "peedy", or "ins" instead of "ort"?)
15+
*/
16+
17+
#include "cache.h"
18+
#include "merge-ort.h"
19+
20+
void merge_switch_to_result(struct merge_options *opt,
21+
struct tree *head,
22+
struct merge_result *result,
23+
int update_worktree_and_index,
24+
int display_update_msgs)
25+
{
26+
die("Not yet implemented");
27+
merge_finalize(opt, result);
28+
}
29+
30+
void merge_finalize(struct merge_options *opt,
31+
struct merge_result *result)
32+
{
33+
die("Not yet implemented");
34+
}
35+
36+
void merge_incore_nonrecursive(struct merge_options *opt,
37+
struct tree *merge_base,
38+
struct tree *side1,
39+
struct tree *side2,
40+
struct merge_result *result)
41+
{
42+
die("Not yet implemented");
43+
}
44+
45+
void merge_incore_recursive(struct merge_options *opt,
46+
struct commit_list *merge_bases,
47+
struct commit *side1,
48+
struct commit *side2,
49+
struct merge_result *result)
50+
{
51+
die("Not yet implemented");
52+
}

merge-ort.h

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
#ifndef MERGE_ORT_H
2+
#define MERGE_ORT_H
3+
4+
#include "merge-recursive.h"
5+
6+
struct commit;
7+
struct tree;
8+
9+
struct merge_result {
10+
/* Whether the merge is clean */
11+
int clean;
12+
13+
/*
14+
* Result of merge. If !clean, represents what would go in worktree
15+
* (thus possibly including files containing conflict markers).
16+
*/
17+
struct tree *tree;
18+
19+
/*
20+
* Additional metadata used by merge_switch_to_result() or future calls
21+
* to merge_incore_*(). Includes data needed to update the index (if
22+
* !clean) and to print "CONFLICT" messages. Not for external use.
23+
*/
24+
void *priv;
25+
};
26+
27+
/*
28+
* rename-detecting three-way merge with recursive ancestor consolidation.
29+
* working tree and index are untouched.
30+
*/
31+
void merge_incore_recursive(struct merge_options *opt,
32+
struct commit_list *merge_bases,
33+
struct commit *side1,
34+
struct commit *side2,
35+
struct merge_result *result);
36+
37+
/*
38+
* rename-detecting three-way merge, no recursion.
39+
* working tree and index are untouched.
40+
*/
41+
void merge_incore_nonrecursive(struct merge_options *opt,
42+
struct tree *merge_base,
43+
struct tree *side1,
44+
struct tree *side2,
45+
struct merge_result *result);
46+
47+
/* Update the working tree and index from head to result after incore merge */
48+
void merge_switch_to_result(struct merge_options *opt,
49+
struct tree *head,
50+
struct merge_result *result,
51+
int update_worktree_and_index,
52+
int display_update_msgs);
53+
54+
/* Do needed cleanup when not calling merge_switch_to_result() */
55+
void merge_finalize(struct merge_options *opt,
56+
struct merge_result *result);
57+
58+
#endif

0 commit comments

Comments
 (0)