Skip to content

Commit fa5e06d

Browse files
newrengitster
authored andcommitted
merge-ort: modify collect_renames() for directory rename handling
collect_renames() is similar to merge-recursive.c's get_renames(), but lacks the directory rename handling found in the latter. Port that code structure over to merge-ort. This introduces three new die-not-yet-implemented functions that will be defined in future commits. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 98d0d08 commit fa5e06d

File tree

1 file changed

+74
-4
lines changed

1 file changed

+74
-4
lines changed

merge-ort.c

Lines changed: 74 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,11 @@ static int handle_content_merge(struct merge_options *opt,
721721

722722
/*** Function Grouping: functions related to directory rename detection ***/
723723

724+
struct collision_info {
725+
struct string_list source_files;
726+
unsigned reported_already:1;
727+
};
728+
724729
static void get_renamed_dir_portion(const char *old_path, const char *new_path,
725730
char **old_dir, char **new_dir)
726731
{
@@ -959,6 +964,31 @@ static void handle_directory_level_conflicts(struct merge_options *opt)
959964
string_list_clear(&duplicated, 0);
960965
}
961966

967+
static void compute_collisions(struct strmap *collisions,
968+
struct strmap *dir_renames,
969+
struct diff_queue_struct *pairs)
970+
{
971+
die("Not yet implemented.");
972+
}
973+
974+
static char *check_for_directory_rename(struct merge_options *opt,
975+
const char *path,
976+
unsigned side_index,
977+
struct strmap *dir_renames,
978+
struct strmap *dir_rename_exclusions,
979+
struct strmap *collisions,
980+
int *clean_merge)
981+
{
982+
die("Not yet implemented.");
983+
}
984+
985+
static void apply_directory_rename_modifications(struct merge_options *opt,
986+
struct diff_filepair *pair,
987+
char *new_path)
988+
{
989+
die("Not yet implemented.");
990+
}
991+
962992
/*** Function Grouping: functions related to regular rename detection ***/
963993

964994
static int process_renames(struct merge_options *opt,
@@ -1284,22 +1314,44 @@ static void detect_regular_renames(struct merge_options *opt,
12841314
*/
12851315
static int collect_renames(struct merge_options *opt,
12861316
struct diff_queue_struct *result,
1287-
unsigned side_index)
1317+
unsigned side_index,
1318+
struct strmap *dir_renames_for_side,
1319+
struct strmap *rename_exclusions)
12881320
{
12891321
int i, clean = 1;
1322+
struct strmap collisions;
12901323
struct diff_queue_struct *side_pairs;
1324+
struct hashmap_iter iter;
1325+
struct strmap_entry *entry;
12911326
struct rename_info *renames = &opt->priv->renames;
12921327

12931328
side_pairs = &renames->pairs[side_index];
1329+
compute_collisions(&collisions, dir_renames_for_side, side_pairs);
12941330

12951331
for (i = 0; i < side_pairs->nr; ++i) {
12961332
struct diff_filepair *p = side_pairs->queue[i];
1333+
char *new_path; /* non-NULL only with directory renames */
12971334

1298-
if (p->status != 'R') {
1335+
if (p->status != 'A' && p->status != 'R') {
12991336
diff_free_filepair(p);
13001337
continue;
13011338
}
13021339

1340+
new_path = check_for_directory_rename(opt, p->two->path,
1341+
side_index,
1342+
dir_renames_for_side,
1343+
rename_exclusions,
1344+
&collisions,
1345+
&clean);
1346+
1347+
if (p->status != 'R' && !new_path) {
1348+
diff_free_filepair(p);
1349+
continue;
1350+
}
1351+
1352+
if (new_path)
1353+
apply_directory_rename_modifications(opt, p, new_path);
1354+
13031355
/*
13041356
* p->score comes back from diffcore_rename_extended() with
13051357
* the similarity of the renamed file. The similarity is
@@ -1314,6 +1366,20 @@ static int collect_renames(struct merge_options *opt,
13141366
result->queue[result->nr++] = p;
13151367
}
13161368

1369+
/* Free each value in the collisions map */
1370+
strmap_for_each_entry(&collisions, &iter, entry) {
1371+
struct collision_info *info = entry->value;
1372+
string_list_clear(&info->source_files, 0);
1373+
}
1374+
/*
1375+
* In compute_collisions(), we set collisions.strdup_strings to 0
1376+
* so that we wouldn't have to make another copy of the new_path
1377+
* allocated by apply_dir_rename(). But now that we've used them
1378+
* and have no other references to these strings, it is time to
1379+
* deallocate them.
1380+
*/
1381+
free_strmap_strings(&collisions);
1382+
strmap_clear(&collisions, 1);
13171383
return clean;
13181384
}
13191385

@@ -1345,8 +1411,12 @@ static int detect_and_process_renames(struct merge_options *opt,
13451411
ALLOC_GROW(combined.queue,
13461412
renames->pairs[1].nr + renames->pairs[2].nr,
13471413
combined.alloc);
1348-
clean &= collect_renames(opt, &combined, MERGE_SIDE1);
1349-
clean &= collect_renames(opt, &combined, MERGE_SIDE2);
1414+
clean &= collect_renames(opt, &combined, MERGE_SIDE1,
1415+
&renames->dir_renames[2],
1416+
&renames->dir_renames[1]);
1417+
clean &= collect_renames(opt, &combined, MERGE_SIDE2,
1418+
&renames->dir_renames[1],
1419+
&renames->dir_renames[2]);
13501420
QSORT(combined.queue, combined.nr, compare_pairs);
13511421

13521422
clean &= process_renames(opt, &combined);

0 commit comments

Comments
 (0)