tree-diff: don't access hash of NULL object_id pointer
[gitweb.git] / sequencer.c
index e44c015b2c925bc3ee001097c9a181ffd66f2081..7a114def84e7d8649934d28c51da7306617b089c 100644 (file)
@@ -344,7 +344,7 @@ static int read_oneliner(struct strbuf *buf,
 
 static struct tree *empty_tree(void)
 {
-       return lookup_tree(EMPTY_TREE_SHA1_BIN);
+       return lookup_tree(&empty_tree_oid);
 }
 
 static int error_dirty_index(struct replay_opts *opts)
@@ -374,7 +374,7 @@ static void update_abort_safety_file(void)
                write_file(git_path_abort_safety_file(), "%s", "");
 }
 
-static int fast_forward_to(const unsigned char *to, const unsigned char *from,
+static int fast_forward_to(const struct object_id *to, const struct object_id *from,
                        int unborn, struct replay_opts *opts)
 {
        struct ref_transaction *transaction;
@@ -390,7 +390,7 @@ static int fast_forward_to(const unsigned char *to, const unsigned char *from,
        transaction = ref_transaction_begin(&err);
        if (!transaction ||
            ref_transaction_update(transaction, "HEAD",
-                                  to, unborn ? null_sha1 : from,
+                                  to->hash, unborn ? null_sha1 : from->hash,
                                   0, sb.buf, &err) ||
            ref_transaction_commit(transaction, &err)) {
                ref_transaction_free(transaction);
@@ -426,7 +426,7 @@ void append_conflicts_hint(struct strbuf *msgbuf)
 
 static int do_recursive_merge(struct commit *base, struct commit *next,
                              const char *base_label, const char *next_label,
-                             unsigned char *head, struct strbuf *msgbuf,
+                             struct object_id *head, struct strbuf *msgbuf,
                              struct replay_opts *opts)
 {
        struct merge_options o;
@@ -488,7 +488,7 @@ static int is_index_unchanged(void)
        if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_oid.hash, NULL))
                return error(_("could not resolve HEAD commit\n"));
 
-       head_commit = lookup_commit(head_oid.hash);
+       head_commit = lookup_commit(&head_oid);
 
        /*
         * If head_commit is NULL, check_commit, called from
@@ -841,7 +841,7 @@ static int update_squash_messages(enum todo_command command,
 
                if (get_oid("HEAD", &head))
                        return error(_("need a HEAD to fixup"));
-               if (!(head_commit = lookup_commit_reference(head.hash)))
+               if (!(head_commit = lookup_commit_reference(&head)))
                        return error(_("could not read HEAD"));
                if (!(head_message = get_commit_buffer(head_commit, NULL)))
                        return error(_("could not read HEAD's commit message"));
@@ -935,7 +935,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
 {
        unsigned int flags = opts->edit ? EDIT_MSG : 0;
        const char *msg_file = opts->edit ? NULL : git_path_merge_msg();
-       unsigned char head[20];
+       struct object_id head;
        struct commit *base, *next, *parent;
        const char *base_label, *next_label;
        struct commit_message msg = { NULL, NULL, NULL, NULL };
@@ -949,12 +949,12 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                 * that represents the "current" state for merge-recursive
                 * to work on.
                 */
-               if (write_cache_as_tree(head, 0, NULL))
+               if (write_cache_as_tree(head.hash, 0, NULL))
                        return error(_("your index file is unmerged."));
        } else {
-               unborn = get_sha1("HEAD", head);
+               unborn = get_oid("HEAD", &head);
                if (unborn)
-                       hashcpy(head, EMPTY_TREE_SHA1_BIN);
+                       oidcpy(&head, &empty_tree_oid);
                if (index_differs_from(unborn ? EMPTY_TREE_SHA1_HEX : "HEAD", 0, 0))
                        return error_dirty_index(opts);
        }
@@ -990,11 +990,11 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                        oid_to_hex(&commit->object.oid));
 
        if (opts->allow_ff && !is_fixup(command) &&
-           ((parent && !hashcmp(parent->object.oid.hash, head)) ||
+           ((parent && !oidcmp(&parent->object.oid, &head)) ||
             (!parent && unborn))) {
                if (is_rebase_i(opts))
                        write_author_script(msg.message);
-               res = fast_forward_to(commit->object.oid.hash, head, unborn,
+               res = fast_forward_to(&commit->object.oid, &head, unborn,
                        opts);
                if (res || command != TODO_REWORD)
                        goto leave;
@@ -1046,6 +1046,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                        strbuf_addstr(&msgbuf, p);
 
                if (opts->record_origin) {
+                       strbuf_complete_line(&msgbuf);
                        if (!has_conforming_footer(&msgbuf, NULL, 0))
                                strbuf_addch(&msgbuf, '\n');
                        strbuf_addstr(&msgbuf, cherry_picked_prefix);
@@ -1081,7 +1082,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                res = -1;
        else if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) {
                res = do_recursive_merge(base, next, base_label, next_label,
-                                        head, &msgbuf, opts);
+                                        &head, &msgbuf, opts);
                if (res < 0)
                        return res;
                res |= write_message(msgbuf.buf, msgbuf.len,
@@ -1097,7 +1098,7 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
                commit_list_insert(next, &remotes);
                res |= try_merge_command(opts->strategy,
                                         opts->xopts_nr, (const char **)opts->xopts,
-                                       common, sha1_to_hex(head), remotes);
+                                       common, oid_to_hex(&head), remotes);
                free_commit_list(common);
                free_commit_list(remotes);
        }
@@ -1280,7 +1281,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
        if (status < 0)
                return -1;
 
-       item->commit = lookup_commit_reference(commit_oid.hash);
+       item->commit = lookup_commit_reference(&commit_oid);
        return !item->commit;
 }
 
@@ -1914,11 +1915,13 @@ static int apply_autostash(struct replay_opts *opts)
        strbuf_trim(&stash_sha1);
 
        child.git_cmd = 1;
+       child.no_stdout = 1;
+       child.no_stderr = 1;
        argv_array_push(&child.args, "stash");
        argv_array_push(&child.args, "apply");
        argv_array_push(&child.args, stash_sha1.buf);
        if (!run_command(&child))
-               printf(_("Applied autostash."));
+               printf(_("Applied autostash.\n"));
        else {
                struct child_process store = CHILD_PROCESS_INIT;
 
@@ -2089,6 +2092,7 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                                res = error(_("could not read orig-head"));
                                goto cleanup_head_ref;
                        }
+                       strbuf_reset(&buf);
                        if (!read_oneliner(&buf, rebase_path_onto(), 0)) {
                                res = error(_("could not read 'onto'"));
                                goto cleanup_head_ref;
@@ -2125,8 +2129,8 @@ static int pick_commits(struct todo_list *todo_list, struct replay_opts *opts)
                        if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
                            !get_sha1(buf.buf, orig.hash) &&
                            !get_sha1("HEAD", head.hash)) {
-                               diff_tree_sha1(orig.hash, head.hash,
-                                              "", &log_tree_opt.diffopt);
+                               diff_tree_oid(&orig, &head, "",
+                                             &log_tree_opt.diffopt);
                                log_tree_diff_flush(&log_tree_opt);
                        }
                }
@@ -2297,7 +2301,7 @@ int sequencer_pick_revisions(struct replay_opts *opts)
                        continue;
 
                if (!get_oid(name, &oid)) {
-                       if (!lookup_commit_reference_gently(oid.hash, 1)) {
+                       if (!lookup_commit_reference_gently(&oid, 1)) {
                                enum object_type type = sha1_object_info(oid.hash, NULL);
                                return error(_("%s: can't cherry-pick a %s"),
                                        name, typename(type));
@@ -2358,6 +2362,9 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
                                getenv("GIT_COMMITTER_EMAIL")));
        strbuf_addch(&sob, '\n');
 
+       if (!ignore_footer)
+               strbuf_complete_line(msgbuf);
+
        /*
         * If the whole message buffer is equal to the sob, pretend that we
         * found a conforming footer with a matching sob
@@ -2378,13 +2385,6 @@ void append_signoff(struct strbuf *msgbuf, int ignore_footer, unsigned flag)
                         * the title and body to be filled in by the user.
                         */
                        append_newlines = "\n\n";
-               } else if (msgbuf->buf[len - 1] != '\n') {
-                       /*
-                        * Incomplete line.  Complete the line and add a
-                        * blank one so that there is an empty line between
-                        * the message body and the sob.
-                        */
-                       append_newlines = "\n\n";
                } else if (len == 1) {
                        /*
                         * Buffer contains a single newline.  Add another