Merge branch 'en/merge-cleanup-more'
authorJunio C Hamano <gitster@pobox.com>
Fri, 2 Nov 2018 15:53:57 +0000 (00:53 +0900)
committerJunio C Hamano <gitster@pobox.com>
Fri, 2 Nov 2018 15:53:57 +0000 (00:53 +0900)
Further clean-up of merge-recursive machinery.

* en/merge-cleanup-more:
merge-recursive: avoid showing conflicts with merge branch before HEAD
merge-recursive: improve auto-merging messages with path collisions

1  2 
merge-recursive.c
diff --combined merge-recursive.c
index c0fb83d2858c056633f306b2c3d49b9fd587b767,73b57103865109fa4f7495fe07fc2f04d670f85c..acc2f64a4e9d03f49165e3c46396ce00a09dc6bd
@@@ -228,7 -228,26 +228,26 @@@ static inline void setup_rename_conflic
                                              struct stage_data *src_entry1,
                                              struct stage_data *src_entry2)
  {
-       struct rename_conflict_info *ci = xcalloc(1, sizeof(struct rename_conflict_info));
+       struct rename_conflict_info *ci;
+       /*
+        * When we have two renames involved, it's easiest to get the
+        * correct things into stage 2 and 3, and to make sure that the
+        * content merge puts HEAD before the other branch if we just
+        * ensure that branch1 == o->branch1.  So, simply flip arguments
+        * around if we don't have that.
+        */
+       if (dst_entry2 && branch1 != o->branch1) {
+               setup_rename_conflict_info(rename_type,
+                                          pair2,      pair1,
+                                          branch2,    branch1,
+                                          dst_entry2, dst_entry1,
+                                          o,
+                                          src_entry2, src_entry1);
+               return;
+       }
+       ci = xcalloc(1, sizeof(struct rename_conflict_info));
        ci->rename_type = rename_type;
        ci->pair1 = pair1;
        ci->branch1 = branch1;
@@@ -1084,8 -1103,7 +1103,8 @@@ static int merge_3way(struct merge_opti
        read_mmblob(&src2, &b->oid);
  
        merge_status = ll_merge(result_buf, a->path, &orig, base_name,
 -                              &src1, name1, &src2, name2, &ll_opts);
 +                              &src1, name1, &src2, name2,
 +                              &the_index, &ll_opts);
  
        free(base_name);
        free(name1);
@@@ -1116,7 -1134,7 +1135,7 @@@ static int find_first_merges(struct obj
        /* get all revisions that merge commit a */
        xsnprintf(merged_revision, sizeof(merged_revision), "^%s",
                  oid_to_hex(&a->object.oid));
 -      init_revisions(&revs, NULL);
 +      repo_init_revisions(the_repository, &revs, NULL);
        rev_opts.submodule = path;
        /* FIXME: can't handle linked worktrees in submodules yet */
        revs.single_worktree = path != NULL;
@@@ -1284,6 -1302,17 +1303,17 @@@ static int merge_mode_and_contents(stru
                                   const char *branch2,
                                   struct merge_file_info *result)
  {
+       if (o->branch1 != branch1) {
+               /*
+                * It's weird getting a reverse merge with HEAD on the bottom
+                * side of the conflict markers and the other branch on the
+                * top.  Fix that.
+                */
+               return merge_mode_and_contents(o, one, b, a,
+                                              filename,
+                                              branch2, branch1, result);
+       }
        result->merge = 0;
        result->clean = 1;
  
@@@ -1675,8 -1704,8 +1705,8 @@@ static int handle_rename_rename_2to1(st
        remove_file(o, 1, a->path, o->call_depth || would_lose_untracked(a->path));
        remove_file(o, 1, b->path, o->call_depth || would_lose_untracked(b->path));
  
-       path_side_1_desc = xstrfmt("%s (was %s)", path, a->path);
-       path_side_2_desc = xstrfmt("%s (was %s)", path, b->path);
+       path_side_1_desc = xstrfmt("version of %s from %s", path, a->path);
+       path_side_2_desc = xstrfmt("version of %s from %s", path, b->path);
        if (merge_mode_and_contents(o, a, c1, &ci->ren1_other, path_side_1_desc,
                                    o->branch1, o->branch2, &mfi_c1) ||
            merge_mode_and_contents(o, b, &ci->ren2_other, c2, path_side_2_desc,
@@@ -1757,7 -1786,7 +1787,7 @@@ static struct diff_queue_struct *get_di
        struct diff_queue_struct *ret;
        struct diff_options opts;
  
 -      diff_setup(&opts);
 +      repo_diff_setup(the_repository, &opts);
        opts.flags.recursive = 1;
        opts.flags.rename_empty = 0;
        opts.detect_rename = merge_detect_rename(o);
@@@ -2184,7 -2213,7 +2214,7 @@@ static struct dir_rename_entry *check_d
  {
        char *temp = xstrdup(path);
        char *end;
 -      struct dir_rename_entry *entry = NULL;;
 +      struct dir_rename_entry *entry = NULL;
  
        while ((end = strrchr(temp, '/'))) {
                *end = '\0';