From b3b1a21d1a5df87e81fa8b53c6c3cf9760ca12d4 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Tue, 19 Jul 2022 18:33:41 +0000 Subject: sequencer: rewrite update-refs as user edits todo list An interactive rebase provides opportunities for the user to edit the todo list. The --update-refs option initializes the list with some 'update-ref ' steps, but the user could add these manually. Further, the user could add or remove these steps during pauses in the interactive rebase. Add a new method, todo_list_filter_update_refs(), that scans a todo_list and compares it to the stored update-refs file. There are two actions that can happen at this point: 1. If a '//' triple in the update-refs file does not have a matching 'update-ref ' command in the todo-list _and_ the value is the null OID, then remove that triple. Here, the user removed the 'update-ref ' command before it was executed, since if it was executed then the value would store the commit at that position. 2. If a 'update-ref ' command in the todo-list does not have a matching '//' triple in the update-refs file, then insert a new one. Store the value to be the current OID pointed at by . This is handled inside of the init_update_ref_record() helper method. We can test that this works by rewriting the todo-list several times in the course of a rebase. Check that each ref is locked or unlocked for updates after each todo-list update. We can also verify that the ref update fails if a concurrent process updates one of the refs after the rebase process records the "locked" ref location. To help these tests, add a new 'set_replace_editor' helper that will replace the todo-list with an exact file. Reported-by: Phillip Wood Signed-off-by: Derrick Stolee Signed-off-by: Junio C Hamano --- rebase-interactive.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'rebase-interactive.c') diff --git a/rebase-interactive.c b/rebase-interactive.c index 1ff07647af..7407c59319 100644 --- a/rebase-interactive.c +++ b/rebase-interactive.c @@ -146,6 +146,12 @@ int edit_todo_list(struct repository *r, struct todo_list *todo_list, return -4; } + /* + * See if branches need to be added or removed from the update-refs + * file based on the new todo list. + */ + todo_list_filter_update_refs(r, new_todo); + return 0; } -- cgit v1.2.3