l10n: it.po: Updated Italian translation
[gitweb.git] / rebase-interactive.c
index dfa6dd530f3dd246de866ca5db5174a549cf31f5..aa18ae82b724812ea0b2939842395ac78f77bab1 100644 (file)
@@ -28,7 +28,8 @@ static enum missing_commit_check_level get_missing_commit_check_level(void)
        return MISSING_COMMIT_CHECK_IGNORE;
 }
 
-void append_todo_help(unsigned edit_todo, unsigned keep_empty,
+void append_todo_help(unsigned keep_empty, int command_count,
+                     const char *shortrevisions, const char *shortonto,
                      struct strbuf *buf)
 {
        const char *msg = _("\nCommands:\n"
@@ -48,6 +49,15 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,
 ".       specified). Use -c <commit> to reword the commit message.\n"
 "\n"
 "These lines can be re-ordered; they are executed from top to bottom.\n");
+       unsigned edit_todo = !(shortrevisions && shortonto);
+
+       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);
+       }
 
        strbuf_add_commented_lines(buf, msg, strlen(msg));
 
@@ -77,39 +87,38 @@ void append_todo_help(unsigned edit_todo, unsigned keep_empty,
        }
 }
 
-int edit_todo_list(struct repository *r, unsigned flags)
+int edit_todo_list(struct repository *r, struct todo_list *todo_list,
+                  struct todo_list *new_todo, const char *shortrevisions,
+                  const char *shortonto, unsigned flags)
 {
-       struct strbuf buf = STRBUF_INIT;
        const char *todo_file = rebase_path_todo();
+       unsigned initial = shortrevisions && shortonto;
 
-       if (strbuf_read_file(&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);
-               return -1;
-       }
-
-       strbuf_release(&buf);
-
-       transform_todo_file(r, flags | TODO_LIST_SHORTEN_IDS);
+       /* If the user is editing the todo list, we first try to parse
+        * it.  If there is an error, we do not return, because the user
+        * might want to fix it in the first place. */
+       if (!initial)
+               todo_list_parse_insn_buffer(r, todo_list->buf.buf, todo_list);
 
-       if (strbuf_read_file(&buf, todo_file, 0) < 0)
-               return error_errno(_("could not read '%s'."), todo_file);
+       if (todo_list_write_to_file(r, todo_list, todo_file, shortrevisions, shortonto,
+                                   -1, flags | TODO_LIST_SHORTEN_IDS | TODO_LIST_APPEND_TODO_HELP))
+               return error_errno(_("could not write '%s'"), todo_file);
 
-       append_todo_help(1, 0, &buf);
-       if (write_message(buf.buf, buf.len, todo_file, 0)) {
-               strbuf_release(&buf);
-               return -1;
-       }
+       if (initial && copy_file(rebase_path_todo_backup(), todo_file, 0666))
+               return error(_("could not copy '%s' to '%s'."), todo_file,
+                            rebase_path_todo_backup());
 
-       strbuf_release(&buf);
+       if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
+               return -2;
 
-       if (launch_sequence_editor(todo_file, NULL, NULL))
-               return -1;
+       strbuf_stripspace(&new_todo->buf, 1);
+       if (initial && new_todo->buf.len == 0)
+               return -3;
 
-       transform_todo_file(r, flags & ~(TODO_LIST_SHORTEN_IDS));
+       /* For the initial edit, the todo list gets parsed in
+        * complete_action(). */
+       if (!initial)
+               return todo_list_parse_insn_buffer(r, new_todo->buf.buf, new_todo);
 
        return 0;
 }