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

[PATCH 05/17] merge-ort: add outline of get_provisional_directory_renames()

From
Elijah Newren <newren@gmail.com>
Date
Jan 4, 2021, 23:49 UTC
Message-ID
<20210104235006.2867404-6-newren@gmail.com>
In-Reply-To
<20210104235006.2867404-1-newren@gmail.com>

This function is based on merge-recursive.c's get_directory_renames(), except that the first half has been split out into a not-yet-implemented compute_rename_counts(). The primary difference here is our lack of the non_unique_new_dir boolean in our strmap. The lack of that field will at first cause us to fail testcase 2b of t6423; however, future optimizations will obviate the need for that ugly field so we have just left it out.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-ort.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 59 insertions(+), 1 deletion(-)
diff --git a/merge-ort.c b/merge-ort.c
index 0bd0ab1e8b..6ccc7a1a45 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -1139,11 +1139,69 @@ static int handle_content_merge(struct merge_options *opt,
 
 /*** Function Grouping: functions related to directory rename detection ***/
 
+static void compute_rename_counts(struct diff_queue_struct *pairs,
+				  struct strmap *dir_rename_count,
+				  struct strset *dirs_removed)
+{
+	die("Not yet implemented!");
+}
+
 static void get_provisional_directory_renames(struct merge_options *opt,
 					      unsigned side,
 					      int *clean)
 {
-	die("Not yet implemented!");
+	struct hashmap_iter iter;
+	struct strmap_entry *entry;
+	struct rename_info *renames = &opt->priv->renames;
+
+	compute_rename_counts(&renames->pairs[side],
+			      &renames->dir_rename_count[side],
+			      &renames->dirs_removed[side]);
+	/*
+	 * Collapse
+	 *    dir_rename_count: old_directory -> {new_directory -> count}
+	 * down to
+	 *    dir_renames: old_directory -> best_new_directory
+	 * where best_new_directory is the one with the unique highest count.
+	 */
+	strmap_for_each_entry(&renames->dir_rename_count[side], &iter, entry) {
+		const char *source_dir = entry->key;
+		struct strintmap *counts = entry->value;
+		struct hashmap_iter count_iter;
+		struct strmap_entry *count_entry;
+		int max = 0;
+		int bad_max = 0;
+		const char *best = NULL;
+
+		strintmap_for_each_entry(counts, &count_iter, count_entry) {
+			const char *target_dir = count_entry->key;
+			intptr_t count = (intptr_t)count_entry->value;
+
+			if (count == max)
+				bad_max = max;
+			else if (count > max) {
+				max = count;
+				best = target_dir;
+			}
+		}
+
+		if (max == 0)
+			continue;
+
+		if (bad_max == max) {
+			path_msg(opt, source_dir, 0,
+			       _("CONFLICT (directory rename split): "
+				 "Unclear where to rename %s to; it was "
+				 "renamed to multiple other directories, with "
+				 "no destination getting a majority of the "
+				 "files."),
+			       source_dir);
+			*clean &= 0;
+		} else {
+			strmap_put(&renames->dir_renames[side],
+				   source_dir, (void*)best);
+		}
+	}
 }
 
 static void handle_directory_level_conflicts(struct merge_options *opt)
-- 
2.29.1.106.g3ff750dc32.dirty
Previous: Elijah NewrenNext: Elijah Newren
Message 11 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.