aboutsummaryrefslogtreecommitdiffstats
path: root/sequencer.c
diff options
context:
space:
mode:
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c175
1 files changed, 90 insertions, 85 deletions
diff --git a/sequencer.c b/sequencer.c
index fc6ea75895..d2c7698c48 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -1,6 +1,9 @@
#include "cache.h"
+#include "abspath.h"
#include "alloc.h"
#include "config.h"
+#include "environment.h"
+#include "gettext.h"
#include "hex.h"
#include "lockfile.h"
#include "dir.h"
@@ -38,6 +41,7 @@
#include "rebase-interactive.h"
#include "reset.h"
#include "branch.h"
+#include "wrapper.h"
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
@@ -415,7 +419,8 @@ struct commit_message {
static const char *short_commit_name(struct commit *commit)
{
- return find_unique_abbrev(&commit->object.oid, DEFAULT_ABBREV);
+ return repo_find_unique_abbrev(the_repository, &commit->object.oid,
+ DEFAULT_ABBREV);
}
static int get_message(struct commit *commit, struct commit_message *out)
@@ -423,7 +428,8 @@ static int get_message(struct commit *commit, struct commit_message *out)
const char *abbrev, *subject;
int subject_len;
- out->message = logmsg_reencode(commit, NULL, get_commit_output_encoding());
+ out->message = repo_logmsg_reencode(the_repository, commit, NULL,
+ get_commit_output_encoding());
abbrev = short_commit_name(commit);
subject_len = find_commit_subject(out->message, &subject);
@@ -440,7 +446,7 @@ 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);
+ repo_unuse_commit_buffer(the_repository, commit, msg->message);
}
static void print_advice(struct repository *r, int show_hint,
@@ -557,7 +563,7 @@ static void update_abort_safety_file(void)
if (!file_exists(git_path_seq_dir()))
return;
- if (!get_oid("HEAD", &head))
+ if (!repo_get_oid(the_repository, "HEAD", &head))
write_file(git_path_abort_safety_file(), "%s", oid_to_hex(&head));
else
write_file(git_path_abort_safety_file(), "%s", "");
@@ -688,8 +694,8 @@ static int do_recursive_merge(struct repository *r,
o.show_rename_progress = 1;
head_tree = parse_tree_indirect(head);
- next_tree = next ? get_commit_tree(next) : empty_tree(r);
- base_tree = base ? get_commit_tree(base) : empty_tree(r);
+ next_tree = next ? repo_get_commit_tree(r, next) : empty_tree(r);
+ base_tree = base ? repo_get_commit_tree(r, base) : empty_tree(r);
for (i = 0; i < opts->xopts.nr; i++)
parse_merge_opt(&o, opts->xopts.v[i]);
@@ -762,12 +768,12 @@ static int is_index_unchanged(struct repository *r)
/*
* If head_commit is NULL, check_commit, called from
* lookup_commit, would have indicated that head_commit is not
- * a commit object already. parse_commit() will return failure
+ * a commit object already. repo_parse_commit() will return failure
* without further complaints in such a case. Otherwise, if
- * the commit is invalid, parse_commit() will complain. So
+ * the commit is invalid, repo_parse_commit() will complain. So
* there is nothing for us to say here. Just return failure.
*/
- if (parse_commit(head_commit))
+ if (repo_parse_commit(r, head_commit))
return -1;
if (!(cache_tree_oid = get_cache_tree_oid(istate)))
@@ -1332,13 +1338,15 @@ void print_commit_summary(struct repository *r,
commit = lookup_commit(r, oid);
if (!commit)
die(_("couldn't look up newly created commit"));
- if (parse_commit(commit))
+ if (repo_parse_commit(r, commit))
die(_("could not parse newly created commit"));
strbuf_addstr(&format, "format:%h] %s");
- format_commit_message(commit, "%an <%ae>", &author_ident, &pctx);
- format_commit_message(commit, "%cn <%ce>", &committer_ident, &pctx);
+ repo_format_commit_message(r, commit, "%an <%ae>", &author_ident,
+ &pctx);
+ repo_format_commit_message(r, commit, "%cn <%ce>", &committer_ident,
+ &pctx);
if (strbuf_cmp(&author_ident, &committer_ident)) {
strbuf_addstr(&format, "\n Author: ");
strbuf_addbuf_percentquote(&format, &author_ident);
@@ -1346,7 +1354,7 @@ void print_commit_summary(struct repository *r,
if (flags & SUMMARY_SHOW_AUTHOR_DATE) {
struct strbuf date = STRBUF_INIT;
- format_commit_message(commit, "%ad", &date, &pctx);
+ repo_format_commit_message(r, commit, "%ad", &date, &pctx);
strbuf_addstr(&format, "\n Date: ");
strbuf_addbuf_percentquote(&format, &date);
strbuf_release(&date);
@@ -1376,7 +1384,7 @@ void print_commit_summary(struct repository *r,
rev.diffopt.detect_rename = DIFF_DETECT_RENAME;
diff_setup_done(&rev.diffopt);
- refs = get_main_ref_store(the_repository);
+ refs = get_main_ref_store(r);
head = refs_resolve_ref_unsafe(refs, "HEAD", 0, NULL, NULL);
if (!head)
die(_("unable to resolve HEAD after creating commit"));
@@ -1402,7 +1410,7 @@ static int parse_head(struct repository *r, struct commit **head)
struct commit *current_head;
struct object_id oid;
- if (get_oid("HEAD", &oid)) {
+ if (repo_get_oid(r, "HEAD", &oid)) {
current_head = NULL;
} else {
current_head = lookup_commit_reference(r, &oid);
@@ -1412,7 +1420,7 @@ static int parse_head(struct repository *r, struct commit **head)
warning(_("HEAD %s is not a commit!"),
oid_to_hex(&oid));
}
- if (parse_commit(current_head))
+ if (repo_parse_commit(r, current_head))
return error(_("could not parse HEAD commit"));
}
*head = current_head;
@@ -1455,8 +1463,8 @@ static int try_to_commit(struct repository *r,
if (flags & AMEND_MSG) {
const char *exclude_gpgsig[] = { "gpgsig", "gpgsig-sha256", NULL };
const char *out_enc = get_commit_output_encoding();
- const char *message = logmsg_reencode(current_head, NULL,
- out_enc);
+ const char *message = repo_logmsg_reencode(r, current_head,
+ NULL, out_enc);
if (!msg) {
const char *orig_message = NULL;
@@ -1467,7 +1475,8 @@ static int try_to_commit(struct repository *r,
hook_commit = "HEAD";
}
author = amend_author = get_author(message);
- unuse_commit_buffer(current_head, message);
+ repo_unuse_commit_buffer(r, current_head,
+ message);
if (!author) {
res = error(_("unable to parse commit author"));
goto out;
@@ -1664,12 +1673,12 @@ static int is_original_commit_empty(struct commit *commit)
{
const struct object_id *ptree_oid;
- if (parse_commit(commit))
+ if (repo_parse_commit(the_repository, commit))
return error(_("could not parse commit %s"),
oid_to_hex(&commit->object.oid));
if (commit->parents) {
struct commit *parent = commit->parents->item;
- if (parse_commit(parent))
+ if (repo_parse_commit(the_repository, parent))
return error(_("could not parse parent commit %s"),
oid_to_hex(&parent->object.oid));
ptree_oid = get_commit_tree_oid(parent);
@@ -1993,17 +2002,18 @@ static int update_squash_messages(struct repository *r,
struct commit *head_commit;
const char *head_message, *body;
- if (get_oid("HEAD", &head))
+ if (repo_get_oid(r, "HEAD", &head))
return error(_("need a HEAD to fixup"));
if (!(head_commit = lookup_commit_reference(r, &head)))
return error(_("could not read HEAD"));
- if (!(head_message = logmsg_reencode(head_commit, NULL, encoding)))
+ if (!(head_message = repo_logmsg_reencode(r, head_commit, NULL,
+ encoding)))
return error(_("could not read HEAD's commit message"));
find_commit_subject(head_message, &body);
if (command == TODO_FIXUP && !flag && write_message(body, strlen(body),
rebase_path_fixup_msg(), 0) < 0) {
- unuse_commit_buffer(head_commit, head_message);
+ repo_unuse_commit_buffer(r, head_commit, head_message);
return error(_("cannot write '%s'"), rebase_path_fixup_msg());
}
strbuf_addf(&buf, "%c ", comment_line_char);
@@ -2018,10 +2028,10 @@ static int update_squash_messages(struct repository *r,
else
strbuf_addstr(&buf, body);
- unuse_commit_buffer(head_commit, head_message);
+ repo_unuse_commit_buffer(r, head_commit, head_message);
}
- if (!(message = logmsg_reencode(commit, NULL, encoding)))
+ if (!(message = repo_logmsg_reencode(r, commit, NULL, encoding)))
return error(_("could not read commit message of %s"),
oid_to_hex(&commit->object.oid));
find_commit_subject(message, &body);
@@ -2036,7 +2046,7 @@ static int update_squash_messages(struct repository *r,
strbuf_add_commented_lines(&buf, body, strlen(body));
} else
return error(_("unknown command: %d"), command);
- unuse_commit_buffer(commit, message);
+ repo_unuse_commit_buffer(r, commit, message);
if (!res)
res = write_message(buf.buf, buf.len, rebase_path_squash_msg(),
@@ -2063,7 +2073,7 @@ static void flush_rewritten_pending(void)
FILE *out;
if (strbuf_read_file(&buf, rebase_path_rewritten_pending(), (GIT_MAX_HEXSZ + 1) * 2) > 0 &&
- !get_oid("HEAD", &newoid) &&
+ !repo_get_oid(the_repository, "HEAD", &newoid) &&
(out = fopen_or_warn(rebase_path_rewritten_list(), "a"))) {
char *bol = buf.buf, *eol;
@@ -2115,7 +2125,8 @@ static void refer_to_commit(struct replay_opts *opts,
.abbrev = DEFAULT_ABBREV,
.date_mode.type = DATE_SHORT,
};
- format_commit_message(commit, "%h (%s, %ad)", msgbuf, &ctx);
+ repo_format_commit_message(the_repository, commit,
+ "%h (%s, %ad)", msgbuf, &ctx);
} else {
strbuf_addstr(msgbuf, oid_to_hex(&commit->object.oid));
}
@@ -2148,7 +2159,7 @@ static int do_pick_commit(struct repository *r,
if (write_index_as_tree(&head, r->index, r->index_file, 0, NULL))
return error(_("your index file is unmerged."));
} else {
- unborn = get_oid("HEAD", &head);
+ unborn = repo_get_oid(r, "HEAD", &head);
/* Do we want to generate a root commit? */
if (is_pick_or_similar(command) && opts->have_squash_onto &&
oideq(&head, &opts->squash_onto)) {
@@ -2210,7 +2221,7 @@ static int do_pick_commit(struct repository *r,
msg_file = NULL;
goto fast_forward_edit;
}
- if (parent && parse_commit(parent) < 0)
+ if (parent && repo_parse_commit(r, parent) < 0)
/* TRANSLATORS: The first %s will be a "todo" command like
"revert" or "pick", the second %s a SHA1. */
return error(_("%s: cannot parse parent commit %s"),
@@ -2602,7 +2613,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
end_of_object_name = (char *) bol + strcspn(bol, " \t\n");
saved = *end_of_object_name;
*end_of_object_name = '\0';
- status = get_oid(bol, &commit_oid);
+ status = repo_get_oid(r, bol, &commit_oid);
if (status < 0)
error(_("could not parse '%s'"), bol); /* return later */
*end_of_object_name = saved;
@@ -3021,7 +3032,7 @@ static int read_populate_opts(struct replay_opts *opts)
}
if (read_oneliner(&buf, rebase_path_squash_onto(), 0)) {
- if (get_oid_committish(buf.buf, &opts->squash_onto) < 0) {
+ if (repo_get_oid_committish(the_repository, buf.buf, &opts->squash_onto) < 0) {
ret = error(_("unusable squash-onto"));
goto done_rebase_i;
}
@@ -3122,7 +3133,9 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
while ((commit = get_revision(opts->revs))) {
struct todo_item *item = append_new_todo(todo_list);
- const char *commit_buffer = logmsg_reencode(commit, NULL, encoding);
+ const char *commit_buffer = repo_logmsg_reencode(the_repository,
+ commit, NULL,
+ encoding);
const char *subject;
int subject_len;
@@ -3134,7 +3147,8 @@ static int walk_revs_populate_todo(struct todo_list *todo_list,
subject_len = find_commit_subject(commit_buffer, &subject);
strbuf_addf(&todo_list->buf, "%s %s %.*s\n", command_string,
short_commit_name(commit), subject_len, subject);
- unuse_commit_buffer(commit, commit_buffer);
+ repo_unuse_commit_buffer(the_repository, commit,
+ commit_buffer);
}
if (!todo_list->nr)
@@ -3184,25 +3198,7 @@ static int create_seq_dir(struct repository *r)
static int save_head(const char *head)
{
- struct lock_file head_lock = LOCK_INIT;
- struct strbuf buf = STRBUF_INIT;
- int fd;
- ssize_t written;
-
- fd = hold_lock_file_for_update(&head_lock, git_path_head_file(), 0);
- if (fd < 0)
- return error_errno(_("could not lock HEAD"));
- strbuf_addf(&buf, "%s\n", head);
- written = write_in_full(fd, buf.buf, buf.len);
- strbuf_release(&buf);
- if (written < 0) {
- error_errno(_("could not write to '%s'"), git_path_head_file());
- rollback_lock_file(&head_lock);
- return -1;
- }
- if (commit_lock_file(&head_lock) < 0)
- return error(_("failed to finalize '%s'"), git_path_head_file());
- return 0;
+ return write_message(head, strlen(head), git_path_head_file(), 1);
}
static int rollback_is_safe(void)
@@ -3223,7 +3219,7 @@ static int rollback_is_safe(void)
else
die_errno(_("could not read '%s'"), git_path_abort_safety_file());
- if (get_oid("HEAD", &actual_head))
+ if (repo_get_oid(the_repository, "HEAD", &actual_head))
oidclr(&actual_head);
return oideq(&actual_head, &expected_head);
@@ -3515,10 +3511,13 @@ static int make_patch(struct repository *r,
strbuf_addf(&buf, "%s/message", get_dir(opts));
if (!file_exists(buf.buf)) {
const char *encoding = get_commit_output_encoding();
- const char *commit_buffer = logmsg_reencode(commit, NULL, encoding);
+ const char *commit_buffer = repo_logmsg_reencode(r,
+ commit, NULL,
+ encoding);
find_commit_subject(commit_buffer, &subject);
res |= write_message(subject, strlen(subject), buf.buf, 1);
- unuse_commit_buffer(commit, commit_buffer);
+ repo_unuse_commit_buffer(r, commit,
+ commit_buffer);
}
strbuf_release(&buf);
release_revisions(&log_tree_opt);
@@ -3531,7 +3530,7 @@ static int intend_to_amend(void)
struct object_id head;
char *p;
- if (get_oid("HEAD", &head))
+ if (repo_get_oid(the_repository, "HEAD", &head))
return error(_("cannot read HEAD"));
p = oid_to_hex(&head);
@@ -3670,7 +3669,6 @@ static int safe_append(const char *filename, const char *fmt, ...)
}
if (commit_lock_file(&lock) < 0) {
strbuf_release(&buf);
- rollback_lock_file(&lock);
return error(_("failed to finalize '%s'"), filename);
}
@@ -3697,7 +3695,7 @@ static int do_label(struct repository *r, const char *name, int len)
if (!transaction) {
error("%s", err.buf);
ret = -1;
- } else if (get_oid("HEAD", &head_oid)) {
+ } else if (repo_get_oid(r, "HEAD", &head_oid)) {
error(_("could not read HEAD"));
ret = -1;
} else if (ref_transaction_update(transaction, ref_name.buf, &head_oid,
@@ -3985,7 +3983,8 @@ static int do_merge(struct repository *r,
if (commit) {
const char *encoding = get_commit_output_encoding();
- const char *message = logmsg_reencode(commit, NULL, encoding);
+ const char *message = repo_logmsg_reencode(r, commit, NULL,
+ encoding);
const char *body;
int len;
@@ -3998,7 +3997,7 @@ static int do_merge(struct repository *r,
find_commit_subject(message, &body);
len = strlen(body);
ret = write_message(body, len, git_path_merge_msg(r), 0);
- unuse_commit_buffer(commit, message);
+ repo_unuse_commit_buffer(r, commit, message);
if (ret) {
error_errno(_("could not write '%s'"),
git_path_merge_msg(r));
@@ -4098,7 +4097,7 @@ static int do_merge(struct repository *r,
}
merge_commit = to_merge->item;
- bases = get_merge_bases(head_commit, merge_commit);
+ bases = repo_get_merge_bases(r, head_commit, merge_commit);
if (bases && oideq(&merge_commit->object.oid,
&bases->item->object.oid)) {
ret = 0;
@@ -4453,7 +4452,7 @@ void create_autostash(struct repository *r, const char *path)
if (capture_command(&stash, &buf, GIT_MAX_HEXSZ))
die(_("Cannot autostash"));
strbuf_trim_trailing_newline(&buf);
- if (get_oid(buf.buf, &oid))
+ if (repo_get_oid(r, buf.buf, &oid))
die(_("Unexpected stash response: '%s'"),
buf.buf);
strbuf_reset(&buf);
@@ -4578,9 +4577,9 @@ static int stopped_at_head(struct repository *r)
struct commit *commit;
struct commit_message message;
- if (get_oid("HEAD", &head) ||
+ if (repo_get_oid(r, "HEAD", &head) ||
!(commit = lookup_commit(r, &head)) ||
- parse_commit(commit) || get_message(commit, &message))
+ repo_parse_commit(r, commit) || get_message(commit, &message))
fprintf(stderr, _("Stopped at HEAD\n"));
else {
fprintf(stderr, _("Stopped at %s\n"), message.label);
@@ -4728,7 +4727,7 @@ static int pick_commits(struct repository *r,
* otherwise we do not.
*/
if (item->command == TODO_REWORD &&
- !get_oid("HEAD", &oid) &&
+ !repo_get_oid(r, "HEAD", &oid) &&
(oideq(&item->commit->object.oid, &oid) ||
(opts->have_squash_onto &&
oideq(&opts->squash_onto, &oid))))
@@ -4817,7 +4816,7 @@ static int pick_commits(struct repository *r,
struct object_id head, orig;
int res;
- if (get_oid("HEAD", &head)) {
+ if (repo_get_oid(r, "HEAD", &head)) {
res = error(_("cannot read HEAD"));
cleanup_head_ref:
strbuf_release(&head_ref);
@@ -4864,8 +4863,8 @@ cleanup_head_ref:
log_tree_opt.disable_stdin = 1;
if (read_oneliner(&buf, rebase_path_orig_head(), 0) &&
- !get_oid(buf.buf, &orig) &&
- !get_oid("HEAD", &head)) {
+ !repo_get_oid(r, buf.buf, &orig) &&
+ !repo_get_oid(r, "HEAD", &head)) {
diff_tree_oid(&orig, &head, "",
&log_tree_opt.diffopt);
log_tree_diff_flush(&log_tree_opt);
@@ -4957,7 +4956,7 @@ static int commit_staged_changes(struct repository *r,
struct strbuf rev = STRBUF_INIT;
struct object_id head, to_amend;
- if (get_oid("HEAD", &head))
+ if (repo_get_oid(r, "HEAD", &head))
return error(_("cannot amend non-existing commit"));
if (!read_oneliner(&rev, rebase_path_amend(), 0))
return error(_("invalid file: '%s'"), rebase_path_amend());
@@ -5037,13 +5036,14 @@ static int commit_staged_changes(struct repository *r,
const char *encoding = get_commit_output_encoding();
if (parse_head(r, &commit) ||
- !(p = logmsg_reencode(commit, NULL, encoding)) ||
+ !(p = repo_logmsg_reencode(r, commit, NULL, encoding)) ||
write_message(p, strlen(p), path, 0)) {
- unuse_commit_buffer(commit, p);
+ repo_unuse_commit_buffer(r, commit, p);
return error(_("could not write file: "
"'%s'"), path);
}
- unuse_commit_buffer(commit, p);
+ repo_unuse_commit_buffer(r,
+ commit, p);
}
}
@@ -5182,7 +5182,7 @@ int sequencer_pick_revisions(struct repository *r,
if (!strlen(name))
continue;
- if (!get_oid(name, &oid)) {
+ if (!repo_get_oid(r, name, &oid)) {
if (!lookup_commit_reference_gently(r, &oid, 1)) {
enum object_type type = oid_object_info(r,
&oid,
@@ -5225,7 +5225,7 @@ int sequencer_pick_revisions(struct repository *r,
if (walk_revs_populate_todo(&todo_list, opts) ||
create_seq_dir(r) < 0)
return -1;
- if (get_oid("HEAD", &oid) && (opts->action == REPLAY_REVERT))
+ if (repo_get_oid(r, "HEAD", &oid) && (opts->action == REPLAY_REVERT))
return error(_("can't revert as initial commit"));
if (save_head(oid_to_hex(&oid)))
return -1;
@@ -5341,7 +5341,7 @@ static const char *label_oid(struct object_id *oid, const char *label,
* For "uninteresting" commits, i.e. commits that are not to be
* rebased, and which can therefore not be labeled, we use a unique
* abbreviation of the commit name. This is slightly more complicated
- * than calling find_unique_abbrev() because we also need to make
+ * than calling repo_find_unique_abbrev() because we also need to make
* sure that the abbreviation does not conflict with any other
* label.
*
@@ -5357,7 +5357,8 @@ static const char *label_oid(struct object_id *oid, const char *label,
strbuf_grow(&state->buf, GIT_MAX_HEXSZ);
label = p = state->buf.buf;
- find_unique_abbrev_r(p, oid, default_abbrev);
+ repo_find_unique_abbrev_r(the_repository, p, oid,
+ default_abbrev);
/*
* We may need to extend the abbreviated hash so that there is
@@ -5919,7 +5920,7 @@ static int skip_unnecessary_picks(struct repository *r,
continue;
if (item->command != TODO_PICK)
break;
- if (parse_commit(item->commit)) {
+ if (repo_parse_commit(r, item->commit)) {
return error(_("could not parse commit '%s'"),
oid_to_hex(&item->commit->object.oid));
}
@@ -6090,7 +6091,8 @@ int complete_action(struct repository *r, struct replay_opts *opts, unsigned fla
struct object_id oid = onto->object.oid;
int res;
- find_unique_abbrev_r(shortonto, &oid, DEFAULT_ABBREV);
+ repo_find_unique_abbrev_r(r, shortonto, &oid,
+ DEFAULT_ABBREV);
if (buf->len == 0) {
struct todo_item *item = append_new_todo(todo_list);
@@ -6251,12 +6253,15 @@ int todo_list_rearrange_squash(struct todo_list *todo_list)
return error(_("the script was already rearranged."));
}
- parse_commit(item->commit);
- commit_buffer = logmsg_reencode(item->commit, NULL, "UTF-8");
+ repo_parse_commit(the_repository, item->commit);
+ commit_buffer = repo_logmsg_reencode(the_repository,
+ item->commit, NULL,
+ "UTF-8");
find_commit_subject(commit_buffer, &subject);
format_subject(&buf, subject, " ");
subject = subjects[i] = strbuf_detach(&buf, &subject_len);
- unuse_commit_buffer(item->commit, commit_buffer);
+ repo_unuse_commit_buffer(the_repository, item->commit,
+ commit_buffer);
if (skip_fixupish(subject, &p)) {
struct commit *commit2;
@@ -6366,8 +6371,8 @@ int sequencer_determine_whence(struct repository *r, enum commit_whence *whence)
if (file_exists(git_path_seq_dir()))
*whence = FROM_CHERRY_PICK_MULTI;
if (file_exists(rebase_path()) &&
- !get_oid("REBASE_HEAD", &rebase_head) &&
- !get_oid("CHERRY_PICK_HEAD", &cherry_pick_head) &&
+ !repo_get_oid(r, "REBASE_HEAD", &rebase_head) &&
+ !repo_get_oid(r, "CHERRY_PICK_HEAD", &cherry_pick_head) &&
oideq(&rebase_head, &cherry_pick_head))
*whence = FROM_REBASE_PICK;
else