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

[PATCH 2/7] merge-ort: add a clear_internal_opts helper

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 3, 2020, 15:59 UTC
Message-ID
<5d73827b8d6c254f5bc4a99afa421ae34f07182e.1607011187.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.803.git.1607011187.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

Move most of merge_finalize() into a new helper function, clear_internal_opts(). This is a step to facilitate recursive merges, as well as some future optimizations.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-ort.c | 40 ++++++++++++++++++++++++----------------
 1 file changed, 24 insertions(+), 16 deletions(-)
diff --git a/merge-ort.c b/merge-ort.c
index b556897bc0..0654c76c8c 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -194,6 +194,29 @@ static void free_strmap_strings(struct strmap *map)
 	}
 }
 
+static void clear_internal_opts(struct merge_options_internal *opti,
+				int reinitialize)
+{
+	assert(!reinitialize);
+
+	/*
+	 * We marked opti->paths with strdup_strings = 0, so that we
+	 * wouldn't have to make another copy of the fullpath created by
+	 * make_traverse_path from setup_path_info().  But, now that we've
+	 * used it and have no other references to these strings, it is time
+	 * to deallocate them.
+	 */
+	free_strmap_strings(&opti->paths);
+	strmap_clear(&opti->paths, 1);
+
+	/*
+	 * All keys and values in opti->conflicted are a subset of those in
+	 * opti->paths.  We don't want to deallocate anything twice, so we
+	 * don't free the keys and we pass 0 for free_values.
+	 */
+	strmap_clear(&opti->conflicted, 0);
+}
+
 static int err(struct merge_options *opt, const char *err, ...)
 {
 	va_list params;
@@ -1132,22 +1155,7 @@ void merge_finalize(struct merge_options *opt,
 
 	assert(opt->priv == NULL);
 
-	/*
-	 * We marked opti->paths with strdup_strings = 0, so that we
-	 * wouldn't have to make another copy of the fullpath created by
-	 * make_traverse_path from setup_path_info().  But, now that we've
-	 * used it and have no other references to these strings, it is time
-	 * to deallocate them.
-	 */
-	free_strmap_strings(&opti->paths);
-	strmap_clear(&opti->paths, 1);
-
-	/*
-	 * All keys and values in opti->conflicted are a subset of those in
-	 * opti->paths.  We don't want to deallocate anything twice, so we
-	 * don't free the keys and we pass 0 for free_values.
-	 */
-	strmap_clear(&opti->conflicted, 0);
+	clear_internal_opts(opti, 0);
 	FREE_AND_NULL(opti);
 }
 
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Derrick Stolee
Message 3 of 13 in “merge-ort: some groundwork for further implementation”
  1. 0/7 merge-ort: some groundwork for further implementationElijah Newren via GitGitGadget, Dec 3, 2020
  2. 3/7 merge-ort: add a path_conflict field to merge_options_internalElijah Newren via GitGitGadget, Dec 3, 2020
  3. 2/7 merge-ort: add a clear_internal_opts helperElijah Newren via GitGitGadget, Dec 3, 2020
  4. Derrick StoleeDec 3, 2020
  5. 4/7 merge-ort: add a paths_to_free field to merge_options_internalElijah Newren via GitGitGadget, Dec 3, 2020
  6. 5/7 merge-ort: add function grouping commentsElijah Newren via GitGitGadget, Dec 3, 2020
  7. 1/7 merge-ort: add a few includesElijah Newren via GitGitGadget, Dec 3, 2020
  8. 6/7 merge-ort: add die-not-implemented stub handle_content_merge() functionElijah Newren via GitGitGadget, Dec 3, 2020
  9. Derrick StoleeDec 3, 2020
  10. Elijah NewrenDec 3, 2020
  11. 7/7 merge-ort: add modify/delete handling and delayed output processingElijah Newren via GitGitGadget, Dec 3, 2020
  12. Derrick StoleeDec 4, 2020
  13. Elijah NewrenDec 4, 2020

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.