ref-filter: consult want_color() before emitting colors
[gitweb.git] / sequencer.c
index 8c72cf16145dc80edec90c6d4fb68811c0c65399..3010faf86398697469e903318a35421d911acb23 100644 (file)
@@ -1,4 +1,5 @@
 #include "cache.h"
+#include "config.h"
 #include "lockfile.h"
 #include "sequencer.h"
 #include "dir.h"
@@ -344,7 +345,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 +375,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 +391,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 +427,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;
@@ -483,13 +484,13 @@ static int do_recursive_merge(struct commit *base, struct commit *next,
 
 static int is_index_unchanged(void)
 {
-       unsigned char head_sha1[20];
+       struct object_id head_oid;
        struct commit *head_commit;
 
-       if (!resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, head_sha1, NULL))
+       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_sha1);
+       head_commit = lookup_commit(&head_oid);
 
        /*
         * If head_commit is NULL, check_commit, called from
@@ -509,7 +510,8 @@ static int is_index_unchanged(void)
                if (cache_tree_update(&the_index, 0))
                        return error(_("unable to update cache tree\n"));
 
-       return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.oid.hash);
+       return !oidcmp(&active_cache_tree->oid,
+                      &head_commit->tree->object.oid);
 }
 
 static int write_author_script(const char *message)
@@ -835,13 +837,13 @@ static int update_squash_messages(enum todo_command command,
                strbuf_splice(&buf, 0, eol - buf.buf, header.buf, header.len);
                strbuf_release(&header);
        } else {
-               unsigned char head[20];
+               struct object_id head;
                struct commit *head_commit;
                const char *head_message, *body;
 
-               if (get_sha1("HEAD", head))
+               if (get_oid("HEAD", &head))
                        return error(_("need a HEAD to fixup"));
-               if (!(head_commit = lookup_commit_reference(head)))
+               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"));
@@ -898,8 +900,8 @@ static void flush_rewritten_pending(void) {
        FILE *out;
 
        if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), 82) > 0 &&
-                       !get_sha1("HEAD", newsha1) &&
-                       (out = fopen(rebase_path_rewritten_list(), "a"))) {
+           !get_sha1("HEAD", newsha1) &&
+           (out = fopen_or_warn(rebase_path_rewritten_list(), "a"))) {
                char *bol = buf.buf, *eol;
 
                while (*bol) {
@@ -918,7 +920,7 @@ static void flush_rewritten_pending(void) {
 
 static void record_in_rewritten(struct object_id *oid,
                enum todo_command next_command) {
-       FILE *out = fopen(rebase_path_rewritten_pending(), "a");
+       FILE *out = fopen_or_warn(rebase_path_rewritten_pending(), "a");
 
        if (!out)
                return;
@@ -935,7 +937,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 +951,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 +992,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;
@@ -1082,7 +1084,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,
@@ -1098,7 +1100,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);
        }
@@ -1210,8 +1212,7 @@ struct todo_list {
 static void todo_list_release(struct todo_list *todo_list)
 {
        strbuf_release(&todo_list->buf);
-       free(todo_list->items);
-       todo_list->items = NULL;
+       FREE_AND_NULL(todo_list->items);
        todo_list->nr = todo_list->alloc = 0;
 }
 
@@ -1223,7 +1224,7 @@ static struct todo_item *append_new_todo(struct todo_list *todo_list)
 
 static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
 {
-       unsigned char commit_sha1[20];
+       struct object_id commit_oid;
        char *end_of_object_name;
        int i, saved, status, padding;
 
@@ -1272,7 +1273,7 @@ static int parse_insn_line(struct todo_item *item, const char *bol, char *eol)
        end_of_object_name = (char *) bol + strcspn(bol, " \t\n");
        saved = *end_of_object_name;
        *end_of_object_name = '\0';
-       status = get_sha1(bol, commit_sha1);
+       status = get_oid(bol, &commit_oid);
        *end_of_object_name = saved;
 
        item->arg = end_of_object_name + strspn(end_of_object_name, " \t");
@@ -1281,7 +1282,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_sha1);
+       item->commit = lookup_commit_reference(&commit_oid);
        return !item->commit;
 }
 
@@ -1380,7 +1381,7 @@ static int read_populate_todo(struct todo_list *todo_list,
 
        if (is_rebase_i(opts)) {
                struct todo_list done = TODO_LIST_INIT;
-               FILE *f = fopen(rebase_path_msgtotal(), "w");
+               FILE *f = fopen_or_warn(rebase_path_msgtotal(), "w");
 
                if (strbuf_read_file(&done.buf, rebase_path_done(), 0) > 0 &&
                                !parse_insn_buffer(done.buf.buf, &done))
@@ -1921,7 +1922,7 @@ static int apply_autostash(struct replay_opts *opts)
        argv_array_push(&child.args, "apply");
        argv_array_push(&child.args, stash_sha1.buf);
        if (!run_command(&child))
-               printf(_("Applied autostash.\n"));
+               fprintf(stderr, _("Applied autostash.\n"));
        else {
                struct child_process store = CHILD_PROCESS_INIT;
 
@@ -1935,10 +1936,11 @@ static int apply_autostash(struct replay_opts *opts)
                if (run_command(&store))
                        ret = error(_("cannot store %s"), stash_sha1.buf);
                else
-                       printf(_("Applying autostash resulted in conflicts.\n"
-                               "Your changes are safe in the stash.\n"
-                               "You can run \"git stash pop\" or"
-                               " \"git stash drop\" at any time.\n"));
+                       fprintf(stderr,
+                               _("Applying autostash resulted in conflicts.\n"
+                                 "Your changes are safe in the stash.\n"
+                                 "You can run \"git stash pop\" or"
+                                 " \"git stash drop\" at any time.\n"));
        }
 
        strbuf_release(&stash_sha1);
@@ -2129,8 +2131,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);
                        }
                }
@@ -2285,7 +2287,7 @@ static int single_pick(struct commit *cmit, struct replay_opts *opts)
 int sequencer_pick_revisions(struct replay_opts *opts)
 {
        struct todo_list todo_list = TODO_LIST_INIT;
-       unsigned char sha1[20];
+       struct object_id oid;
        int i, res;
 
        assert(opts->revs);
@@ -2293,16 +2295,16 @@ int sequencer_pick_revisions(struct replay_opts *opts)
                return -1;
 
        for (i = 0; i < opts->revs->pending.nr; i++) {
-               unsigned char sha1[20];
+               struct object_id oid;
                const char *name = opts->revs->pending.objects[i].name;
 
                /* This happens when using --stdin. */
                if (!strlen(name))
                        continue;
 
-               if (!get_sha1(name, sha1)) {
-                       if (!lookup_commit_reference_gently(sha1, 1)) {
-                               enum object_type type = sha1_object_info(sha1, NULL);
+               if (!get_oid(name, &oid)) {
+                       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));
                        }
@@ -2339,9 +2341,9 @@ int sequencer_pick_revisions(struct replay_opts *opts)
        if (walk_revs_populate_todo(&todo_list, opts) ||
                        create_seq_dir() < 0)
                return -1;
-       if (get_sha1("HEAD", sha1) && (opts->action == REPLAY_REVERT))
+       if (get_oid("HEAD", &oid) && (opts->action == REPLAY_REVERT))
                return error(_("can't revert as initial commit"));
-       if (save_head(sha1_to_hex(sha1)))
+       if (save_head(oid_to_hex(&oid)))
                return -1;
        if (save_opts(opts))
                return -1;