]> git.ipfire.org Git - thirdparty/git.git/commitdiff
sequencer (rebase -i): write an author-script file
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Mon, 2 Jan 2017 15:27:18 +0000 (16:27 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 9 Jan 2017 22:57:29 +0000 (14:57 -0800)
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>
sequencer.c

index 29b944d724a4f91ce694e65499e98c8f8544f230..991388260354f26e016c449d0fc6de9e4cf7a71c 100644 (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)