git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 3/3] merge: small code readability improvement

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Aug 23, 2022, 02:42 UTC
Message-ID
<88173eba0b9cdd861b9c8e3d229decae3b312681.1661222541.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.1331.v2.git.1661222541.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

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.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 builtin/merge.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/builtin/merge.c b/builtin/merge.c
index abf0567b20f..5900b81729d 100644
--- a/builtin/merge.c
+++ b/builtin/merge.c
@@ -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;
 			}
 		}
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren
Message 13 of 15 in “Miscellaneous merge fixes”
  1. 0/2 Miscellaneous merge fixesElijah Newren via GitGitGadget, Aug 21, 2022
  2. 2/2 merge: avoid searching for strategies with fewer than 0 conflictsElijah Newren via GitGitGadget, Aug 21, 2022
  3. Junio C HamanoAug 21, 2022
  4. Elijah NewrenAug 22, 2022
  5. Junio C HamanoAug 22, 2022
  6. Elijah NewrenAug 23, 2022
  7. 1/2 merge: only apply autostash when appropriateElijah Newren via GitGitGadget, Aug 21, 2022
  8. Eric SunshineAug 21, 2022
  9. Elijah NewrenAug 21, 2022
  10. 0/3 Miscellaneous merge fixesElijah Newren via GitGitGadget, Aug 23, 2022
  11. 1/3 merge: only apply autostash when appropriateElijah Newren via GitGitGadget, Aug 23, 2022
  12. 2/3 merge: cleanup confusing logic for handling successful mergesElijah Newren via GitGitGadget, Aug 23, 2022
  13. 3/3 merge: small code readability improvementElijah Newren via GitGitGadget, Aug 23, 2022
  14. Elijah NewrenAug 23, 2022
  15. Junio C HamanoAug 24, 2022

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.