]> git.ipfire.org Git - thirdparty/git.git/blobdiff - merge-recursive.c
merge-recursive: fix the fix to the diff3 common ancestor label
[thirdparty/git.git] / merge-recursive.c
index c92993e8f032a7af72a35a9f466db317c549aecb..2653ba9a50c5d3c727e95ade81fcace7aba1d79a 100644 (file)
@@ -4,30 +4,31 @@
  * The thieves were Alex Riesen and Johannes Schindelin, in June/July 2006
  */
 #include "cache.h"
-#include "config.h"
+#include "merge-recursive.h"
+
 #include "advice.h"
-#include "lockfile.h"
-#include "cache-tree.h"
-#include "object-store.h"
-#include "repository.h"
-#include "commit.h"
+#include "alloc.h"
+#include "attr.h"
 #include "blob.h"
 #include "builtin.h"
-#include "tree-walk.h"
+#include "cache-tree.h"
+#include "commit.h"
+#include "commit-reach.h"
+#include "config.h"
 #include "diff.h"
 #include "diffcore.h"
+#include "dir.h"
+#include "ll-merge.h"
+#include "lockfile.h"
+#include "object-store.h"
+#include "repository.h"
+#include "revision.h"
+#include "string-list.h"
+#include "submodule.h"
 #include "tag.h"
-#include "alloc.h"
+#include "tree-walk.h"
 #include "unpack-trees.h"
-#include "string-list.h"
 #include "xdiff-interface.h"
-#include "ll-merge.h"
-#include "attr.h"
-#include "merge-recursive.h"
-#include "dir.h"
-#include "submodule.h"
-#include "revision.h"
-#include "commit-reach.h"
 
 struct merge_options_internal {
        int call_depth;
@@ -1045,10 +1046,10 @@ static int merge_3way(struct merge_options *opt,
                ll_opts.variant = 0;
        } else {
                switch (opt->recursive_variant) {
-               case MERGE_RECURSIVE_OURS:
+               case MERGE_VARIANT_OURS:
                        ll_opts.variant = XDL_MERGE_FAVOR_OURS;
                        break;
-               case MERGE_RECURSIVE_THEIRS:
+               case MERGE_VARIANT_THEIRS:
                        ll_opts.variant = XDL_MERGE_FAVOR_THEIRS;
                        break;
                default:
@@ -1355,15 +1356,15 @@ static int merge_mode_and_contents(struct merge_options *opt,
                                                        &b->oid);
                } else if (S_ISLNK(a->mode)) {
                        switch (opt->recursive_variant) {
-                       case MERGE_RECURSIVE_NORMAL:
+                       case MERGE_VARIANT_NORMAL:
                                oidcpy(&result->blob.oid, &a->oid);
                                if (!oid_eq(&a->oid, &b->oid))
                                        result->clean = 0;
                                break;
-                       case MERGE_RECURSIVE_OURS:
+                       case MERGE_VARIANT_OURS:
                                oidcpy(&result->blob.oid, &a->oid);
                                break;
-                       case MERGE_RECURSIVE_THEIRS:
+                       case MERGE_VARIANT_THEIRS:
                                oidcpy(&result->blob.oid, &b->oid);
                                break;
                        }
@@ -3549,6 +3550,8 @@ static int merge_recursive_internal(struct merge_options *opt,
                merged_merge_bases = make_virtual_commit(opt->repo, tree,
                                                         "ancestor");
                ancestor_name = "empty tree";
+       } else if (opt->ancestor && !opt->priv->call_depth) {
+               ancestor_name = opt->ancestor;
        } else if (merge_bases) {
                ancestor_name = "merged common ancestors";
        } else {
@@ -3597,6 +3600,7 @@ static int merge_recursive_internal(struct merge_options *opt,
                                                          merged_merge_bases),
                                     &result_tree);
        strbuf_release(&merge_base_abbrev);
+       opt->ancestor = NULL;  /* avoid accidental re-use of opt->ancestor */
        if (clean < 0) {
                flush_output(opt);
                return clean;
@@ -3615,6 +3619,30 @@ static int merge_start(struct merge_options *opt, struct tree *head)
 {
        struct strbuf sb = STRBUF_INIT;
 
+       /* Sanity checks on opt */
+       assert(opt->repo);
+
+       assert(opt->branch1 && opt->branch2);
+
+       assert(opt->detect_renames >= -1 &&
+              opt->detect_renames <= DIFF_DETECT_COPY);
+       assert(opt->detect_directory_renames >= MERGE_DIRECTORY_RENAMES_NONE &&
+              opt->detect_directory_renames <= MERGE_DIRECTORY_RENAMES_TRUE);
+       assert(opt->rename_limit >= -1);
+       assert(opt->rename_score >= 0 && opt->rename_score <= MAX_SCORE);
+       assert(opt->show_rename_progress >= 0 && opt->show_rename_progress <= 1);
+
+       assert(opt->xdl_opts >= 0);
+       assert(opt->recursive_variant >= MERGE_VARIANT_NORMAL &&
+              opt->recursive_variant <= MERGE_VARIANT_THEIRS);
+
+       assert(opt->verbosity >= 0 && opt->verbosity <= 5);
+       assert(opt->buffer_output <= 2);
+       assert(opt->obuf.len == 0);
+
+       assert(opt->priv == NULL);
+
+       /* Sanity check on repo state; index must match head */
        if (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);
@@ -3664,7 +3692,8 @@ int merge_recursive(struct merge_options *opt,
 {
        int clean;
 
-       assert(opt->ancestor == NULL);
+       assert(opt->ancestor == NULL ||
+              !strcmp(opt->ancestor, "constructed merge base"));
 
        if (merge_start(opt, repo_get_commit_tree(opt->repo, h1)))
                return -1;
@@ -3716,6 +3745,8 @@ int merge_recursive_generic(struct merge_options *opt,
                                           oid_to_hex(merge_bases[i]));
                        commit_list_insert(base, &ca);
                }
+               if (num_merge_bases == 1)
+                       opt->ancestor = "constructed merge base";
        }
 
        repo_hold_locked_index(opt->repo, &lock, LOCK_DIE_ON_ERROR);
@@ -3795,9 +3826,9 @@ int parse_merge_opt(struct merge_options *opt, const char *s)
        if (!s || !*s)
                return -1;
        if (!strcmp(s, "ours"))
-               opt->recursive_variant = MERGE_RECURSIVE_OURS;
+               opt->recursive_variant = MERGE_VARIANT_OURS;
        else if (!strcmp(s, "theirs"))
-               opt->recursive_variant = MERGE_RECURSIVE_THEIRS;
+               opt->recursive_variant = MERGE_VARIANT_THEIRS;
        else if (!strcmp(s, "subtree"))
                opt->subtree_shift = "";
        else if (skip_prefix(s, "subtree=", &arg))