MCPcopy Create free account
hub / github.com/git/git / edit_todo_list

Function edit_todo_list

rebase-interactive.c:106–167  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

104}
105
106int edit_todo_list(struct repository *r, struct replay_opts *opts,
107 struct todo_list *todo_list, struct todo_list *new_todo,
108 const char *shortrevisions, const char *shortonto,
109 unsigned flags)
110{
111 const char *todo_file = rebase_path_todo(),
112 *todo_backup = rebase_path_todo_backup();
113 unsigned initial = shortrevisions && shortonto;
114 int incorrect = 0;
115
116 /* If the user is editing the todo list, we first try to parse
117 * it. If there is an error, we do not return, because the user
118 * might want to fix it in the first place. */
119 if (!initial)
120 incorrect = todo_list_parse_insn_buffer(r, opts,
121 todo_list->buf.buf,
122 todo_list) |
123 file_exists(rebase_path_dropped());
124
125 if (todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto,
126 -1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP))
127 return error_errno(_("could not write '%s'"), todo_file);
128
129 if (!incorrect &&
130 todo_list_write_to_file(r, todo_list, todo_backup,
131 shortrevisions, shortonto, -1,
132 (flags | TODO_LIST_APPEND_TODO_HELP) & ~TODO_LIST_SHORTEN_IDS) < 0)
133 return error(_("could not write '%s'."), rebase_path_todo_backup());
134
135 if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
136 return -2;
137
138 strbuf_stripspace(&new_todo->buf, comment_line_str);
139 if (initial && new_todo->buf.len == 0)
140 return -3;
141
142 if (todo_list_parse_insn_buffer(r, opts, new_todo->buf.buf, new_todo)) {
143 fprintf(stderr, _(edit_todo_list_advice));
144 return -4;
145 }
146
147 if (incorrect) {
148 if (todo_list_check_against_backup(r, opts, new_todo)) {
149 write_file(rebase_path_dropped(), "%s", "");
150 return -4;
151 }
152
153 if (incorrect > 0)
154 unlink(rebase_path_dropped());
155 } else if (todo_list_check(todo_list, new_todo)) {
156 write_file(rebase_path_dropped(), "%s", "");
157 return -4;
158 }
159
160 /*
161 * See if branches need to be added or removed from the update-refs
162 * file based on the new todo list.
163 */

Callers 2

complete_actionFunction · 0.85
edit_todo_fileFunction · 0.85

Calls 11

file_existsFunction · 0.85
todo_list_write_to_fileFunction · 0.85
error_errnoFunction · 0.85
errorFunction · 0.85
launch_sequence_editorFunction · 0.85
strbuf_stripspaceFunction · 0.85
write_fileFunction · 0.85
todo_list_checkFunction · 0.85

Tested by

no test coverage detected