git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>, Elijah Newren <newren@gmail.com>
Subject: [PATCH 2/2] merge: avoid searching for strategies with fewer than 0 conflicts
Date: Sun, 21 Aug 2022 04:38:29 +0000	[thread overview]
Message-ID: <5657a05e7635ecadbb8d2e41ad97fe19f3633fdd.1661056709.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1331.git.1661056709.gitgitgadget@gmail.com>

From: Elijah Newren <newren@gmail.com>

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 <newren@gmail.com>
---
 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) {
-- 
gitgitgadget

  parent reply	other threads:[~2022-08-21  4:38 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-21  4:38 [PATCH 0/2] Miscellaneous merge fixes Elijah Newren via GitGitGadget
2022-08-21  4:38 ` [PATCH 1/2] merge: only apply autostash when appropriate Elijah Newren via GitGitGadget
2022-08-21  4:52   ` Eric Sunshine
2022-08-21  5:18     ` Elijah Newren
2022-08-21  4:38 ` Elijah Newren via GitGitGadget [this message]
2022-08-21 18:05   ` [PATCH 2/2] merge: avoid searching for strategies with fewer than 0 conflicts Junio C Hamano
2022-08-22 15:00     ` Elijah Newren
2022-08-22 16:19       ` Junio C Hamano
2022-08-23  1:18         ` Elijah Newren
2022-08-23  2:42 ` [PATCH v2 0/3] Miscellaneous merge fixes Elijah Newren via GitGitGadget
2022-08-23  2:42   ` [PATCH v2 1/3] merge: only apply autostash when appropriate Elijah Newren via GitGitGadget
2022-08-23  2:42   ` [PATCH v2 2/3] merge: cleanup confusing logic for handling successful merges Elijah Newren via GitGitGadget
2022-08-23  2:42   ` [PATCH v2 3/3] merge: small code readability improvement Elijah Newren via GitGitGadget
2022-08-23  3:03   ` [PATCH v2 0/3] Miscellaneous merge fixes Elijah Newren
2022-08-24 21:09     ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5657a05e7635ecadbb8d2e41ad97fe19f3633fdd.1661056709.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=newren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).