Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.kernel.org/pub/scm/git/git.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin <alban.gruin@gmail.com>2019-01-29 18:01:48 +0300
committerJunio C Hamano <gitster@pobox.com>2019-01-29 23:09:24 +0300
commit616d7740cfbe65533af8ff1dabcf4e56f6baad5a (patch)
treef77ddc77782231113d0b828c7a36a0556553f204 /sequencer.c
parentcbef27d61cd6ae4f1ecae054eb9df06e898148d8 (diff)
sequencer: introduce todo_list_write_to_file()
This introduces a new function to recreate the text of a todo list from its commands and write it to a file. This will be useful as the next few commits will change the use of the buffer in struct todo_list so it will no longer be a mirror of the file on disk. This functionality already exists in todo_list_transform(), but this function was made to replace the buffer of a todo list, which is not what we want here. Thus, the part of todo_list_transform() that replaces the buffer is dropped, and the function is renamed todo_list_to_strbuf(). It is called by todo_list_write_to_file() to fill the buffer to write to the disk. todo_list_write_to_file() can also take care of appending the help text to the buffer before writing it to the disk, or to write only the first n items of the list. This feature will be used by skip_unnecessary_picks(), which has to write done commands in a file. Signed-off-by: Alban Gruin <alban.gruin@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sequencer.c')
-rw-r--r--sequencer.c61
1 files changed, 41 insertions, 20 deletions
diff --git a/sequencer.c b/sequencer.c
index 346706029c..4809b22ce4 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -4562,26 +4562,28 @@ int sequencer_add_exec_commands(struct repository *r,
return i;
}
-void todo_list_transform(struct repository *r, struct todo_list *todo_list,
- unsigned flags)
+static void todo_list_to_strbuf(struct repository *r, struct todo_list *todo_list,
+ struct strbuf *buf, int num, unsigned flags)
{
- struct strbuf buf = STRBUF_INIT;
struct todo_item *item;
- int i;
+ int i, max = todo_list->nr;
- for (item = todo_list->items, i = 0; i < todo_list->nr; i++, item++) {
+ if (num > 0 && num < max)
+ max = num;
+
+ for (item = todo_list->items, i = 0; i < max; i++, item++) {
/* if the item is not a command write it and continue */
if (item->command >= TODO_COMMENT) {
- strbuf_addf(&buf, "%.*s\n", item->arg_len,
+ strbuf_addf(buf, "%.*s\n", item->arg_len,
todo_item_get_arg(todo_list, item));
continue;
}
/* add command to the buffer */
if (flags & TODO_LIST_ABBREVIATE_CMDS)
- strbuf_addch(&buf, command_to_char(item->command));
+ strbuf_addch(buf, command_to_char(item->command));
else
- strbuf_addstr(&buf, command_to_string(item->command));
+ strbuf_addstr(buf, command_to_string(item->command));
/* add commit id */
if (item->commit) {
@@ -4591,28 +4593,48 @@ void todo_list_transform(struct repository *r, struct todo_list *todo_list,
if (item->command == TODO_MERGE) {
if (item->flags & TODO_EDIT_MERGE_MSG)
- strbuf_addstr(&buf, " -c");
+ strbuf_addstr(buf, " -c");
else
- strbuf_addstr(&buf, " -C");
+ strbuf_addstr(buf, " -C");
}
- strbuf_addf(&buf, " %s", oid);
+ strbuf_addf(buf, " %s", oid);
}
/* add all the rest */
if (!item->arg_len)
- strbuf_addch(&buf, '\n');
+ strbuf_addch(buf, '\n');
else
- strbuf_addf(&buf, " %.*s\n", item->arg_len,
+ strbuf_addf(buf, " %.*s\n", item->arg_len,
todo_item_get_arg(todo_list, item));
}
+}
- strbuf_reset(&todo_list->buf);
- strbuf_add(&todo_list->buf, buf.buf, buf.len);
+int todo_list_write_to_file(struct repository *r, struct todo_list *todo_list,
+ const char *file, const char *shortrevisions,
+ const char *shortonto, int num, unsigned flags)
+{
+ int edit_todo = !(shortrevisions && shortonto), res;
+ struct strbuf buf = STRBUF_INIT;
+
+ todo_list_to_strbuf(r, todo_list, &buf, num, flags);
+
+ if (flags & TODO_LIST_APPEND_TODO_HELP) {
+ int command_count = count_commands(todo_list);
+ if (!edit_todo) {
+ strbuf_addch(&buf, '\n');
+ strbuf_commented_addf(&buf, Q_("Rebase %s onto %s (%d command)",
+ "Rebase %s onto %s (%d commands)",
+ command_count),
+ shortrevisions, shortonto, command_count);
+ }
+ append_todo_help(edit_todo, flags & TODO_LIST_KEEP_EMPTY, &buf);
+ }
+
+ res = write_message(buf.buf, buf.len, file, 0);
strbuf_release(&buf);
- if (todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list))
- BUG("unusable todo list");
+ return res;
}
int transform_todo_file(struct repository *r, unsigned flags)
@@ -4629,9 +4651,8 @@ int transform_todo_file(struct repository *r, unsigned flags)
return error(_("unusable todo list: '%s'"), todo_file);
}
- todo_list_transform(r, &todo_list, flags);
-
- res = write_message(todo_list.buf.buf, todo_list.buf.len, todo_file, 0);
+ res = todo_list_write_to_file(r, &todo_list, todo_file,
+ NULL, NULL, -1, flags);
todo_list_release(&todo_list);
if (res)