unlock_ref(): move definition higher in the file
[gitweb.git] / sequencer.c
index 129fa8f04f15db99658ea56ee0fe710dc5e82953..e66f2fe0f0409cccf1647f7851044f91d68252a6 100644 (file)
@@ -124,42 +124,33 @@ static const char *action_name(const struct replay_opts *opts)
 
 struct commit_message {
        char *parent_label;
-       const char *label;
-       const char *subject;
+       char *label;
+       char *subject;
        const char *message;
 };
 
 static int get_message(struct commit *commit, struct commit_message *out)
 {
        const char *abbrev, *subject;
-       int abbrev_len, subject_len;
-       char *q;
-
-       if (!git_commit_encoding)
-               git_commit_encoding = "UTF-8";
+       int subject_len;
 
-       out->message = logmsg_reencode(commit, NULL, git_commit_encoding);
+       out->message = logmsg_reencode(commit, NULL, get_commit_output_encoding());
        abbrev = find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV);
-       abbrev_len = strlen(abbrev);
 
        subject_len = find_commit_subject(out->message, &subject);
 
-       out->parent_label = xmalloc(strlen("parent of ") + abbrev_len +
-                             strlen("... ") + subject_len + 1);
-       q = out->parent_label;
-       q = mempcpy(q, "parent of ", strlen("parent of "));
-       out->label = q;
-       q = mempcpy(q, abbrev, abbrev_len);
-       q = mempcpy(q, "... ", strlen("... "));
-       out->subject = q;
-       q = mempcpy(q, subject, subject_len);
-       *q = '\0';
+       out->subject = xmemdupz(subject, subject_len);
+       out->label = xstrfmt("%s... %s", abbrev, out->subject);
+       out->parent_label = xstrfmt("parent of %s", out->label);
+
        return 0;
 }
 
 static void free_message(struct commit *commit, struct commit_message *msg)
 {
        free(msg->parent_label);
+       free(msg->label);
+       free(msg->subject);
        unuse_commit_buffer(commit, msg->message);
 }
 
@@ -346,7 +337,7 @@ 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, get_object_hash(head_commit->tree->object));
+       return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.oid.hash);
 }
 
 /*
@@ -403,12 +394,12 @@ static int is_original_commit_empty(struct commit *commit)
                if (parse_commit(parent))
                        return error(_("Could not parse parent commit %s\n"),
                                oid_to_hex(&parent->object.oid));
-               ptree_sha1 = get_object_hash(parent->tree->object);
+               ptree_sha1 = parent->tree->object.oid.hash;
        } else {
                ptree_sha1 = EMPTY_TREE_SHA1_BIN; /* commit is root */
        }
 
-       return !hashcmp(ptree_sha1, get_object_hash(commit->tree->object));
+       return !hashcmp(ptree_sha1, commit->tree->object.oid.hash);
 }
 
 /*
@@ -503,9 +494,9 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
                parent = commit->parents->item;
 
        if (opts->allow_ff &&
-           ((parent && !hashcmp(get_object_hash(parent->object), head)) ||
+           ((parent && !hashcmp(parent->object.oid.hash, head)) ||
             (!parent && unborn)))
-               return fast_forward_to(get_object_hash(commit->object), head, unborn, opts);
+               return fast_forward_to(commit->object.oid.hash, head, unborn, opts);
 
        if (parent && parse_commit(parent) < 0)
                /* TRANSLATORS: The first %s will be "revert" or
@@ -592,17 +583,17 @@ static int do_pick_commit(struct commit *commit, struct replay_opts *opts)
         * write it at all.
         */
        if (opts->action == REPLAY_PICK && !opts->no_commit && (res == 0 || res == 1))
-               update_ref(NULL, "CHERRY_PICK_HEAD", get_object_hash(commit->object), NULL,
+               update_ref(NULL, "CHERRY_PICK_HEAD", commit->object.oid.hash, NULL,
                           REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
        if (opts->action == REPLAY_REVERT && ((opts->no_commit && res == 0) || res == 1))
-               update_ref(NULL, "REVERT_HEAD", get_object_hash(commit->object), NULL,
+               update_ref(NULL, "REVERT_HEAD", commit->object.oid.hash, NULL,
                           REF_NODEREF, UPDATE_REFS_DIE_ON_ERR);
 
        if (res) {
                error(opts->action == REPLAY_REVERT
                      ? _("could not revert %s... %s")
                      : _("could not apply %s... %s"),
-                     find_unique_abbrev(get_object_hash(commit->object), DEFAULT_ABBREV),
+                     find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV),
                      msg.subject);
                print_advice(res == 1, opts);
                rerere(opts->allow_rerere_auto);
@@ -664,7 +655,7 @@ static int format_todo(struct strbuf *buf, struct commit_list *todo_list,
 
        for (cur = todo_list; cur; cur = cur->next) {
                const char *commit_buffer = get_commit_buffer(cur->item, NULL);
-               sha1_abbrev = find_unique_abbrev(get_object_hash(cur->item->object), DEFAULT_ABBREV);
+               sha1_abbrev = find_unique_abbrev(cur->item->object.oid.hash, DEFAULT_ABBREV);
                subject_len = find_commit_subject(commit_buffer, &subject);
                strbuf_addf(buf, "%s %s %.*s\n", action_str, sha1_abbrev,
                        subject_len, subject);
@@ -886,7 +877,7 @@ static int sequencer_rollback(struct replay_opts *opts)
        if (!f)
                return error(_("cannot open %s: %s"), git_path_head_file(),
                                                strerror(errno));
-       if (strbuf_getline(&buf, f, '\n')) {
+       if (strbuf_getline_lf(&buf, f)) {
                error(_("cannot read %s: %s"), git_path_head_file(),
                      ferror(f) ?  strerror(errno) : _("unexpected end of file"));
                fclose(f);