summaryrefslogtreecommitdiff
path: root/sequencer.c
diff options
context:
space:
mode:
authorLiam Beguin <liambeguin@gmail.com>2017-12-05 17:52:33 (GMT)
committerJunio C Hamano <gitster@pobox.com>2017-12-05 18:20:51 (GMT)
commit0cce4a2756eb2c66544615e5ccd74671afb33256 (patch)
tree5165b7868b62a88b7f26a58efe90993c2520f9c1 /sequencer.c
parent313a48eaca58ecd170bef9e6a5a55001c7511f08 (diff)
downloadgit-0cce4a2756eb2c66544615e5ccd74671afb33256.zip
git-0cce4a2756eb2c66544615e5ccd74671afb33256.tar.gz
git-0cce4a2756eb2c66544615e5ccd74671afb33256.tar.bz2
rebase -i -x: add exec commands via the rebase--helper
Recent work on `git-rebase--interactive` aims to convert shell code to C. Even if this is most likely not a big performance enhancement, let's convert it too since a coming change to abbreviate command names requires it to be updated. Signed-off-by: Liam Beguin <liambeguin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/sequencer.c b/sequencer.c
index 8b0dd61..892d242 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -2494,6 +2494,45 @@ int sequencer_make_script(FILE *out, int argc, const char **argv,
return 0;
}
+/*
+ * Add commands after pick and (series of) squash/fixup commands
+ * in the todo list.
+ */
+int sequencer_add_exec_commands(const char *commands)
+{
+ const char *todo_file = rebase_path_todo();
+ struct todo_list todo_list = TODO_LIST_INIT;
+ struct todo_item *item;
+ struct strbuf *buf = &todo_list.buf;
+ size_t offset = 0, commands_len = strlen(commands);
+ int i, first;
+
+ if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
+ return error(_("could not read '%s'."), todo_file);
+
+ if (parse_insn_buffer(todo_list.buf.buf, &todo_list)) {
+ todo_list_release(&todo_list);
+ return error(_("unusable todo list: '%s'"), todo_file);
+ }
+
+ first = 1;
+ /* insert <commands> before every pick except the first one */
+ for (item = todo_list.items, i = 0; i < todo_list.nr; i++, item++) {
+ if (item->command == TODO_PICK && !first) {
+ strbuf_insert(buf, item->offset_in_buf + offset,
+ commands, commands_len);
+ offset += commands_len;
+ }
+ first = 0;
+ }
+
+ /* append final <commands> */
+ strbuf_add(buf, commands, commands_len);
+
+ i = write_message(buf->buf, buf->len, todo_file, 0);
+ todo_list_release(&todo_list);
+ return i;
+}
int transform_todos(unsigned flags)
{