summaryrefslogtreecommitdiff
path: root/merge-ort.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-01-19 19:53:41 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-01-21 06:18:55 (GMT)
commit04264d4079a4423f32d85d7833d63faa5ace4e33 (patch)
tree600e914836492015d5b7fbd0122397635f0a353c /merge-ort.c
parent112e11126b963923d84f90f12dae9b96271ccedb (diff)
downloadgit-04264d4079a4423f32d85d7833d63faa5ace4e33.zip
git-04264d4079a4423f32d85d7833d63faa5ace4e33.tar.gz
git-04264d4079a4423f32d85d7833d63faa5ace4e33.tar.bz2
merge-ort: add outline of get_provisional_directory_renames()
This function is based on merge-recursive.c's get_directory_renames(), except that the first half has been split out into a not-yet-implemented compute_rename_counts(). The primary difference here is our lack of the non_unique_new_dir boolean in our strmap. The lack of that field will at first cause us to fail testcase 2b of t6423; however, future optimizations will obviate the need for that ugly field so we have just left it out. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-ort.c')
-rw-r--r--merge-ort.c57
1 files changed, 56 insertions, 1 deletions
diff --git a/merge-ort.c b/merge-ort.c
index b4c1fe2..2a1c62c 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -721,11 +721,66 @@ static int handle_content_merge(struct merge_options *opt,
/*** Function Grouping: functions related to directory rename detection ***/
+static void compute_rename_counts(struct diff_queue_struct *pairs,
+ struct strmap *dir_rename_count,
+ struct strset *dirs_removed)
+{
+ die("Not yet implemented!");
+}
+
static void get_provisional_directory_renames(struct merge_options *opt,
unsigned side,
int *clean)
{
- die("Not yet implemented!");
+ struct hashmap_iter iter;
+ struct strmap_entry *entry;
+ struct rename_info *renames = &opt->priv->renames;
+
+ compute_rename_counts(&renames->pairs[side],
+ &renames->dir_rename_count[side],
+ &renames->dirs_removed[side]);
+ /*
+ * Collapse
+ * dir_rename_count: old_directory -> {new_directory -> count}
+ * down to
+ * dir_renames: old_directory -> best_new_directory
+ * where best_new_directory is the one with the unique highest count.
+ */
+ strmap_for_each_entry(&renames->dir_rename_count[side], &iter, entry) {
+ const char *source_dir = entry->key;
+ struct strintmap *counts = entry->value;
+ struct hashmap_iter count_iter;
+ struct strmap_entry *count_entry;
+ int max = 0;
+ int bad_max = 0;
+ const char *best = NULL;
+
+ strintmap_for_each_entry(counts, &count_iter, count_entry) {
+ const char *target_dir = count_entry->key;
+ intptr_t count = (intptr_t)count_entry->value;
+
+ if (count == max)
+ bad_max = max;
+ else if (count > max) {
+ max = count;
+ best = target_dir;
+ }
+ }
+
+ if (bad_max == max) {
+ path_msg(opt, source_dir, 0,
+ _("CONFLICT (directory rename split): "
+ "Unclear where to rename %s to; it was "
+ "renamed to multiple other directories, with "
+ "no destination getting a majority of the "
+ "files."),
+ source_dir);
+ *clean = 0;
+ } else {
+ strmap_put(&renames->dir_renames[side],
+ source_dir, (void*)best);
+ }
+ }
}
static void handle_directory_level_conflicts(struct merge_options *opt)