Merge branch 'sb/submodule-helper-clone-regression-fix' into maint
[gitweb.git] / builtin / merge.c
index 3ec97a83455ea2f14fba0f7530e8bf476692c30c..bf2f2614fbb5ba82df3dca5cad8f79dbe605feff 100644 (file)
@@ -365,7 +365,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
        while ((commit = get_revision(&rev)) != NULL) {
                strbuf_addch(&out, '\n');
                strbuf_addf(&out, "commit %s\n",
-                       sha1_to_hex(commit->object.sha1));
+                       oid_to_hex(&commit->object.oid));
                pretty_print_commit(&ctx, commit, &out);
        }
        if (write_in_full(fd, out.buf, out.len) != out.len)
@@ -380,7 +380,7 @@ static void finish(struct commit *head_commit,
                   const unsigned char *new_head, const char *msg)
 {
        struct strbuf reflog_message = STRBUF_INIT;
-       const unsigned char *head = head_commit->object.sha1;
+       const unsigned char *head = head_commit->object.oid.hash;
 
        if (!msg)
                strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
@@ -404,6 +404,7 @@ static void finish(struct commit *head_commit,
                         * We ignore errors in 'gc --auto', since the
                         * user should see them.
                         */
+                       close_all_packs();
                        run_command_v_opt(argv_gc_auto, RUN_GIT_CMD);
                }
        }
@@ -497,7 +498,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
                if (ref_exists(truname.buf)) {
                        strbuf_addf(msg,
                                    "%s\t\tbranch '%s'%s of .\n",
-                                   sha1_to_hex(remote_head->object.sha1),
+                                   sha1_to_hex(remote_head->object.oid.hash),
                                    truname.buf + 11,
                                    (early ? " (early part)" : ""));
                        strbuf_release(&truname);
@@ -511,7 +512,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
                desc = merge_remote_util(remote_head);
                if (desc && desc->obj && desc->obj->type == OBJ_TAG) {
                        strbuf_addf(msg, "%s\t\t%s '%s'\n",
-                                   sha1_to_hex(desc->obj->sha1),
+                                   sha1_to_hex(desc->obj->oid.hash),
                                    typename(desc->obj->type),
                                    remote);
                        goto cleanup;
@@ -519,7 +520,7 @@ static void merge_name(const char *remote, struct strbuf *msg)
        }
 
        strbuf_addf(msg, "%s\t\tcommit '%s'\n",
-               sha1_to_hex(remote_head->object.sha1), remote);
+               sha1_to_hex(remote_head->object.oid.hash), remote);
 cleanup:
        strbuf_release(&buf);
        strbuf_release(&bname);
@@ -892,7 +893,7 @@ static struct commit *is_old_style_invocation(int argc, const char **argv,
                second_token = lookup_commit_reference_gently(second_sha1, 0);
                if (!second_token)
                        die(_("'%s' is not a commit"), argv[1]);
-               if (hashcmp(second_token->object.sha1, head))
+               if (hashcmp(second_token->object.oid.hash, head))
                        return NULL;
        }
        return second_token;
@@ -938,7 +939,7 @@ static int setup_with_upstream(const char ***argv)
        if (!branch->merge_nr)
                die(_("No default upstream defined for the current branch."));
 
-       args = xcalloc(branch->merge_nr + 1, sizeof(char *));
+       args = xcalloc(st_add(branch->merge_nr, 1), sizeof(char *));
        for (i = 0; i < branch->merge_nr; i++) {
                if (!branch->merge[i]->dst)
                        die(_("No remote-tracking branch for %s from %s"),
@@ -958,14 +959,14 @@ static void write_merge_state(struct commit_list *remoteheads)
        struct strbuf buf = STRBUF_INIT;
 
        for (j = remoteheads; j; j = j->next) {
-               unsigned const char *sha1;
+               struct object_id *oid;
                struct commit *c = j->item;
                if (c->util && merge_remote_util(c)->obj) {
-                       sha1 = merge_remote_util(c)->obj->sha1;
+                       oid = &merge_remote_util(c)->obj->oid;
                } else {
-                       sha1 = c->object.sha1;
+                       oid = &c->object.oid;
                }
-               strbuf_addf(&buf, "%s\n", sha1_to_hex(sha1));
+               strbuf_addf(&buf, "%s\n", oid_to_hex(oid));
        }
        filename = git_path_merge_head();
        fd = open(filename, O_WRONLY | O_CREAT, 0666);
@@ -1256,12 +1257,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        builtin_merge_options);
 
        if (!head_commit) {
-               struct commit *remote_head;
                /*
                 * If the merged head is a valid one there is no reason
                 * to forbid "git merge" into a branch yet to be born.
                 * We do the same for "git pull".
                 */
+               unsigned char *remote_head_sha1;
                if (squash)
                        die(_("Squash commit into empty head not supported yet"));
                if (fast_forward == FF_NO)
@@ -1269,13 +1270,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                            "an empty head"));
                remoteheads = collect_parents(head_commit, &head_subsumed,
                                              argc, argv, NULL);
-               remote_head = remoteheads->item;
-               if (!remote_head)
+               if (!remoteheads)
                        die(_("%s - not something we can merge"), argv[0]);
                if (remoteheads->next)
                        die(_("Can merge only exactly one commit into empty head"));
-               read_empty(remote_head->object.sha1, 0);
-               update_ref("initial pull", "HEAD", remote_head->object.sha1,
+               remote_head_sha1 = remoteheads->item->object.oid.hash;
+               read_empty(remote_head_sha1, 0);
+               update_ref("initial pull", "HEAD", remote_head_sha1,
                           NULL, 0, UPDATE_REFS_DIE_ON_ERR);
                goto done;
        }
@@ -1289,7 +1290,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * additional safety measure to check for it.
         */
        if (!have_message &&
-           is_old_style_invocation(argc, argv, head_commit->object.sha1)) {
+           is_old_style_invocation(argc, argv, head_commit->object.oid.hash)) {
                warning("old-style 'git merge <msg> HEAD <commit>' is deprecated.");
                strbuf_addstr(&merge_msg, argv[0]);
                head_arg = argv[1];
@@ -1317,13 +1318,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (verify_signatures) {
                for (p = remoteheads; p; p = p->next) {
                        struct commit *commit = p->item;
-                       char hex[41];
+                       char hex[GIT_SHA1_HEXSZ + 1];
                        struct signature_check signature_check;
                        memset(&signature_check, 0, sizeof(signature_check));
 
                        check_commit_signature(commit, &signature_check);
 
-                       strcpy(hex, find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV));
+                       find_unique_abbrev_r(hex, commit->object.oid.hash, DEFAULT_ABBREV);
                        switch (signature_check.result) {
                        case 'G':
                                break;
@@ -1353,7 +1354,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        for (p = remoteheads; p; p = p->next) {
                struct commit *commit = p->item;
                strbuf_addf(&buf, "GITHEAD_%s",
-                           sha1_to_hex(commit->object.sha1));
+                           sha1_to_hex(commit->object.oid.hash));
                setenv(buf.buf, merge_remote_util(commit)->name, 1);
                strbuf_reset(&buf);
                if (fast_forward != FF_ONLY &&
@@ -1393,7 +1394,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                free(list);
        }
 
-       update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.sha1,
+       update_ref("updating ORIG_HEAD", "ORIG_HEAD", head_commit->object.oid.hash,
                   NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 
        if (remoteheads && !common)
@@ -1409,19 +1410,19 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                goto done;
        } else if (fast_forward != FF_NO && !remoteheads->next &&
                        !common->next &&
-                       !hashcmp(common->item->object.sha1, head_commit->object.sha1)) {
+                       !hashcmp(common->item->object.oid.hash, head_commit->object.oid.hash)) {
                /* Again the most common case of merging one remote. */
                struct strbuf msg = STRBUF_INIT;
                struct commit *commit;
-               char hex[41];
-
-               strcpy(hex, find_unique_abbrev(head_commit->object.sha1, DEFAULT_ABBREV));
 
-               if (verbosity >= 0)
-                       printf(_("Updating %s..%s\n"),
-                               hex,
-                               find_unique_abbrev(remoteheads->item->object.sha1,
-                               DEFAULT_ABBREV));
+               if (verbosity >= 0) {
+                       char from[GIT_SHA1_HEXSZ + 1], to[GIT_SHA1_HEXSZ + 1];
+                       find_unique_abbrev_r(from, head_commit->object.oid.hash,
+                                             DEFAULT_ABBREV);
+                       find_unique_abbrev_r(to, remoteheads->item->object.oid.hash,
+                                             DEFAULT_ABBREV);
+                       printf(_("Updating %s..%s\n"), from, to);
+               }
                strbuf_addstr(&msg, "Fast-forward");
                if (have_message)
                        strbuf_addstr(&msg,
@@ -1432,14 +1433,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        goto done;
                }
 
-               if (checkout_fast_forward(head_commit->object.sha1,
-                                         commit->object.sha1,
+               if (checkout_fast_forward(head_commit->object.oid.hash,
+                                         commit->object.oid.hash,
                                          overwrite_ignore)) {
                        ret = 1;
                        goto done;
                }
 
-               finish(head_commit, remoteheads, commit->object.sha1, msg.buf);
+               finish(head_commit, remoteheads, commit->object.oid.hash, msg.buf);
                drop_save();
                goto done;
        } else if (!remoteheads->next && common->next)
@@ -1458,9 +1459,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        /* See if it is really trivial. */
                        git_committer_info(IDENT_STRICT);
                        printf(_("Trying really trivial in-index merge...\n"));
-                       if (!read_tree_trivial(common->item->object.sha1,
-                                              head_commit->object.sha1,
-                                              remoteheads->item->object.sha1)) {
+                       if (!read_tree_trivial(common->item->object.oid.hash,
+                                              head_commit->object.oid.hash,
+                                              remoteheads->item->object.oid.hash)) {
                                ret = merge_trivial(head_commit, remoteheads);
                                goto done;
                        }
@@ -1483,8 +1484,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                         * HEAD^^" would be missed.
                         */
                        common_one = get_merge_bases(head_commit, j->item);
-                       if (hashcmp(common_one->item->object.sha1,
-                               j->item->object.sha1)) {
+                       if (hashcmp(common_one->item->object.oid.hash,
+                               j->item->object.oid.hash)) {
                                up_to_date = 0;
                                break;
                        }
@@ -1520,7 +1521,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                int ret;
                if (i) {
                        printf(_("Rewinding the tree to pristine...\n"));
-                       restore_state(head_commit->object.sha1, stash);
+                       restore_state(head_commit->object.oid.hash, stash);
                }
                if (use_strategies_nr != 1)
                        printf(_("Trying merge strategy %s...\n"),
@@ -1586,7 +1587,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
         * it up.
         */
        if (!best_strategy) {
-               restore_state(head_commit->object.sha1, stash);
+               restore_state(head_commit->object.oid.hash, stash);
                if (use_strategies_nr > 1)
                        fprintf(stderr,
                                _("No merge strategy handled the merge.\n"));
@@ -1599,7 +1600,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                ; /* We already have its result in the working tree. */
        else {
                printf(_("Rewinding the tree to pristine...\n"));
-               restore_state(head_commit->object.sha1, stash);
+               restore_state(head_commit->object.oid.hash, stash);
                printf(_("Using the %s to prepare resolving by hand.\n"),
                        best_strategy);
                try_merge_strategy(best_strategy, common, remoteheads,