From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Elijah Newren via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Jonathan Tan <jonathantanmy@google.com>,
Calvin Wan <calvinwan@google.com>,
Elijah Newren <newren@gmail.com>
Subject: Re: [PATCH v2 3/3] merge-ort: fix issue with dual rename and add/add conflict
Date: Thu, 30 Jun 2022 12:31:52 +0200 [thread overview]
Message-ID: <220630.86letee8mz.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <da3ae38e390df8acf86e910389d1620569a95a87.1656572226.git.gitgitgadget@gmail.com>
On Thu, Jun 30 2022, Elijah Newren via GitGitGadget wrote:
> 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 | 7 +++++++
> t/t6423-merge-rename-directories.sh | 4 ++--
> 2 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/merge-ort.c b/merge-ort.c
> index fa6667de18c..17db4c30e5b 100644
> --- a/merge-ort.c
> +++ b/merge-ort.c
> @@ -2292,9 +2292,16 @@ static char *check_for_directory_rename(struct merge_options *opt,
> struct strmap_entry *rename_info;
> struct strmap_entry *otherinfo = NULL;
> const char *new_dir;
> + int other_side = 3 - side_index;
>
> + /*
> + * Cases where we don't have or don't want a directory rename for
> + * this path, so we return NULL.
> + */
> if (strmap_empty(dir_renames))
> return new_path;
> + if (strmap_get(&collisions[other_side], path))
> + return new_path;
I realize from looking at merge-recursive.c that this is carrying
forward some legacy debt, but I find this code and the need for a
comment more complex than it needs to. On top of master this will work
just as well:
diff --git a/merge-ort.c b/merge-ort.c
index b5015b9afd4..f5a02b1ff6f 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -2268,16 +2268,16 @@ static char *check_for_directory_rename(struct merge_options *opt,
struct strmap *collisions,
int *clean_merge)
{
- char *new_path = NULL;
+ char *new_path;
struct strmap_entry *rename_info;
struct strmap_entry *otherinfo = NULL;
const char *new_dir;
if (strmap_empty(dir_renames))
- return new_path;
+ return NULL;
rename_info = check_dir_renamed(path, dir_renames);
if (!rename_info)
- return new_path;
+ return NULL;
/* old_dir = rename_info->key; */
new_dir = rename_info->value;
I.e. we're really just making the reader squint to see that we're
actually returning NULL here, it's only later that we have an actual
"new path".
Wouldn't sticking that earlier in this series be an improvement? The
reason you need to explain "so we return NULL" is because we're carrying
forward this oddity, but if we just don't initialize it and return NULL
instead...
If you want to keep this pretty much as-is I think you should add a \n
before the (not seen in your context) "old_dir" comment seen in the
context here above, to make it visually clear that your new comment is
referring to these chains of returns. That could also be made clearer
with (again, on top of master, and could be combined with the above):
diff --git a/merge-ort.c b/merge-ort.c
index b5015b9afd4..a418f81a3eb 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -2278,8 +2278,6 @@ static char *check_for_directory_rename(struct merge_options *opt,
rename_info = check_dir_renamed(path, dir_renames);
if (!rename_info)
return new_path;
- /* old_dir = rename_info->key; */
- new_dir = rename_info->value;
/*
* This next part is a little weird. We do not want to do an
@@ -2305,6 +2303,7 @@ static char *check_for_directory_rename(struct merge_options *opt,
* As it turns out, this also prevents N-way transient rename
* confusion; See testcases 9c and 9d of t6043.
*/
+ new_dir = rename_info->value; /* old_dir = rename_info->key; */
otherinfo = strmap_get_entry(dir_rename_exclusions, new_dir);
if (otherinfo) {
path_msg(opt, rename_info->key, 1,
next prev parent reply other threads:[~2022-06-30 10:43 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 [this message]
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 ` [PATCH v3 5/5] merge-ort: fix issue with dual rename and add/add conflict Elijah Newren via GitGitGadget
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=220630.86letee8mz.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=calvinwan@google.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--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.
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 NNTP newsgroup(s).