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

[PATCH 10/10] merge-ort: add handling for different types of files at same path

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Dec 18, 2020, 05:51 UTC
Message-ID
<0a5778df2535c12b1ecb1484878e62d37e69d7cb.1608270687.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.815.git.1608270687.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
Add some handling that explicitly considers collisions of the following
types:
  * file/submodule
  * file/symlink
  * submodule/symlink
Leaving them as conflicts at the same path are hard for users to
resolve, so move one or both of them aside so that they each get their
own path.

Note that in the case of recursive handling (i.e. call_depth > 0), we can just use the merge base of the two merge bases as the merge result much like we do with modify/delete conflicts, binary files, conflicting submodule values, and so on.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-ort.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 103 insertions(+), 4 deletions(-)
diff --git a/merge-ort.c b/merge-ort.c
index 203fa987e43..afe721182e2 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -1521,10 +1521,109 @@ static void process_entry(struct merge_options *opt,
 	} else if (ci->filemask >= 6 &&
 		   (S_IFMT & ci->stages[1].mode) !=
 		   (S_IFMT & ci->stages[2].mode)) {
-		/*
-		 * Two different items from (file/submodule/symlink)
-		 */
-		die("Not yet implemented.");
+		/* Two different items from (file/submodule/symlink) */
+		if (opt->priv->call_depth) {
+			/* Just use the version from the merge base */
+			ci->merged.clean = 0;
+			oidcpy(&ci->merged.result.oid, &ci->stages[0].oid);
+			ci->merged.result.mode = ci->stages[0].mode;
+			ci->merged.is_null = (ci->merged.result.mode == 0);
+		} else {
+			/* Handle by renaming one or both to separate paths. */
+			unsigned o_mode = ci->stages[0].mode;
+			unsigned a_mode = ci->stages[1].mode;
+			unsigned b_mode = ci->stages[2].mode;
+			struct conflict_info *new_ci;
+			const char *a_path = NULL, *b_path = NULL;
+			int rename_a = 0, rename_b = 0;
+
+			new_ci = xmalloc(sizeof(*new_ci));
+
+			if (S_ISREG(a_mode))
+				rename_a = 1;
+			else if (S_ISREG(b_mode))
+				rename_b = 1;
+			else {
+				rename_a = 1;
+				rename_b = 1;
+			}
+
+			path_msg(opt, path, 0,
+				 _("CONFLICT (distinct types): %s had different "
+				   "types on each side; renamed %s of them so "
+				   "each can be recorded somewhere."),
+				 path,
+				 (rename_a && rename_b) ? _("both") : _("one"));
+
+			ci->merged.clean = 0;
+			memcpy(new_ci, ci, sizeof(*new_ci));
+
+			/* Put b into new_ci, removing a from stages */
+			new_ci->merged.result.mode = ci->stages[2].mode;
+			oidcpy(&new_ci->merged.result.oid, &ci->stages[2].oid);
+			new_ci->stages[1].mode = 0;
+			oidcpy(&new_ci->stages[1].oid, &null_oid);
+			new_ci->filemask = 5;
+			if ((S_IFMT & b_mode) != (S_IFMT & o_mode)) {
+				new_ci->stages[0].mode = 0;
+				oidcpy(&new_ci->stages[0].oid, &null_oid);
+				new_ci->filemask = 4;
+			}
+
+			/* Leave only a in ci, fixing stages. */
+			ci->merged.result.mode = ci->stages[1].mode;
+			oidcpy(&ci->merged.result.oid, &ci->stages[1].oid);
+			ci->stages[2].mode = 0;
+			oidcpy(&ci->stages[2].oid, &null_oid);
+			ci->filemask = 3;
+			if ((S_IFMT & a_mode) != (S_IFMT & o_mode)) {
+				ci->stages[0].mode = 0;
+				oidcpy(&ci->stages[0].oid, &null_oid);
+				ci->filemask = 2;
+			}
+
+			/* Insert entries into opt->priv_paths */
+			assert(rename_a || rename_b);
+			if (rename_a) {
+				a_path = unique_path(&opt->priv->paths,
+						     path, opt->branch1);
+				strmap_put(&opt->priv->paths, a_path, ci);
+			}
+
+			if (rename_b)
+				b_path = unique_path(&opt->priv->paths,
+						     path, opt->branch2);
+			else
+				b_path = path;
+			strmap_put(&opt->priv->paths, b_path, new_ci);
+
+			if (rename_a && rename_b) {
+				strmap_remove(&opt->priv->paths, path, 0);
+				/*
+				 * We removed path from opt->priv->paths.  path
+				 * will also eventually need to be freed, but
+				 * it may still be used by e.g.  ci->pathnames.
+				 * So, store it in another string-list for now.
+				 */
+				string_list_append(&opt->priv->paths_to_free,
+						   path);
+			}
+
+			/*
+			 * Do special handling for b_path since process_entry()
+			 * won't be called on it specially.
+			 */
+			strmap_put(&opt->priv->conflicted, b_path, new_ci);
+			record_entry_for_tree(dir_metadata, b_path,
+					      &new_ci->merged);
+
+			/*
+			 * Remaining code for processing this entry should
+			 * think in terms of processing a_path.
+			 */
+			if (a_path)
+				path = a_path;
+		}
 	} else if (ci->filemask >= 6) {
 		/* Need a two-way or three-way content merge */
 		struct version_info merged_file;
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 16 of 37 in “merge-ort: add more handling of basic conflict types”
  1. 00/10 merge-ort: add more handling of basic conflict typesElijah Newren via GitGitGadget, Dec 18, 2020
  2. 01/10 merge-ort: handle D/F conflict where directory disappears due to mergeElijah Newren via GitGitGadget, Dec 18, 2020
  3. Derrick StoleeDec 30, 2020
  4. Elijah NewrenDec 30, 2020
  5. Derrick StoleeDec 31, 2020
  6. Elijah NewrenDec 31, 2020
  7. 03/10 merge-ort: implement unique_path() helperElijah Newren via GitGitGadget, Dec 18, 2020
  8. Derrick StoleeDec 30, 2020
  9. Elijah NewrenDec 30, 2020
  10. Derrick StoleeDec 31, 2020
  11. 04/10 merge-ort: handle book-keeping around two- and three-way content mergeElijah Newren via GitGitGadget, Dec 18, 2020
  12. 02/10 merge-ort: handle directory/file conflicts that remainElijah Newren via GitGitGadget, Dec 18, 2020
  13. 05/10 merge-ort: flesh out implementation of handle_content_merge()Elijah Newren via GitGitGadget, Dec 18, 2020
  14. 07/10 merge-ort: copy and adapt merge_submodule() from merge-recursive.cElijah Newren via GitGitGadget, Dec 18, 2020
  15. 09/10 merge-ort: copy find_first_merges() implementation from merge-recursive.cElijah Newren via GitGitGadget, Dec 18, 2020
  16. 10/10 merge-ort: add handling for different types of files at same pathElijah Newren via GitGitGadget, Dec 18, 2020
  17. 06/10 merge-ort: copy and adapt merge_3way() from merge-recursive.cElijah Newren via GitGitGadget, Dec 18, 2020
  18. 08/10 merge-ort: implement format_commit()Elijah Newren via GitGitGadget, Dec 18, 2020
  19. Elijah NewrenDec 29, 2020
  20. 00/10 merge-ort: add more handling of basic conflict typesElijah Newren via GitGitGadget, Jan 1, 2021
  21. 01/10 merge-ort: handle D/F conflict where directory disappears due to mergeElijah Newren via GitGitGadget, Jan 1, 2021
  22. 05/10 merge-ort: flesh out implementation of handle_content_merge()Elijah Newren via GitGitGadget, Jan 1, 2021
  23. A merge-ort TODO comment, and how to test merge-ort?Ævar Arnfjörð Bjarmason, Mar 4, 2021
  24. Elijah NewrenMar 4, 2021
  25. Ævar Arnfjörð BjarmasonMar 4, 2021
  26. Elijah NewrenMar 4, 2021
  27. Ævar Arnfjörð BjarmasonMar 8, 2021
  28. 03/10 merge-ort: implement unique_path() helperElijah Newren via GitGitGadget, Jan 1, 2021
  29. 04/10 merge-ort: handle book-keeping around two- and three-way content mergeElijah Newren via GitGitGadget, Jan 1, 2021
  30. 07/10 merge-ort: copy and adapt merge_submodule() from merge-recursive.cElijah Newren via GitGitGadget, Jan 1, 2021
  31. 02/10 merge-ort: handle directory/file conflicts that remainElijah Newren via GitGitGadget, Jan 1, 2021
  32. 09/10 merge-ort: copy find_first_merges() implementation from merge-recursive.cElijah Newren via GitGitGadget, Jan 1, 2021
  33. 08/10 merge-ort: implement format_commit()Elijah Newren via GitGitGadget, Jan 1, 2021
  34. 10/10 merge-ort: add handling for different types of files at same pathElijah Newren via GitGitGadget, Jan 1, 2021
  35. 06/10 merge-ort: copy and adapt merge_3way() from merge-recursive.cElijah Newren via GitGitGadget, Jan 1, 2021
  36. Derrick StoleeJan 5, 2021
  37. Elijah NewrenJan 6, 2021

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.