Convert struct object to object_id
[gitweb.git] / builtin / merge.c
index 63563b9ab00025cee466939bf000eb5b3a806d85..c804218fb4dea0daff8f9b0f1ca277cf732e5f46 100644 (file)
@@ -231,9 +231,9 @@ static struct option builtin_merge_options[] = {
 /* Cleans up metadata that is uninteresting after a succeeded merge. */
 static void drop_save(void)
 {
-       unlink(git_path("MERGE_HEAD"));
-       unlink(git_path("MERGE_MSG"));
-       unlink(git_path("MERGE_MODE"));
+       unlink(git_path_merge_head());
+       unlink(git_path_merge_msg());
+       unlink(git_path_merge_mode());
 }
 
 static int save_state(unsigned char *stash)
@@ -338,7 +338,7 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead
        struct pretty_print_context ctx = {0};
 
        printf(_("Squash commit -- not updating HEAD\n"));
-       filename = git_path("SQUASH_MSG");
+       filename = git_path_squash_msg();
        fd = open(filename, O_WRONLY | O_CREAT, 0666);
        if (fd < 0)
                die_errno(_("Could not write to '%s'"), filename);
@@ -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 = get_object_hash(head_commit->object);
 
        if (!msg)
                strbuf_addstr(&reflog_message, getenv("GIT_REFLOG_ACTION"));
@@ -497,7 +497,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(get_object_hash(remote_head->object)),
                                    truname.buf + 11,
                                    (early ? " (early part)" : ""));
                        strbuf_release(&truname);
@@ -511,7 +511,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(get_object_hash(*desc->obj)),
                                    typename(desc->obj->type),
                                    remote);
                        goto cleanup;
@@ -519,7 +519,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(get_object_hash(remote_head->object)), remote);
 cleanup:
        strbuf_release(&buf);
        strbuf_release(&bname);
@@ -754,7 +754,7 @@ static void add_strategies(const char *string, unsigned attr)
 
 static void write_merge_msg(struct strbuf *msg)
 {
-       const char *filename = git_path("MERGE_MSG");
+       const char *filename = git_path_merge_msg();
        int fd = open(filename, O_WRONLY | O_CREAT, 0666);
        if (fd < 0)
                die_errno(_("Could not open '%s' for writing"),
@@ -766,7 +766,7 @@ static void write_merge_msg(struct strbuf *msg)
 
 static void read_merge_msg(struct strbuf *msg)
 {
-       const char *filename = git_path("MERGE_MSG");
+       const char *filename = git_path_merge_msg();
        strbuf_reset(msg);
        if (strbuf_read_file(msg, filename, 0) < 0)
                die_errno(_("Could not read from '%s'"), filename);
@@ -799,14 +799,14 @@ static void prepare_to_commit(struct commit_list *remoteheads)
                strbuf_commented_addf(&msg, _(merge_editor_comment), comment_line_char);
        write_merge_msg(&msg);
        if (run_commit_hook(0 < option_edit, get_index_file(), "prepare-commit-msg",
-                           git_path("MERGE_MSG"), "merge", NULL))
+                           git_path_merge_msg(), "merge", NULL))
                abort_commit(remoteheads, NULL);
        if (0 < option_edit) {
-               if (launch_editor(git_path("MERGE_MSG"), NULL, NULL))
+               if (launch_editor(git_path_merge_msg(), NULL, NULL))
                        abort_commit(remoteheads, NULL);
        }
        read_merge_msg(&msg);
-       stripspace(&msg, 0 < option_edit);
+       strbuf_stripspace(&msg, 0 < option_edit);
        if (!msg.len)
                abort_commit(remoteheads, _("Empty commit message."));
        strbuf_release(&merge_msg);
@@ -865,7 +865,7 @@ static int suggest_conflicts(void)
        FILE *fp;
        struct strbuf msgbuf = STRBUF_INIT;
 
-       filename = git_path("MERGE_MSG");
+       filename = git_path_merge_msg();
        fp = fopen(filename, "a");
        if (!fp)
                die_errno(_("Could not open '%s' for writing"), filename);
@@ -892,7 +892,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(get_object_hash(second_token->object), head))
                        return NULL;
        }
        return second_token;
@@ -958,16 +958,16 @@ 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");
+       filename = git_path_merge_head();
        fd = open(filename, O_WRONLY | O_CREAT, 0666);
        if (fd < 0)
                die_errno(_("Could not open '%s' for writing"), filename);
@@ -977,7 +977,7 @@ static void write_merge_state(struct commit_list *remoteheads)
        strbuf_addch(&merge_msg, '\n');
        write_merge_msg(&merge_msg);
 
-       filename = git_path("MERGE_MODE");
+       filename = git_path_merge_mode();
        fd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666);
        if (fd < 0)
                die_errno(_("Could not open '%s' for writing"), filename);
@@ -1068,7 +1068,7 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge
        if (!merge_names)
                merge_names = &fetch_head_file;
 
-       filename = git_path("FETCH_HEAD");
+       filename = git_path_fetch_head();
        fd = open(filename, O_RDONLY);
        if (fd < 0)
                die_errno(_("could not open '%s' for reading"), filename);
@@ -1202,7 +1202,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                int nargc = 2;
                const char *nargv[] = {"reset", "--merge", NULL};
 
-               if (!file_exists(git_path("MERGE_HEAD")))
+               if (!file_exists(git_path_merge_head()))
                        die(_("There is no merge to abort (MERGE_HEAD missing)."));
 
                /* Invoke 'git reset --merge' */
@@ -1213,7 +1213,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
        if (read_cache_unmerged())
                die_resolve_conflict("merge");
 
-       if (file_exists(git_path("MERGE_HEAD"))) {
+       if (file_exists(git_path_merge_head())) {
                /*
                 * There is no unmerged entry, don't advise 'git
                 * add/rm <file>', just 'git commit'.
@@ -1224,7 +1224,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                else
                        die(_("You have not concluded your merge (MERGE_HEAD exists)."));
        }
-       if (file_exists(git_path("CHERRY_PICK_HEAD"))) {
+       if (file_exists(git_path_cherry_pick_head())) {
                if (advice_resolve_conflict)
                        die(_("You have not concluded your cherry-pick (CHERRY_PICK_HEAD exists).\n"
                            "Please, commit your changes before you merge."));
@@ -1274,8 +1274,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
                        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,
+               read_empty(get_object_hash(remote_head->object), 0);
+               update_ref("initial pull", "HEAD", get_object_hash(remote_head->object),
                           NULL, 0, UPDATE_REFS_DIE_ON_ERR);
                goto done;
        }
@@ -1289,7 +1289,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, get_object_hash(head_commit->object))) {
                warning("old-style 'git merge <msg> HEAD <commit>' is deprecated.");
                strbuf_addstr(&merge_msg, argv[0]);
                head_arg = argv[1];
@@ -1317,13 +1317,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, get_object_hash(commit->object), DEFAULT_ABBREV);
                        switch (signature_check.result) {
                        case 'G':
                                break;
@@ -1353,7 +1353,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(get_object_hash(commit->object)));
                setenv(buf.buf, merge_remote_util(commit)->name, 1);
                strbuf_reset(&buf);
                if (fast_forward != FF_ONLY &&
@@ -1393,7 +1393,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", get_object_hash(head_commit->object),
                   NULL, 0, UPDATE_REFS_DIE_ON_ERR);
 
        if (remoteheads && !common)
@@ -1409,19 +1409,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(get_object_hash(common->item->object), get_object_hash(head_commit->object))) {
                /* 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, get_object_hash(head_commit->object),
+                                             DEFAULT_ABBREV);
+                       find_unique_abbrev_r(to, get_object_hash(remoteheads->item->object),
+                                             DEFAULT_ABBREV);
+                       printf(_("Updating %s..%s\n"), from, to);
+               }
                strbuf_addstr(&msg, "Fast-forward");
                if (have_message)
                        strbuf_addstr(&msg,
@@ -1432,14 +1432,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(get_object_hash(head_commit->object),
+                                         get_object_hash(commit->object),
                                          overwrite_ignore)) {
                        ret = 1;
                        goto done;
                }
 
-               finish(head_commit, remoteheads, commit->object.sha1, msg.buf);
+               finish(head_commit, remoteheads, get_object_hash(commit->object), msg.buf);
                drop_save();
                goto done;
        } else if (!remoteheads->next && common->next)
@@ -1458,9 +1458,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(get_object_hash(common->item->object),
+                                              get_object_hash(head_commit->object),
+                                              get_object_hash(remoteheads->item->object))) {
                                ret = merge_trivial(head_commit, remoteheads);
                                goto done;
                        }
@@ -1483,8 +1483,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(get_object_hash(common_one->item->object),
+                               get_object_hash(j->item->object))) {
                                up_to_date = 0;
                                break;
                        }
@@ -1520,7 +1520,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(get_object_hash(head_commit->object), stash);
                }
                if (use_strategies_nr != 1)
                        printf(_("Trying merge strategy %s...\n"),
@@ -1586,7 +1586,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(get_object_hash(head_commit->object), stash);
                if (use_strategies_nr > 1)
                        fprintf(stderr,
                                _("No merge strategy handled the merge.\n"));
@@ -1599,7 +1599,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(get_object_hash(head_commit->object), stash);
                printf(_("Using the %s to prepare resolving by hand.\n"),
                        best_strategy);
                try_merge_strategy(best_strategy, common, remoteheads,