Skip to content

Commit ddb81e5

Browse files
agrngitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6bfeb7f commit ddb81e5

File tree

3 files changed

+18
-27
lines changed

3 files changed

+18
-27
lines changed

rebase-interactive.c

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -79,39 +79,33 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,
7979

8080
int edit_todo_list(struct repository *r, unsigned flags)
8181
{
82-
struct strbuf buf = STRBUF_INIT;
8382
const char *todo_file = rebase_path_todo();
83+
struct todo_list todo_list = TODO_LIST_INIT;
84+
int res = 0;
8485

85-
if (strbuf_read_file(&buf, todo_file, 0) < 0)
86+
if (strbuf_read_file(&todo_list.buf, todo_file, 0) < 0)
8687
return error_errno(_("could not read '%s'."), todo_file);
8788

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);
9194
return -1;
9295
}
9396

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);
104100
return -1;
105101
}
106102

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));
108106

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;
115109
}
116110

117111
define_commit_slab(commit_seen, unsigned char);

sequencer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ static void print_advice(struct repository *r, int show_hint,
383383
}
384384
}
385385

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)
388388
{
389389
struct lock_file msg_file = LOCK_INIT;
390390

sequencer.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,6 @@ struct replay_opts {
6464
};
6565
#define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT }
6666

67-
int write_message(const void *buf, size_t len, const char *filename,
68-
int append_eol);
69-
7067
/*
7168
* Note that ordering matters in this enum. Not only must it match the mapping
7269
* of todo_command_info (in sequencer.c), it is also divided into several

0 commit comments

Comments
 (0)