30
#include "oidset.h"
31
#include "commit-slab.h"
32
#include "alias.h"
33
+#include "rebase-interactive.h"
34
35
#define GIT_REFLOG_ACTION "GIT_REFLOG_ACTION"
36
54
* file and written to the tail of 'done'.
55
*/
56
GIT_PATH_FUNC(rebase_path_todo, "rebase-merge/git-rebase-todo")
57
+static GIT_PATH_FUNC(rebase_path_todo_backup,
58
+ "rebase-merge/git-rebase-todo.backup")
59
+
60
/*
61
* The rebase command lines that have already been processed. A line
62
* is moved here when it is first handled, before any associated user
4499
return 0;
4500
}
4501
4502
+int complete_action(struct replay_opts *opts, unsigned flags,
4503
+ const char *shortrevisions, const char *onto_name,
4504
+ const char *onto, const char *orig_head, const char *cmd,
4505
+ unsigned autosquash)
4506
+{
4507
+ const char *shortonto, *todo_file = rebase_path_todo();
4508
+ struct todo_list todo_list = TODO_LIST_INIT;
4509
+ struct strbuf *buf = &(todo_list.buf);
4510
+ struct object_id oid;
4511
+ struct stat st;
4512
+
4513
+ get_oid(onto, &oid);
4514
+ shortonto = find_unique_abbrev(&oid, DEFAULT_ABBREV);
4515
+
4516
+ if (!lstat(todo_file, &st) && st.st_size == 0 &&
4517
+ write_message("noop\n", 5, todo_file, 0))
4518
+ return -1;
4519
+
4520
+ if (autosquash && rearrange_squash())
4521
+ return -1;
4522
+
4523
+ if (cmd && *cmd)
4524
+ sequencer_add_exec_commands(cmd);
4525
+
4526
+ if (strbuf_read_file(buf, todo_file, 0) < 0)
4527
+ return error_errno(_("could not read '%s'."), todo_file);
4528
+
4529
+ if (parse_insn_buffer(buf->buf, &todo_list)) {
4530
+ todo_list_release(&todo_list);
4531
+ return error(_("unusable todo list: '%s'"), todo_file);
4532
+ }
4533
+
4534
+ if (count_commands(&todo_list) == 0) {
4535
+ apply_autostash(opts);
4536
+ sequencer_remove_state(opts);
4537
+ todo_list_release(&todo_list);
4538
+
4539
+ return error(_("nothing to do"));
4540
+ }
4541
+
4542
+ strbuf_addch(buf, '\n');
4543
+ strbuf_commented_addf(buf, Q_("Rebase %s onto %s (%d command)",
4544
+ "Rebase %s onto %s (%d commands)",
4545
+ count_commands(&todo_list)),
4546
+ shortrevisions, shortonto, count_commands(&todo_list));
4547
+ append_todo_help(0, flags & TODO_LIST_KEEP_EMPTY, buf);
4548
+
4549
+ if (write_message(buf->buf, buf->len, todo_file, 0)) {
4550
+ todo_list_release(&todo_list);
4551
+ return -1;
4552
+ }
4553
+
4554
+ if (copy_file(rebase_path_todo_backup(), todo_file, 0666))
4555
+ return error(_("could not copy '%s' to '%s'."), todo_file,
4556
+ rebase_path_todo_backup());
4557
+
4558
+ if (transform_todos(flags | TODO_LIST_SHORTEN_IDS))
4559
+ return error(_("could not transform the todo list"));
4560
+
4561
+ strbuf_reset(buf);
4562
+
4563
+ if (launch_sequence_editor(todo_file, buf, NULL)) {
4564
+ apply_autostash(opts);
4565
+ sequencer_remove_state(opts);
4566
+ todo_list_release(&todo_list);
4567
+
4568
+ return -1;
4569
+ }
4570
+
4571
+ strbuf_stripspace(buf, 1);
4572
+ if (buf->len == 0) {
4573
+ apply_autostash(opts);
4574
+ sequencer_remove_state(opts);
4575
+ todo_list_release(&todo_list);
4576
+
4577
+ return error(_("nothing to do"));
4578
+ }
4579
+
4580
+ todo_list_release(&todo_list);
4581
+
4582
+ if (check_todo_list()) {
4583
+ checkout_onto(opts, onto_name, onto, orig_head);
4584
+ return -1;
4585
+ }
4586
+
4587
+ if (transform_todos(flags & ~(TODO_LIST_SHORTEN_IDS)))
4588
+ return error(_("could not transform the todo list"));
4589
+
4590
+ if (opts->allow_ff && skip_unnecessary_picks(&oid))
4591
+ return error(_("could not skip unnecessary pick commands"));
4592
+
4593
+ if (checkout_onto(opts, onto_name, oid_to_hex(&oid), orig_head))
4594
+ return -1;
4595
+;
4596
+ if (require_clean_work_tree("rebase", "", 1, 1))
4597
+ return -1;
4598
+
4599
+ return sequencer_continue(opts);
4600
+}
4601
+
4602
struct subject2item_entry {
4603
struct hashmap_entry entry;
4604
int i;