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>
This commit is contained in:
Johannes Schindelin
2016-04-13 14:11:12 +02:00
parent f8579f6065
commit efef23da3e

View File

@@ -528,6 +528,51 @@ 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;
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++));
strbuf_addstr(&buf, "'\n");
return write_message(&buf, rebase_path_author_script());
}
static char **read_author_script(void)
{
struct strbuf script = STRBUF_INIT;
@@ -972,7 +1017,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)