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

[PATCH 08/17] merge-ort: implement handle_directory_level_conflicts()

From
Elijah Newren <newren@gmail.com>
Date
Jan 4, 2021, 23:49 UTC
Message-ID
<20210104235006.2867404-9-newren@gmail.com>
In-Reply-To
<20210104235006.2867404-1-newren@gmail.com>
This is modelled on the version of handle_directory_level_conflicts()
from merge-recursive.c, but is massively simplified due to the following
factors:
  * strmap API provides simplifications over using direct hashamp
  * we have a dirs_removed field in struct rename_info that we have an
    easy way to populate from collect_merge_info(); this was already
    used in compute_rename_counts() and thus we do not need to check
    for condition #2.
  * The removal of condition #2 by handling it earlier in the code also
    obviates the need to check for condition #3 -- if both sides renamed
    a directory, meaning that the directory no longer exists on either
    side, then neither side could have added any new files to that
    directory, and thus there are no files whose locations we need to
    move due to such a directory rename.

In fact, the same logic that makes condition #3 irrelevant means condition #1 is also irrelevant so we could drop this function. However, it is cheap to check if both sides rename the same directory, and doing so can save future computation. So, simply remove any directories that both sides renamed from the list of directory renames.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-ort.c | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
diff --git a/merge-ort.c b/merge-ort.c
index 05bac9c5bd..c4f437d4c0 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -1359,7 +1359,23 @@ static void get_provisional_directory_renames(struct merge_options *opt,
 
 static void handle_directory_level_conflicts(struct merge_options *opt)
 {
-	die("Not yet implemented!");
+	struct hashmap_iter iter;
+	struct strmap_entry *entry;
+	struct string_list duplicated = STRING_LIST_INIT_NODUP;
+	struct strmap *side1_dir_renames = &opt->priv->renames.dir_renames[1];
+	struct strmap *side2_dir_renames = &opt->priv->renames.dir_renames[2];
+	int i;
+
+	strmap_for_each_entry(side1_dir_renames, &iter, entry) {
+		if (strmap_contains(side2_dir_renames, entry->key))
+			string_list_append(&duplicated, entry->key);
+	}
+
+	for (i=0; i<duplicated.nr; ++i) {
+		strmap_remove(side1_dir_renames, duplicated.items[i].string, 0);
+		strmap_remove(side2_dir_renames, duplicated.items[i].string, 0);
+	}
+	string_list_clear(&duplicated, 0);
 }
 
 /*** Function Grouping: functions related to regular rename detection ***/
-- 
2.29.1.106.g3ff750dc32.dirty
Previous: Elijah NewrenNext: Elijah Newren
Message 2 of 18 in “Add directory rename detection to merge-ort”
  1. 00/17 Add directory rename detection to merge-ortElijah Newren, Jan 4, 2021
  2. 08/17 merge-ort: implement handle_directory_level_conflicts()Elijah Newren, Jan 4, 2021
  3. 02/17 merge-ort: initialize and free new directory rename data structuresElijah Newren, Jan 4, 2021
  4. 10/17 merge-ort: implement compute_collisions()Elijah Newren, Jan 4, 2021
  5. 01/17 merge-ort: add new data structures for directory rename detectionElijah Newren, Jan 4, 2021
  6. 12/17 merge-ort: implement check_for_directory_rename()Elijah Newren, Jan 4, 2021
  7. 03/17 merge-ort: collect which directories are removed in dirs_removedElijah Newren, Jan 4, 2021
  8. 04/17 merge-ort: add outline for computing directory renamesElijah Newren, Jan 4, 2021
  9. 06/17 merge-ort: copy get_renamed_dir_portion() from merge-recursive.cElijah Newren, Jan 4, 2021
  10. 14/17 merge-ort: add a new toplevel_dir fieldElijah Newren, Jan 4, 2021
  11. 05/17 merge-ort: add outline of get_provisional_directory_renames()Elijah Newren, Jan 4, 2021
  12. 09/17 merge-ort: modify collect_renames() for directory rename handlingElijah Newren, Jan 4, 2021
  13. 07/17 merge-ort: implement compute_rename_counts()Elijah Newren, Jan 4, 2021
  14. 15/17 merge-ort: implement apply_directory_rename_modifications()Elijah Newren, Jan 4, 2021
  15. 17/17 merge-ort: fix a directory rename detection bugElijah Newren, Jan 4, 2021
  16. 11/17 merge-ort: implement apply_dir_rename() and check_dir_renamed()Elijah Newren, Jan 4, 2021
  17. 13/17 merge-ort: implement handle_path_level_conflicts()Elijah Newren, Jan 4, 2021
  18. 16/17 merge-ort: process_renames() now needs more defensivenessElijah Newren, Jan 4, 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.