summaryrefslogtreecommitdiff
path: root/merge-ort.c
diff options
context:
space:
mode:
authorElijah Newren <newren@gmail.com>2021-01-19 19:53:45 (GMT)
committerJunio C Hamano <gitster@pobox.com>2021-01-21 06:18:55 (GMT)
commitfa5e06d6902003f5f115b7497030b5c66537726e (patch)
treec0a9354dfe4409ff86ec1b064ac9e910c07456d9 /merge-ort.c
parent98d0d08128200e244a83d917b63567c30547c36d (diff)
downloadgit-fa5e06d6902003f5f115b7497030b5c66537726e.zip
git-fa5e06d6902003f5f115b7497030b5c66537726e.tar.gz
git-fa5e06d6902003f5f115b7497030b5c66537726e.tar.bz2
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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'merge-ort.c')
-rw-r--r--merge-ort.c78
1 files changed, 74 insertions, 4 deletions
diff --git a/merge-ort.c b/merge-ort.c
index 6dea420..c86ed85 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -721,6 +721,11 @@ static int handle_content_merge(struct merge_options *opt,
/*** Function Grouping: functions related to directory rename detection ***/
+struct collision_info {
+ struct string_list source_files;
+ unsigned reported_already:1;
+};
+
static void get_renamed_dir_portion(const char *old_path, const char *new_path,
char **old_dir, char **new_dir)
{
@@ -959,6 +964,31 @@ static void handle_directory_level_conflicts(struct merge_options *opt)
string_list_clear(&duplicated, 0);
}
+static void compute_collisions(struct strmap *collisions,
+ struct strmap *dir_renames,
+ struct diff_queue_struct *pairs)
+{
+ die("Not yet implemented.");
+}
+
+static char *check_for_directory_rename(struct merge_options *opt,
+ const char *path,
+ unsigned side_index,
+ struct strmap *dir_renames,
+ struct strmap *dir_rename_exclusions,
+ struct strmap *collisions,
+ int *clean_merge)
+{
+ die("Not yet implemented.");
+}
+
+static void apply_directory_rename_modifications(struct merge_options *opt,
+ struct diff_filepair *pair,
+ char *new_path)
+{
+ die("Not yet implemented.");
+}
+
/*** Function Grouping: functions related to regular rename detection ***/
static int process_renames(struct merge_options *opt,
@@ -1284,22 +1314,44 @@ static void detect_regular_renames(struct merge_options *opt,
*/
static int collect_renames(struct merge_options *opt,
struct diff_queue_struct *result,
- unsigned side_index)
+ unsigned side_index,
+ struct strmap *dir_renames_for_side,
+ struct strmap *rename_exclusions)
{
int i, clean = 1;
+ struct strmap collisions;
struct diff_queue_struct *side_pairs;
+ struct hashmap_iter iter;
+ struct strmap_entry *entry;
struct rename_info *renames = &opt->priv->renames;
side_pairs = &renames->pairs[side_index];
+ compute_collisions(&collisions, dir_renames_for_side, side_pairs);
for (i = 0; i < side_pairs->nr; ++i) {
struct diff_filepair *p = side_pairs->queue[i];
+ char *new_path; /* non-NULL only with directory renames */
- if (p->status != 'R') {
+ if (p->status != 'A' && p->status != 'R') {
diff_free_filepair(p);
continue;
}
+ new_path = check_for_directory_rename(opt, p->two->path,
+ side_index,
+ dir_renames_for_side,
+ rename_exclusions,
+ &collisions,
+ &clean);
+
+ if (p->status != 'R' && !new_path) {
+ diff_free_filepair(p);
+ continue;
+ }
+
+ if (new_path)
+ apply_directory_rename_modifications(opt, p, new_path);
+
/*
* p->score comes back from diffcore_rename_extended() with
* the similarity of the renamed file. The similarity is
@@ -1314,6 +1366,20 @@ static int collect_renames(struct merge_options *opt,
result->queue[result->nr++] = p;
}
+ /* Free each value in the collisions map */
+ strmap_for_each_entry(&collisions, &iter, entry) {
+ struct collision_info *info = entry->value;
+ string_list_clear(&info->source_files, 0);
+ }
+ /*
+ * In compute_collisions(), we set collisions.strdup_strings to 0
+ * so that we wouldn't have to make another copy of the new_path
+ * allocated by apply_dir_rename(). But now that we've used them
+ * and have no other references to these strings, it is time to
+ * deallocate them.
+ */
+ free_strmap_strings(&collisions);
+ strmap_clear(&collisions, 1);
return clean;
}
@@ -1345,8 +1411,12 @@ static int detect_and_process_renames(struct merge_options *opt,
ALLOC_GROW(combined.queue,
renames->pairs[1].nr + renames->pairs[2].nr,
combined.alloc);
- clean &= collect_renames(opt, &combined, MERGE_SIDE1);
- clean &= collect_renames(opt, &combined, MERGE_SIDE2);
+ clean &= collect_renames(opt, &combined, MERGE_SIDE1,
+ &renames->dir_renames[2],
+ &renames->dir_renames[1]);
+ clean &= collect_renames(opt, &combined, MERGE_SIDE2,
+ &renames->dir_renames[1],
+ &renames->dir_renames[2]);
QSORT(combined.queue, combined.nr, compare_pairs);
clean &= process_renames(opt, &combined);