sequencer: make the todo_list structure public
[gitweb.git] / rebase-interactive.c
index d7996bc8d9ff2e3f47f5fb45cb32b98884e853dc..68aff1dac28878f2f9c010459bf5f4362322bd3f 100644 (file)
@@ -4,11 +4,9 @@
 #include "sequencer.h"
 #include "strbuf.h"
 
-int append_todo_help(unsigned edit_todo, unsigned keep_empty)
+void append_todo_help(unsigned edit_todo, unsigned keep_empty,
+                     struct strbuf *buf)
 {
-       struct strbuf buf = STRBUF_INIT;
-       FILE *todo;
-       int ret;
        const char *msg = _("\nCommands:\n"
 "p, pick <commit> = use commit\n"
 "r, reword <commit> = use commit, but edit the commit message\n"
@@ -16,6 +14,7 @@ int append_todo_help(unsigned edit_todo, unsigned keep_empty)
 "s, squash <commit> = use commit, but meld into previous commit\n"
 "f, fixup <commit> = like \"squash\", but discard this commit's log message\n"
 "x, exec <command> = run command (the rest of the line) using shell\n"
+"b, break = stop here (continue rebase later with 'git rebase --continue')\n"
 "d, drop <commit> = remove commit\n"
 "l, label <label> = label current HEAD with a name\n"
 "t, reset <label> = reset HEAD to a label\n"
@@ -26,11 +25,7 @@ int append_todo_help(unsigned edit_todo, unsigned keep_empty)
 "\n"
 "These lines can be re-ordered; they are executed from top to bottom.\n");
 
-       todo = fopen_or_warn(rebase_path_todo(), "a");
-       if (!todo)
-               return 1;
-
-       strbuf_add_commented_lines(&buf, msg, strlen(msg));
+       strbuf_add_commented_lines(buf, msg, strlen(msg));
 
        if (get_missing_commit_check_level() == MISSING_COMMIT_CHECK_ERROR)
                msg = _("\nDo not remove any line. Use 'drop' "
@@ -39,7 +34,7 @@ int append_todo_help(unsigned edit_todo, unsigned keep_empty)
                msg = _("\nIf you remove a line here "
                         "THAT COMMIT WILL BE LOST.\n");
 
-       strbuf_add_commented_lines(&buf, msg, strlen(msg));
+       strbuf_add_commented_lines(buf, msg, strlen(msg));
 
        if (edit_todo)
                msg = _("\nYou are editing the todo file "
@@ -50,19 +45,47 @@ int append_todo_help(unsigned edit_todo, unsigned keep_empty)
                msg = _("\nHowever, if you remove everything, "
                        "the rebase will be aborted.\n\n");
 
-       strbuf_add_commented_lines(&buf, msg, strlen(msg));
+       strbuf_add_commented_lines(buf, msg, strlen(msg));
 
        if (!keep_empty) {
                msg = _("Note that empty commits are commented out");
-               strbuf_add_commented_lines(&buf, msg, strlen(msg));
+               strbuf_add_commented_lines(buf, msg, strlen(msg));
+       }
+}
+
+int edit_todo_list(struct repository *r, unsigned flags)
+{
+       struct strbuf buf = STRBUF_INIT;
+       const char *todo_file = rebase_path_todo();
+
+       if (strbuf_read_file(&buf, todo_file, 0) < 0)
+               return error_errno(_("could not read '%s'."), todo_file);
+
+       strbuf_stripspace(&buf, 1);
+       if (write_message(buf.buf, buf.len, todo_file, 0)) {
+               strbuf_release(&buf);
+               return -1;
        }
 
-       ret = fputs(buf.buf, todo);
-       if (ret < 0)
-               error_errno(_("could not append help text to '%s'"), rebase_path_todo());
+       strbuf_release(&buf);
+
+       transform_todos(r, flags | TODO_LIST_SHORTEN_IDS);
+
+       if (strbuf_read_file(&buf, todo_file, 0) < 0)
+               return error_errno(_("could not read '%s'."), todo_file);
+
+       append_todo_help(1, 0, &buf);
+       if (write_message(buf.buf, buf.len, todo_file, 0)) {
+               strbuf_release(&buf);
+               return -1;
+       }
 
-       fclose(todo);
        strbuf_release(&buf);
 
-       return ret;
+       if (launch_sequence_editor(todo_file, NULL, NULL))
+               return -1;
+
+       transform_todos(r, flags & ~(TODO_LIST_SHORTEN_IDS));
+
+       return 0;
 }