]> git.ipfire.org Git - thirdparty/git.git/blobdiff - merge-recursive.c
merge-recursive: provide a better label for diff3 common ancestor
[thirdparty/git.git] / merge-recursive.c
index 12300131fc12b15fbc9514e90ca45d76113d7267..e6b84db2ef8eb5b9bdc1de66136c54b2848f23fa 100644 (file)
@@ -1019,7 +1019,7 @@ static int merge_3way(struct merge_options *opt,
 {
        mmfile_t orig, src1, src2;
        struct ll_merge_options ll_opts = {0};
-       char *base_name, *name1, *name2;
+       char *base, *name1, *name2;
        int merge_status;
 
        ll_opts.renormalize = opt->renormalize;
@@ -1043,16 +1043,13 @@ static int merge_3way(struct merge_options *opt,
                }
        }
 
-       assert(a->path && b->path);
-       if (strcmp(a->path, b->path) ||
-           (opt->ancestor != NULL && strcmp(a->path, o->path) != 0)) {
-               base_name = opt->ancestor == NULL ? NULL :
-                       mkpathdup("%s:%s", opt->ancestor, o->path);
+       assert(a->path && b->path && o->path && opt->ancestor);
+       if (strcmp(a->path, b->path) || strcmp(a->path, o->path) != 0) {
+               base  = mkpathdup("%s:%s", opt->ancestor, o->path);
                name1 = mkpathdup("%s:%s", branch1, a->path);
                name2 = mkpathdup("%s:%s", branch2, b->path);
        } else {
-               base_name = opt->ancestor == NULL ? NULL :
-                       mkpathdup("%s", opt->ancestor);
+               base  = mkpathdup("%s", opt->ancestor);
                name1 = mkpathdup("%s", branch1);
                name2 = mkpathdup("%s", branch2);
        }
@@ -1061,11 +1058,11 @@ static int merge_3way(struct merge_options *opt,
        read_mmblob(&src1, &a->oid);
        read_mmblob(&src2, &b->oid);
 
-       merge_status = ll_merge(result_buf, a->path, &orig, base_name,
+       merge_status = ll_merge(result_buf, a->path, &orig, base,
                                &src1, name1, &src2, name2,
                                opt->repo->index, &ll_opts);
 
-       free(base_name);
+       free(base);
        free(name1);
        free(name2);
        free(orig.ptr);
@@ -2863,7 +2860,8 @@ static int detect_and_process_renames(struct merge_options *opt,
        head_pairs = get_diffpairs(opt, common, head);
        merge_pairs = get_diffpairs(opt, common, merge);
 
-       if (opt->detect_directory_renames) {
+       if ((opt->detect_directory_renames == 2) ||
+           (opt->detect_directory_renames == 1 && !opt->call_depth)) {
                dir_re_head = get_directory_renames(head_pairs);
                dir_re_merge = get_directory_renames(merge_pairs);
 
@@ -3389,6 +3387,8 @@ int merge_trees(struct merge_options *opt,
        int code, clean;
        struct strbuf sb = STRBUF_INIT;
 
+       assert(opt->ancestor != NULL);
+
        if (!opt->call_depth && repo_index_has_changes(opt->repo, head, &sb)) {
                err(opt, _("Your local changes to the following files would be overwritten by merge:\n  %s"),
                    sb.buf);
@@ -3507,6 +3507,11 @@ int merge_recursive(struct merge_options *opt,
        struct commit *merged_common_ancestors;
        struct tree *mrtree;
        int clean;
+       const char *ancestor_name;
+       struct strbuf merge_base_abbrev = STRBUF_INIT;
+
+       if (!opt->call_depth)
+               assert(opt->ancestor == NULL);
 
        if (show(opt, 4)) {
                output(opt, 4, _("Merging:"));
@@ -3535,6 +3540,14 @@ int merge_recursive(struct merge_options *opt,
 
                tree = lookup_tree(opt->repo, opt->repo->hash_algo->empty_tree);
                merged_common_ancestors = make_virtual_commit(opt->repo, tree, "ancestor");
+               ancestor_name = "empty tree";
+       } else if (ca) {
+               ancestor_name = "merged common ancestors";
+       } else {
+               strbuf_add_unique_abbrev(&merge_base_abbrev,
+                                        &merged_common_ancestors->object.oid,
+                                        DEFAULT_ABBREV);
+               ancestor_name = merge_base_abbrev.buf;
        }
 
        for (iter = ca; iter; iter = iter->next) {
@@ -3568,10 +3581,11 @@ int merge_recursive(struct merge_options *opt,
        if (!opt->call_depth)
                repo_read_index(opt->repo);
 
-       opt->ancestor = "merged common ancestors";
+       opt->ancestor = ancestor_name;
        clean = merge_trees(opt, get_commit_tree(h1), get_commit_tree(h2),
                            get_commit_tree(merged_common_ancestors),
                            &mrtree);
+       strbuf_release(&merge_base_abbrev);
        if (clean < 0) {
                flush_output(opt);
                return clean;