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>
Elijah Newren committed
Dec 13, 2020 at 08:04 UTC
6a02dd90c99c59eada5e5b80e7140e56c1d4a2b0
1 file changed
+102
-1
merge-ort.c
+102
-1
@@ -492,10 +492,111 @@ static int detect_and_process_renames(struct merge_options *opt,
492
return clean;
493
}
494
495
+/* Per entry merge function */
496
+static void process_entry(struct merge_options *opt,
497
+ const char *path,
498
+ struct conflict_info *ci)
499
+{
500
+ VERIFY_CI(ci);
501
+ assert(ci->filemask >= 0 && ci->filemask <= 7);
502
+ /* ci->match_mask == 7 was handled in collect_merge_info_callback() */
503
+ assert(ci->match_mask == 0 || ci->match_mask == 3 ||
504
+ ci->match_mask == 5 || ci->match_mask == 6);
505
+
506
+ if (ci->df_conflict) {
507
+ die("Not yet implemented.");
508
+ }
509
+
510
+ /*
511
+ * NOTE: Below there is a long switch-like if-elseif-elseif... block
512
+ * which the code goes through even for the df_conflict cases
513
+ * above. Well, it will once we don't die-not-implemented above.
514
+ */
515
+ if (ci->match_mask) {
516
+ ci->merged.clean = 1;
517
+ if (ci->match_mask == 6) {
518
+ /* stages[1] == stages[2] */
519
+ ci->merged.result.mode = ci->stages[1].mode;
520
+ oidcpy(&ci->merged.result.oid, &ci->stages[1].oid);
521
+ } else {
522
+ /* determine the mask of the side that didn't match */
523
+ unsigned int othermask = 7 & ~ci->match_mask;
524
+ int side = (othermask == 4) ? 2 : 1;
525
+
526
+ ci->merged.result.mode = ci->stages[side].mode;
527
+ ci->merged.is_null = !ci->merged.result.mode;
528
+ oidcpy(&ci->merged.result.oid, &ci->stages[side].oid);
529
+
530
+ assert(othermask == 2 || othermask == 4);
531
+ assert(ci->merged.is_null ==
532
+ (ci->filemask == ci->match_mask));
533
+ }
534
+ } else if (ci->filemask >= 6 &&
535
+ (S_IFMT & ci->stages[1].mode) !=
536
+ (S_IFMT & ci->stages[2].mode)) {
537
+ /*
538
+ * Two different items from (file/submodule/symlink)
539
+ */
540
+ die("Not yet implemented.");
541
+ } else if (ci->filemask >= 6) {
542
+ /*
543
+ * TODO: Needs a two-way or three-way content merge, but we're
544
+ * just being lazy and copying the version from HEAD and
545
+ * leaving it as conflicted.
546
+ */
547
+ ci->merged.clean = 0;
548
+ ci->merged.result.mode = ci->stages[1].mode;
549
+ oidcpy(&ci->merged.result.oid, &ci->stages[1].oid);
550
+ } else if (ci->filemask == 3 || ci->filemask == 5) {
551
+ /* Modify/delete */
552
+ die("Not yet implemented.");
553
+ } else if (ci->filemask == 2 || ci->filemask == 4) {
554
+ /* Added on one side */
555
+ int side = (ci->filemask == 4) ? 2 : 1;
556
+ ci->merged.result.mode = ci->stages[side].mode;
557
+ oidcpy(&ci->merged.result.oid, &ci->stages[side].oid);
558
+ ci->merged.clean = !ci->df_conflict;
559
+ } else if (ci->filemask == 1) {
560
+ /* Deleted on both sides */
561
+ ci->merged.is_null = 1;
562
+ ci->merged.result.mode = 0;
563
+ oidcpy(&ci->merged.result.oid, &null_oid);
564
+ ci->merged.clean = 1;
565
+ }
566
+
567
+ /*
568
+ * If still conflicted, record it separately. This allows us to later
569
+ * iterate over just conflicted entries when updating the index instead
570
+ * of iterating over all entries.
571
+ */
572
+ if (!ci->merged.clean)
573
+ strmap_put(&opt->priv->conflicted, path, ci);
574
+}
575
+
576
static void process_entries(struct merge_options *opt,
577
struct object_id *result_oid)
578
{
498
- die("Not yet implemented.");
579
+ struct hashmap_iter iter;
580
+ struct strmap_entry *e;
581
+
582
+ if (strmap_empty(&opt->priv->paths)) {
583
+ oidcpy(result_oid, opt->repo->hash_algo->empty_tree);
584
+ return;
585
+ }
586
+
587
+ strmap_for_each_entry(&opt->priv->paths, &iter, e) {
588
+ /*
589
+ * NOTE: mi may actually be a pointer to a conflict_info, but
590
+ * we have to check mi->clean first to see if it's safe to
591
+ * reassign to such a pointer type.
592
+ */
593
+ struct merged_info *mi = e->value;
594
+
595
+ if (!mi->clean)
596
+ process_entry(opt, e->key, e->value);
597
+ }
598
+
599
+ die("Tree creation not yet implemented");
600
}
601
602
void merge_switch_to_result(struct merge_options *opt,