rebase-interactive: use todo_list_write_to_file() in edit_todo_list()

Just like complete_action(), edit_todo_list() used a function (transform_todo_file()) that read the todo list from the disk and wrote it back, resulting in useless disk accesses. This changes edit_todo_list() to call directly todo_list_write_to_file() instead. Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alban Gruin committed Mar 5, 2019 at 20:18 UTC ddb81e50724002645d7ec7d9ffdb714d02a47759
3 files changed +18 -27
rebase-interactive.c
+16 -22
@@ -79,39 +79,33 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,
79
80 int edit_todo_list(struct repository *r, unsigned flags)
81 {
82 - struct strbuf buf = STRBUF_INIT;
82 const char *todo_file = rebase_path_todo();
83 + struct todo_list todo_list = TODO_LIST_INIT;
84 + int res = 0;
85
85 - if (strbuf_read_file(&buf, todo_file, 0) < 0)
86 + if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
87 return error_errno(_("could not read '%s'."), todo_file);
88
88 - strbuf_stripspace(&buf, 1);
89 - if (write_message(buf.buf, buf.len, todo_file, 0)) {
90 - strbuf_release(&buf);
89 + strbuf_stripspace(&todo_list.buf, 1);
90 + todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
91 + if (todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1,
92 + flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) {
93 + todo_list_release(&todo_list);
94 return -1;
95 }
96
94 - strbuf_release(&buf);
95 -
96 - transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS);
97 -
98 - if (strbuf_read_file(&buf, todo_file, 0) < 0)
99 - return error_errno(_("could not read '%s'."), todo_file);
100 -
101 - append_todo_help(1, 0, &buf);
102 - if (write_message(buf.buf, buf.len, todo_file, 0)) {
103 - strbuf_release(&buf);
97 + strbuf_reset(&todo_list.buf);
98 + if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) {
99 + todo_list_release(&todo_list);
100 return -1;
101 }
102
107 - strbuf_release(&buf);
103 + if (!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list))
104 + res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1,
105 + flags & ~(TODO_LIST_SHORTEN_IDS));
106
109 - if (launch_sequence_editor(todo_file, NULL, NULL))
110 - return -1;
111 -
112 - transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS));
113 -
114 - return 0;
107 + todo_list_release(&todo_list);
108 + return res;
109 }
110
111 define_commit_slab(commit_seen, unsigned char);
sequencer.c
+2 -2
@@ -383,8 +383,8 @@ static void print_advice(struct repository *r, int show_hint,
383 }
384 }
385
386 -int write_message(const void *buf, size_t len, const char *filename,
387 - int append_eol)
386 +static int write_message(const void *buf, size_t len, const char *filename,
387 + int append_eol)
388 {
389 struct lock_file msg_file = LOCK_INIT;
390
sequencer.h
-3
@@ -64,9 +64,6 @@ struct replay_opts {
64 };
65 #define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT }
66
67 -int write_message(const void *buf, size_t len, const char *filename,
68 - int append_eol);
69 -
67 /*
68 * Note that ordering matters in this enum. Not only must it match the mapping
69 * of todo_command_info (in sequencer.c), it is also divided into several