Skip to content

Commit 98d0d08

Browse files
newrengitster
authored andcommitted
merge-ort: implement handle_directory_level_conflicts()
This is modelled on the version of handle_directory_level_conflicts() from merge-recursive.c, but is massively simplified due to the following factors: * strmap API provides simplifications over using direct hashmap * we have a dirs_removed field in struct rename_info that we have an easy way to populate from collect_merge_info(); this was already used in compute_rename_counts() and thus we do not need to check for condition #2. * The removal of condition #2 by handling it earlier in the code also obviates the need to check for condition #3 -- if both sides renamed a directory, meaning that the directory no longer exists on either side, then neither side could have added any new files to that directory, and thus there are no files whose locations we need to move due to such a directory rename. In fact, the same logic that makes condition #3 irrelevant means condition #1 is also irrelevant so we could drop this function. However, it is cheap to check if both sides rename the same directory, and doing so can save future computation. So, simply remove any directories that both sides renamed from the list of directory renames. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2f620a4 commit 98d0d08

File tree

1 file changed

+18
-1
lines changed

1 file changed

+18
-1
lines changed

merge-ort.c

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -939,7 +939,24 @@ static void get_provisional_directory_renames(struct merge_options *opt,
939939

940940
static void handle_directory_level_conflicts(struct merge_options *opt)
941941
{
942-
die("Not yet implemented!");
942+
struct hashmap_iter iter;
943+
struct strmap_entry *entry;
944+
struct string_list duplicated = STRING_LIST_INIT_NODUP;
945+
struct rename_info *renames = &opt->priv->renames;
946+
struct strmap *side1_dir_renames = &renames->dir_renames[MERGE_SIDE1];
947+
struct strmap *side2_dir_renames = &renames->dir_renames[MERGE_SIDE2];
948+
int i;
949+
950+
strmap_for_each_entry(side1_dir_renames, &iter, entry) {
951+
if (strmap_contains(side2_dir_renames, entry->key))
952+
string_list_append(&duplicated, entry->key);
953+
}
954+
955+
for (i = 0; i < duplicated.nr; i++) {
956+
strmap_remove(side1_dir_renames, duplicated.items[i].string, 0);
957+
strmap_remove(side2_dir_renames, duplicated.items[i].string, 0);
958+
}
959+
string_list_clear(&duplicated, 0);
943960
}
944961

945962
/*** Function Grouping: functions related to regular rename detection ***/

0 commit comments

Comments
 (0)