Skip to contentSkip to conversation

Miscellaneous merge fixes

PATCH Superseded Elijah Newren via GitGitGadget 4 participants 15 messages Aug 21, 2022 – Aug 24, 2022

lore
Share & tools
lore
#0 lore raw

cover Miscellaneous merge fixes

While working on other things, I noticed a few miscellaneous issues in builtin/merge.c. Here's a few small fixes to address them.

Elijah Newren (2):
merge: only apply autostash when appropriate
merge: avoid searching for strategies with fewer than 0 conflicts

 builtin/merge.c  | 19 ++++++++++++++-----
 t/t7600-merge.sh |  9 +++++++++
 2 files changed, 23 insertions(+), 5 deletions(-)

base-commit: 9bf691b78cf906751e65d65ba0c6ffdcd9a5a12c
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1331%2Fnewren%2Fmisc-merge-fixes-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1331/newren/misc-merge-fixes-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1331

Signature · 1 line
gitgitgadget
#4 lore raw

PATCH 2/2 merge: avoid searching for strategies with fewer than 0 conflicts

From: Elijah Newren <[email protected]>

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.

---
 builtin/merge.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
builtin/merge.c +10 -4
index b4253710d19..f04100ce0da 100644
@@ -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) {
Signature · 1 line
gitgitgadget
#1 lore raw

PATCH 1/2 merge: only apply autostash when appropriate

In reply to Elijah Newren via GitGitGadget

From: Elijah Newren <[email protected]>

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.

---
 builtin/merge.c  | 5 ++++-
 t/t7600-merge.sh | 9 +++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
builtin/merge.c +4 -1
index f7c92c0e64f..b4253710d19 100644
@@ -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) {
t/t7600-merge.sh +9 -0
index f0f6fda150b..6a39bc72122 100755
@@ -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 &&
Signature · 1 line
gitgitgadget
#2 lore raw

Re: [PATCH 1/2] merge: only apply autostash when appropriate

Quoted 13 lines · Elijah Newren via GitGitGadget

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.

---

t/t7600-merge.sh test_expect_success 'merge --squash c3 with c7' ' · line 255

Quoted 1 line
t/t7600-merge.sh +1 -0
@@ -255,6 +255,15 @@ test_expect_success 'merge --squash c3 with c7' '
+test_expect_success 'merge --squash --autostash conflict does not attempt to play autostash' '

Did you mean s/play/apply/ ?

#3 lore raw

Re: [PATCH 1/2] merge: only apply autostash when appropriate

Quoted 12 lines · Eric Sunshine
Quoted 9 lines · Elijah Newren via GitGitGadget

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.

Quoted 7 lines

t/t7600-merge.sh test_expect_success 'merge --squash c3 with c7' ' · line 255

Quoted 5 lines

---

t/t7600-merge.sh +1 -0
@@ -255,6 +255,15 @@ test_expect_success 'merge --squash c3 with c7' '
+test_expect_success 'merge --squash --autostash conflict does not attempt to play autostash' '

Did you mean s/play/apply/ ?

Yep; will fix.

#5 lore raw

Re: [PATCH 2/2] merge: avoid searching for strategies with fewer than 0 conflicts

In reply to Elijah Newren via GitGitGadget
Quoted 6 lines · Elijah Newren via GitGitGadget

From: Elijah Newren <[email protected]>

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.

Quoted 7 lines

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.

Let's imagine "git merge -s ours -s ort X", both of which resolve the merge cleanly but differently.

The "best_cnt" thing tries to find the last strategy with the lowest score from evaluate_result(), so strictly speaking I think this changes the behaviour. Am I mistaken?

When two strategies 'ours' and 'ort' resolved a given merge cleanly (but differently), we would have taken the result from 'ort' in the original code, but now we stop at seeing that 'ours' resolved the merge cleanly and use its result.

builtin/merge.c int cmd_merge(int argc, const char **argv, const char *prefix) · line 1735

Quoted 2 lines
builtin/merge.c +0 -0
 			cnt = (use_strategies_nr > 1) ? evaluate_result() : 0;
 			if (best_cnt <= 0 || cnt <= best_cnt) {

While I think "we see one clean merge, so it is OK to quit" is more intuitive than the current behaviour, we need to update this comparison to require the new candidate to have strictly better result to take over the tentative best from the current candidate. That will make things consistent with this change and makes it easier to sell.

As the userbase of Git is so wide, it is very plausible that somebody already invented and publisized that prepending "-s ours" before the real strategy they want to use as an idiom to say "fall back to pretend merge cleanly succeeded but did not affect the tree" in a script that automate rebuilding tentative integration branch to test, or something. They can "fix" their "idiom" to append instead of prepend "-s ours", and that would arguably make the resulting command line more intuitive and easier to understand, but the fact that whatever that was working for them to their liking suddenly changes the behaviour is a regression we have to ask them to accept.

I do not mind writing something like this

"git merge" with multiple strategies chooses to leave the least number of conflicted paths as the result. Among multiple strategies that give the same number of conflicted paths, it used to use the last such strategy with the smallest number of conflicted paths. The command now prefers the first such strategy instead.

If you have been using "git merge -s ours -s another X" as a way to say "we prefer 'another' strategy to merge, but use 'ours' strategy to make progress if it does not", you now have to swap the order of strategies you list on the command line.

in the "Backward Incompatibility Notes" section of the release notes.

Thanks.

#6 lore raw

Re: [PATCH 2/2] merge: avoid searching for strategies with fewer than 0 conflicts

Quoted 17 lines · Junio C Hamano
Quoted 6 lines · Elijah Newren via GitGitGadget

From: Elijah Newren <[email protected]>

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.

Quoted 7 lines

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.

Quoted 6 lines

Let's imagine "git merge -s ours -s ort X", both of which resolve the merge cleanly but differently.

The "best_cnt" thing tries to find the last strategy with the lowest score from evaluate_result(), so strictly speaking I think this changes the behaviour. Am I mistaken?

Yes, you are.

Though, to be fair, my commit message is wrong too.

I'll explain below...

Quoted 7 lines

When two strategies 'ours' and 'ort' resolved a given merge cleanly (but differently), we would have taken the result from 'ort' in the original code, but now we stop at seeing that 'ours' resolved the merge cleanly and use its result.

Quoted 2 lines
                      cnt = (use_strategies_nr > 1) ? evaluate_result() : 0;
                      if (best_cnt <= 0 || cnt <= best_cnt) {

No, the original code would not have taken 'ort'. You have overlooked the part of the code immediately above these two lines:

    if (ret < 2) {
        if (!ret) {
            if (option_commit) {
                /* Automerge succeeded. */
                automerge_was_ok = 1;
                break;
            }
        merge_was_ok = 1;
        }

In particular, the "break" is key. If the first strategy succeeds (and the user did not specify --no-commit), then the loop will hit that break statement and bail out of the loop, preventing any other merge strategy from being tried. In contrast, if the user did specify --no-commit and the previous strategy succeeded, then we will continue the loop. That seems rather inconsistent, since --no-commit should not affect the choice of strategy.

However, I missed two things in my reading. You are correct that I missed the "<=" as opposed to "<" when I wrote my commit message, though that turns out to not matter much due to the second thing. The second thing I missed was part of the code at the beginning of the loop:

    for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) {

In particular, that "!merge_was_ok" check means that the code would bail early whenever ret was 0, regardless of whether --no-commit was passed. So, my code turns out to not only leave behavior alone, but also doesn't count as an optimization either -- it's simply a half-baked cleanup. If I also get rid of the now-redundant "!merge_was_ok" check in the for loop and fix my commit message, then I think it'd be a fully-baked code cleanup.

I'll submit an update.

#7 lore raw

Re: [PATCH 2/2] merge: avoid searching for strategies with fewer than 0 conflicts

Quoted 13 lines · Elijah Newren

No, the original code would not have taken 'ort'. You have overlooked the part of the code immediately above these two lines:

    if (ret < 2) {
        if (!ret) {
            if (option_commit) {
                /* Automerge succeeded. */
                automerge_was_ok = 1;
                break;
            }
        merge_was_ok = 1;
        }
Quoted 1 line

In particular, the "break" is key.

I noticed that much but then would "git merge --no-commit -s A -s B" have the issue?

Quoted 4 lines

... In contrast, if the user did specify
--no-commit and the previous strategy succeeded, then we will continue the loop. That seems rather inconsistent, since --no-commit should not affect the choice of strategy.

Yeah, exactly.

Quoted 7 lines

However, I missed two things in my reading. You are correct that I missed the "<=" as opposed to "<" when I wrote my commit message, though that turns out to not matter much due to the second thing. The second thing I missed was part of the code at the beginning of the loop:

    for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) {

Ahhhh, that explains it. We leave as soon as we find merge_was_ok so this patch is not necessary. There is nothing to fix. The original was fine as-is.

Thanks.

#8 lore raw

Re: [PATCH 2/2] merge: avoid searching for strategies with fewer than 0 conflicts

Quoted 3 lines · Junio C Hamano

Elijah Newren <[email protected]> writes:

[...]

Quoted 13 lines
Quoted 4 lines

... In contrast, if the user did specify
--no-commit and the previous strategy succeeded, then we will continue the loop. That seems rather inconsistent, since --no-commit should not affect the choice of strategy.

Yeah, exactly.

Quoted 6 lines

However, I missed two things in my reading. You are correct that I missed the "<=" as opposed to "<" when I wrote my commit message, though that turns out to not matter much due to the second thing. The second thing I missed was part of the code at the beginning of the loop:

Quoted 5 lines
Quoted 1 line
    for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) {

Ahhhh, that explains it. We leave as soon as we find merge_was_ok so this patch is not necessary. There is nothing to fix. The original was fine as-is.

Right, there was no bug or even optimization opportunity in the original, it was just confusing...as evidenced by the fact that we both misread the code.

The fact that we both misread the code, though, suggests there is something to fix: code readability.

#9 lore raw

v2 cover Miscellaneous merge fixes

In reply to Elijah Newren via GitGitGadget

While working on other things, I noticed a few miscellaneous issues in builtin/merge.c. Here's a few small fixes to address them.

Elijah Newren (3):
merge: only apply autostash when appropriate
merge: cleanup confusing logic for handling successful merges
merge: small code readability improvement

 builtin/merge.c  | 25 +++++++++++++++----------
 t/t7600-merge.sh |  9 +++++++++
 2 files changed, 24 insertions(+), 10 deletions(-)

base-commit: 9bf691b78cf906751e65d65ba0c6ffdcd9a5a12c
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1331%2Fnewren%2Fmisc-merge-fixes-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1331/newren/misc-merge-fixes-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/1331

Range-diff vs v1:

1: 92840bf6378 ! 1: 610b8d089db merge: only apply autostash when appropriate

     @@ t/t7600-merge.sh: 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' '
     ++test_expect_success 'merge --squash --autostash conflict does not attempt to apply autostash' '
      +	git reset --hard c3 &&
      +	>unrelated &&
      +	git add unrelated &&

2: 5657a05e763 ! 2: 9817d4b19bc merge: avoid searching for strategies with fewer than 0 conflicts
@@ Metadata
Author: Elijah Newren <[email protected]>

## Commit message ##
- merge: avoid searching for strategies with fewer than 0 conflicts
+ merge: cleanup confusing logic for handling successful merges

- 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.
+ 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.
+ would continue. That seems weird; --no-commit should not affect the
+ choice of merge strategy, but the code as written makes one think it
+ does. However, since the loop itself embeds "!merge_was_ok" as a
+ condition on continuing to loop, it actually would also exit early if
+ --no-commit was specified, it just exited from a different location.

- 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.
+ Restructure the code slightly to make it clear that the loop will
+ immediately exit whenever we find a merge strategy that is successful.

## builtin/merge.c ##
+@@ builtin/merge.c: int cmd_merge(int argc, const char **argv, const char *prefix)
+ if (save_state(&stash))
+ oidclr(&stash);
+
+- for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) {
++ for (i = 0; i < use_strategies_nr; i++) {
+ int ret, cnt;
+ if (i) {
+ printf(_("Rewinding the tree to pristine...\n"));
@@ builtin/merge.c: 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;
+- /* 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;
+ merge_was_ok = 1;
++ best_strategy = use_strategies[i]->name;
+ break;
}
cnt = (use_strategies_nr > 1) ? evaluate_result() : 0; if (best_cnt <= 0 || cnt <= best_cnt) {
+@@ builtin/merge.c: int cmd_merge(int argc, const char **argv, const char *prefix)
+ * If we have a resulting tree, that means the strategy module
+ * auto resolved the merge cleanly.
+ */
+- if (automerge_was_ok) {
++ if (merge_was_ok && option_commit) {
++ automerge_was_ok = 1;
+ ret = finish_automerge(head_commit, head_subsumed,
+ common, remoteheads,
+ &result_tree, wt_strategy);
-: ----------- > 3: 88173eba0b9 merge: small code readability improvement

Signature · 1 line
gitgitgadget
#10 lore raw

PATCH v2 1/3 merge: only apply autostash when appropriate

From: Elijah Newren <[email protected]>

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.

---
 builtin/merge.c  | 5 ++++-
 t/t7600-merge.sh | 9 +++++++++
 2 files changed, 13 insertions(+), 1 deletion(-)
builtin/merge.c +4 -1
index f7c92c0e64f..b4253710d19 100644
@@ -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) {
t/t7600-merge.sh +9 -0
index f0f6fda150b..7c3f6ed9943 100755
@@ -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 apply 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 &&
Signature · 1 line
gitgitgadget
#11 lore raw

PATCH v2 2/3 merge: cleanup confusing logic for handling successful merges

In reply to Elijah Newren via GitGitGadget

From: Elijah Newren <[email protected]>

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. That seems weird; --no-commit should not affect the choice of merge strategy, but the code as written makes one think it does. However, since the loop itself embeds "!merge_was_ok" as a condition on continuing to loop, it actually would also exit early if --no-commit was specified, it just exited from a different location.

Restructure the code slightly to make it clear that the loop will immediately exit whenever we find a merge strategy that is successful.

---
 builtin/merge.c | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)
builtin/merge.c +9 -7
index b4253710d19..abf0567b20f 100644
@@ -1693,7 +1693,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	if (save_state(&stash))
 		oidclr(&stash);
 
-	for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) {
+	for (i = 0; i < use_strategies_nr; i++) {
 		int ret, cnt;
 		if (i) {
 			printf(_("Rewinding the tree to pristine...\n"));
@@ -1718,12 +1718,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		 */
 		if (ret < 2) {
 			if (!ret) {
-				if (option_commit) {
-					/* Automerge succeeded. */
-					automerge_was_ok = 1;
-					break;
-				}
+				/*
+				 * This strategy worked; no point in trying
+				 * another.
+				 */
 				merge_was_ok = 1;
+				best_strategy = use_strategies[i]->name;
+				break;
 			}
 			cnt = (use_strategies_nr > 1) ? evaluate_result() : 0;
 			if (best_cnt <= 0 || cnt <= best_cnt) {
@@ -1737,7 +1738,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 	 * If we have a resulting tree, that means the strategy module
 	 * auto resolved the merge cleanly.
 	 */
-	if (automerge_was_ok) {
+	if (merge_was_ok && option_commit) {
+		automerge_was_ok = 1;
 		ret = finish_automerge(head_commit, head_subsumed,
 				       common, remoteheads,
 				       &result_tree, wt_strategy);
Signature · 1 line
gitgitgadget
#12 lore raw

PATCH v2 3/3 merge: small code readability improvement

In reply to Elijah Newren via GitGitGadget

From: Elijah Newren <[email protected]>

After our loop through the selected strategies, we compare best_strategy to wt_strategy. This is fine, but the fact that the code setting best_strategy sets it to use_strategies[i]->name requires a little bit of extra checking to determine that at the time of setting, that's the same as wt_strategy. Just setting best_strategy to wt_strategy makes it a little easier to verify what the loop is doing, at least for this reader.

Further, use_strategies[i]->name is used in a number of places, where we could just use wt_strategy. The latter takes less time for this reader to parse (one variable name instead of three), so just use wt_strategy to make the code slightly faster for human readers to parse.

---
 builtin/merge.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
builtin/merge.c +3 -3
index abf0567b20f..5900b81729d 100644
@@ -1708,7 +1708,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 		 */
 		wt_strategy = use_strategies[i]->name;
 
-		ret = try_merge_strategy(use_strategies[i]->name,
+		ret = try_merge_strategy(wt_strategy,
 					 common, remoteheads,
 					 head_commit);
 		/*
@@ -1723,12 +1723,12 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
 				 * another.
 				 */
 				merge_was_ok = 1;
-				best_strategy = use_strategies[i]->name;
+				best_strategy = wt_strategy;
 				break;
 			}
 			cnt = (use_strategies_nr > 1) ? evaluate_result() : 0;
 			if (best_cnt <= 0 || cnt <= best_cnt) {
-				best_strategy = use_strategies[i]->name;
+				best_strategy = wt_strategy;
 				best_cnt = cnt;
 			}
 		}
Signature · 1 line
gitgitgadget
#13 lore raw
In reply to Elijah Newren via GitGitGadget
Quoted 3 lines · Elijah Newren via GitGitGadget

While working on other things, I noticed a few miscellaneous issues in builtin/merge.c. Here's a few small fixes to address them.

Sorry, forgot to include a high level summary:

Changes since v1:
* Fix play/apply typo, spotted by Eric
* Almost completely rewrote patch 2; it's now merely a "code cleanup"
* Added a third patch, just a very minor code simplification

#14 lore raw
Quoted 6 lines · Elijah Newren
Quoted 3 lines · Elijah Newren via GitGitGadget

While working on other things, I noticed a few miscellaneous issues in builtin/merge.c. Here's a few small fixes to address them.

Quoted 6 lines

Sorry, forgot to include a high level summary:

Changes since v1:
* Fix play/apply typo, spotted by Eric
* Almost completely rewrote patch 2; it's now merely a "code cleanup"
* Added a third patch, just a very minor code simplification

I was skeptical about patch 2 before I saw it, but removal of !merge_was_ok in the loop condition alone is very well worth it.

As to patch 3, I do not think it makes huge difference either way, but I've queued it anyway.

Thanks.