merge-ort: add a preliminary simple process_entries() implementation
Add a process_entries() implementation that just loops over the paths and processes each one individually with an auxiliary process_entry() call. Add a basic process_entry() as well, which handles several cases but leaves a few of the more involved ones with die-not-implemented messages. Also, although process_entries() is supposed to create a tree, it does not yet have code to do so -- except in the special case of merging completely empty trees. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
291f29caf6
commit
6a02dd90c9
103
merge-ort.c
103
merge-ort.c
@ -492,10 +492,111 @@ static int detect_and_process_renames(struct merge_options *opt,
|
||||
return clean;
|
||||
}
|
||||
|
||||
/* Per entry merge function */
|
||||
static void process_entry(struct merge_options *opt,
|
||||
const char *path,
|
||||
struct conflict_info *ci)
|
||||
{
|
||||
VERIFY_CI(ci);
|
||||
assert(ci->filemask >= 0 && ci->filemask <= 7);
|
||||
/* ci->match_mask == 7 was handled in collect_merge_info_callback() */
|
||||
assert(ci->match_mask == 0 || ci->match_mask == 3 ||
|
||||
ci->match_mask == 5 || ci->match_mask == 6);
|
||||
|
||||
if (ci->df_conflict) {
|
||||
die("Not yet implemented.");
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: Below there is a long switch-like if-elseif-elseif... block
|
||||
* which the code goes through even for the df_conflict cases
|
||||
* above. Well, it will once we don't die-not-implemented above.
|
||||
*/
|
||||
if (ci->match_mask) {
|
||||
ci->merged.clean = 1;
|
||||
if (ci->match_mask == 6) {
|
||||
/* stages[1] == stages[2] */
|
||||
ci->merged.result.mode = ci->stages[1].mode;
|
||||
oidcpy(&ci->merged.result.oid, &ci->stages[1].oid);
|
||||
} else {
|
||||
/* determine the mask of the side that didn't match */
|
||||
unsigned int othermask = 7 & ~ci->match_mask;
|
||||
int side = (othermask == 4) ? 2 : 1;
|
||||
|
||||
ci->merged.result.mode = ci->stages[side].mode;
|
||||
ci->merged.is_null = !ci->merged.result.mode;
|
||||
oidcpy(&ci->merged.result.oid, &ci->stages[side].oid);
|
||||
|
||||
assert(othermask == 2 || othermask == 4);
|
||||
assert(ci->merged.is_null ==
|
||||
(ci->filemask == ci->match_mask));
|
||||
}
|
||||
} else if (ci->filemask >= 6 &&
|
||||
(S_IFMT & ci->stages[1].mode) !=
|
||||
(S_IFMT & ci->stages[2].mode)) {
|
||||
/*
|
||||
* Two different items from (file/submodule/symlink)
|
||||
*/
|
||||
die("Not yet implemented.");
|
||||
} else if (ci->filemask >= 6) {
|
||||
/*
|
||||
* TODO: Needs a two-way or three-way content merge, but we're
|
||||
* just being lazy and copying the version from HEAD and
|
||||
* leaving it as conflicted.
|
||||
*/
|
||||
ci->merged.clean = 0;
|
||||
ci->merged.result.mode = ci->stages[1].mode;
|
||||
oidcpy(&ci->merged.result.oid, &ci->stages[1].oid);
|
||||
} else if (ci->filemask == 3 || ci->filemask == 5) {
|
||||
/* Modify/delete */
|
||||
die("Not yet implemented.");
|
||||
} else if (ci->filemask == 2 || ci->filemask == 4) {
|
||||
/* Added on one side */
|
||||
int side = (ci->filemask == 4) ? 2 : 1;
|
||||
ci->merged.result.mode = ci->stages[side].mode;
|
||||
oidcpy(&ci->merged.result.oid, &ci->stages[side].oid);
|
||||
ci->merged.clean = !ci->df_conflict;
|
||||
} else if (ci->filemask == 1) {
|
||||
/* Deleted on both sides */
|
||||
ci->merged.is_null = 1;
|
||||
ci->merged.result.mode = 0;
|
||||
oidcpy(&ci->merged.result.oid, &null_oid);
|
||||
ci->merged.clean = 1;
|
||||
}
|
||||
|
||||
/*
|
||||
* If still conflicted, record it separately. This allows us to later
|
||||
* iterate over just conflicted entries when updating the index instead
|
||||
* of iterating over all entries.
|
||||
*/
|
||||
if (!ci->merged.clean)
|
||||
strmap_put(&opt->priv->conflicted, path, ci);
|
||||
}
|
||||
|
||||
static void process_entries(struct merge_options *opt,
|
||||
struct object_id *result_oid)
|
||||
{
|
||||
die("Not yet implemented.");
|
||||
struct hashmap_iter iter;
|
||||
struct strmap_entry *e;
|
||||
|
||||
if (strmap_empty(&opt->priv->paths)) {
|
||||
oidcpy(result_oid, opt->repo->hash_algo->empty_tree);
|
||||
return;
|
||||
}
|
||||
|
||||
strmap_for_each_entry(&opt->priv->paths, &iter, e) {
|
||||
/*
|
||||
* NOTE: mi may actually be a pointer to a conflict_info, but
|
||||
* we have to check mi->clean first to see if it's safe to
|
||||
* reassign to such a pointer type.
|
||||
*/
|
||||
struct merged_info *mi = e->value;
|
||||
|
||||
if (!mi->clean)
|
||||
process_entry(opt, e->key, e->value);
|
||||
}
|
||||
|
||||
die("Tree creation not yet implemented");
|
||||
}
|
||||
|
||||
void merge_switch_to_result(struct merge_options *opt,
|
||||
|
Loading…
Reference in New Issue
Block a user