sequencer (rebase -i): write an author-script file

When the interactive rebase aborts, it writes out an author-script file
to record the author information for the current commit. As we are about
to teach the sequencer how to perform the actions behind an interactive
rebase, it needs to write those author-script files, too.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Johannes Schindelin 2017-01-02 16:27:18 +01:00 committed by Junio C Hamano
parent 414697a9d8
commit 0473f28ad7

View File

@ -483,6 +483,52 @@ static int is_index_unchanged(void)
return !hashcmp(active_cache_tree->sha1, head_commit->tree->object.oid.hash);
}
static int write_author_script(const char *message)
{
struct strbuf buf = STRBUF_INIT;
const char *eol;
int res;
for (;;)
if (!*message || starts_with(message, "\n")) {
missing_author:
/* Missing 'author' line? */
unlink(rebase_path_author_script());
return 0;
} else if (skip_prefix(message, "author ", &message))
break;
else if ((eol = strchr(message, '\n')))
message = eol + 1;
else
goto missing_author;
strbuf_addstr(&buf, "GIT_AUTHOR_NAME='");
while (*message && *message != '\n' && *message != '\r')
if (skip_prefix(message, " <", &message))
break;
else if (*message != '\'')
strbuf_addch(&buf, *(message++));
else
strbuf_addf(&buf, "'\\\\%c'", *(message++));
strbuf_addstr(&buf, "'\nGIT_AUTHOR_EMAIL='");
while (*message && *message != '\n' && *message != '\r')
if (skip_prefix(message, "> ", &message))
break;
else if (*message != '\'')
strbuf_addch(&buf, *(message++));
else
strbuf_addf(&buf, "'\\\\%c'", *(message++));
strbuf_addstr(&buf, "'\nGIT_AUTHOR_DATE='@");
while (*message && *message != '\n' && *message != '\r')
if (*message != '\'')
strbuf_addch(&buf, *(message++));
else
strbuf_addf(&buf, "'\\\\%c'", *(message++));
res = write_message(buf.buf, buf.len, rebase_path_author_script(), 1);
strbuf_release(&buf);
return res;
}
/*
* Read the author-script file into an environment block, ready for use in
* run_command(), that can be free()d afterwards.
@ -935,7 +981,9 @@ static int do_pick_commit(enum todo_command command, struct commit *commit,
}
}
if (!opts->strategy || !strcmp(opts->strategy, "recursive") || command == TODO_REVERT) {
if (is_rebase_i(opts) && write_author_script(msg.message) < 0)
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);
if (res < 0)