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

[PATCH v6 3/5] [RFC] Handle the simpler case of a subdir invalidating bulk move.

From
Yann Dirson <ydirson@altern.org>
Date
Oct 14, 2010, 23:29 UTC
Message-ID
<1287098999-9244-4-git-send-email-ydirson@altern.org>
In-Reply-To
<1287098999-9244-3-git-send-email-ydirson@altern.org>

Doing it so simply depends on the subdir moves being noticed later, this fixes only one of the remaining failing testcases. Doing better requires real handling of deep trees, which is addressed by next patch, but add much complexity.

Signed-off-by: Yann Dirson <ydirson@free.fr>
---
 diffcore-rename.c |   59 ++++++++++++++++++++++++++++++++++++++++------------
 1 files changed, 45 insertions(+), 14 deletions(-)
diff --git a/diffcore-rename.c b/diffcore-rename.c
index f252da7..1be1af1 100644
--- a/diffcore-rename.c
+++ b/diffcore-rename.c
@@ -596,10 +596,52 @@ static void check_one_bulk_move(struct diff_filepair *dstpair)
 	    maybe_disqualify_bulkmove(one_parent_path, one_leftover))
 		return;
 
+	fprintf(stderr, "[] %s -> %s ?\n",dstpair->one->path, dstpair->two->path);
+
+	// FIXME: loop over successive prefixes
+	unsigned needs_adding = 1;
+
 	/* already considered ? */
-	for (seen=bulkmove_candidates; seen; seen = seen->next)
-		if (!strcmp(seen->one->path, one_parent_path)) break;
-	if (!seen) { /* record potential dir rename */
+	for (seen=bulkmove_candidates; seen; seen = seen->next) {
+		if (seen->discarded) {
+			/* already seen a rename from seen->one to some than ->two */
+			needs_adding = 0;
+			continue;
+		}
+		/* check exact dir */
+		if (!strcmp(seen->one->path, one_parent_path)) {
+			/* already added */
+			needs_adding = 0;
+			/* check that seen entry matches this rename */
+			if (strcmp(two_parent_path, seen->two->path)) {
+				fprintf(stderr, "[DBG] discarding dir %s from bulk moves (split into %s and %s)\n",
+					seen->one->path, two_parent_path, seen->two->path);
+				// FIXME: may be worth to free it instead
+				seen->discarded = 1;
+			}
+			continue;
+		}
+		if (!prefixcmp(one_parent_path, seen->one->path)) {
+			if (prefixcmp(two_parent_path, seen->two->path)) {
+				fprintf(stderr, "[DBG] discarding dir %s from bulk moves (split into %s and %s)\n",
+					seen->one->path, two_parent_path, seen->two->path);
+				// FIXME: may be worth to free it instead
+				seen->discarded = 1;
+				continue;
+			}
+		} else {
+			fprintf(stderr, "[DBG]  %s considered irrelevant for %s -> %s\n",
+				dstpair->one->path, seen->one->path, seen->two->path);
+			continue;
+		}
+
+		/* dstpair confirms seen */
+		fprintf(stderr, "[DBG] %s -> %s DOES NOT cause discard of %s -> %s\n",
+			dstpair->one->path, dstpair->two->path,
+			seen->one->path, seen->two->path);
+	}
+	if (needs_adding) { /* record potential dir rename */
+		/* all checks ok, we keep that entry */
 		seen = xmalloc(sizeof(*seen));
 		seen->one = alloc_filespec(one_parent_path);
 		fill_filespec(seen->one, null_sha1, S_IFDIR);
@@ -614,17 +656,6 @@ static void check_one_bulk_move(struct diff_filepair *dstpair)
 			one_parent_path, two_parent_path);
 		return;
 	}
-	if (seen->discarded)
-		/* already seen a rename from seen->one to some than ->two */
-		return;
-	/* check that seen entry matches this rename */
-	if (strcmp(two_parent_path, seen->two->path)) {
-		fprintf(stderr, "[DBG] discarding dir %s from bulk moves (split into %s and %s)\n",
-			one_parent_path, two_parent_path, seen->two->path);
-		seen->discarded = 1;
-	}
-
-	/* all checks ok, we keep that entry */
 }
 
 /*
-- 
1.7.2.3
Previous: Yann DirsonNext: Yann Dirson
Message 4 of 17 in “Detection of directory renames”
  1. 0/5 Detection of directory renamesYann Dirson, Oct 14, 2010
  2. 1/5 Introduce bulk-move detection in diffcore.Yann Dirson, Oct 14, 2010
  3. 2/5 Add testcases for the --detect-bulk-moves diffcore flag.Yann Dirson, Oct 14, 2010
  4. 3/5 [RFC] Handle the simpler case of a subdir invalidating bulk move.Yann Dirson, Oct 14, 2010
  5. 4/5 [RFC] Consider all parents of a file as candidates for bulk rename.Yann Dirson, Oct 14, 2010
  6. 5/5 [WIP] Allow hiding renames of individual files involved in a directory rename.Yann Dirson, Oct 14, 2010
  7. [RFC] Consider all parents of a file as candidates for bulk rename.Yann Dirson, Oct 17, 2010
  8. compat: add memrchr()Jonathan Nieder, Oct 15, 2010
  9. Ævar Arnfjörð BjarmasonOct 15, 2010
  10. Jonathan NiederOct 15, 2010
  11. Ævar Arnfjörð BjarmasonOct 15, 2010
  12. Junio C HamanoOct 15, 2010
  13. Johannes SixtOct 15, 2010
  14. Ludvig StrigeusOct 15, 2010
  15. compat: add memrchr()Jonathan Nieder, Oct 15, 2010
  16. Erik Faye-LundOct 15, 2010
  17. Johannes SixtOct 15, 2010

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.