Skip to content

Commit 624a936

Browse files
committed
Merge branch 'en/merge-multi-strategies'
The code that implements multi-strategy support in "git merge" has been clean-up a bit. * en/merge-multi-strategies: merge: small code readability improvement merge: cleanup confusing logic for handling successful merges
2 parents 014a9ea + ae15fd4 commit 624a936

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

builtin/merge.c

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
16931693
if (save_state(&stash))
16941694
oidclr(&stash);
16951695

1696-
for (i = 0; !merge_was_ok && i < use_strategies_nr; i++) {
1696+
for (i = 0; i < use_strategies_nr; i++) {
16971697
int ret, cnt;
16981698
if (i) {
16991699
printf(_("Rewinding the tree to pristine...\n"));
@@ -1708,7 +1708,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
17081708
*/
17091709
wt_strategy = use_strategies[i]->name;
17101710

1711-
ret = try_merge_strategy(use_strategies[i]->name,
1711+
ret = try_merge_strategy(wt_strategy,
17121712
common, remoteheads,
17131713
head_commit);
17141714
/*
@@ -1718,16 +1718,17 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
17181718
*/
17191719
if (ret < 2) {
17201720
if (!ret) {
1721-
if (option_commit) {
1722-
/* Automerge succeeded. */
1723-
automerge_was_ok = 1;
1724-
break;
1725-
}
1721+
/*
1722+
* This strategy worked; no point in trying
1723+
* another.
1724+
*/
17261725
merge_was_ok = 1;
1726+
best_strategy = wt_strategy;
1727+
break;
17271728
}
17281729
cnt = (use_strategies_nr > 1) ? evaluate_result() : 0;
17291730
if (best_cnt <= 0 || cnt <= best_cnt) {
1730-
best_strategy = use_strategies[i]->name;
1731+
best_strategy = wt_strategy;
17311732
best_cnt = cnt;
17321733
}
17331734
}
@@ -1737,7 +1738,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
17371738
* If we have a resulting tree, that means the strategy module
17381739
* auto resolved the merge cleanly.
17391740
*/
1740-
if (automerge_was_ok) {
1741+
if (merge_was_ok && option_commit) {
1742+
automerge_was_ok = 1;
17411743
ret = finish_automerge(head_commit, head_subsumed,
17421744
common, remoteheads,
17431745
&result_tree, wt_strategy);

0 commit comments

Comments
 (0)