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

[PATCH 6/8] diffcore-rename: add computation of number of unknown renames

From
Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Date
Mar 13, 2021, 22:22 UTC
Message-ID
<b62e26fb1213b69a2008d4ec2c2cb862329ee0b9.1615674128.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.853.git.1615674128.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>

The previous commit can only be effective if we have a computation of the number of paths under a given directory which are still have pending renames, and expected this number to be recorded in the dir_rename_count map under the key UNKNOWN_DIR. Add the code necessary to compute these values.

Note that this change means dir_rename_count might have a directory whose only entry (for UNKNOWN_DIR) was removed by the time merge-ort goes to check it. To account for this, merge-ort needs to check for the case where the max count is 0.

With this change we are now computing the necessary value for each directory in dirs_removed, but are not using that value anywhere. The next two commits will make use of the values stored in dirs_removed in order to compute whether each relevant_source (that is needed only for directory rename detection) has become unnecessary.

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 diffcore-rename.c | 41 +++++++++++++++++++++++++++++++++++++----
 merge-ort.c       |  3 +++
 2 files changed, 40 insertions(+), 4 deletions(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index 8fa29076e0aa..9844cd48788e 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -699,7 +699,8 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
 	/*
 	 * Although dir_rename_count was passed in
 	 * diffcore_rename_extended() and we want to keep it around and
-	 * return it to that caller, we first want to remove any data
+	 * return it to that caller, we first want to remove any counts in
+	 * the maps associated with UNKNOWN_DIR entries and any data
 	 * associated with directories that weren't renamed.
 	 */
 	strmap_for_each_entry(info->dir_rename_count, &iter, entry) {
@@ -711,6 +712,9 @@ static void cleanup_dir_rename_info(struct dir_rename_info *info,
 			strintmap_clear(counts);
 			continue;
 		}
+
+		if (strintmap_contains(counts, UNKNOWN_DIR))
+			strintmap_remove(counts, UNKNOWN_DIR);
 	}
 	for (i = 0; i < to_remove.nr; ++i)
 		strmap_remove(info->dir_rename_count,
@@ -1125,6 +1129,7 @@ static void handle_early_known_dir_renames(struct dir_rename_info *info,
 	 * a majority.
 	 */
 
+	int i;
 	struct hashmap_iter iter;
 	struct strmap_entry *entry;
 
@@ -1134,10 +1139,38 @@ static void handle_early_known_dir_renames(struct dir_rename_info *info,
 		return; /* culling incompatbile with break detection */
 
 	/*
-	 * FIXME: Supplement dir_rename_count with number of potential
-	 * renames, marking all potential rename sources as mapping to
-	 * UNKNOWN_DIR.
+	 * Supplement dir_rename_count with number of potential renames,
+	 * marking all potential rename sources as mapping to UNKNOWN_DIR.
 	 */
+	for (i = 0; i < rename_src_nr; i++) {
+		char *old_dir;
+		struct diff_filespec *one = rename_src[i].p->one;
+
+		/*
+		 * sources that are part of a rename will have already been
+		 * removed by a prior call to remove_unneeded_paths_from_src()
+		 */
+		assert(!one->rename_used);
+
+		old_dir = get_dirname(one->path);
+		while (*old_dir != '\0' &&
+		       NOT_RELEVANT != strintmap_get(dirs_removed, old_dir)) {
+			char *freeme = old_dir;
+
+			increment_count(info, old_dir, UNKNOWN_DIR);
+			old_dir = get_dirname(old_dir);
+
+			/* Free resources we don't need anymore */
+			free(freeme);
+		}
+		/*
+		 * old_dir and new_dir free'd in increment_count, but
+		 * get_dirname() gives us a new pointer we need to free for
+		 * old_dir.  Also, if the loop runs 0 times we need old_dir
+		 * to be freed.
+		 */
+		free(old_dir);
+	}
 
 	/*
 	 * For any directory which we need a potential rename detected for
diff --git a/merge-ort.c b/merge-ort.c
index e2606c73ad88..f2b259986e22 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -1546,6 +1546,9 @@ static void get_provisional_directory_renames(struct merge_options *opt,
 			}
 		}
 
+		if (max == 0)
+			continue;
+
 		if (bad_max == max) {
 			path_msg(opt, source_dir, 0,
 			       _("CONFLICT (directory rename split): "
-- 
gitgitgadget
Previous: Elijah Newren via GitGitGadgetNext: Elijah Newren via GitGitGadget
Message 2 of 14 in “Optimization batch 10: avoid detecting even more irrelevant renames”
  1. 0/8 Optimization batch 10: avoid detecting even more irrelevant renamesElijah Newren via GitGitGadget, Mar 13, 2021
  2. 6/8 diffcore-rename: add computation of number of unknown renamesElijah Newren via GitGitGadget, Mar 13, 2021
  3. 4/8 diffcore-rename: only compute dir_rename_count for relevant directoriesElijah Newren via GitGitGadget, Mar 13, 2021
  4. 1/8 diffcore-rename: take advantage of "majority rules" to skip more renamesElijah Newren via GitGitGadget, Mar 13, 2021
  5. 5/8 diffcore-rename: check if we have enough renames for directories early onElijah Newren via GitGitGadget, Mar 13, 2021
  6. 2/8 merge-ort, diffcore-rename: tweak dirs_removed and relevant_source typeElijah Newren via GitGitGadget, Mar 13, 2021
  7. 3/8 merge-ort: record the reason that we want a rename for a directoryElijah Newren via GitGitGadget, Mar 13, 2021
  8. Derrick StoleeMar 15, 2021
  9. Elijah NewrenMar 15, 2021
  10. Junio C HamanoMar 28, 2021
  11. 8/8 diffcore-rename: determine which relevant_sources are no longer relevantElijah Newren via GitGitGadget, Mar 13, 2021
  12. 7/8 merge-ort: record the reason that we want a rename for a fileElijah Newren via GitGitGadget, Mar 13, 2021
  13. Derrick StoleeMar 15, 2021
  14. Elijah NewrenMar 15, 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.