sequencer: add update-ref command

Add the boilerplate for an "update-ref" command in the sequencer. This connects to the current no-op do_update_ref() which will be filled in after more connections are created. The syntax in the todo list will be "update-ref <ref-name>" to signal that we should store the current commit as the value for updating <ref-name> at the end of the rebase. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Jul 19, 2022 at 18:33 UTC a97d79163e16e2d3777ab4d86c8f006f260c2836
3 files changed +17 -1
rebase-interactive.c
+3
@@ -57,6 +57,9 @@ void append_todo_help(int command_count,
57 " create a merge commit using the original merge commit's\n"
58 " message (or the oneline, if no original merge commit was\n"
59 " specified); use -c <commit> to reword the commit message\n"
60 +"u, update-ref <ref> = track a placeholder for the <ref> to be updated\n"
61 +" to this position in the new commits. The <ref> is\n"
62 +" updated at the end of the rebase\n"
63 "\n"
64 "These lines can be re-ordered; they are executed from top to bottom.\n");
65 unsigned edit_todo = !(shortrevisions && shortonto);
sequencer.c
+13 -1
@@ -1723,6 +1723,7 @@ static struct {
1723 [TODO_LABEL] = { 'l', "label" },
1724 [TODO_RESET] = { 't', "reset" },
1725 [TODO_MERGE] = { 'm', "merge" },
1726 + [TODO_UPDATE_REF] = { 'u', "update-ref" },
1727 [TODO_NOOP] = { 0, "noop" },
1728 [TODO_DROP] = { 'd', "drop" },
1729 [TODO_COMMENT] = { 0, NULL },
@@ -2504,7 +2505,7 @@ static int parse_insn_line(struct repository *r, struct todo_item *item,
2505 command_to_string(item->command));
2506
2507 if (item->command == TODO_EXEC || item->command == TODO_LABEL ||
2507 - item->command == TODO_RESET) {
2508 + item->command == TODO_RESET || item->command == TODO_UPDATE_REF) {
2509 item->commit = NULL;
2510 item->arg_offset = bol - buf;
2511 item->arg_len = (int)(eol - bol);
@@ -4104,6 +4105,11 @@ leave_merge:
4105 return ret;
4106 }
4107
4108 +static int do_update_ref(struct repository *r, const char *ref_name)
4109 +{
4110 + return 0;
4111 +}
4112 +
4113 static int is_final_fixup(struct todo_list *todo_list)
4114 {
4115 int i = todo_list->current;
@@ -4479,6 +4485,12 @@ static int pick_commits(struct repository *r,
4485 return error_with_patch(r, item->commit,
4486 arg, item->arg_len,
4487 opts, res, 0);
4488 + } else if (item->command == TODO_UPDATE_REF) {
4489 + struct strbuf ref = STRBUF_INIT;
4490 + strbuf_add(&ref, arg, item->arg_len);
4491 + if ((res = do_update_ref(r, ref.buf)))
4492 + reschedule = 1;
4493 + strbuf_release(&ref);
4494 } else if (!is_noop(item->command))
4495 return error(_("unknown command %d"), item->command);
4496
sequencer.h
+1
@@ -96,6 +96,7 @@ enum todo_command {
96 TODO_LABEL,
97 TODO_RESET,
98 TODO_MERGE,
99 + TODO_UPDATE_REF,
100 /* commands that do nothing but are counted for reporting progress */
101 TODO_NOOP,
102 TODO_DROP,