From patchwork Sun Aug 21 04:38:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12949863 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 98319C32774 for ; Sun, 21 Aug 2022 04:38:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229555AbiHUEik (ORCPT ); Sun, 21 Aug 2022 00:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229455AbiHUEif (ORCPT ); Sun, 21 Aug 2022 00:38:35 -0400 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 7BDC0E0D7 for ; Sat, 20 Aug 2022 21:38:33 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id u14so9430426wrq.9 for ; Sat, 20 Aug 2022 21:38:33 -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; bh=X0II+Ol8/Sk6L+GKhipKwRFR7Ybf9+yL/dwYpVt3Z40=; b=eC7hd2b131AukPMwkPCvMJUbUQnLuLsRp/qekbw1na/bl0pmY7tFkeiRacHXz4GfHk tczyrK/xXzJNkJkQJ+Qy3l6F06DHhcNGW5vGLZcORKfrgAppJZ0DVpLyj8bV6nbVbtwa FqHO5LkXGOrXMPs1qKFM2LrPMO3kXy9HNpGaJVCCHcWtmXOXHo9uX4raAZdrN1bkZQfs m0TmJR6Pfjsjq/cdzik+mizsiSWDXEmECfusiFu/NjA3r8DlgZ4ifDy7MzfCTWylg2YJ /nBVp0+rf3cMNDf8Hc3rEsoGImt/My1s2AA3M6JxYLkwaI3eZ99kGxieM1eyy+I9RKga 08WQ== 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; bh=X0II+Ol8/Sk6L+GKhipKwRFR7Ybf9+yL/dwYpVt3Z40=; b=rpoGoLy0Qu9bvwiyPsDTUlrKWxPhc0MpkLlMDfd0uVdvcpUEpggGHBKxSw/TGpIKf5 b01DJ+OVvmkaEzLDuRPQjXwSdQ/Wu5EliTUtM7FDqvpYQzHrtPblh9KcbRz87u/pUfBN zho+iZTx/EIsgl3wsuyV2XyXpSx7U7B2aeGxgddc8/GNtTvo/HPt/qyqUdN3lfHfBbyD WkgQeJFfnp/PLwnHl0jwi4WO5nDL0qrULu7jAS3mB3gaJgSUHvv9kUzlIQo413QhqyxO sl/S4hLvhLEUcU68Ghe8EHcmfrXgEwCnmUzCJaRFACyTXr2zcw6DOdsuEbuO8mPw0HO1 fh5A== X-Gm-Message-State: ACgBeo3RH6n+IlTMCZ9pW2ptMmAFakYUtzxFre+L7U9AtvAA+F3gJOCt yc1SxPoKiSpYxyryD+Sx9moAxGiiTAs= X-Google-Smtp-Source: AA6agR6visLtHoOAxAT/61omDaXvP+AzGttej+mth3vFTk9nSj/orZDO5VTStzAX5IU0E5K4oE6E0w== X-Received: by 2002:a5d:5889:0:b0:225:58c7:e9b2 with SMTP id n9-20020a5d5889000000b0022558c7e9b2mr5672wrf.227.1661056711579; Sat, 20 Aug 2022 21:38:31 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id 15-20020a05600c228f00b003a327b98c0asm9998724wmf.22.2022.08.20.21.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Aug 2022 21:38:31 -0700 (PDT) Message-Id: <92840bf63782ca302e9d48a12faf7d4f5b3cc2d5.1661056709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 21 Aug 2022 04:38:28 +0000 Subject: [PATCH 1/2] merge: only apply autostash when appropriate Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren If a merge failed and we are leaving conflicts in the working directory for the user to resolve, we should not attempt to apply any autostash. Further, if we fail to apply the autostash (because either the merge failed, or the user requested --no-commit), then we should instruct the user how to apply it later. Add a testcase verifying we have corrected this behavior. Signed-off-by: Elijah Newren --- builtin/merge.c | 5 ++++- t/t7600-merge.sh | 9 +++++++++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/builtin/merge.c b/builtin/merge.c index f7c92c0e64f..b4253710d19 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -503,7 +503,8 @@ static void finish(struct commit *head_commit, /* Run a post-merge hook */ run_hooks_l("post-merge", squash ? "1" : "0", NULL); - apply_autostash(git_path_merge_autostash(the_repository)); + if (new_head) + apply_autostash(git_path_merge_autostash(the_repository)); strbuf_release(&reflog_message); } @@ -1781,6 +1782,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix) "stopped before committing as requested\n")); else ret = suggest_conflicts(); + if (autostash) + printf(_("When finished, apply stashed changes with `git stash pop`\n")); done: if (!automerge_was_ok) { diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh index f0f6fda150b..6a39bc72122 100755 --- a/t/t7600-merge.sh +++ b/t/t7600-merge.sh @@ -255,6 +255,15 @@ test_expect_success 'merge --squash c3 with c7' ' test_cmp expect actual ' +test_expect_success 'merge --squash --autostash conflict does not attempt to play autostash' ' + git reset --hard c3 && + >unrelated && + git add unrelated && + test_must_fail git merge --squash c7 --autostash >out 2>err && + ! grep "Applying autostash resulted in conflicts." err && + grep "When finished, apply stashed changes with \`git stash pop\`" out +' + test_expect_success 'merge c3 with c7 with commit.cleanup = scissors' ' git config commit.cleanup scissors && git reset --hard c3 && From patchwork Sun Aug 21 04:38:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12949862 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 A8C87C28D13 for ; Sun, 21 Aug 2022 04:38:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229530AbiHUEii (ORCPT ); Sun, 21 Aug 2022 00:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbiHUEif (ORCPT ); Sun, 21 Aug 2022 00:38:35 -0400 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5ECBADFEB for ; Sat, 20 Aug 2022 21:38:34 -0700 (PDT) Received: by mail-wm1-x333.google.com with SMTP id m17-20020a7bce11000000b003a5bedec07bso6050515wmc.0 for ; Sat, 20 Aug 2022 21:38:34 -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; bh=MFYwz6PheNpX7vbXD74uZ2DSWZj9pWuhH4L1hfLaq58=; b=AZsp1PT54uwzBi1vC6yspgReTkbAAc7lU8FpnEgQvDo866YdBieFW0HbMdGuIqrH/A EmaqOuyL44wjACOGQ68wX/9IaXDCX4g+bp+h1MS2yaq7X7wmQGRxxcmeO5yb+aztC2Bl WSLA70cJZTA9RCqjd+zlCH5nfVxW1iGJKrYZPHSe/k+EsdjIHI0ipvWZVjgRRMORBGFY R0dgpYiIVW6/KFKSiwTnd5vq96m2taRtQmaunPqwvG+boBiOOWf7WSw4ifuA7XiCwd+r dR6eoUDRMUe2aRszgsJ2GbsIViwcl6/n0IVoV7X+KYCjXCoeVSCUor0ny9AbZgk2t2/H PQFw== 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; bh=MFYwz6PheNpX7vbXD74uZ2DSWZj9pWuhH4L1hfLaq58=; b=rWnTUFi/Mexl72zkmF0ebWTIqU0NluNCioO+otyur7KIpYu0IDSxc31m7GpQyb3krY XAluWRPki7oak4HHGOWn62i7vKieyAQ8QbylflHp63Hl02jmKTj0ct3AQeBD60W8xsRW oagWLz2tSZbdvVe5sGdUSOV8Tc/oA2CW3l6w48BKYMPaLZuLaTN31ieb3YIDWGeGw/6y wAk/DXy/Cgf/UuX9hDsQeEtQVMihbFKsmmwHe2yRHFMRvTFOolLZmZolUe5AsLKOnYn/ 0ZxewgZB/O05/OEtbdGv+PuM7eeRpl1NgNWPdII4lUgTUnzz/JKXju8J0OmDpxpsW90+ tMnA== X-Gm-Message-State: ACgBeo2Jhej/6GgDpKbQWQA0MZwiLowgl3/UiwKoafDKkcRSd4DNCqzs 35UbhaEkhbyYrFPmdTSynv3oQBwAEeQ= X-Google-Smtp-Source: AA6agR7Lr1X3ZiF+mA6bVcuWSjvOVnQEEwPKPIIHoHZKuCHWu5rf11d/eB9eC1tSAfV7i28321hasw== X-Received: by 2002:a05:600c:1084:b0:3a6:150d:b92 with SMTP id e4-20020a05600c108400b003a6150d0b92mr12001547wmd.151.1661056712638; Sat, 20 Aug 2022 21:38:32 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id d7-20020a05600c34c700b003a53731f273sm10484237wmq.31.2022.08.20.21.38.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Aug 2022 21:38:32 -0700 (PDT) Message-Id: <5657a05e7635ecadbb8d2e41ad97fe19f3633fdd.1661056709.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Sun, 21 Aug 2022 04:38:29 +0000 Subject: [PATCH 2/2] merge: avoid searching for strategies with fewer than 0 conflicts Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren builtin/merge.c has a loop over the specified strategies, where if they all fail with conflicts, it picks the one with the least number of conflicts. In the codepath that finds a successful merge, if an automatic commit was wanted, the code breaks out of the above loop, which makes sense. However, if the user requested there be no automatic commit, the loop would continue looking for a "better" strategy. Since it had just found a strategy with 0 conflicts though, and it is not possible to have fewer than 0 conflicts, the continuing search is guaranteed to be futile. While searching additional strategies won't cause problems other than wasting energy, it is wasteful. Avoid searching for other strategies with fewer than 0 conflicts. Signed-off-by: Elijah Newren --- builtin/merge.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/builtin/merge.c b/builtin/merge.c index b4253710d19..f04100ce0da 100644 --- a/builtin/merge.c +++ b/builtin/merge.c @@ -1718,12 +1718,18 @@ int cmd_merge(int argc, const char **argv, const char *prefix) */ if (ret < 2) { if (!ret) { - if (option_commit) { + if (option_commit) /* Automerge succeeded. */ automerge_was_ok = 1; - break; - } - merge_was_ok = 1; + else + /* Merge good, but let user commit */ + merge_was_ok = 1; + /* + * This strategy worked; no point in trying + * another. + */ + best_strategy = wt_strategy; + break; } cnt = (use_strategies_nr > 1) ? evaluate_result() : 0; if (best_cnt <= 0 || cnt <= best_cnt) {