From patchwork Fri Oct 21 09:21:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13014499 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 36676C4332F for ; Fri, 21 Oct 2022 09:22:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230098AbiJUJV7 (ORCPT ); Fri, 21 Oct 2022 05:21:59 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33114 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231130AbiJUJV5 (ORCPT ); Fri, 21 Oct 2022 05:21:57 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3012565F0 for ; Fri, 21 Oct 2022 02:21:53 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id l14-20020a05600c1d0e00b003c6ecc94285so3607610wms.1 for ; Fri, 21 Oct 2022 02:21:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=9mjLVzcTdft0VJLpC4LtMhvdey7E5X+kofVDbGuLTEk=; b=Azf7iPZd9BTkEW+SLifPbTJQNhNwL/tKYdnKTyMjaBityZqTPeh/Xs0S9TmnAkW8AC 7x1lk1rxdfq3JeuE+3Bss4+2ZAyNWqgzMw4MMhS8wh3YB8vGm5RnO/YV+tA1ha7dO5Lj IRQH4N+YroMnppQqM8nTRYIW3YxQfWzJtMEpUMjnuBL+Qt6w+LWnemFB6FxJSdFz1t+B DloCgTY0sof4zb5FYQPwScOWL+4VeE5ad1MuzXRwqFI/ZIB7mxg/J+zeU+5XhQRdI+DC 60ijm0L8YopJBFiW0TcSYC13gto65lHN8S5DLQq+ES7SFNwycMb1SBEm/pigJiRPxHKX yIEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9mjLVzcTdft0VJLpC4LtMhvdey7E5X+kofVDbGuLTEk=; b=kEAE+k7QlATqD/nY9PCra5aw/0aH6bUslbG5esSKMP9j2SL7exiD2gVfW+4r421Y5D eegGuXxfoFwoqJ+m2HASQj+Muiskz3EQbXZybMtPN3Bw3R/ZbbtNKuGWJZaHvbTY/GO2 PQ/zK6wX/WEO2iB8HqxAHHDy0yY4/MGvtptenGaBEwMD7j7Jt57aEJOkyMh00+6riwum jKd5tv/jFtjGVufYIwZ64UDroyipltoPjgANTwZs7pnsQWWYOXgvtM/sqHNrj+Xny+q9 BHw35w2yYrKvFABMxD5F3/EvPx6H1pe9qpzUn4UN6APITynOJ6Wk9Rwb799QRHvBr5Mh 3OvQ== X-Gm-Message-State: ACrzQf1+EC49aSAH/PKAQ/+jK1D1QbcFyOFuPZpmXqIqiFVPkCQzyxAV 7FxFp74bsZBJA3KgxJBZw1dB5zeiUik= X-Google-Smtp-Source: AMsMyM7kMFPGs3I6KY2kYrJpFXLivNTRJ9VicILBBWmA3Z+GN0Uk1oI1cy7nkUQqvPX5EidJm2ARmg== X-Received: by 2002:a05:600c:1da8:b0:3c6:ca7c:2e87 with SMTP id p40-20020a05600c1da800b003c6ca7c2e87mr11740296wms.126.1666344111304; Fri, 21 Oct 2022 02:21:51 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id a18-20020a056000101200b0023655e51c33sm714978wrx.4.2022.10.21.02.21.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:21:50 -0700 (PDT) Message-Id: <8d5ae067ce361f986634b0f218cf09bb0e2ae33f.1666344108.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 09:21:41 +0000 Subject: [PATCH v4 1/8] t3406: rework rebase reflog tests Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Christian Couder , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Calvin Wan , Emily Shaffer , Glen Choo , Victoria Dye , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Refactor the tests in preparation for adding more tests in the next few commits. The reworked tests use the same function for testing both the "merge" and "apply" backends. The test coverage for the "apply" backend now includes setting GIT_REFLOG_ACTION. Note that rebasing the "conflicts" branch does not create any conflicts yet. A commit to do that will be added shortly and the diff ends up smaller if we have don't rename the branch when it is added. Signed-off-by: Phillip Wood --- t/t3406-rebase-message.sh | 121 ++++++++++++++++++++++++++------------ 1 file changed, 82 insertions(+), 39 deletions(-) diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index d17b450e811..413d6132ea2 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -10,10 +10,15 @@ 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 Q && + git checkout -b topic O && git cherry-pick A B && test_commit Z fileZ && @@ -79,54 +84,92 @@ 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 && + git rebase $mode main + ) && + + 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 && - 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 && + if test "$mode" = "--apply" + then + finish_msg="refs/heads/fast-forward onto $(git rev-parse main)" + else + finish_msg="returning to refs/heads/fast-forward" + fi && + write_reflog_expect <<-EOF && + ${reflog_action:-rebase} (finish): $finish_msg + ${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 Fri Oct 21 09:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13014500 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 1B0F0C433FE for ; Fri, 21 Oct 2022 09:22:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231234AbiJUJWD (ORCPT ); Fri, 21 Oct 2022 05:22:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33106 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230474AbiJUJV5 (ORCPT ); Fri, 21 Oct 2022 05:21:57 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA8422565FA for ; Fri, 21 Oct 2022 02:21:55 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id j7so3927700wrr.3 for ; Fri, 21 Oct 2022 02:21:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=jnFrEQZq/tYFelV4w6tUcxxWcgExlvUcEYhQ0895DKQ=; b=oVy2IYp1Fx+RUnD9JgxiRsfB9Pv8hfdVf97TC00/T8GN7aYBpS4E6Lry7yPFjecsju sPSYs61pdrD+hfaNs6LYCsBDCt6qGpKqb3HVVHvv7eErw6vcChjvtSqRCWIUbAoTbbSM y5bTn3NmMiuXcnIpX02xDCKCm7Eek0vnoirK/8TvjilS1EDdfU9Mfjtr9Bmmyf6ZCJrA fmOvLxV18KkRNvoqoRPmzGH1uTPxD8S1lnZoQqNeNj+BMztL5YJ4pI6bxz7dfqG77Jv/ OlvHLMqKj/rsmb1zkK3d64wSrw8GZ6BNwGNMtbneU7MpFwmCnwMSMw68IdVgsAOA+eJY gR5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jnFrEQZq/tYFelV4w6tUcxxWcgExlvUcEYhQ0895DKQ=; b=mo8vcvG92QNJuJzXP1Vme4Drhw+Dg/6lNjSL18qJsBQymhH/EKu40XpAvWQ5AhQmmO G89oA/q8uculyOCVopm+DU/08DOwbjzim3gCrWs6yLvfZ+cq650o7l647n29sfhdhpS8 TnljA/+kqpuxUih3VbWS02HnCK0qMYS2b+xdso8EVJh6o+PLdNSHC2MPm7CZgrEjFEKt Uiodg34EeOALKWSeiBmfMgjiI6q49bej0F9LZh+bVPBw/RV1zwO0G6XVLFiQu7A+gMIN EBdTilkNIYLtT2mWDakhrabigQDntYstZkjTGtcOROHicUYikni4o2ZUOlUJkAmzByGo nfDQ== X-Gm-Message-State: ACrzQf0HcyHogs0SUGWBWB7MyaRUVUBZTf25JM9r8xyjMgob8/N8IiWE TlmsYYUXMluTgPv13BhydN34q3Nq15w= X-Google-Smtp-Source: AMsMyM6/PIdx0Ny1edLpc0zFX/7cziPhsg/nfi0xvuS9E0VCYfNkxPTRBfkIeSDWXdHfgmHOhOKa5g== X-Received: by 2002:a05:6000:1565:b0:22f:1407:9bfd with SMTP id 5-20020a056000156500b0022f14079bfdmr11389778wrz.620.1666344112612; Fri, 21 Oct 2022 02:21:52 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c5-20020a05600c0a4500b003b5054c6f87sm2157110wmq.21.2022.10.21.02.21.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:21:51 -0700 (PDT) Message-Id: <12701ef7c7cd5a2cde57670db2afa071a5e5622f.1666344108.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 09:21:42 +0000 Subject: [PATCH v4 2/8] rebase --apply: improve fast-forward reflog message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Christian Couder , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Calvin Wan , Emily Shaffer , Glen Choo , Victoria Dye , Phillip Wood , Phillip Wood Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Phillip Wood From: Phillip Wood Using move_to_original_branch() when reattaching HEAD after a fast-forward improves HEAD's reflog message when rebasing a branch. This is because it uses separate reflog messages for "HEAD" and "branch". HEAD's reflog will now record which branch we're returning to. When rebasing a detached HEAD there is no change in behavior. We currently call reset_head() when head_name is NULL but move_to_original_branch() does not. However the existing call does not add a message to the reflog because we're not changing the commit that HEAD points to and so lock_ref_for_update() skips the update. Note that the removal of "strbuf_reset(&msg)" is safe as there is a call to strbuf_release(&msf) just above this hunk which can be seen by viewing the diff with -U6. Helped-by: Junio C Hamano Signed-off-by: Phillip Wood --- builtin/rebase.c | 11 +---------- t/t3406-rebase-message.sh | 8 +------- 2 files changed, 2 insertions(+), 17 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index ef520f66fb8..e67020b3586 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1811,19 +1811,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(&branch_base, &options.orig_head->object.oid)) { 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; } diff --git a/t/t3406-rebase-message.sh b/t/t3406-rebase-message.sh index 413d6132ea2..5253dd1551d 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -143,14 +143,8 @@ test_reflog () { ) && git log -g --format=%gs -2 >actual && - if test "$mode" = "--apply" - then - finish_msg="refs/heads/fast-forward onto $(git rev-parse main)" - else - finish_msg="returning to refs/heads/fast-forward" - fi && write_reflog_expect <<-EOF && - ${reflog_action:-rebase} (finish): $finish_msg + ${reflog_action:-rebase} (finish): returning to refs/heads/fast-forward ${reflog_action:-rebase} (start): checkout main EOF test_cmp expect actual && From patchwork Fri Oct 21 09:21:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13014501 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 873FFC433FE for ; Fri, 21 Oct 2022 09:22:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230187AbiJUJWF (ORCPT ); Fri, 21 Oct 2022 05:22:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33158 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbiJUJV5 (ORCPT ); Fri, 21 Oct 2022 05:21:57 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69D622565FD for ; Fri, 21 Oct 2022 02:21:56 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id b4so3938086wrs.1 for ; Fri, 21 Oct 2022 02:21:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=iNOWMl9EcaK5ZRazLD58gGlH6HzJEyYziWhujACWvKo=; b=WBs6Vnwah0g3sZFK+d2z87qKWvsN3XOALxaO0DtP/HdD12BO5/LdrNKICi3ajLH10f AOcNM0Emz/LVv+XWuvHy9ohX1VF+9CSC2gkpqVyp7UC3v/eukIbTRaZIRa9QnW5UzEuF LwVPFUoPvf7G8kfnijTE146ibrcEkoe4qykoiF7qFT/uM+HewNtGXglDBO4UW4zXc+w5 fD32TjfukEzQKVbW0AYP32SnPfbUxHO8dd0ptfuA1DMb2BFipppvoPzZBvzdWHqj1OlW BzTpRto28q4bQIUCi5KpKGMm1c8WI/YhH7jcfwoXJP/UhMIgsXoqsP3ckEhdctJOu8nQ mzMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=iNOWMl9EcaK5ZRazLD58gGlH6HzJEyYziWhujACWvKo=; b=la8wYhUMcWFMLUUS1IrkF9wVFZ2HYPKDF97LKZ8NQLk/cP4oN8HeZSv7OLeLBbwX0g WHX/3Yb5TDua+/dUMWOCbk5W+QMzyl2TG5JDWQj9Y/mUlLvKbKWjkZPH8R+SjdupODPi Tahaa6r9K7yY/9Jkruo19jTbwwOTeLyjDqyLskVZFjoJBafO5842XWyTqroT2auBzhal kPg+SbK83Ch0193tFBenXQCJCEag0FdnJ+gXKY6viltgdI7RI7lnNFvPMmEAWcpgEJnJ CMf7sMIND2jwLjHbisXBJ1dGraKfv8/k4Yps/q+rLsKUuShQom36tcnG+RQG6krTLThj Ofaw== X-Gm-Message-State: ACrzQf0a1mxwye4Jge+Sdtw2c0/Rt0+zHkbsNE9lb6O23027WLBdkHcJ pmazTPQybThoY/bGQy6IqeAcX4tSLZo= X-Google-Smtp-Source: AMsMyM7utX4HHyFTmeTAyc/vSkULkagSoQFyuVt0K29kCA5YKb1kl0vkeiVov+58KcACM7ohXAi0Bw== X-Received: by 2002:adf:dd88:0:b0:236:57e3:fc86 with SMTP id x8-20020adfdd88000000b0023657e3fc86mr327974wrl.493.1666344114236; Fri, 21 Oct 2022 02:21:54 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id o14-20020a1c750e000000b003b4cba4ef71sm2127916wmc.41.2022.10.21.02.21.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:21:53 -0700 (PDT) Message-Id: <2c965f4b97c1773abc6b844b87fa64c5d6d1524c.1666344108.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 09:21:43 +0000 Subject: [PATCH v4 3/8] rebase --merge: fix reflog when continuing Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Christian Couder , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Calvin Wan , Emily Shaffer , Glen Choo , Victoria Dye , 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(). If we fail to commit the staged changes then we error out so GIT_REFLOG_ACTION does not need to be reset in that case. Signed-off-by: Phillip Wood --- builtin/rebase.c | 2 -- sequencer.c | 5 +++++ t/t3406-rebase-message.sh | 9 +++++++-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index e67020b3586..414526f83a8 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1271,8 +1271,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 61a8e0020d5..5790b35d763 100644 --- a/sequencer.c +++ b/sequencer.c @@ -4785,6 +4785,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; @@ -4795,10 +4797,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 5253dd1551d..3ca2fbb0d59 100755 --- a/t/t3406-rebase-message.sh +++ b/t/t3406-rebase-message.sh @@ -17,6 +17,7 @@ test_expect_success 'setup' ' git checkout -b conflicts O && test_commit P && + test_commit conflict-X fileX && test_commit Q && git checkout -b topic O && @@ -107,13 +108,17 @@ test_reflog () { GIT_REFLOG_ACTION="$reflog_action" && export GIT_REFLOG_ACTION fi && - git rebase $mode main + test_must_fail git rebase $mode main && + echo resolved >fileX && + git add fileX && + git rebase --continue ) && - git log -g --format=%gs -4 >actual && + 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 From patchwork Fri Oct 21 09:21:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13014502 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 80C24C4332F for ; Fri, 21 Oct 2022 09:22:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231264AbiJUJWH (ORCPT ); Fri, 21 Oct 2022 05:22:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231196AbiJUJV6 (ORCPT ); Fri, 21 Oct 2022 05:21:58 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FECB25643E for ; Fri, 21 Oct 2022 02:21:57 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id t4so1761823wmj.5 for ; Fri, 21 Oct 2022 02:21:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=ikwH0ZCyDmVigWp++0TStZaMRC3NsaFyNHVd7o2ShXc=; b=fLbdSuEiCVu9C1r9e/UOe+A7EJ19+rsHZ8qmJsJJhiKDvktpc9En65nugMain5l2vU ZzJdna+WX7PiVbmI2WvGm/ed+Rb5HHqgbR5+WRn9y1iUsu6alruP8jFSO/46G9cm/G1N WC3l3FscVLQZwcBvA11RYNNUQw1U5jE9cZb8mhlakoxkNzVBTIDx4HuTyjJisbyOjqjY ciFphgPwp5VmAb5Pgo5Bb4bJMJf9hV6FtzYlTgbBbLEV7vcTtBvwKGfqgQzWlfvJKKMu bmlLgPQsSn/CiIfQD5OabNcNmF20J7aysVgUaRoqMzK7NYaEdF/GRgKHlzy8iRhKpUE0 hmCw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ikwH0ZCyDmVigWp++0TStZaMRC3NsaFyNHVd7o2ShXc=; b=IixJTE7duhsVzpd16I/8GZvEe7MCayOFXWdbNA7pEUpMwJ1Y3Wv9rHD3t6Mm7b0miw 2zuzPRoijwqXZ1dTlKXGiwEmROv9//n5etPaUVc1gqDDKxcdULcNK9GVCXfJC7qxLKuE GBTafn50TkZ38iMkVb2I3EDxwr9fQqOWJggYHeXOoig8xVfN4pyS7IBo92FLEcD51Gwa edB6OFtM0LkxGkeYR0EDEPAUFLXoUJ4YvD/hkersltjshH6JtlibbHImtt7i8j//SyHM /qa7+5R6MumXfJERkhjW313m0ZeSIkYEeXzuawufpw9+wFU0QquI7Gbvq5fZPBQcdCzr EghQ== X-Gm-Message-State: ACrzQf01U+3+YaKuo3nrUnWAXNn1RMsZRp6j1QLUtlDkif4MWQRGUAbJ cigigRhlI6vgLfmeIhWtNNj2sPpX+eE= X-Google-Smtp-Source: AMsMyM4pnGT9fnPIweYDCXULuc5w/f2s7ttMKlgkK99plt0eT2mX0cZ8D2db+ZLzLBrjRF3CO67qZA== X-Received: by 2002:a05:600c:2f08:b0:3c6:befc:9778 with SMTP id r8-20020a05600c2f0800b003c6befc9778mr12086691wmn.101.1666344115219; Fri, 21 Oct 2022 02:21:55 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id f18-20020adff452000000b0022584c82c80sm18332205wrp.19.2022.10.21.02.21.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:21:54 -0700 (PDT) Message-Id: <17138d910f0019927f0e7686c626ab7ccc33be93.1666344108.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 09:21:44 +0000 Subject: [PATCH v4 4/8] rebase --merge: fix reflog message after skipping Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Christian Couder , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Calvin Wan , Emily Shaffer , Glen Choo , Victoria Dye , 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 414526f83a8..c1e68173b5f 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1297,8 +1297,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 Fri Oct 21 09:21:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13014503 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 91D79C433FE for ; Fri, 21 Oct 2022 09:22:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231146AbiJUJWM (ORCPT ); Fri, 21 Oct 2022 05:22:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33452 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231219AbiJUJWC (ORCPT ); Fri, 21 Oct 2022 05:22:02 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 82A7225641B for ; Fri, 21 Oct 2022 02:21:58 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id bk15so3812543wrb.13 for ; Fri, 21 Oct 2022 02:21:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=CSEIaLYWwqPrjb06JkAriDRxYvo8kNvRobBzwV8/xxo=; b=bbwvMy8CyQdAVEL138Hlqwe5dHEMw/pjb67kNpIjDAfRA/SvLFYHFYeWZFW7zvD+tZ 5ZgfMu4UZzoyPEb1HQXnmRdXx5ZdhIrNtV6vxugy1Gk4nj2nyltQQNRYXJUziKHRl5wI ywjs+7LT4jWgANUOVPYVLEc+d0DGHHiAnrbr07xGGOfQwW2dA3DNUrrUt+qZHrttA93l rLEvGWJy6yuzPLkf6/MIEfou/lsQyX3tp6CVJ9wmvrXrd8gLH7Fqhfqhb9VCQIqesuHu c04klI7iuIzMwNNSdgVP9VJGOIxC4ld7H1uzpBDr/QSHUVk6GBmuo9Fqyjwz75C20jxJ /xaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=CSEIaLYWwqPrjb06JkAriDRxYvo8kNvRobBzwV8/xxo=; b=lDq1Kku+sEYerYESMM/q5+8tHQo9xFJjlrdZuksRcd9WwFPsNg7p002UizIRdal51J Hc8b+3sPZncqO2KZYbqwRU8kK6iqa725IV1iDw2eZAhBAUJ5gyIvltziAk0cRxPQ7Ayo 59SRXbMODNrVd55oWid6n2XEJNZ6tHfqlEJsxFK6IFl1z1aZ6TwICyzfdA4/WwTVomNS vBN6lx2dxQJSz6oWFdiZ/NXb3zUHrM+QKj7n46EUZvIcppY84aNvu4bwJ34C5BQGmxZa 51oqzE/nq6nvUbWU9MqgHXwSIJzB9qX77+zjyq65Y1yatjhNlXwOed81rOnyrin8UbVU PoKg== X-Gm-Message-State: ACrzQf3KRvTtZ7/hoJzM51apF3Ky96wHqGgunYoNGrJw08MOrPNNnPMa OtAtLN+CV8/0DCSsRvOgLv6zX4kkS/c= X-Google-Smtp-Source: AMsMyM62Sui6Jj9Fhmz8aFyqCGScxkY265wa0Xvt5J387ITk2Z9ytSKHeC/BfFEmhFAeNOVMo4M3xw== X-Received: by 2002:a05:6000:1d8d:b0:22e:6371:65b6 with SMTP id bk13-20020a0560001d8d00b0022e637165b6mr11624699wrb.657.1666344116432; Fri, 21 Oct 2022 02:21:56 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id p9-20020a05600c468900b003c452678025sm2392511wmo.4.2022.10.21.02.21.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:21:55 -0700 (PDT) Message-Id: <0c71c73290441b67e2d70809cfaf605a1f3f70ca.1666344108.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 09:21:45 +0000 Subject: [PATCH v4 5/8] rebase --apply: respect GIT_REFLOG_ACTION Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Christian Couder , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Calvin Wan , Emily Shaffer , Glen Choo , Victoria Dye , 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 c1e68173b5f..ea246c6bb3a 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -582,10 +582,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 Fri Oct 21 09:21:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13014504 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 B2995C4332F for ; Fri, 21 Oct 2022 09:22:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231284AbiJUJWN (ORCPT ); Fri, 21 Oct 2022 05:22:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbiJUJWH (ORCPT ); Fri, 21 Oct 2022 05:22:07 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC1C425590A for ; Fri, 21 Oct 2022 02:21:59 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id e18so1772441wmq.3 for ; Fri, 21 Oct 2022 02:21:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=aUqPYjlgyRZ2KRHIh7Lay3mIu1RDwi4TVB0J1FOnfnQ=; b=g5DYe+EqxuWQ48kRWMTkkcfAdautx1aReUmUfiTNSH7FhARpI2f7LS+qdRXfs1DAoB J4tNHcJJvg3SapLMvuzkPpqW7h6xgor8AuBsP94R81c/dCWuoP4Do54vKS21wH1OL3aS qxevPPVtvtNYFQhcmETVptjUxUnkC/+BUtPvgcbWOsLwGhRqdYgnHdCy92s/PvaAAzJs WSX6XGAycQ/ti6+BIvVzhHpGGxM/2SbqbIWIShzRjSoIBqv1kMr1TsIFLeiT2cWhOyMo Q01WjlCnl3R5oMtQq/dv53pCxmhUI36Hj6u0rFUGc25ppeg0BzSyrBDIkBxJ98E8yxVa tWBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aUqPYjlgyRZ2KRHIh7Lay3mIu1RDwi4TVB0J1FOnfnQ=; b=icQsvp7AvFdvyUF6JM90DvUeW4BV+F8/ssXYA/kFFR3lli0xSIq/O8Zpgwa4T4S0pO ifgHAGP5OhEMkQcC8mIqb5a6r5YNnZlgei6ugyt0bHLcP/jMsMyb/BCPSfFs7R7bXP8H /xikBzx3oM2EFviowWqhdX47RCH7Kr+WKRXWoEdi/A4p2j/tuTsXQXmOkU58frCpBntz xN2JZoYUarLAden/KLFTfSp17pOSWlG6nkXuz4Q1WGsSA9sDFH/Yu1mnWY54/9MSaYD2 mlQzEbkgXEideTa/JbdVeD+Vmo7JqzCQPIydod+BbV897T6vXUhsuh4GmpBinPRsebJo +XBw== X-Gm-Message-State: ACrzQf32B7e19g/3MzlV6BadixYPB4Q6ZgeJ6Oyc2+PJJyE59yq+jtq4 uWvhhrmHP1Kt3aY7bx4IE3LqLgkWAQE= X-Google-Smtp-Source: AMsMyM4e4Bsj45gQIKo25p0YvcSYFXk93jW61rIE9FypfJd7DNvUwosNiW8tNWOgtG9DEndD2oGisQ== X-Received: by 2002:a05:600c:3512:b0:3c8:2c4e:8680 with SMTP id h18-20020a05600c351200b003c82c4e8680mr970855wmq.165.1666344117431; Fri, 21 Oct 2022 02:21:57 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id g11-20020a5d488b000000b0022eafed36ebsm18470474wrq.73.2022.10.21.02.21.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:21:56 -0700 (PDT) Message-Id: <3f6b2e39f4091e891f3ab83da7944a0c497ec300.1666344108.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 21 Oct 2022 09:21:46 +0000 Subject: [PATCH v4 6/8] rebase --apply: make reflog messages match rebase --merge Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Christian Couder , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Calvin Wan , Emily Shaffer , Glen Choo , Victoria Dye , 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 or finishing a rebase and when picking commits. These differences make it harder than it needs to be to parse the reflog (I have a script that reads the finishing messages from rebase and it is a pain to have to accommodate two different message formats). While it is possible to determine the backend used for a rebase from the reflog messages, the differences are not designed for that purpose. c2417d3af7 (rebase: drop '-i' from the reflog for interactive-based rebases, 2020-02-15) removed the clear distinction between the reflog messages of the two backends without complaint. As the merge backend is the default it is likely to be the format most common in existing reflogs. For that reason the apply backend is changed to format its reflog messages to match the merge backend as closely as possible. Note that there is still a difference as when committing a conflict resolution the apply backend will use "(pick)" rather than "(continue)" because it is not currently possible to change the message for a single commit. In addition to c2417d3af7 we also changed the reflog messages in 68aa495b59 (rebase: implement --merge via the interactive machinery, 2018-12-11) and 2ac0d6273f (rebase: change the default backend from "am" to "merge", 2020-02-15). This commit makes the same change to "git rebase --apply" that 2ac0d6273f made to "git rebase" without any backend specific options. As the messages are changed to use an existing format any scripts that can parse the reflog messages of the default rebase backend should be unaffected by this change. There are existing tests for the messages from both backends which are adjusted to ensure that they do not get out of sync in the future. 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 ea246c6bb3a..5253ba66861 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -582,10 +582,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; @@ -615,7 +615,8 @@ static int run_am(struct rebase_options *opts) am.git_cmd = 1; strvec_push(&am.args, "am"); - + strvec_pushf(&am.env, 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); @@ -1792,7 +1793,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->object.oid, 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 Fri Oct 21 09:21:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood X-Patchwork-Id: 13014505 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 E5B7AC43217 for ; Fri, 21 Oct 2022 09:22:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230363AbiJUJWP (ORCPT ); Fri, 21 Oct 2022 05:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33744 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbiJUJWH (ORCPT ); Fri, 21 Oct 2022 05:22:07 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D28D32565F0 for ; Fri, 21 Oct 2022 02:22:00 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id bv10so3907159wrb.4 for ; Fri, 21 Oct 2022 02:22:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=jCtQUYDJQX3GAiniLMUYw+pLQXAUjLsw2bX/8F0aMls=; b=dxGJ5DeVFUadG+AQbOPn455WieEVGgGa3+xPa4/O4tNFzT58ELCLJIG+cTI+8eflEG EDS7zdGNxcSSa+/2IXZ/S6HDjSxutmXpOKRB8Yw1+SoGxFVjH5AWuM/OjsURDHYGucGq csrCn8wv74MH8lhzxDVNEnL0Wt+cbtrDfntKOQLMpcUQKKOo0YQVELWt2/ziDbChGOOr 4XKELxuTY0EtAhVKvU1IHhKm4NzITYKOQTyoDq4bSKG43BZOjpdNcEqU8+DSQLqxEWsH lGtxiL9hwN01uVD5yKjZsFpR6wt6K5qMxhaGdGrR9OyWluyJpv6PS1o7eXq5n8XrqIHc bnAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=jCtQUYDJQX3GAiniLMUYw+pLQXAUjLsw2bX/8F0aMls=; b=hXZ6mok+fYHhYAuKQ9F9XChvCz9DbfYQSD2kmotye+SyXPiUrkkc1bRrHCr/5t4TsD MN0Yc9CxbiqbdGo90w0zJF3TvNhGHnwXRWXgVKPlCEK1nGTTwK4L7nqMWy8fGluCo8Oy r0Omjq1nI57VjFxrRobuApOtJzrsm+8fCnSOqaOQ6V8U2/IQgnZmg2Ra3PNTp4Kqjl/t hb7mM5I92vfjVXuTjhbQOnhUa1xsPyK6//exJaHKeGwqGYqBsuIAlohhShceL05GTyTg +afSsANHUnIGW7iLypjeFi/wgWEMS07/HfMAv74N3KVQzr3BV5iQTNWQN4812DELIGKO B07g== X-Gm-Message-State: ACrzQf08xGS7f3pBuz/L1B7U9QP5vFvvZWejB+EgDi454C3KndyOrKuu FP5GJMYW8UUdLpYsJpCQX6DymSs+OgA= X-Google-Smtp-Source: AMsMyM726bcOmfovmqnZ0byYQ76LOmGeSGURn5BW7t3ydSoFrVUvtPhDgJFg8ZzMGCQHjwbcctrOxQ== X-Received: by 2002:adf:d1c4:0:b0:230:7771:f618 with SMTP id b4-20020adfd1c4000000b002307771f618mr10774147wrd.203.1666344118411; Fri, 21 Oct 2022 02:21:58 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id k5-20020a5d6d45000000b0022e57e66824sm21702181wri.99.2022.10.21.02.21.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:21:57 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 21 Oct 2022 09:21:47 +0000 Subject: [PATCH v4 7/8] rebase --abort: improve reflog message Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Christian Couder , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Calvin Wan , Emily Shaffer , Glen Choo , Victoria Dye , 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 5253ba66861..d63d77757e8 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -1001,23 +1001,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')) @@ -1311,18 +1294,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->object.oid)); ropts.oid = &options.orig_head->object.oid; + 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->object.oid)); 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 Fri Oct 21 09:21: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: 13014506 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 30D21C433FE for ; Fri, 21 Oct 2022 09:22:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231302AbiJUJWV (ORCPT ); Fri, 21 Oct 2022 05:22:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231196AbiJUJWJ (ORCPT ); Fri, 21 Oct 2022 05:22:09 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6821A257CFA for ; Fri, 21 Oct 2022 02:22:01 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id fn7-20020a05600c688700b003b4fb113b86so1612095wmb.0 for ; Fri, 21 Oct 2022 02:22:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=GIdaEDuIXBCdWyQdTPC2jFwiLwkfSA1pLH/SgRpvQVM=; b=M0CDV/CxZ2Tuu0VqnPbMD7UrG9VkVfSBpDRnbWesuVl0t/HOuwMXDtj0dwzJuAKoXI t0M/aPG1K5uA+e4kOZOpEl/uBoVX3zJZALKZ/jnq+JBIuvHvIxW5n6e7u3Ikb3ZkjvId nCQ54iStcCG/urKL32h6MJiDzz//7B6YA6WRY59gv4A2UWLEjKGeFTe/+KJmVTpmr8HI ox58gSgFVz7Cyvz3emaG+6E7azWRl66HrPWZGkzLtbKzdFc8xKE6erC+yVEFbA16zSv2 Ns5BBIaRK5gef83utKZspGH9+VQc2UJzI33duETCsR5MGpbph9JDPgVxqu77FtH8WyrP Sx/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=GIdaEDuIXBCdWyQdTPC2jFwiLwkfSA1pLH/SgRpvQVM=; b=Z0EmWTXT53t091bwXzgrzsSVkOPF0jojE0JByBruL9vMwxG5QgopEpmKudXkCPu+Zh sHwgugKkZC8hcq8wxcBRTnAbElIk1wH8Rpyr1O7wFut5ViODeUCZJ0X0UvKoVH7SzheU 8zzbIo9aIP5AIvGstsg4vFxfF2HuP+EyeDXNBzb+eWt0ZVyQ9CpUAP/Fj1y28LDInP6A RWnk3Enp0/1XVeU52Y4EzJw8IHj5InZcsLaxAMuchnX3j0al7RPZLnWIfRslY9C0VY37 AsbfXR+PtoUd4rQfN4ad6xFbDjiKoyfOYsJQUCpMEBhfetMQ4oV77T+F/DJBJwsa9W4c s3Rw== X-Gm-Message-State: ACrzQf0KOA6DJZJrPNVT+ryBgARF6sZlTAupEIb55ameq8H+5rvPowBp xsxSyHf9gZJSFv2mmgfgl6Yqr3II5tw= X-Google-Smtp-Source: AMsMyM7cwuv1aybpaliuCmKi9g1HH0P5eFdf+mM91THlbcFuCwVAp86zgPv3JYUZjVrMM/Ax3WFUWA== X-Received: by 2002:a05:600c:35c8:b0:3c8:33dc:c262 with SMTP id r8-20020a05600c35c800b003c833dcc262mr309492wmq.206.1666344119552; Fri, 21 Oct 2022 02:21:59 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b13-20020a5d45cd000000b0023657e1b97esm326473wrs.11.2022.10.21.02.21.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 21 Oct 2022 02:21:58 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 21 Oct 2022 09:21:48 +0000 Subject: [PATCH v4 8/8] rebase: cleanup action handling Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Phillip Wood , Christian Couder , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsA==?= Bjarmason , Calvin Wan , Emily Shaffer , Glen Choo , Victoria Dye , 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 | 93 +++++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 49 deletions(-) diff --git a/builtin/rebase.c b/builtin/rebase.c index d63d77757e8..d5e684a7cec 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -59,6 +59,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; @@ -85,7 +105,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; @@ -156,24 +176,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(); @@ -310,8 +312,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; @@ -326,7 +327,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")); @@ -359,7 +360,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; @@ -617,7 +618,7 @@ static int run_am(struct rebase_options *opts) strvec_push(&am.args, "am"); strvec_pushf(&am.env, 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) @@ -628,7 +629,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); @@ -637,7 +638,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); } @@ -730,7 +731,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; @@ -748,7 +749,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 @@ -1025,7 +1026,6 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) struct strbuf buf = STRBUF_INIT; struct object_id branch_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; @@ -1074,18 +1074,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, @@ -1174,7 +1174,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) } else if (is_directory(merge_dir())) { strbuf_reset(&buf); strbuf_addf(&buf, "%s/rewritten", merge_dir()); - if (!(action == ACTION_ABORT) && is_directory(buf.buf)) { + if (!(options.action == ACTION_ABORT) && is_directory(buf.buf)) { die(_("`rebase --preserve-merges` (-p) is no longer supported.\n" "Use `git rebase --abort` to terminate current rebase.\n" "Or downgrade to v2.33, or earlier, to complete the rebase.")); @@ -1201,7 +1201,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) "Note: Your `pull.rebase` configuration may also be set to 'preserve',\n" "which is no longer supported; use 'merges' instead")); - if (action != ACTION_NONE && total_argc != 2) { + if (options.action != ACTION_NONE && total_argc != 2) { usage_with_options(builtin_rebase_usage, builtin_rebase_options); } @@ -1232,11 +1232,11 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (options.root && options.fork_point > 0) die(_("options '%s' and '%s' cannot be used together"), "--root", "--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.")); @@ -1246,16 +1246,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")); @@ -1281,7 +1280,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; @@ -1296,7 +1294,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); @@ -1336,17 +1333,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 */ @@ -1370,7 +1365,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; @@ -1815,7 +1810,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);