git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: "Elijah Newren" <newren@gmail.com>,
	"Jonathan Tan" <jonathantanmy@google.com>,
	"Calvin Wan" <calvinwan@google.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Elijah Newren" <newren@gmail.com>,
	"Elijah Newren" <newren@gmail.com>
Subject: [PATCH v3 5/5] merge-ort: fix issue with dual rename and add/add conflict
Date: Fri, 01 Jul 2022 05:23:20 +0000	[thread overview]
Message-ID: <121761e26e2468d77910a7bee2e1f18776995c68.1656653000.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1268.v3.git.1656653000.gitgitgadget@gmail.com>

From: Elijah Newren <newren@gmail.com>

There is code in both merge-recursive and merge-ort for avoiding doubly
transitive renames (i.e. one side renames directory A/ -> B/, and the
other side renames directory B/ -> C/), because this combination would
otherwise make a mess for new files added to A/ on the first side and
wondering which directory they end up in -- especially if there were
even more renames such as the first side renaming C/ -> D/.  In such
cases, it just turns "off" directory rename detection for the higher
order transitive cases.

The testcases added in t6423 a couple commits ago are slightly different
but similar in principle.  They involve a similar case of paired
renaming but instead of A/ -> B/ and B/ -> C/, the second side renames
a leading directory of B/ to C/.  And both sides add a new file
somewhere under the directory that the other side will rename.  While
the new files added start within different directories and thus could
logically end up within different directories, it is weird for a file
on one side to end up where the other one started and not move along
with it.  So, let's just turn off directory rename detection in this
case as well.

Another way to look at this is that if the source name involved in a
directory rename on one side is the target name of a directory rename
operation for a file from the other side, then we avoid the doubly
transitive rename.  (More concretely, if a directory rename on side D
wants to rename a file on side E from OLD_NAME -> NEW_NAME, and side D
already had a file named NEW_NAME, and a directory rename on side E
wants to rename side D's NEW_NAME -> NEWER_NAME, then we turn off the
directory rename detection for NEW_NAME to prevent the
NEW_NAME -> NEWER_NAME rename, and instead end up with an add/add
conflict on NEW_NAME.)

Signed-off-by: Elijah Newren <newren@gmail.com>
---
 merge-ort.c                         | 8 +++++++-
 t/t6423-merge-rename-directories.sh | 4 ++--
 2 files changed, 9 insertions(+), 3 deletions(-)

diff --git a/merge-ort.c b/merge-ort.c
index b496f0e3803..daa0e4496f8 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -2292,10 +2292,16 @@ static char *check_for_directory_rename(struct merge_options *opt,
 	struct strmap_entry *rename_info;
 	struct strmap_entry *otherinfo;
 	const char *new_dir;
+	int other_side = 3 - side_index;
 
-	/* Cases where we don't have a directory rename for this path */
+	/*
+	 * Cases where we don't have or don't want a directory rename for
+	 * this path.
+	 */
 	if (strmap_empty(dir_renames))
 		return NULL;
+	if (strmap_get(&collisions[other_side], path))
+		return NULL;
 	rename_info = check_dir_renamed(path, dir_renames);
 	if (!rename_info)
 		return NULL;
diff --git a/t/t6423-merge-rename-directories.sh b/t/t6423-merge-rename-directories.sh
index ed5586de28c..99baf77cbfd 100755
--- a/t/t6423-merge-rename-directories.sh
+++ b/t/t6423-merge-rename-directories.sh
@@ -5250,7 +5250,7 @@ test_setup_12l () {
 	)
 }
 
-test_expect_merge_algorithm failure failure '12l (B into A): Rename into each other + add/add conflict' '
+test_expect_merge_algorithm failure success '12l (B into A): Rename into each other + add/add conflict' '
 	test_setup_12l BintoA &&
 	(
 		cd 12l_BintoA &&
@@ -5277,7 +5277,7 @@ test_expect_merge_algorithm failure failure '12l (B into A): Rename into each ot
 	)
 '
 
-test_expect_merge_algorithm failure failure '12l (A into B): Rename into each other + add/add conflict' '
+test_expect_merge_algorithm failure success '12l (A into B): Rename into each other + add/add conflict' '
 	test_setup_12l AintoB &&
 	(
 		cd 12l_AintoB &&
-- 
gitgitgadget

  parent reply	other threads:[~2022-07-01  5:26 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-22  4:20 [PATCH 0/3] Fix dual rename into each other plus conflicting adds Elijah Newren via GitGitGadget
2022-06-22  4:20 ` [PATCH 1/3] t6423: add tests of dual directory rename plus add/add conflict Elijah Newren via GitGitGadget
2022-06-27 18:20   ` Jonathan Tan
2022-06-30  0:06     ` Elijah Newren
2022-06-30 22:32       ` Jonathan Tan
2022-07-01  2:57         ` Elijah Newren
2022-06-27 22:30   ` Calvin Wan
2022-06-30  0:07     ` Elijah Newren
2022-06-22  4:20 ` [PATCH 2/3] merge-ort: shuffle the computation and cleanup of potential collisions Elijah Newren via GitGitGadget
2022-06-27 18:48   ` Jonathan Tan
2022-06-27 21:04     ` Calvin Wan
2022-06-30  0:05       ` Elijah Newren
2022-06-22  4:20 ` [PATCH 3/3] merge-ort: fix issue with dual rename and add/add conflict Elijah Newren via GitGitGadget
2022-06-27 18:47   ` Jonathan Tan
2022-06-30  0:05     ` Elijah Newren
2022-07-06 17:25       ` Jonathan Tan
2022-06-22  4:36 ` [PATCH 0/3] Fix dual rename into each other plus conflicting adds Elijah Newren
2022-06-30  6:57 ` [PATCH v2 " Elijah Newren via GitGitGadget
2022-06-30  6:57   ` [PATCH v2 1/3] t6423: add tests of dual directory rename plus add/add conflict Elijah Newren via GitGitGadget
2022-06-30 10:21     ` Ævar Arnfjörð Bjarmason
2022-07-01  2:57       ` Elijah Newren
2022-07-01  9:29         ` Ævar Arnfjörð Bjarmason
2022-06-30  6:57   ` [PATCH v2 2/3] merge-ort: shuffle the computation and cleanup of potential collisions Elijah Newren via GitGitGadget
2022-06-30 10:28     ` Ævar Arnfjörð Bjarmason
2022-07-01  3:02       ` Elijah Newren
2022-06-30  6:57   ` [PATCH v2 3/3] merge-ort: fix issue with dual rename and add/add conflict Elijah Newren via GitGitGadget
2022-06-30 10:31     ` Ævar Arnfjörð Bjarmason
2022-07-01  3:03       ` Elijah Newren
2022-07-01  5:23   ` [PATCH v3 0/5] Fix dual rename into each other plus conflicting adds Elijah Newren via GitGitGadget
2022-07-01  5:23     ` [PATCH v3 1/5] t6423: add tests of dual directory rename plus add/add conflict Elijah Newren via GitGitGadget
2022-07-01  5:23     ` [PATCH v3 2/5] merge-ort: small cleanups of check_for_directory_rename Elijah Newren via GitGitGadget
2022-07-01  5:23     ` [PATCH v3 3/5] merge-ort: make a separate function for freeing struct collisions Elijah Newren via GitGitGadget
2022-07-01  5:23     ` [PATCH v3 4/5] merge-ort: shuffle the computation and cleanup of potential collisions Elijah Newren via GitGitGadget
2022-07-01  9:16       ` Ævar Arnfjörð Bjarmason
2022-07-25 12:00         ` C99 "for (int ..." form on "master" (was: [PATCH v3 4/5] merge-ort: shuffle the computation and cleanup of potential collisions) Ævar Arnfjörð Bjarmason
2022-07-26  2:14           ` Elijah Newren
2022-07-26  4:48             ` C99 "for (int ..." form on "master" Junio C Hamano
2022-07-01  5:23     ` Elijah Newren via GitGitGadget [this message]
2022-07-05  1:33     ` [PATCH v4 0/5] Fix dual rename into each other plus conflicting adds Elijah Newren via GitGitGadget
2022-07-05  1:33       ` [PATCH v4 1/5] t6423: add tests of dual directory rename plus add/add conflict Elijah Newren via GitGitGadget
2022-07-05  1:33       ` [PATCH v4 2/5] merge-ort: small cleanups of check_for_directory_rename Elijah Newren via GitGitGadget
2022-07-05  1:33       ` [PATCH v4 3/5] merge-ort: make a separate function for freeing struct collisions Elijah Newren via GitGitGadget
2022-07-05  1:33       ` [PATCH v4 4/5] merge-ort: shuffle the computation and cleanup of potential collisions Elijah Newren via GitGitGadget
2022-07-05  1:33       ` [PATCH v4 5/5] merge-ort: fix issue with dual rename and add/add conflict Elijah Newren via GitGitGadget
2022-07-06 16:52       ` [PATCH v4 0/5] Fix dual rename into each other plus conflicting adds Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=121761e26e2468d77910a7bee2e1f18776995c68.1656653000.git.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=avarab@gmail.com \
    --cc=calvinwan@google.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    --cc=newren@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).