{"thread":{"id":"51672","subject":"[PATCH 1/3] rebase -i: always update HEAD before rewording","startedAt":"2019-08-19T09:18:26Z","lastAt":"2019-08-22T18:48:55Z","messageCount":6,"participants":["Phillip Wood via GitGitGadget","Eric Sunshine","Phillip Wood"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"380691","messageId":"628939679c63e735b1f81a9da11c31e1bbc929e3.1566206300.git.gitgitgadget@gmail.com","threadId":"51672","inReplyTo":"pull.312.git.gitgitgadget@gmail.com","subject":"[PATCH 1/3] rebase -i: always update HEAD before rewording","fromName":"Phillip Wood via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-08-19T09:18:21Z","receivedAt":"2019-08-19T09:18:26Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"From: Phillip Wood <phillip.wood@dunelm.org.uk>\n\nIf the user runs git log while rewording a commit it is confusing if\nsometimes we're amending the commit that's being reworded and at other\ntimes we're creating a new commit depending on whether we could\nfast-forward or not[1]. Fix this inconsistency by always committing the\npicked commit and then running 'git commit --amend' to do the reword.\n\nThe first commit is performed by the sequencer without forking git\ncommit and does not impact on the speed of rebase. In a test rewording\n100 commits with\n\n    GIT_EDITOR=true GIT_SEQUENCE_EDITOR='sed -i s/pick/reword/' \\\n\t../bin-wrappers/git rebase -i --root\n\nand taking the best of three runs the current master took\n957ms and with this patch it took 961ms.\n\nThis change fixes rewording the new root commit when rearranging commits\nwith --root.\n\nNote that the new code no longer updates CHERRY_PICK_HEAD after creating\na root commit - I'm not sure why the old code was that creating that ref\nafter a successful commit, everywhere else it is removed after a\nsuccessful commit.\n\n[1] https://public-inbox.org/git/xmqqlfvu4be3.fsf@gitster-ct.c.googlers.com/T/#m133009cb91cf0917bcf667300f061178be56680a\n\nReported-by: SZEDER Gábor <szeder.dev@gmail.com>\nSigned-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n---\n sequencer.c                        | 19 +++++++++++--------\n t/t3404-rebase-interactive.sh      | 16 +++++++++++++---\n t/t7505-prepare-commit-msg-hook.sh |  8 +-------\n t/t7505/expected-rebase-i          |  3 ++-\n 4 files changed, 27 insertions(+), 19 deletions(-)\n\ndiff --git a/sequencer.c b/sequencer.c\nindex 34ebf8ed94..085777f4a1 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -986,12 +986,10 @@ static int run_git_commit(struct repository *r,\n \n \t\tstrbuf_release(&msg);\n \t\tstrbuf_release(&script);\n-\t\tif (!res) {\n-\t\t\tupdate_ref(NULL, \"CHERRY_PICK_HEAD\", &root_commit, NULL,\n-\t\t\t\t   REF_NO_DEREF, UPDATE_REFS_MSG_ON_ERR);\n+\t\tif (!res)\n \t\t\tres = update_ref(NULL, \"HEAD\", &root_commit, NULL, 0,\n \t\t\t\t\t UPDATE_REFS_MSG_ON_ERR);\n-\t\t}\n+\n \t\treturn res < 0 ? error(_(\"writing root commit\")) : 0;\n \t}\n \n@@ -1785,7 +1783,7 @@ static int do_pick_commit(struct repository *r,\n \tchar *author = NULL;\n \tstruct commit_message msg = { NULL, NULL, NULL, NULL };\n \tstruct strbuf msgbuf = STRBUF_INIT;\n-\tint res, unborn = 0, allow;\n+\tint res, unborn = 0, reword = 0, allow;\n \n \tif (opts->no_commit) {\n \t\t/*\n@@ -1855,7 +1853,7 @@ static int do_pick_commit(struct repository *r,\n \t\t\topts);\n \t\tif (res || command != TODO_REWORD)\n \t\t\tgoto leave;\n-\t\tflags |= EDIT_MSG | AMEND_MSG | VERIFY_MSG;\n+\t\treword = 1;\n \t\tmsg_file = NULL;\n \t\tgoto fast_forward_edit;\n \t}\n@@ -1913,7 +1911,7 @@ static int do_pick_commit(struct repository *r,\n \t}\n \n \tif (command == TODO_REWORD)\n-\t\tflags |= EDIT_MSG | VERIFY_MSG;\n+\t\treword = 1;\n \telse if (is_fixup(command)) {\n \t\tif (update_squash_messages(r, command, commit, opts))\n \t\t\treturn -1;\n@@ -1997,13 +1995,18 @@ static int do_pick_commit(struct repository *r,\n \t} else if (allow)\n \t\tflags |= ALLOW_EMPTY;\n \tif (!opts->no_commit) {\n-fast_forward_edit:\n \t\tif (author || command == TODO_REVERT || (flags & AMEND_MSG))\n \t\t\tres = do_commit(r, msg_file, author, opts, flags);\n \t\telse\n \t\t\tres = error(_(\"unable to parse commit author\"));\n+\t\tif (!res && reword)\n+fast_forward_edit:\n+\t\t\tres = run_git_commit(r, NULL, opts, EDIT_MSG |\n+\t\t\t\t\t     VERIFY_MSG | AMEND_MSG |\n+\t\t\t\t\t     (flags & ALLOW_EMPTY));\n \t}\n \n+\n \tif (!res && final_fixup) {\n \t\tunlink(rebase_path_fixup_msg());\n \t\tunlink(rebase_path_squash_msg());\ndiff --git a/t/t3404-rebase-interactive.sh b/t/t3404-rebase-interactive.sh\nindex 461dd539ff..d2f1d5bd23 100755\n--- a/t/t3404-rebase-interactive.sh\n+++ b/t/t3404-rebase-interactive.sh\n@@ -1016,9 +1016,9 @@ test_expect_success 'rebase -i --root fixup root commit' '\n \ttest 0 = $(git cat-file commit HEAD | grep -c ^parent\\ )\n '\n \n-test_expect_success 'rebase -i --root reword root commit' '\n+test_expect_success 'rebase -i --root reword original root commit' '\n \ttest_when_finished \"test_might_fail git rebase --abort\" &&\n-\tgit checkout -b reword-root-branch master &&\n+\tgit checkout -b reword-original-root-branch master &&\n \tset_fake_editor &&\n \tFAKE_LINES=\"reword 1 2\" FAKE_COMMIT_MESSAGE=\"A changed\" \\\n \tgit rebase -i --root &&\n@@ -1026,6 +1026,16 @@ test_expect_success 'rebase -i --root reword root commit' '\n \ttest -z \"$(git show -s --format=%p HEAD^)\"\n '\n \n+test_expect_success 'rebase -i --root reword new root commit' '\n+\ttest_when_finished \"test_might_fail git rebase --abort\" &&\n+\tgit checkout -b reword-now-root-branch master &&\n+\tset_fake_editor &&\n+\tFAKE_LINES=\"reword 3 1\" FAKE_COMMIT_MESSAGE=\"C changed\" \\\n+\tgit rebase -i --root &&\n+\tgit show HEAD^ | grep \"C changed\" &&\n+\ttest -z \"$(git show -s --format=%p HEAD^)\"\n+'\n+\n test_expect_success 'rebase -i --root when root has untracked file conflict' '\n \ttest_when_finished \"reset_rebase\" &&\n \tgit checkout -b failing-root-pick A &&\n@@ -1054,7 +1064,7 @@ test_expect_success 'rebase -i --root reword root when root has untracked file c\n '\n \n test_expect_success C_LOCALE_OUTPUT 'rebase --edit-todo does not work on non-interactive rebase' '\n-\tgit checkout reword-root-branch &&\n+\tgit checkout reword-original-root-branch &&\n \tgit reset --hard &&\n \tgit checkout conflict-branch &&\n \tset_fake_editor &&\ndiff --git a/t/t7505-prepare-commit-msg-hook.sh b/t/t7505-prepare-commit-msg-hook.sh\nindex ba8bd1b514..94f85cdf83 100755\n--- a/t/t7505-prepare-commit-msg-hook.sh\n+++ b/t/t7505-prepare-commit-msg-hook.sh\n@@ -241,13 +241,7 @@ test_rebase () {\n \t\t\tgit add b &&\n \t\t\tgit rebase --continue\n \t\t) &&\n-\t\tif test \"$mode\" = -p # reword amended after pick\n-\t\tthen\n-\t\t\tn=18\n-\t\telse\n-\t\t\tn=17\n-\t\tfi &&\n-\t\tgit log --pretty=%s -g -n$n HEAD@{1} >actual &&\n+\t\tgit log --pretty=%s -g -n18 HEAD@{1} >actual &&\n \t\ttest_cmp \"$TEST_DIRECTORY/t7505/expected-rebase${mode:--i}\" actual\n \t'\n }\ndiff --git a/t/t7505/expected-rebase-i b/t/t7505/expected-rebase-i\nindex c514bdbb94..93bada596e 100644\n--- a/t/t7505/expected-rebase-i\n+++ b/t/t7505/expected-rebase-i\n@@ -7,7 +7,8 @@ message (no editor) [edit rebase-10]\n message [fixup rebase-9]\n message (no editor) [fixup rebase-8]\n message (no editor) [squash rebase-7]\n-message [reword rebase-6]\n+HEAD [reword rebase-6]\n+message (no editor) [reword rebase-6]\n message [squash rebase-5]\n message (no editor) [fixup rebase-4]\n message (no editor) [pick rebase-3]\n-- \ngitgitgadget\n\n"},{"id":"380692","messageId":"pull.312.git.gitgitgadget@gmail.com","threadId":"51672","inReplyTo":null,"subject":"[PATCH 0/3] rebase -i: always update HEAD before rewording","fromName":"Phillip Wood via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-08-19T09:18:20Z","receivedAt":"2019-08-19T09:18:27Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"This series contains a couple of patches to make the C version of rebase\n--interactive behave more like the scripted version. The third patch is not\nstrictly related to the first two but is included here to avoid merge\nconflicts.\n\nPhillip Wood (3):\n  rebase -i: always update HEAD before rewording\n  rebase -i: check for updated todo after squash and reword\n  sequencer: simplify root commit creation\n\n sequencer.c                        | 130 +++++++++--------------------\n t/t3404-rebase-interactive.sh      |  16 +++-\n t/t3429-rebase-edit-todo.sh        |  21 ++++-\n t/t7505-prepare-commit-msg-hook.sh |   8 +-\n t/t7505/expected-rebase-i          |   3 +-\n 5 files changed, 75 insertions(+), 103 deletions(-)\n\n\nbase-commit: ff66981f4593aec0f3b3eeace0eacb7dbe44fd8c\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-312%2Fphillipwood%2Fwip%2Frebase-reword-update-head-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-312/phillipwood/wip/rebase-reword-update-head-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/312\n-- \ngitgitgadget\n"},{"id":"380693","messageId":"7839a84778d085665da70910d9a5897f3353ff45.1566206300.git.gitgitgadget@gmail.com","threadId":"51672","inReplyTo":"pull.312.git.gitgitgadget@gmail.com","subject":"[PATCH 2/3] rebase -i: check for updated todo after squash and reword","fromName":"Phillip Wood via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-08-19T09:18:22Z","receivedAt":"2019-08-19T09:18:27Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"From: Phillip Wood <phillip.wood@dunelm.org.uk>\n\nWhile a rebase is stopped for the user to edit a commit message it can\nbe convenient for them to also edit the todo list. The scripted version\nof rebase supported this but the C version does not. We already check to\nsee if the todo list has been updated by an exec command so extend this\nto rewords and squashes. It only costs a single stat call to do this so\nit should not affect the speed of the rebase (especially as it has just\nstopped for the user to edit a message)\n\nNote that for squashes the editor may be opened on a different pick to\nthe squash itself as we edit the message at the end of a chain fixups\nand squashes.\n\nSigned-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n---\n sequencer.c                 | 42 ++++++++++++++++++++++++-------------\n t/t3429-rebase-edit-todo.sh | 21 ++++++++++++++++++-\n 2 files changed, 47 insertions(+), 16 deletions(-)\n\ndiff --git a/sequencer.c b/sequencer.c\nindex 085777f4a1..a13e1a7466 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -1773,7 +1773,7 @@ static int do_pick_commit(struct repository *r,\n \t\t\t  enum todo_command command,\n \t\t\t  struct commit *commit,\n \t\t\t  struct replay_opts *opts,\n-\t\t\t  int final_fixup)\n+\t\t\t  int final_fixup, int *check_todo)\n {\n \tunsigned int flags = opts->edit ? EDIT_MSG : 0;\n \tconst char *msg_file = opts->edit ? NULL : git_path_merge_msg(r);\n@@ -1999,11 +1999,14 @@ static int do_pick_commit(struct repository *r,\n \t\t\tres = do_commit(r, msg_file, author, opts, flags);\n \t\telse\n \t\t\tres = error(_(\"unable to parse commit author\"));\n-\t\tif (!res && reword)\n+\t\t*check_todo = !!(flags & EDIT_MSG);\n+\t\tif (!res && reword) {\n fast_forward_edit:\n \t\t\tres = run_git_commit(r, NULL, opts, EDIT_MSG |\n \t\t\t\t\t     VERIFY_MSG | AMEND_MSG |\n \t\t\t\t\t     (flags & ALLOW_EMPTY));\n+\t\t\t*check_todo = 1;\n+\t\t}\n \t}\n \n \n@@ -3821,6 +3824,7 @@ static int pick_commits(struct repository *r,\n \twhile (todo_list->current < todo_list->nr) {\n \t\tstruct todo_item *item = todo_list->items + todo_list->current;\n \t\tconst char *arg = todo_item_get_arg(todo_list, item);\n+\t\tint check_todo = 0;\n \n \t\tif (save_todo(todo_list, opts))\n \t\t\treturn -1;\n@@ -3859,7 +3863,8 @@ static int pick_commits(struct repository *r,\n \t\t\t\t\tcommand_to_string(item->command), NULL),\n \t\t\t\t\t1);\n \t\t\tres = do_pick_commit(r, item->command, item->commit,\n-\t\t\t\t\topts, is_final_fixup(todo_list));\n+\t\t\t\t\t     opts, is_final_fixup(todo_list),\n+\t\t\t\t\t     &check_todo);\n \t\t\tif (is_rebase_i(opts) && res < 0) {\n \t\t\t\t/* Reschedule */\n \t\t\t\tadvise(_(rescheduled_advice),\n@@ -3916,7 +3921,6 @@ static int pick_commits(struct repository *r,\n \t\t} else if (item->command == TODO_EXEC) {\n \t\t\tchar *end_of_arg = (char *)(arg + item->arg_len);\n \t\t\tint saved = *end_of_arg;\n-\t\t\tstruct stat st;\n \n \t\t\tif (!opts->verbose)\n \t\t\t\tterm_clear_line();\n@@ -3927,17 +3931,8 @@ static int pick_commits(struct repository *r,\n \t\t\tif (res) {\n \t\t\t\tif (opts->reschedule_failed_exec)\n \t\t\t\t\treschedule = 1;\n-\t\t\t} else if (stat(get_todo_path(opts), &st))\n-\t\t\t\tres = error_errno(_(\"could not stat '%s'\"),\n-\t\t\t\t\t\t  get_todo_path(opts));\n-\t\t\telse if (match_stat_data(&todo_list->stat, &st)) {\n-\t\t\t\t/* Reread the todo file if it has changed. */\n-\t\t\t\ttodo_list_release(todo_list);\n-\t\t\t\tif (read_populate_todo(r, todo_list, opts))\n-\t\t\t\t\tres = -1; /* message was printed */\n-\t\t\t\t/* `current` will be incremented below */\n-\t\t\t\ttodo_list->current = -1;\n \t\t\t}\n+\t\t\tcheck_todo = 1;\n \t\t} else if (item->command == TODO_LABEL) {\n \t\t\tif ((res = do_label(r, arg, item->arg_len)))\n \t\t\t\treschedule = 1;\n@@ -3973,6 +3968,20 @@ static int pick_commits(struct repository *r,\n \t\t\t\t\t\t\titem->commit,\n \t\t\t\t\t\t\targ, item->arg_len,\n \t\t\t\t\t\t\topts, res, 0);\n+\t\t} else if (check_todo && !res) {\n+\t\t\tstruct stat st;\n+\n+\t\t\tif (stat(get_todo_path(opts), &st)) {\n+\t\t\t\tres = error_errno(_(\"could not stat '%s'\"),\n+\t\t\t\t\t\t  get_todo_path(opts));\n+\t\t\t} else if (match_stat_data(&todo_list->stat, &st)) {\n+\t\t\t\t/* Reread the todo file if it has changed. */\n+\t\t\t\ttodo_list_release(todo_list);\n+\t\t\t\tif (read_populate_todo(r, todo_list, opts))\n+\t\t\t\t\tres = -1; /* message was printed */\n+\t\t\t\t/* `current` will be incremented below */\n+\t\t\t\ttodo_list->current = -1;\n+\t\t\t}\n \t\t}\n \n \t\ttodo_list->current++;\n@@ -4299,9 +4308,12 @@ static int single_pick(struct repository *r,\n \t\t       struct commit *cmit,\n \t\t       struct replay_opts *opts)\n {\n+\tint check_todo;\n+\n \tsetenv(GIT_REFLOG_ACTION, action_name(opts), 0);\n \treturn do_pick_commit(r, opts->action == REPLAY_PICK ?\n-\t\tTODO_PICK : TODO_REVERT, cmit, opts, 0);\n+\t\t\t      TODO_PICK : TODO_REVERT, cmit, opts, 0,\n+\t\t\t      &check_todo);\n }\n \n int sequencer_pick_revisions(struct repository *r,\ndiff --git a/t/t3429-rebase-edit-todo.sh b/t/t3429-rebase-edit-todo.sh\nindex 76f6d306ea..8739cb60a7 100755\n--- a/t/t3429-rebase-edit-todo.sh\n+++ b/t/t3429-rebase-edit-todo.sh\n@@ -3,9 +3,15 @@\n test_description='rebase should reread the todo file if an exec modifies it'\n \n . ./test-lib.sh\n+. \"$TEST_DIRECTORY\"/lib-rebase.sh\n+\n+test_expect_success 'setup' '\n+\ttest_commit first file &&\n+\ttest_commit second file &&\n+\ttest_commit third file\n+'\n \n test_expect_success 'rebase exec modifies rebase-todo' '\n-\ttest_commit initial &&\n \ttodo=.git/rebase-merge/git-rebase-todo &&\n \tgit rebase HEAD -x \"echo exec touch F >>$todo\" &&\n \ttest -e F\n@@ -33,4 +39,17 @@ test_expect_success SHA1 'loose object cache vs re-reading todo list' '\n \tgit rebase HEAD -x \"./append-todo.sh 5 6\"\n '\n \n+test_expect_success 'todo is re-read after reword and squash' '\n+\twrite_script reword-editor.sh <<-\\EOS &&\n+\tGIT_SEQUENCE_EDITOR=\"echo \\\"exec echo $(cat file) >>actual\\\" >>\" \\\n+\t\tgit rebase --edit-todo\n+\tEOS\n+\n+\ttest_write_lines first third >expected &&\n+\tset_fake_editor &&\n+\tGIT_SEQUENCE_EDITOR=\"$EDITOR\" FAKE_LINES=\"reword 1 squash 2 fixup 3\" \\\n+\t\tGIT_EDITOR=./reword-editor.sh git rebase -i --root third &&\n+\ttest_cmp expected actual\n+'\n+\n test_done\n-- \ngitgitgadget\n\n"},{"id":"380694","messageId":"3c3b4599e5a82824fdaa88a76fccd7a57ca3c3b9.1566206300.git.gitgitgadget@gmail.com","threadId":"51672","inReplyTo":"pull.312.git.gitgitgadget@gmail.com","subject":"[PATCH 3/3] sequencer: simplify root commit creation","fromName":"Phillip Wood via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2019-08-19T09:18:23Z","receivedAt":"2019-08-19T09:18:28Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"From: Phillip Wood <phillip.wood@dunelm.org.uk>\n\nAdapt try_to_commit() to create a new root commit rather than special\ncasing this in run_git_commit(). The significantly reduces the amount of\nspecial case code for creating the root commit and reduces the number of\ncommit code paths we have to worry about.\n\nSigned-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n---\n sequencer.c | 75 +++--------------------------------------------------\n 1 file changed, 4 insertions(+), 71 deletions(-)\n\ndiff --git a/sequencer.c b/sequencer.c\nindex a13e1a7466..758c780790 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -869,34 +869,6 @@ static char *get_author(const char *message)\n \treturn NULL;\n }\n \n-/* Read author-script and return an ident line (author <email> timestamp) */\n-static const char *read_author_ident(struct strbuf *buf)\n-{\n-\tstruct strbuf out = STRBUF_INIT;\n-\tchar *name, *email, *date;\n-\n-\tif (read_author_script(rebase_path_author_script(),\n-\t\t\t       &name, &email, &date, 0))\n-\t\treturn NULL;\n-\n-\t/* validate date since fmt_ident() will die() on bad value */\n-\tif (parse_date(date, &out)){\n-\t\twarning(_(\"invalid date format '%s' in '%s'\"),\n-\t\t\tdate, rebase_path_author_script());\n-\t\tstrbuf_release(&out);\n-\t\treturn NULL;\n-\t}\n-\n-\tstrbuf_reset(&out);\n-\tstrbuf_addstr(&out, fmt_ident(name, email, WANT_AUTHOR_IDENT, date, 0));\n-\tstrbuf_swap(buf, &out);\n-\tstrbuf_release(&out);\n-\tfree(name);\n-\tfree(email);\n-\tfree(date);\n-\treturn buf->buf;\n-}\n-\n static const char staged_changes_advice[] =\n N_(\"you have staged changes in your working tree\\n\"\n \"If these changes are meant to be squashed into the previous commit, run:\\n\"\n@@ -954,45 +926,6 @@ static int run_git_commit(struct repository *r,\n {\n \tstruct child_process cmd = CHILD_PROCESS_INIT;\n \n-\tif ((flags & CREATE_ROOT_COMMIT) && !(flags & AMEND_MSG)) {\n-\t\tstruct strbuf msg = STRBUF_INIT, script = STRBUF_INIT;\n-\t\tconst char *author = NULL;\n-\t\tstruct object_id root_commit, *cache_tree_oid;\n-\t\tint res = 0;\n-\n-\t\tif (is_rebase_i(opts)) {\n-\t\t\tauthor = read_author_ident(&script);\n-\t\t\tif (!author) {\n-\t\t\t\tstrbuf_release(&script);\n-\t\t\t\treturn -1;\n-\t\t\t}\n-\t\t}\n-\n-\t\tif (!defmsg)\n-\t\t\tBUG(\"root commit without message\");\n-\n-\t\tif (!(cache_tree_oid = get_cache_tree_oid(r->index)))\n-\t\t\tres = -1;\n-\n-\t\tif (!res)\n-\t\t\tres = strbuf_read_file(&msg, defmsg, 0);\n-\n-\t\tif (res <= 0)\n-\t\t\tres = error_errno(_(\"could not read '%s'\"), defmsg);\n-\t\telse\n-\t\t\tres = commit_tree(msg.buf, msg.len, cache_tree_oid,\n-\t\t\t\t\t  NULL, &root_commit, author,\n-\t\t\t\t\t  opts->gpg_sign);\n-\n-\t\tstrbuf_release(&msg);\n-\t\tstrbuf_release(&script);\n-\t\tif (!res)\n-\t\t\tres = update_ref(NULL, \"HEAD\", &root_commit, NULL, 0,\n-\t\t\t\t\t UPDATE_REFS_MSG_ON_ERR);\n-\n-\t\treturn res < 0 ? error(_(\"writing root commit\")) : 0;\n-\t}\n-\n \tcmd.git_cmd = 1;\n \n \tif (is_rebase_i(opts) && read_env_script(&cmd.env_array)) {\n@@ -1376,7 +1309,7 @@ static int try_to_commit(struct repository *r,\n \t\t\t struct object_id *oid)\n {\n \tstruct object_id tree;\n-\tstruct commit *current_head;\n+\tstruct commit *current_head = NULL;\n \tstruct commit_list *parents = NULL;\n \tstruct commit_extra_header *extra = NULL;\n \tstruct strbuf err = STRBUF_INIT;\n@@ -1411,7 +1344,8 @@ static int try_to_commit(struct repository *r,\n \t\t}\n \t\tparents = copy_commit_list(current_head->parents);\n \t\textra = read_commit_extra_headers(current_head, exclude_gpgsig);\n-\t} else if (current_head) {\n+\t} else if (current_head &&\n+\t\t   (!(flags & CREATE_ROOT_COMMIT) || (flags & AMEND_MSG))) {\n \t\tcommit_list_insert(current_head, &parents);\n \t}\n \n@@ -1488,8 +1422,7 @@ static int do_commit(struct repository *r,\n {\n \tint res = 1;\n \n-\tif (!(flags & EDIT_MSG) && !(flags & VERIFY_MSG) &&\n-\t    !(flags & CREATE_ROOT_COMMIT)) {\n+\tif (!(flags & EDIT_MSG) && !(flags & VERIFY_MSG)) {\n \t\tstruct object_id oid;\n \t\tstruct strbuf sb = STRBUF_INIT;\n \n-- \ngitgitgadget\n"},{"id":"380713","messageId":"CAPig+cS+Wt1Bskhj+3hTw=W56zXfZ8w-G4dXEmQr-BBUMpEicQ@mail.gmail.com","threadId":"51672","inReplyTo":"3c3b4599e5a82824fdaa88a76fccd7a57ca3c3b9.1566206300.git.gitgitgadget@gmail.com","subject":"Re: [PATCH 3/3] sequencer: simplify root commit creation","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2019-08-19T16:09:31Z","receivedAt":"2019-08-19T16:09:44Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Aug 19, 2019 at 5:18 AM Phillip Wood via GitGitGadget\n<gitgitgadget@gmail.com> wrote:\n> Adapt try_to_commit() to create a new root commit rather than special\n> casing this in run_git_commit(). The significantly reduces the amount of\n\ns/The/This/\n\n> special case code for creating the root commit and reduces the number of\n> commit code paths we have to worry about.\n>\n> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n"},{"id":"380967","messageId":"b0586e10-1727-3dee-7660-fd66b8ac9ade@gmail.com","threadId":"51672","inReplyTo":"CAPig+cS+Wt1Bskhj+3hTw=W56zXfZ8w-G4dXEmQr-BBUMpEicQ@mail.gmail.com","subject":"Re: [PATCH 3/3] sequencer: simplify root commit creation","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2019-08-22T18:48:47Z","receivedAt":"2019-08-22T18:48:55Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"On 19/08/2019 17:09, Eric Sunshine wrote:\n> On Mon, Aug 19, 2019 at 5:18 AM Phillip Wood via GitGitGadget\n> <gitgitgadget@gmail.com> wrote:\n>> Adapt try_to_commit() to create a new root commit rather than special\n>> casing this in run_git_commit(). The significantly reduces the amount of\n> \n> s/The/This/\n\nThanks Eric - well spotted as ever. Thanks Junio for fixing this up in pu.\n\nBest Wishes\n\nPhillip\n\n>> special case code for creating the root commit and reduces the number of\n>> commit code paths we have to worry about.\n>>\n>> Signed-off-by: Phillip Wood <phillip.wood@dunelm.org.uk>\n"}]}