Skip to content

Commit b658536

Browse files
committed
merge-ort: add some high-level algorithm structure
merge_ort_nonrecursive_internal() will be used by both merge_inmemory_nonrecursive() and merge_inmemory_recursive(); let's focus on it for now. It involves some setup -- merge_start() -- followed by the following chain of functions: collect_merge_info() This function will populate merge_options_internal's paths field, via a call to traverse_trees() and a new callback that will be added later. detect_and_process_renames() This function will detect renames, and then adjust entries in paths to move conflict stages from old pathnames into those for new pathnames, so that the next step doesn't have to think about renames and just can do three-way content merging and such. process_entries() This function determines how to take the various stages (versions of a file from the three different sides) and merge them, and whether to mark the result as conflicted or cleanly merged. It also writes out these merged file versions as it goes to create a tree. Signed-off-by: Elijah Newren <[email protected]>
1 parent 2568ec9 commit b658536

File tree

1 file changed

+67
-1
lines changed

1 file changed

+67
-1
lines changed

merge-ort.c

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "merge-ort.h"
1919

2020
#include "strmap.h"
21+
#include "tree.h"
2122

2223
struct merge_options_internal {
2324
/*
@@ -154,6 +155,38 @@ struct conflict_info {
154155
unsigned match_mask:3;
155156
};
156157

158+
static int collect_merge_info(struct merge_options *opt,
159+
struct tree *merge_base,
160+
struct tree *side1,
161+
struct tree *side2)
162+
{
163+
/* TODO: Implement this using traverse_trees() */
164+
die("Not yet implemented.");
165+
}
166+
167+
static int detect_and_process_renames(struct merge_options *opt,
168+
struct tree *merge_base,
169+
struct tree *side1,
170+
struct tree *side2)
171+
{
172+
int clean = 1;
173+
174+
/*
175+
* Rename detection works by detecting file similarity. Here we use
176+
* a really easy-to-implement scheme: files are similar IFF they have
177+
* the same filename. Therefore, by this scheme, there are no renames.
178+
*
179+
* TODO: Actually implement a real rename detection scheme.
180+
*/
181+
return clean;
182+
}
183+
184+
static void process_entries(struct merge_options *opt,
185+
struct object_id *result_oid)
186+
{
187+
die("Not yet implemented.");
188+
}
189+
157190
void merge_switch_to_result(struct merge_options *opt,
158191
struct tree *head,
159192
struct merge_result *result,
@@ -170,13 +203,46 @@ void merge_finalize(struct merge_options *opt,
170203
die("Not yet implemented");
171204
}
172205

206+
static void merge_start(struct merge_options *opt, struct merge_result *result)
207+
{
208+
die("Not yet implemented.");
209+
}
210+
211+
/*
212+
* Originally from merge_trees_internal(); heavily adapted, though.
213+
*/
214+
static void merge_ort_nonrecursive_internal(struct merge_options *opt,
215+
struct tree *merge_base,
216+
struct tree *side1,
217+
struct tree *side2,
218+
struct merge_result *result)
219+
{
220+
struct object_id working_tree_oid;
221+
222+
collect_merge_info(opt, merge_base, side1, side2);
223+
result->clean = detect_and_process_renames(opt, merge_base,
224+
side1, side2);
225+
process_entries(opt, &working_tree_oid);
226+
227+
/* Set return values */
228+
result->tree = parse_tree_indirect(&working_tree_oid);
229+
/* existence of conflicted entries implies unclean */
230+
result->clean &= strmap_empty(&opt->priv->conflicted);
231+
if (!opt->priv->call_depth) {
232+
result->priv = opt->priv;
233+
opt->priv = NULL;
234+
}
235+
}
236+
173237
void merge_incore_nonrecursive(struct merge_options *opt,
174238
struct tree *merge_base,
175239
struct tree *side1,
176240
struct tree *side2,
177241
struct merge_result *result)
178242
{
179-
die("Not yet implemented");
243+
assert(opt->ancestor != NULL);
244+
merge_start(opt, result);
245+
merge_ort_nonrecursive_internal(opt, merge_base, side1, side2, result);
180246
}
181247

182248
void merge_incore_recursive(struct merge_options *opt,

0 commit comments

Comments
 (0)