From patchwork Mon Feb 21 11:10:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12753476 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 76DE9C433EF for ; Mon, 21 Feb 2022 11:21:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347506AbiBULV5 (ORCPT ); Mon, 21 Feb 2022 06:21:57 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54756 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356230AbiBULUu (ORCPT ); Mon, 21 Feb 2022 06:20:50 -0500 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FACDE93 for ; Mon, 21 Feb 2022 03:10:58 -0800 (PST) Received: by mail-wm1-x330.google.com with SMTP id q198-20020a1ca7cf000000b0037bb52545c6so13282268wme.1 for ; Mon, 21 Feb 2022 03:10:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=uMp87Jqr9jdETqR6KHqdKgyX/oAA9i5SfRxts8jQ3oc=; b=mA3uc5ycsDqV/vTefiPI3Vu5ANLYhnSN3FVNKcOwRyagN6duQ7xNGZRicsNFBD8QLV hhVO3hNqpqwhOveowYr8Ba+eKcn8mUSYfD4bFdsNHFxOFxBc49BgSugVw0gGaSjjfgWr X/p9CtwNVuzCyhTz8CrDT7CDDshVDMYUl1wDzpWeni2W9ryXxoGtgMPMW/zS9sdPB46w zashRAe2yV+cZG3iGYr/CT3CmLHzlWJaCakhDIuBHWm1gPFasfLOjxVUWg1qJ3omQ1Jm 23hZV1coNevNMGEH1ApVwLrGlHFiBdBO73bi0T7NfV3C8xyNvE6/egJGAHFwUmMMZ/49 q+3g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=uMp87Jqr9jdETqR6KHqdKgyX/oAA9i5SfRxts8jQ3oc=; b=o5fDWqSuK5z0I5bfif9LUkg7sww2Qvc0+nRmFYh0CpAk+OFA7D2iFvESyO09BHFKMS Vu7TcBvLfwEZIJzb6nDpT1hof5wZTf7aO42T6ctVNxO5YKL27jzWJaFNq/iFxVhpGWoW GUkYl49s+Mzj0pq9KqcZmXxFjqSQqbRrlqjsOaXZry635gUKDRGjNWN9ds2w27kiykmY EAqDREtSXnCAUIur0dIKdoEmOIMPUPG/LFWtF+aFEruDOiG6o2V2affdBnFDwPooGSVJ gnwsaP/IHRnmXtvc7ezlJCkOS9qNy6j+g1Y3ox2va7JxbWdi1gLzosvyyFIWT9RldPrP Evkw== X-Gm-Message-State: AOAM532zEMHh6yLb/gPjkTgIKqWvJxDNZYO84j+Ix2LqKTeiuiTFX3x+ nniy8KfYwHLZ/AtS88IDtKN54ex3ZRo= X-Google-Smtp-Source: ABdhPJxMLI8tqEHTbNZsd06BQg+3zHWnuYRgcRzccfnL7jTdlMuaUlG/1xBTTbSUcrt9HCjrK/oxzA== X-Received: by 2002:a05:600c:190d:b0:351:4a49:4bda with SMTP id j13-20020a05600c190d00b003514a494bdamr17103804wmq.194.1645441856617; Mon, 21 Feb 2022 03:10:56 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id q76sm7889092wme.1.2022.02.21.03.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:10:56 -0800 (PST) Message-Id: <243e7b0c372c15cc907c838ee74794433aa79858.1645441854.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 21 Feb 2022 11:10:48 +0000 Subject: [PATCH 1/7] rebase --apply: remove duplicated code Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood When we are reattaching HEAD after a fast-forward we can use move_to_original_branch() rather than open coding a copy of that code. The old code appears to handle the case where the rebase is started from a detached HEAD but in fact in that case there is nothing to do as we have already updated HEAD. Note that the removal of "strbuf_release(&msg)" is safe as there is an identical call just above this hunk. Signed-off-by: Phillip Wood --- builtin/rebase.c | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index e942c300f8c..4832f16e675 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1782,19 +1782,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) * If the onto is a proper descendant of the tip of the branch, then * we just fast-forwarded. */ - strbuf_reset(&msg); if (oideq(&merge_base, &options.orig_head)) { printf(_("Fast-forwarded %s to %s.\n"), branch_name, options.onto_name); - strbuf_addf(&msg, "rebase finished: %s onto %s", - options.head_name ? options.head_name : "detached HEAD", - oid_to_hex(&options.onto->object.oid)); - memset(&ropts, 0, sizeof(ropts)); - ropts.branch = options.head_name; - ropts.flags = RESET_HEAD_REFS_ONLY; - ropts.head_msg = msg.buf; - reset_head(the_repository, &ropts); - strbuf_release(&msg); + move_to_original_branch(&options); ret = finish_rebase(&options); goto cleanup; } From patchwork Mon Feb 21 11:10:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12753475 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 546C8C433F5 for ; Mon, 21 Feb 2022 11:21:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356095AbiBULVz (ORCPT ); Mon, 21 Feb 2022 06:21:55 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48506 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356234AbiBULUu (ORCPT ); Mon, 21 Feb 2022 06:20:50 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3C957E9B for ; Mon, 21 Feb 2022 03:10:59 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id q9-20020a1ca709000000b0037fa5c3e5c1so370053wme.0 for ; Mon, 21 Feb 2022 03:10:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=H0xmYX7WTo/eAAmTFmsHnHnOXy0zdouLtD/crs0rORo=; b=Pjdw3dhKTcuwbejKCjYTpxBtnigm+jjM1q3gUIUqpCiRLtf0dxHPr3DaijxJaEJhB5 cA0tnv6sdgM1VUpUs9B19/Y3RU6M9UjbnMVl55LIBjzfBhjxWwc0WSQ7fVTQFLOpGaEI 1p8cW3L5hLW7uU94fVO8bb3iDkQkYVxSga3i9VG0fUQ3jKxvPrYGEVxnekCc4HcZfLA5 H0pn3j6yiPPcEBj0C5tYiXymXsDF+2jSyicgeHFuQkWgALpkm1+nhIGSEQq++r2Nq5q1 YdBZWd/Sd+wLPr9DEnw99KgG7B98a4vIHot/ddzdP1gUvKJJwhVTmj1VPXfnnCUKls+i lHFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=H0xmYX7WTo/eAAmTFmsHnHnOXy0zdouLtD/crs0rORo=; b=UkslwIwdGCzmzJVyTBT2WAN8PS28Pvk3yPgzkkk7aRO2FRa9le3RzWIV3xD2IP/EuV McSCktbN5vx0xXA4gF5TX+L+kJF9s+kugGZSGrl8VpogIiB00G24DJZHidx2Ib1BjXvG B8gZmkytLd+QiyxqgU+vmiNu4SxTDPpjXuibQ2zECj2Tv+9fFwyBLiXwiodG/SJXPeNj xaux3m7ZxlcLNzPLLLcfeP2wfWwvMtwyDC5ocO6QB15OsiKP0NXab/yzjhANfYn3XfGp 0BA/sRP1TlV1HC9z5ZsLxjnyoGC+bi4DZFedw2ObBBCvHAtH/JiKvUTXa6UfmfelB9XL lNuw== X-Gm-Message-State: AOAM532URTM8msX/JdlDzn5mOK6jno7n9fp5vLk28jTQjVk2asuJGEMw gDzyvoaP5mzIomh0VA1EHnZucVzdYEo= X-Google-Smtp-Source: ABdhPJyjKj+92VtSBnw3pKFZoUoh/QusSzGsSCDxWTXyuHBWiB/p1ezyn1bn4EaPhmrp+evAR1LH5g== X-Received: by 2002:a05:600c:364f:b0:37b:ba9e:2805 with SMTP id y15-20020a05600c364f00b0037bba9e2805mr17269229wmq.119.1645441857467; Mon, 21 Feb 2022 03:10:57 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d13sm31251152wri.38.2022.02.21.03.10.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:10:57 -0800 (PST) Message-Id: <493254ffbb8b11f325f5995790341d70198b5c97.1645441854.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 21 Feb 2022 11:10:49 +0000 Subject: [PATCH 2/7] rebase --merge: fix reflog when continuing Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood The reflog message for a conflict resolution committed by "rebase --continue" looks like rebase (continue): commit subject line Unfortunately the reflog message each subsequent pick look like rebase (continue) (pick): commit subject line Fix this by setting the reflog message for "rebase --continue" in sequencer_continue() so it does not affect subsequent commits. This introduces a memory leak similar to the one leaking GIT_REFLOG_ACTION in pick_commits(). Both of these will be fixed in a future series that stops the sequencer calling setenv(). Signed-off-by: Phillip Wood --- builtin/rebase.c | 2 - sequencer.c | 5 ++ t/t3406-rebase-message.sh | 120 +++++++++++++++++++++++++------------- 3 files changed, 86 insertions(+), 41 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 4832f16e675..cd9a4f3e2f1 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1247,8 +1247,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) int fd; options.action = "continue"; - set_reflog_action(&options); - /* Sanity check */ if (get_oid("HEAD", &head)) die(_("Cannot read HEAD")); diff --git a/sequencer.c b/sequencer.c index bdd66b4b67a..3634ad5baa9 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4777,6 +4777,8 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) if (read_populate_opts(opts)) return -1; if (is_rebase_i(opts)) { + char *previous_reflog_action; + if ((res = read_populate_todo(r, &todo_list, opts))) goto release_todo_list; @@ -4787,10 +4789,13 @@ int sequencer_continue(struct repository *r, struct replay_opts *opts) unlink(rebase_path_dropped()); } + previous_reflog_action = xstrdup(getenv(GIT_REFLOG_ACTION)); + setenv(GIT_REFLOG_ACTION, reflog_message(opts, "continue", NULL), 1); if (commit_staged_changes(r, opts, &todo_list)) { res = -1; goto release_todo_list; } + setenv(GIT_REFLOG_ACTION, previous_reflog_action, 1); } else if (!file_exists(get_todo_path(opts))) return continue_single_pick(r, opts); else if ((res = read_populate_todo(r, &todo_list, opts))) diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index d17b450e811..3ca2fbb0d59 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -10,10 +10,16 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME test_expect_success 'setup' ' test_commit O fileO && test_commit X fileX && + git branch fast-forward && test_commit A fileA && test_commit B fileB && test_commit Y fileY && + git checkout -b conflicts O && + test_commit P && + test_commit conflict-X fileX && + test_commit Q && + git checkout -b topic O && git cherry-pick A B && test_commit Z fileZ && @@ -79,54 +85,90 @@ test_expect_success 'error out early upon -C or --whitespace=' ' test_i18ngrep "Invalid whitespace option" err ' -test_expect_success 'GIT_REFLOG_ACTION' ' - git checkout start && - test_commit reflog-onto && - git checkout -b reflog-topic start && - test_commit reflog-to-rebase && - - git rebase reflog-onto && - git log -g --format=%gs -3 >actual && - cat >expect <<-\EOF && - rebase (finish): returning to refs/heads/reflog-topic - rebase (pick): reflog-to-rebase - rebase (start): checkout reflog-onto +write_reflog_expect () { + if test $mode = --apply + then + sed 's/.*(finish)/rebase finished/; s/ ([^)]*)//' + else + cat + fi >expect +} + +test_reflog () { + mode=$1 + reflog_action="$2" + + test_expect_success "rebase $mode reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' + git checkout conflicts && + test_when_finished "git reset --hard Q" && + + ( + if test -n "$reflog_action" + then + GIT_REFLOG_ACTION="$reflog_action" && + export GIT_REFLOG_ACTION + fi && + test_must_fail git rebase $mode main && + echo resolved >fileX && + git add fileX && + git rebase --continue + ) && + + git log -g --format=%gs -5 >actual && + write_reflog_expect <<-EOF && + ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts + ${reflog_action:-rebase} (pick): Q + ${reflog_action:-rebase} (continue): conflict-X + ${reflog_action:-rebase} (pick): P + ${reflog_action:-rebase} (start): checkout main EOF test_cmp expect actual && - git checkout -b reflog-prefix reflog-to-rebase && - GIT_REFLOG_ACTION=change-the-reflog git rebase reflog-onto && - git log -g --format=%gs -3 >actual && - cat >expect <<-\EOF && - change-the-reflog (finish): returning to refs/heads/reflog-prefix - change-the-reflog (pick): reflog-to-rebase - change-the-reflog (start): checkout reflog-onto + git log -g --format=%gs -1 conflicts >actual && + write_reflog_expect <<-EOF && + ${reflog_action:-rebase} (finish): refs/heads/conflicts onto $(git rev-parse main) EOF - test_cmp expect actual -' - -test_expect_success 'rebase --apply reflog' ' - git checkout -b reflog-apply start && - old_head_reflog="$(git log -g --format=%gs -1 HEAD)" && - - git rebase --apply Y && + test_cmp expect actual && - git log -g --format=%gs -4 HEAD >actual && - cat >expect <<-EOF && - rebase finished: returning to refs/heads/reflog-apply - rebase: Z - rebase: checkout Y - $old_head_reflog + # check there is only one new entry in the branch reflog + test_cmp_rev conflicts@{1} Q + ' + + test_expect_success "rebase $mode fast-forward reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' + git checkout fast-forward && + test_when_finished "git reset --hard X" && + + ( + if test -n "$reflog_action" + then + GIT_REFLOG_ACTION="$reflog_action" && + export GIT_REFLOG_ACTION + fi && + git rebase $mode main + ) && + + git log -g --format=%gs -2 >actual && + write_reflog_expect <<-EOF && + ${reflog_action:-rebase} (finish): returning to refs/heads/fast-forward + ${reflog_action:-rebase} (start): checkout main EOF test_cmp expect actual && - git log -g --format=%gs -2 reflog-apply >actual && - cat >expect <<-EOF && - rebase finished: refs/heads/reflog-apply onto $(git rev-parse Y) - branch: Created from start + git log -g --format=%gs -1 fast-forward >actual && + write_reflog_expect <<-EOF && + ${reflog_action:-rebase} (finish): refs/heads/fast-forward onto $(git rev-parse main) EOF - test_cmp expect actual -' + test_cmp expect actual && + + # check there is only one new entry in the branch reflog + test_cmp_rev fast-forward@{1} X + ' +} + +test_reflog --merge +test_reflog --merge my-reflog-action +test_reflog --apply +test_reflog --apply my-reflog-action test_expect_success 'rebase -i onto unrelated history' ' git init unrelated && From patchwork Mon Feb 21 11:10:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12753471 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AD55DC433F5 for ; Mon, 21 Feb 2022 11:21:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356180AbiBULVj (ORCPT ); Mon, 21 Feb 2022 06:21:39 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356235AbiBULUu (ORCPT ); Mon, 21 Feb 2022 06:20:50 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 18F94EA5 for ; Mon, 21 Feb 2022 03:11:00 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id k1so26396881wrd.8 for ; Mon, 21 Feb 2022 03:11:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=iqaxVSiB12UtAol0ouxrRdYyVpj3Yne/p84KirKNfjA=; b=Cn637Sc8A6DeenlFXGI4AxbS1QgJE2uqkcGKgMkxc1munj1kOKpCzzD/A7PIk2Juth g9dHN1ZIb+xZ7UoCESGJPh4rY5kCZX/c6gZUPPVfYEKJmwfaAjBzfJsG/GW+CUldxYIB 3pdhQK4ZXmvfO1XFw2jd0wmRA+NaTu7WoKF3p74G7//L8Xd7Xj8Kq70QksD5W2Y6TICs lnB/S5NpYxdCv3cQRQsq2fma5WIv5AuwfGqVfBUr0Pc4uhug0845AptJoQ/p3wAqe759 jz8Gx5YUBoXoMMiewZW6XaqJF/mWKBS9ntxOnRYcrgdOn3pMnnhIiNY8PRttmklBzi+9 Kjxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=iqaxVSiB12UtAol0ouxrRdYyVpj3Yne/p84KirKNfjA=; b=qO7QunLWd7Zhl5YtCZoR2pnwop+zNTgYcEZMot1GDUr+VjckojHLHQDnSd0CDcBBxS 66t+qy2I30h/n+BCH0CbHnSyXjnI3AtR/K8gbDvRtP+0XIUK3EYv79I2Wb5Pvc1FjnlF 6Sha+ewHeb/A3qunV9Z8ReSEPcC0y8IKAXvDwZVURlGQjziv2lJHykuUjJ4OebkzU0Yo 3SRm1NVFJkidUUwzL3H1G+1yfMEAs7y94zYCYUqY1YT3w3JyhpmG5go6UUZSJgAwkNlS DSfBHZfY5+RhfbrosWOHND2mN+i4us40NYbk7tz+d4shDNzsKDB9hyvAbpSbO/rPT/Gk o+7g== X-Gm-Message-State: AOAM532UVj2XZubEqc5oDU8JPmwZOVKaMP7nnTLDgyeBI3659gjuqz8i ioowYeNYzcv3f+LKBKOapD0LvVfB8g4= X-Google-Smtp-Source: ABdhPJxb0z71FVna0XKiZVorAujozoxKs8D1EsgG/+bsFRpHs2dvaHJM+g6hG2GLnbDajeUA79vvOA== X-Received: by 2002:a05:6000:1a89:b0:1e8:db90:54cd with SMTP id f9-20020a0560001a8900b001e8db9054cdmr15241999wry.303.1645441858537; Mon, 21 Feb 2022 03:10:58 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r12sm17731234wrz.50.2022.02.21.03.10.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:10:57 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 21 Feb 2022 11:10:50 +0000 Subject: [PATCH 3/7] rebase --merge: fix reflog message after skipping Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood The reflog message for every pick after running "rebase --skip" looks like rebase (skip) (pick): commit subject line Fix this by not appending " (skip)" to the reflog action. Signed-off-by: Phillip Wood --- builtin/rebase.c | 2 -- t/t3406-rebase-message.sh | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index cd9a4f3e2f1..36863117fba 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1273,8 +1273,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) struct string_list merge_rr = STRING_LIST_INIT_DUP; options.action = "skip"; - set_reflog_action(&options); - rerere_clear(the_repository, &merge_rr); string_list_clear(&merge_rr, 1); ropts.flags = RESET_HEAD_HARD; diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index 3ca2fbb0d59..8aa6a79acc1 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -163,6 +163,30 @@ test_reflog () { # check there is only one new entry in the branch reflog test_cmp_rev fast-forward@{1} X ' + + test_expect_success "rebase $mode --skip reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' + git checkout conflicts && + test_when_finished "git reset --hard Q" && + + ( + if test -n "$reflog_action" + then + GIT_REFLOG_ACTION="$reflog_action" && + export GIT_REFLOG_ACTION + fi && + test_must_fail git rebase $mode main && + git rebase --skip + ) && + + git log -g --format=%gs -4 >actual && + write_reflog_expect <<-EOF && + ${reflog_action:-rebase} (finish): returning to refs/heads/conflicts + ${reflog_action:-rebase} (pick): Q + ${reflog_action:-rebase} (pick): P + ${reflog_action:-rebase} (start): checkout main + EOF + test_cmp expect actual + ' } test_reflog --merge From patchwork Mon Feb 21 11:10:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12753472 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9C935C433EF for ; Mon, 21 Feb 2022 11:21:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356253AbiBULVo (ORCPT ); Mon, 21 Feb 2022 06:21:44 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356241AbiBULUv (ORCPT ); Mon, 21 Feb 2022 06:20:51 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CCFFAEAF for ; Mon, 21 Feb 2022 03:11:00 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id i14so26378866wrc.10 for ; Mon, 21 Feb 2022 03:11:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=PnEkkU9Wx6HdLyfYv/KNN6gAbLsvuSzZ8V5DKhxVJIc=; b=iTwoWtK3QLj8NGPfT8dTM5RjqTN0rDzKj+C4gXWpgv3RQa3pTLtJLieDeELZC0ehF/ 5WwtiiR4n6rv5lJtGAgKumdYV1Ss26cLVdS8UF9eOFwPMUcF3RYQFntGMG4xPs63JzeH m6DqCtHIriaUWgYo4jZdQkNUimmZuKu5eqkTlGNV0lKVmsnrkDZKSxHZyYHKnenM15e1 +xSkwBfZGolExU4G0tzJKUVTjXWkXu+ql5ukZVATe4FekGQ3ewFjlbhypTBYdozuR6Np Bz2WfxOs0v4Y+Vc2tk38DElCVjfYprSFK/zz52bHINWzt9I35sydRqr60R+bNhRZogmS dJiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=PnEkkU9Wx6HdLyfYv/KNN6gAbLsvuSzZ8V5DKhxVJIc=; b=Mf8fQEMEE/9nd+vqNOV83eKjWUnXvjc+k7pmKIJTYcIlF1m3N+BEFgl2yEZoRNkBIn TfMlyi7fD76Xd6rmWaKNfa5zh5rMnYFRyT+7dJKH5Nqm8jeiHFrvr5TR9fHWD1ciW6VZ 5jTRL/Zsvs7BCBZMg/Xa+iVsDtMduuRh/ihD4qzlyyUvOJ6HNuOSUEdWmt4kPEi25Evj giruGfzkNL5OkiWliZRu6XCbqwPmcjtuUf/Z68V79bW61C4HfYtbhTfAs1zOtAQQfWHC IFUqZw3U6cXAYhIAoxhqeLGL3sWTCbi06W6kwmNFovbN0LLbVGGN96roSWn2RKhWZeop FZWg== X-Gm-Message-State: AOAM5301w64WGCmLTry3cxED7ej67WGHxChi3hCep0+XYFcvMxrToQKG FomLtupA0R6FLnliF1DuIEjyGvJpQwY= X-Google-Smtp-Source: ABdhPJxwZ2ZJ4hogvsDoFYCH8zTbuAKqGqTEl7KVGiF3KosKFpo3LzSIZzLUhrIlZU2mik3RrAaH9g== X-Received: by 2002:a5d:6d8f:0:b0:1dd:1ced:4050 with SMTP id l15-20020a5d6d8f000000b001dd1ced4050mr15242039wrs.549.1645441859303; Mon, 21 Feb 2022 03:10:59 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f13-20020a05600c4e8d00b0037bc5ce6042sm9614631wmq.27.2022.02.21.03.10.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:10:58 -0800 (PST) Message-Id: <58c560d0e19a3fa6dd5de547821c9642089de3fb.1645441854.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 21 Feb 2022 11:10:51 +0000 Subject: [PATCH 4/7] rebase --apply: respect GIT_REFLOG_ACTION Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood The reflog messages when finishing a rebase hard code "rebase" rather than using GIT_REFLOG_ACTION. Signed-off-by: Phillip Wood --- builtin/rebase.c | 7 ++++--- t/t3406-rebase-message.sh | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 36863117fba..e50361fc2a9 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -580,10 +580,11 @@ static int move_to_original_branch(struct rebase_options *opts) if (!opts->onto) BUG("move_to_original_branch without onto"); - strbuf_addf(&branch_reflog, "rebase finished: %s onto %s", + strbuf_addf(&branch_reflog, "%s finished: %s onto %s", + getenv(GIT_REFLOG_ACTION_ENVIRONMENT), opts->head_name, oid_to_hex(&opts->onto->object.oid)); - strbuf_addf(&head_reflog, "rebase finished: returning to %s", - opts->head_name); + strbuf_addf(&head_reflog, "%s finished: returning to %s", + getenv(GIT_REFLOG_ACTION_ENVIRONMENT), opts->head_name); ropts.branch = opts->head_name; ropts.flags = RESET_HEAD_REFS_ONLY; ropts.branch_msg = branch_reflog.buf; diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index 8aa6a79acc1..bb2a4949abc 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -88,7 +88,7 @@ test_expect_success 'error out early upon -C or --whitespace=' ' write_reflog_expect () { if test $mode = --apply then - sed 's/.*(finish)/rebase finished/; s/ ([^)]*)//' + sed 's/(finish)/finished/; s/ ([^)]*)//' else cat fi >expect From patchwork Mon Feb 21 11:10:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12753474 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 89606C433F5 for ; Mon, 21 Feb 2022 11:21:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356298AbiBULVw (ORCPT ); Mon, 21 Feb 2022 06:21:52 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356247AbiBULUv (ORCPT ); Mon, 21 Feb 2022 06:20:51 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8956FEB2 for ; Mon, 21 Feb 2022 03:11:01 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id o34so9305190wms.1 for ; Mon, 21 Feb 2022 03:11:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=2SYDa+rcqivkvUif5+HUoX5QbBb/oga7GCGFMYTLewY=; b=ZjzGkz3rPo+wcUv/AP3HcP8GjTCpUalIc886j2eaVIUemkRrTNS6e1/feTw6BqPpTz ZcX3JYCHTCwLQvHM7fCWnFbY3KSvSFvClzQwS3GHOwfrviDa1rQvvj0zvkJS3K6QL28m dPFk3b3sO+04dcDgaiPrlP8zjKIPJPWnkw8eH99ML4yhqCnDrnMbv6b3dXKLusaivGtN ctbFmpeKZqNyZPvQyyRlYgwuvCdm0YvSKJraXT0xJ5SVMSHNHxSfruTe2zIxeogG8n/t U+k9wN1Sim83IWQhcHKv+6W1Chs6ScQNetBrqEEdkm41d87mC81SFiz+JJ6fwZEVHSNn ZMrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=2SYDa+rcqivkvUif5+HUoX5QbBb/oga7GCGFMYTLewY=; b=N3E4SNl5dZrfRkvk1yEeWfRPG8AsvWMmVWhx9/HrQj4zHT+DHRzU0NgTmx/ndRbKS2 VolwehYy4+Fhl13p4MZ93bje6BusxSflCCeiJGi3wQcheCvHNuToPWdRlISPoQjLNKvs dXqiSZWdLSs6nm7kU6wONq8awy5okvojqSbGXEPsnl4wpwXGIh56o7x8xNM1pEuJZhYk 3Cik+nBeAS/ukjk01lhC1fxln5mP81CBNSHpzINPQBRIXmTrIQOFzLlbjjySSXYJy7+5 ZxVbmyHE4BOYAo89fP8VU3gE3ECgLEjecS5hmjdHGq7Rlnv3GM9ltQQZ/s+PovBADTvM 5qFA== X-Gm-Message-State: AOAM533vj/gttF8ed+m3ggchLzTrN1GwXsaqFCUI0PpugpBMgDPbXhWx Umsgwb+cIQIHb2KiBBTXbMpUMZQ3lvo= X-Google-Smtp-Source: ABdhPJw4C6g0R0LLihTGmqclA2fEHEom60bEB+f76JlDkSN2q2iUUeJL+GlwMnHki63idvDk+PRcCg== X-Received: by 2002:a7b:c938:0:b0:37b:fdaa:2749 with SMTP id h24-20020a7bc938000000b0037bfdaa2749mr20975127wml.88.1645441860025; Mon, 21 Feb 2022 03:11:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id l10-20020a7bc44a000000b0037c32873258sm7204329wmi.2.2022.02.21.03.10.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:10:59 -0800 (PST) Message-Id: <1c3ec1654225ff090c194fa646f974082bd9c944.1645441854.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Mon, 21 Feb 2022 11:10:52 +0000 Subject: [PATCH 5/7] rebase --apply: make reflog messages match rebase --merge Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood The apply backend creates slightly different reflog messages to the merge backend when starting and finishing a rebase and when picking commits. The choice of backend is really an implementation detail so it is confusing to have the same command create different messages depending on which backend is selected. Change the apply backend so the reflog messages from the two backends match as closely as possible. Note that there is still a difference when committing a conflict resolution - the merge backend will use "(continue)" rather than "(pick)" in that case as it does not know which command created the conflict that it is committing. Signed-off-by: Phillip Wood --- builtin/rebase.c | 9 +++++---- t/t3406-rebase-message.sh | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index e50361fc2a9..678339c7bf7 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -580,10 +580,10 @@ static int move_to_original_branch(struct rebase_options *opts) if (!opts->onto) BUG("move_to_original_branch without onto"); - strbuf_addf(&branch_reflog, "%s finished: %s onto %s", + strbuf_addf(&branch_reflog, "%s (finish): %s onto %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), opts->head_name, oid_to_hex(&opts->onto->object.oid)); - strbuf_addf(&head_reflog, "%s finished: returning to %s", + strbuf_addf(&head_reflog, "%s (finish): returning to %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), opts->head_name); ropts.branch = opts->head_name; ropts.flags = RESET_HEAD_REFS_ONLY; @@ -613,7 +613,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd = 1; strvec_push(&am.args, "am"); - + strvec_pushf(&am.env_array, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)", + getenv(GIT_REFLOG_ACTION_ENVIRONMENT)); if (opts->action && !strcmp("continue", opts->action)) { strvec_push(&am.args, "--resolved"); strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); @@ -1763,7 +1764,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) printf(_("First, rewinding head to replay your work on top of " "it...\n")); - strbuf_addf(&msg, "%s: checkout %s", + strbuf_addf(&msg, "%s (start): checkout %s", getenv(GIT_REFLOG_ACTION_ENVIRONMENT), options.onto_name); ropts.oid = &options.onto->object.oid; ropts.orig_head = &options.orig_head, diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index bb2a4949abc..5c6cd9af3bc 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -88,7 +88,7 @@ test_expect_success 'error out early upon -C or --whitespace=' ' write_reflog_expect () { if test $mode = --apply then - sed 's/(finish)/finished/; s/ ([^)]*)//' + sed 's/(continue)/(pick)/' else cat fi >expect From patchwork Mon Feb 21 11:10:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12753478 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F6BCC433EF for ; Mon, 21 Feb 2022 11:21:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356124AbiBULWA (ORCPT ); Mon, 21 Feb 2022 06:22:00 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:54160 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356249AbiBULUv (ORCPT ); Mon, 21 Feb 2022 06:20:51 -0500 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8145FEBE for ; Mon, 21 Feb 2022 03:11:02 -0800 (PST) Received: by mail-wr1-x42c.google.com with SMTP id i14so26379024wrc.10 for ; Mon, 21 Feb 2022 03:11:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=DbmCoZwypBuMMIe4XObqTM7EOQuZ449bEHECh/zC6tc=; b=MdHNP0fW5NGPEj07Dz9s81BMSxiD5yyFZPoRnJyFfGXxVLqEqclCAx5mIdmrwDUIs+ Oox+Y3t7A7kgI3t/zDlKP8q4WAiYN7QmTJXnnrrcJGNcN1p7qi1isxrdw1NJSFPxd+a3 q4av2Mfw2XZW1KlS+wEaVxVnZWyf0rAKxE4nVIQJ5aRzZJrR1jJ5TAdQOVucrJHv9XRI 9BnIFvEajJVlEBsYXAWhTZbQEmjW7JAycS4T+Y131hnZEMgQSRLJn05vlGcgBIo/qJAH ZDj7m8r43MvZ4wJjzGG2J6W6fkLluvozEPJ5UrWXoAx1wzyo3egwuwjPjL1Qod1TXo8u 1Eew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=DbmCoZwypBuMMIe4XObqTM7EOQuZ449bEHECh/zC6tc=; b=CKmju5g+eBbw66xVU8izbkl0UA3Pz/p49Qvk9BrhjYsUGaZwNgqSptlIgrkS8Lgtcm M43uR4ZfAXkp0lnf/lYmNF6s+TGI5fBq54tJHrkQKwnXQLqunLHoYO0g6VNDkDlvEA+L LMhcoCRgfT+S9JEoj9pEhaDCUC3qKOWmeyBdc/t9gUaT/4fnM5J/xSp53D4b/h8U6MUM GDXkhSibg+9OHS7m0pZIOFQoV5u2JjoS/FD01f8wLeFlmBkgFt/ph8Au3E8uePWc3CiD vRsNk63o0sh0LSi3FeZauFvlaa5z6CvaofJ8LRfbeZAFl0pGB9n9K4az/gC38UkxZFc+ BWdg== X-Gm-Message-State: AOAM532iKj49vtnEjsnbR3Z04uvXiLwfosp+ltC5T18ErqrROb5XN/Z3 6H5P1F8vQmt4dpL1dwxh+/0Llc8yTyg= X-Google-Smtp-Source: ABdhPJwbTU58+Y6AUd+tOvOvWkLGq2Anw7/+/aQWAq0zGI/321hriesJclvSlA52bxPW6mG4KHv5rw== X-Received: by 2002:a05:6000:1289:b0:1d5:c107:b63e with SMTP id f9-20020a056000128900b001d5c107b63emr15450808wrx.651.1645441860870; Mon, 21 Feb 2022 03:11:00 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r10sm9923421wrv.28.2022.02.21.03.11.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:11:00 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 21 Feb 2022 11:10:53 +0000 Subject: [PATCH 6/7] rebase --abort: improve reflog message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood When aborting a rebase the reflog message looks like rebase (abort): updating HEAD which is not very informative. Improve the message by mentioning the branch that we are returning to as we do at the end of a successful rebase so it looks like. rebase (abort): returning to refs/heads/topic If GIT_REFLOG_ACTION is set in the environment we no longer omit "(abort)" from the reflog message. We don't omit "(start)" and "(finish)" when starting and finishing a rebase in that case so we shouldn't omit "(abort)". Signed-off-by: Phillip Wood --- builtin/rebase.c | 28 ++++++--------------- t/t3406-rebase-message.sh | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 20 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 678339c7bf7..70426e17b40 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -992,23 +992,6 @@ static void NORETURN error_on_missing_default_upstream(void) exit(1); } -static void set_reflog_action(struct rebase_options *options) -{ - const char *env; - struct strbuf buf = STRBUF_INIT; - - if (!is_merge(options)) - return; - - env = getenv(GIT_REFLOG_ACTION_ENVIRONMENT); - if (env && strcmp("rebase", env)) - return; /* only override it if it is "rebase" */ - - strbuf_addf(&buf, "rebase (%s)", options->action); - setenv(GIT_REFLOG_ACTION_ENVIRONMENT, buf.buf, 1); - strbuf_release(&buf); -} - static int check_exec_cmd(const char *cmd) { if (strchr(cmd, '\n')) @@ -1287,18 +1270,23 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } case ACTION_ABORT: { struct string_list merge_rr = STRING_LIST_INIT_DUP; - options.action = "abort"; - set_reflog_action(&options); + struct strbuf head_msg = STRBUF_INIT; + options.action = "abort"; rerere_clear(the_repository, &merge_rr); string_list_clear(&merge_rr, 1); if (read_basic_state(&options)) exit(1); + + strbuf_addf(&head_msg, "%s (abort): returning to %s", + getenv(GIT_REFLOG_ACTION_ENVIRONMENT), + options.head_name ? options.head_name + : oid_to_hex(&options.orig_head)); ropts.oid = &options.orig_head; + ropts.head_msg = head_msg.buf; ropts.branch = options.head_name; ropts.flags = RESET_HEAD_HARD; - ropts.default_reflog_action = DEFAULT_REFLOG_ACTION; if (reset_head(the_repository, &ropts) < 0) die(_("could not move back to %s"), oid_to_hex(&options.orig_head)); diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index 5c6cd9af3bc..ceca1600053 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -187,6 +187,57 @@ test_reflog () { EOF test_cmp expect actual ' + + test_expect_success "rebase $mode --abort reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' + git checkout conflicts && + test_when_finished "git reset --hard Q" && + + git log -g -1 conflicts >branch-expect && + ( + if test -n "$reflog_action" + then + GIT_REFLOG_ACTION="$reflog_action" && + export GIT_REFLOG_ACTION + fi && + test_must_fail git rebase $mode main && + git rebase --abort + ) && + + git log -g --format=%gs -3 >actual && + write_reflog_expect <<-EOF && + ${reflog_action:-rebase} (abort): returning to refs/heads/conflicts + ${reflog_action:-rebase} (pick): P + ${reflog_action:-rebase} (start): checkout main + EOF + test_cmp expect actual && + + # check branch reflog is unchanged + git log -g -1 conflicts >branch-actual && + test_cmp branch-expect branch-actual + ' + + test_expect_success "rebase $mode --abort detached HEAD reflog${reflog_action:+ GIT_REFLOG_ACTION=$reflog_action}" ' + git checkout Q && + test_when_finished "git reset --hard Q" && + + ( + if test -n "$reflog_action" + then + GIT_REFLOG_ACTION="$reflog_action" && + export GIT_REFLOG_ACTION + fi && + test_must_fail git rebase $mode main && + git rebase --abort + ) && + + git log -g --format=%gs -3 >actual && + write_reflog_expect <<-EOF && + ${reflog_action:-rebase} (abort): returning to $(git rev-parse Q) + ${reflog_action:-rebase} (pick): P + ${reflog_action:-rebase} (start): checkout main + EOF + test_cmp expect actual + ' } test_reflog --merge From patchwork Mon Feb 21 11:10:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 12753473 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D1450C433FE for ; Mon, 21 Feb 2022 11:21:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356140AbiBULVs (ORCPT ); Mon, 21 Feb 2022 06:21:48 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:53552 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356250AbiBULUv (ORCPT ); Mon, 21 Feb 2022 06:20:51 -0500 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 553B8F03 for ; Mon, 21 Feb 2022 03:11:03 -0800 (PST) Received: by mail-wr1-x42a.google.com with SMTP id v12so26432324wrv.2 for ; Mon, 21 Feb 2022 03:11:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=y1ESANf/m0uLV1VxDTeCxu5by2O2N28lW6PIgjqXsEY=; b=BCwwYlErQmguYLwgm9UecW3heWMbSxo9dP1Nc1vGdxLKSbKWqV20tZ1XEbLrRQsOrG zJrQPC5qG9iHKlX2RAcfdc2dN2mNQLQvU15PXgePnyoqfxNXSdSyMuGhs0t1gF8tATkG Rywps3mxbMkglromiP/uDaaUkRvtrLFbV62fddB1JWSY4fWhrB81ZInwgRGzRK24tTnj ehd30yzAfCV+Zn/dAfjhH13U8hm/krMamBTmHcY4DBPpyLKe6T7p2D49hp8ZZBGKcRXF hi21fT4Yl6mPMpASf0+jdE3mCI5lTzrZLIqjO/JAq9iW/NSzxLJqTRvVgpyUbNwhymrr fb7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=y1ESANf/m0uLV1VxDTeCxu5by2O2N28lW6PIgjqXsEY=; b=tEBLk6Sbvd/9bh3LxV0i12MrJtCBXomkI54Tk9xKIBb/1CB2KXTD0k8UvX64p2y3Zy Q/dp4SJ6jmYO3qhfm6/mvmiPRFc+8LcVSTqtlk8/2rt1hR7nF7zyZ4gcY4ghOI8w0R49 cT7KydoQtN4MunJ7+7ZPs7EtKc4VYPsubikYE5PhD9ye9zIygEXp9oMzW0lvr89c86Ct f7d1y6yWQPnCevy1uLOxb69Nd6jTVoaALrUVeH5rX035JPe4e0PDS/DEnqjeNj2Ujuu7 SZOUTJ9XKJNsNuPboFUmL5zGqihkZ1lrCR6YnKTCsMw5iTjjpMPY0eyvXCrJa380qCV7 mPvA== X-Gm-Message-State: AOAM530DJziAGooh/vyOJNooB1XLWNCjPq+f+VrhYSnl4vFa7/rO8V+U dZ8DR3NUXhYdIokSwEs5xNWH24cqWrk= X-Google-Smtp-Source: ABdhPJx/ft2fMf/M8AS8D9vCD5Yei2P1/p3gLxs0vvstxJL4NeeYHSn1qf8G5/KH341fmwAphtk7sg== X-Received: by 2002:a5d:64c1:0:b0:1e4:987a:51b with SMTP id f1-20020a5d64c1000000b001e4987a051bmr15891422wri.471.1645441861737; Mon, 21 Feb 2022 03:11:01 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id x17sm40797691wrv.107.2022.02.21.03.11.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Feb 2022 03:11:01 -0800 (PST) Message-Id: In-Reply-To: References: Date: Mon, 21 Feb 2022 11:10:54 +0000 Subject: [PATCH 7/7] rebase: cleanup action handling Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Treating the action as a string is a hang over from the scripted rebase. The last commit removed the only remaining use of the action that required a string so lets convert the other action users to use the existing action enum instead. If we ever need the action name as a string in the future the action_names array exists exactly for that purpose. Signed-off-by: Phillip Wood --- builtin/rebase.c | 91 +++++++++++++++++++++++------------------------- 1 file changed, 43 insertions(+), 48 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index 70426e17b40..323f5154092 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -58,6 +58,26 @@ enum empty_type { EMPTY_ASK }; +enum action { + ACTION_NONE = 0, + ACTION_CONTINUE, + ACTION_SKIP, + ACTION_ABORT, + ACTION_QUIT, + ACTION_EDIT_TODO, + ACTION_SHOW_CURRENT_PATCH +}; + +static const char *action_names[] = { + "undefined", + "continue", + "skip", + "abort", + "quit", + "edit_todo", + "show_current_patch" +}; + struct rebase_options { enum rebase_type type; enum empty_type empty; @@ -84,7 +104,7 @@ struct rebase_options { REBASE_INTERACTIVE_EXPLICIT = 1<<4, } flags; struct strvec git_am_opts; - const char *action; + enum action action; int signoff; int allow_rerere_autoupdate; int keep_empty; @@ -155,24 +175,6 @@ static struct replay_opts get_replay_opts(const struct rebase_options *opts) return replay; } -enum action { - ACTION_NONE = 0, - ACTION_CONTINUE, - ACTION_SKIP, - ACTION_ABORT, - ACTION_QUIT, - ACTION_EDIT_TODO, - ACTION_SHOW_CURRENT_PATCH -}; - -static const char *action_names[] = { "undefined", - "continue", - "skip", - "abort", - "quit", - "edit_todo", - "show_current_patch" }; - static int edit_todo_file(unsigned flags) { const char *todo_file = rebase_path_todo(); @@ -309,8 +311,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) return ret; } -static int run_sequencer_rebase(struct rebase_options *opts, - enum action command) +static int run_sequencer_rebase(struct rebase_options *opts) { unsigned flags = 0; int abbreviate_commands = 0, ret = 0; @@ -325,7 +326,7 @@ static int run_sequencer_rebase(struct rebase_options *opts, flags |= opts->reapply_cherry_picks ? TODO_LIST_REAPPLY_CHERRY_PICKS : 0; flags |= opts->flags & REBASE_NO_QUIET ? TODO_LIST_WARN_SKIPPED_CHERRY_PICKS : 0; - switch (command) { + switch (opts->action) { case ACTION_NONE: { if (!opts->onto && !opts->upstream) die(_("a base commit must be provided with --upstream or --onto")); @@ -358,7 +359,7 @@ static int run_sequencer_rebase(struct rebase_options *opts, break; } default: - BUG("invalid command '%d'", command); + BUG("invalid command '%d'", opts->action); } return ret; @@ -615,7 +616,7 @@ static int run_am(struct rebase_options *opts) strvec_push(&am.args, "am"); strvec_pushf(&am.env_array, GIT_REFLOG_ACTION_ENVIRONMENT "=%s (pick)", getenv(GIT_REFLOG_ACTION_ENVIRONMENT)); - if (opts->action && !strcmp("continue", opts->action)) { + if (opts->action == ACTION_CONTINUE) { strvec_push(&am.args, "--resolved"); strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); if (opts->gpg_sign_opt) @@ -626,7 +627,7 @@ static int run_am(struct rebase_options *opts) return move_to_original_branch(opts); } - if (opts->action && !strcmp("skip", opts->action)) { + if (opts->action == ACTION_SKIP) { strvec_push(&am.args, "--skip"); strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); status = run_command(&am); @@ -635,7 +636,7 @@ static int run_am(struct rebase_options *opts) return move_to_original_branch(opts); } - if (opts->action && !strcmp("show-current-patch", opts->action)) { + if (opts->action == ACTION_SHOW_CURRENT_PATCH) { strvec_push(&am.args, "--show-current-patch"); return run_command(&am); } @@ -728,7 +729,7 @@ static int run_am(struct rebase_options *opts) return status; } -static int run_specific_rebase(struct rebase_options *opts, enum action action) +static int run_specific_rebase(struct rebase_options *opts) { int status; @@ -746,7 +747,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action) opts->gpg_sign_opt = tmp; } - status = run_sequencer_rebase(opts, action); + status = run_sequencer_rebase(opts); } else if (opts->type == REBASE_APPLY) status = run_am(opts); else @@ -1016,7 +1017,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) struct strbuf buf = STRBUF_INIT; struct object_id merge_base; int ignore_whitespace = 0; - enum action action = ACTION_NONE; const char *gpg_sign = NULL; struct string_list exec = STRING_LIST_INIT_NODUP; const char *rebase_merges = NULL; @@ -1065,18 +1065,18 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) OPT_BIT(0, "no-ff", &options.flags, N_("cherry-pick all commits, even if unchanged"), REBASE_FORCE), - OPT_CMDMODE(0, "continue", &action, N_("continue"), + OPT_CMDMODE(0, "continue", &options.action, N_("continue"), ACTION_CONTINUE), - OPT_CMDMODE(0, "skip", &action, + OPT_CMDMODE(0, "skip", &options.action, N_("skip current patch and continue"), ACTION_SKIP), - OPT_CMDMODE(0, "abort", &action, + OPT_CMDMODE(0, "abort", &options.action, N_("abort and check out the original branch"), ACTION_ABORT), - OPT_CMDMODE(0, "quit", &action, + OPT_CMDMODE(0, "quit", &options.action, N_("abort but keep HEAD where it is"), ACTION_QUIT), - OPT_CMDMODE(0, "edit-todo", &action, N_("edit the todo list " + OPT_CMDMODE(0, "edit-todo", &options.action, N_("edit the todo list " "during an interactive rebase"), ACTION_EDIT_TODO), - OPT_CMDMODE(0, "show-current-patch", &action, + OPT_CMDMODE(0, "show-current-patch", &options.action, N_("show the patch file being applied or merged"), ACTION_SHOW_CURRENT_PATCH), OPT_CALLBACK_F(0, "apply", &options, NULL, @@ -1189,7 +1189,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (preserve_merges_selected) die(_("--preserve-merges was replaced by --rebase-merges")); - if (action != ACTION_NONE && total_argc != 2) { + if (options.action != ACTION_NONE && total_argc != 2) { usage_with_options(builtin_rebase_usage, builtin_rebase_options); } @@ -1208,11 +1208,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (options.root && options.fork_point > 0) die(_("cannot combine '--root' with '--fork-point'")); - if (action != ACTION_NONE && !in_progress) + if (options.action != ACTION_NONE && !in_progress) die(_("No rebase in progress?")); setenv(GIT_REFLOG_ACTION_ENVIRONMENT, "rebase", 0); - if (action == ACTION_EDIT_TODO && !is_merge(&options)) + if (options.action == ACTION_EDIT_TODO && !is_merge(&options)) die(_("The --edit-todo action can only be used during " "interactive rebase.")); @@ -1222,16 +1222,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) else if (exec.nr) trace2_cmd_mode("interactive-exec"); else - trace2_cmd_mode(action_names[action]); + trace2_cmd_mode(action_names[options.action]); } - switch (action) { + switch (options.action) { case ACTION_CONTINUE: { struct object_id head; struct lock_file lock_file = LOCK_INIT; int fd; - options.action = "continue"; /* Sanity check */ if (get_oid("HEAD", &head)) die(_("Cannot read HEAD")); @@ -1257,7 +1256,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) case ACTION_SKIP: { struct string_list merge_rr = STRING_LIST_INIT_DUP; - options.action = "skip"; rerere_clear(the_repository, &merge_rr); string_list_clear(&merge_rr, 1); ropts.flags = RESET_HEAD_HARD; @@ -1272,7 +1270,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) struct string_list merge_rr = STRING_LIST_INIT_DUP; struct strbuf head_msg = STRBUF_INIT; - options.action = "abort"; rerere_clear(the_repository, &merge_rr); string_list_clear(&merge_rr, 1); @@ -1312,17 +1309,15 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) goto cleanup; } case ACTION_EDIT_TODO: - options.action = "edit-todo"; options.dont_finish_rebase = 1; goto run_rebase; case ACTION_SHOW_CURRENT_PATCH: - options.action = "show-current-patch"; options.dont_finish_rebase = 1; goto run_rebase; case ACTION_NONE: break; default: - BUG("action: %d", action); + BUG("action: %d", options.action); } /* Make sure no rebase is in progress */ @@ -1346,7 +1341,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } if ((options.flags & REBASE_INTERACTIVE_EXPLICIT) || - (action != ACTION_NONE) || + (options.action != ACTION_NONE) || (exec.nr > 0) || options.autosquash) { allow_preemptive_ff = 0; @@ -1786,7 +1781,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) options.revisions = revisions.buf; run_rebase: - ret = run_specific_rebase(&options, action); + ret = run_specific_rebase(&options); cleanup: strbuf_release(&buf);