Skip to content

Commit 231e2dd

Browse files
newrengitster
authored andcommitted
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]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5b59c3d commit 231e2dd

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
/*
@@ -164,6 +165,38 @@ struct conflict_info {
164165
unsigned match_mask:3;
165166
};
166167

168+
static int collect_merge_info(struct merge_options *opt,
169+
struct tree *merge_base,
170+
struct tree *side1,
171+
struct tree *side2)
172+
{
173+
/* TODO: Implement this using traverse_trees() */
174+
die("Not yet implemented.");
175+
}
176+
177+
static int detect_and_process_renames(struct merge_options *opt,
178+
struct tree *merge_base,
179+
struct tree *side1,
180+
struct tree *side2)
181+
{
182+
int clean = 1;
183+
184+
/*
185+
* Rename detection works by detecting file similarity. Here we use
186+
* a really easy-to-implement scheme: files are similar IFF they have
187+
* the same filename. Therefore, by this scheme, there are no renames.
188+
*
189+
* TODO: Actually implement a real rename detection scheme.
190+
*/
191+
return clean;
192+
}
193+
194+
static void process_entries(struct merge_options *opt,
195+
struct object_id *result_oid)
196+
{
197+
die("Not yet implemented.");
198+
}
199+
167200
void merge_switch_to_result(struct merge_options *opt,
168201
struct tree *head,
169202
struct merge_result *result,
@@ -180,13 +213,46 @@ void merge_finalize(struct merge_options *opt,
180213
die("Not yet implemented");
181214
}
182215

216+
static void merge_start(struct merge_options *opt, struct merge_result *result)
217+
{
218+
die("Not yet implemented.");
219+
}
220+
221+
/*
222+
* Originally from merge_trees_internal(); heavily adapted, though.
223+
*/
224+
static void merge_ort_nonrecursive_internal(struct merge_options *opt,
225+
struct tree *merge_base,
226+
struct tree *side1,
227+
struct tree *side2,
228+
struct merge_result *result)
229+
{
230+
struct object_id working_tree_oid;
231+
232+
collect_merge_info(opt, merge_base, side1, side2);
233+
result->clean = detect_and_process_renames(opt, merge_base,
234+
side1, side2);
235+
process_entries(opt, &working_tree_oid);
236+
237+
/* Set return values */
238+
result->tree = parse_tree_indirect(&working_tree_oid);
239+
/* existence of conflicted entries implies unclean */
240+
result->clean &= strmap_empty(&opt->priv->conflicted);
241+
if (!opt->priv->call_depth) {
242+
result->priv = opt->priv;
243+
opt->priv = NULL;
244+
}
245+
}
246+
183247
void merge_incore_nonrecursive(struct merge_options *opt,
184248
struct tree *merge_base,
185249
struct tree *side1,
186250
struct tree *side2,
187251
struct merge_result *result)
188252
{
189-
die("Not yet implemented");
253+
assert(opt->ancestor != NULL);
254+
merge_start(opt, result);
255+
merge_ort_nonrecursive_internal(opt, merge_base, side1, side2, result);
190256
}
191257

192258
void merge_incore_recursive(struct merge_options *opt,

0 commit comments

Comments
 (0)