From: "Elijah Newren via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
Elijah Newren <newren@gmail.com>,
Elijah Newren <newren@gmail.com>
Subject: [PATCH 10/18] merge-ort: implement compute_collisions()
Date: Thu, 07 Jan 2021 20:01:19 +0000 [thread overview]
Message-ID: <9a06c698857d4067ea34f9ae9dd610b999b907b8.1610049687.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.835.git.1610049687.gitgitgadget@gmail.com>
From: Elijah Newren <newren@gmail.com>
This is nearly a wholesale copy of compute_collisions() from
merge-recursive.c, and the logic remains the same, but it has been
tweaked slightly due to:
* using strmap.h API (instead of direct hashmaps)
* allocation/freeing of data structures were done separately in
merge_start() and clear_or_reinit_internal_opts() in an earlier
patch in this series
* there is no non_unique_new_dir data field in merge-ort; that will
be handled a different way
It does depend on two new functions, apply_dir_rename() and
check_dir_renamed() which were introduced with simple
die-not-yet-implemented shells and will be implemented in subsequent
patches.
Signed-off-by: Elijah Newren <newren@gmail.com>
---
merge-ort.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 67 insertions(+), 1 deletion(-)
diff --git a/merge-ort.c b/merge-ort.c
index f7ecd76c479..e436418d0d2 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -726,6 +726,19 @@ struct collision_info {
unsigned reported_already:1;
};
+/*
+ * Return a new string that replaces the beginning portion (which matches
+ * rename_info->key), with rename_info->util.new_dir. In perl-speak:
+ * new_path_name = (old_path =~ s/rename_info->key/rename_info->value/);
+ * NOTE:
+ * Caller must ensure that old_path starts with rename_info->key + '/'.
+ */
+static char *apply_dir_rename(struct strmap_entry *rename_info,
+ const char *old_path)
+{
+ die("Not yet implemented!");
+}
+
static void get_renamed_dir_portion(const char *old_path, const char *new_path,
char **old_dir, char **new_dir)
{
@@ -965,11 +978,64 @@ static void handle_directory_level_conflicts(struct merge_options *opt)
string_list_clear(&duplicated, 0);
}
+static struct strmap_entry *check_dir_renamed(const char *path,
+ struct strmap *dir_renames)
+{
+ die("Not yet implemented!");
+}
+
static void compute_collisions(struct strmap *collisions,
struct strmap *dir_renames,
struct diff_queue_struct *pairs)
{
- die("Not yet implemented.");
+ int i;
+
+ strmap_init_with_options(collisions, NULL, 0);
+ if (strmap_empty(dir_renames))
+ return;
+
+ /*
+ * Multiple files can be mapped to the same path due to directory
+ * renames done by the other side of history. Since that other
+ * side of history could have merged multiple directories into one,
+ * if our side of history added the same file basename to each of
+ * those directories, then all N of them would get implicitly
+ * renamed by the directory rename detection into the same path,
+ * and we'd get an add/add/.../add conflict, and all those adds
+ * from *this* side of history. This is not representable in the
+ * index, and users aren't going to easily be able to make sense of
+ * it. So we need to provide a good warning about what's
+ * happening, and fall back to no-directory-rename detection
+ * behavior for those paths.
+ *
+ * See testcases 9e and all of section 5 from t6043 for examples.
+ */
+ for (i = 0; i < pairs->nr; ++i) {
+ struct strmap_entry *rename_info;
+ struct collision_info *collision_info;
+ char *new_path;
+ struct diff_filepair *pair = pairs->queue[i];
+
+ if (pair->status != 'A' && pair->status != 'R')
+ continue;
+ rename_info = check_dir_renamed(pair->two->path, dir_renames);
+ if (!rename_info)
+ continue;
+
+ new_path = apply_dir_rename(rename_info, pair->two->path);
+ assert(new_path);
+ collision_info = strmap_get(collisions, new_path);
+ if (collision_info) {
+ free(new_path);
+ } else {
+ collision_info = xcalloc(1,
+ sizeof(struct collision_info));
+ string_list_init(&collision_info->source_files, 0);
+ strmap_put(collisions, new_path, collision_info);
+ }
+ string_list_insert(&collision_info->source_files,
+ pair->two->path);
+ }
}
static char *check_for_directory_rename(struct merge_options *opt,
--
gitgitgadget
next prev parent reply other threads:[~2021-01-07 20:02 UTC|newest]
Thread overview: 66+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-01-07 20:01 [PATCH 00/18] Add directory rename detection to merge-ort Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 01/18] merge-ort: add new data structures for directory rename detection Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 02/18] merge-ort: initialize and free new directory rename data structures Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 03/18] merge-ort: collect which directories are removed in dirs_removed Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 04/18] merge-ort: add outline for computing directory renames Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 05/18] merge-ort: add outline of get_provisional_directory_renames() Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 06/18] merge-ort: copy get_renamed_dir_portion() from merge-recursive.c Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 07/18] merge-ort: implement compute_rename_counts() Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 08/18] merge-ort: implement handle_directory_level_conflicts() Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 09/18] merge-ort: modify collect_renames() for directory rename handling Elijah Newren via GitGitGadget
2021-01-07 20:01 ` Elijah Newren via GitGitGadget [this message]
2021-01-07 20:01 ` [PATCH 11/18] merge-ort: implement apply_dir_rename() and check_dir_renamed() Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 12/18] merge-ort: implement check_for_directory_rename() Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 13/18] merge-ort: implement handle_path_level_conflicts() Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 14/18] merge-ort: add a new toplevel_dir field Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 15/18] merge-ort: implement apply_directory_rename_modifications() Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 16/18] merge-ort: process_renames() now needs more defensiveness Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 17/18] merge-ort: fix a directory rename detection bug Elijah Newren via GitGitGadget
2021-01-07 20:01 ` [PATCH 18/18] DO NOT SUBMIT: directory rename stuff for redo_after_renames Elijah Newren via GitGitGadget
2021-01-07 20:02 ` Elijah Newren
2021-01-07 21:35 ` [PATCH v2 00/17] Add directory rename detection to merge-ort Elijah Newren via GitGitGadget
2021-01-07 21:35 ` [PATCH v2 01/17] merge-ort: add new data structures for directory rename detection Elijah Newren via GitGitGadget
2021-01-07 21:35 ` [PATCH v2 02/17] merge-ort: initialize and free new directory rename data structures Elijah Newren via GitGitGadget
2021-01-07 21:35 ` [PATCH v2 03/17] merge-ort: collect which directories are removed in dirs_removed Elijah Newren via GitGitGadget
2021-01-07 21:35 ` [PATCH v2 04/17] merge-ort: add outline for computing directory renames Elijah Newren via GitGitGadget
2021-01-18 19:54 ` Taylor Blau
2021-01-18 20:15 ` Elijah Newren
2021-01-18 20:28 ` Taylor Blau
2021-01-07 21:35 ` [PATCH v2 05/17] merge-ort: add outline of get_provisional_directory_renames() Elijah Newren via GitGitGadget
2021-01-18 20:10 ` Taylor Blau
2021-01-18 20:34 ` Elijah Newren
2021-01-07 21:35 ` [PATCH v2 06/17] merge-ort: copy get_renamed_dir_portion() from merge-recursive.c Elijah Newren via GitGitGadget
2021-01-07 21:35 ` [PATCH v2 07/17] merge-ort: implement compute_rename_counts() Elijah Newren via GitGitGadget
2021-01-18 20:36 ` Taylor Blau
2021-01-18 20:41 ` Elijah Newren
2021-01-07 21:35 ` [PATCH v2 08/17] merge-ort: implement handle_directory_level_conflicts() Elijah Newren via GitGitGadget
2021-01-18 21:00 ` Taylor Blau
2021-01-18 21:36 ` Elijah Newren
2021-01-07 21:35 ` [PATCH v2 09/17] merge-ort: modify collect_renames() for directory rename handling Elijah Newren via GitGitGadget
2021-01-07 21:35 ` [PATCH v2 10/17] merge-ort: implement compute_collisions() Elijah Newren via GitGitGadget
2021-01-07 21:35 ` [PATCH v2 11/17] merge-ort: implement apply_dir_rename() and check_dir_renamed() Elijah Newren via GitGitGadget
2021-01-07 21:36 ` [PATCH v2 12/17] merge-ort: implement check_for_directory_rename() Elijah Newren via GitGitGadget
2021-01-07 21:36 ` [PATCH v2 13/17] merge-ort: implement handle_path_level_conflicts() Elijah Newren via GitGitGadget
2021-01-07 21:36 ` [PATCH v2 14/17] merge-ort: add a new toplevel_dir field Elijah Newren via GitGitGadget
2021-01-07 21:36 ` [PATCH v2 15/17] merge-ort: implement apply_directory_rename_modifications() Elijah Newren via GitGitGadget
2021-01-07 21:36 ` [PATCH v2 16/17] merge-ort: process_renames() now needs more defensiveness Elijah Newren via GitGitGadget
2021-01-07 21:36 ` [PATCH v2 17/17] merge-ort: fix a directory rename detection bug Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 00/17] Add directory rename detection to merge-ort Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 01/17] merge-ort: add new data structures for directory rename detection Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 02/17] merge-ort: initialize and free new directory rename data structures Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 03/17] merge-ort: collect which directories are removed in dirs_removed Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 04/17] merge-ort: add outline for computing directory renames Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 05/17] merge-ort: add outline of get_provisional_directory_renames() Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 06/17] merge-ort: copy get_renamed_dir_portion() from merge-recursive.c Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 07/17] merge-ort: implement compute_rename_counts() Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 08/17] merge-ort: implement handle_directory_level_conflicts() Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 09/17] merge-ort: modify collect_renames() for directory rename handling Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 10/17] merge-ort: implement compute_collisions() Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 11/17] merge-ort: implement apply_dir_rename() and check_dir_renamed() Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 12/17] merge-ort: implement check_for_directory_rename() Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 13/17] merge-ort: implement handle_path_level_conflicts() Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 14/17] merge-ort: add a new toplevel_dir field Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 15/17] merge-ort: implement apply_directory_rename_modifications() Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 16/17] merge-ort: process_renames() now needs more defensiveness Elijah Newren via GitGitGadget
2021-01-19 19:53 ` [PATCH v3 17/17] merge-ort: fix a directory rename detection bug Elijah Newren via GitGitGadget
2021-01-19 22:48 ` [PATCH v3 00/17] Add directory rename detection to merge-ort Taylor Blau
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=9a06c698857d4067ea34f9ae9dd610b999b907b8.1610049687.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).