summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin <alban.gruin@gmail.com>2019-03-05 19:18:01 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-03-07 00:17:57 (GMT)
commitddb81e50724002645d7ec7d9ffdb714d02a47759 (patch)
treea7ab39d1ae267659d0ebabdd8f55977242fe4c20
parent6bfeb7f1b503cf3fa0fd5690c0c98a9813c7c875 (diff)
downloadgit-ddb81e50724002645d7ec7d9ffdb714d02a47759.zip
git-ddb81e50724002645d7ec7d9ffdb714d02a47759.tar.gz
git-ddb81e50724002645d7ec7d9ffdb714d02a47759.tar.bz2
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>
-rw-r--r--rebase-interactive.c38
-rw-r--r--sequencer.c4
-rw-r--r--sequencer.h3
3 files changed, 18 insertions, 27 deletions
diff --git a/rebase-interactive.c b/rebase-interactive.c
index dfa6dd5..d396ecc 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -79,39 +79,33 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,
int edit_todo_list(struct repository *r, unsigned flags)
{
- struct strbuf buf = STRBUF_INIT;
const char *todo_file = rebase_path_todo();
+ struct todo_list todo_list = TODO_LIST_INIT;
+ int res = 0;
- if (strbuf_read_file(&buf, todo_file, 0) < 0)
+ if (strbuf_read_file(&todo_list.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);
+ strbuf_stripspace(&todo_list.buf, 1);
+ todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list);
+ if (todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1,
+ flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP)) {
+ todo_list_release(&todo_list);
return -1;
}
- strbuf_release(&buf);
-
- transform_todo_file(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);
+ strbuf_reset(&todo_list.buf);
+ if (launch_sequence_editor(todo_file, &todo_list.buf, NULL)) {
+ todo_list_release(&todo_list);
return -1;
}
- strbuf_release(&buf);
+ if (!todo_list_parse_insn_buffer(r, todo_list.buf.buf, &todo_list))
+ res = todo_list_write_to_file(r, &todo_list, todo_file, NULL, NULL, -1,
+ flags & ~(TODO_LIST_SHORTEN_IDS));
- if (launch_sequence_editor(todo_file, NULL, NULL))
- return -1;
-
- transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS));
-
- return 0;
+ todo_list_release(&todo_list);
+ return res;
}
define_commit_slab(commit_seen, unsigned char);
diff --git a/sequencer.c b/sequencer.c
index 894c753..b7289c9 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -383,8 +383,8 @@ static void print_advice(struct repository *r, int show_hint,
}
}
-int write_message(const void *buf, size_t len, const char *filename,
- int append_eol)
+static int write_message(const void *buf, size_t len, const char *filename,
+ int append_eol)
{
struct lock_file msg_file = LOCK_INIT;
diff --git a/sequencer.h b/sequencer.h
index 13c5676..fb31a30 100644
--- a/sequencer.h
+++ b/sequencer.h
@@ -64,9 +64,6 @@ struct replay_opts {
};
#define REPLAY_OPTS_INIT { .action = -1, .current_fixups = STRBUF_INIT }
-int write_message(const void *buf, size_t len, const char *filename,
- int append_eol);
-
/*
* Note that ordering matters in this enum. Not only must it match the mapping
* of todo_command_info (in sequencer.c), it is also divided into several