Skip to content

Commit c2d267d

Browse files
newrengitster
authored andcommitted
merge-ort: add basic outline for process_renames()
Add code which determines which kind of special rename case each rename corresponds to, but leave the handling of each type unimplemented for now. Future commits will implement each one. There is some tenuous resemblance to merge-recursive's process_renames(), but comparing the two is very unlikely to yield any insights. merge-ort's process_renames() is a bit complex and I would prefer if I could simplify it more, but it is far easier to grok than merge-recursive's function of the same name in my opinion. Plus, merge-ort handles more rename conflict types than merge-recursive does. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 965a7bc commit c2d267d

File tree

1 file changed

+97
-1
lines changed

1 file changed

+97
-1
lines changed

merge-ort.c

Lines changed: 97 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,103 @@ static int handle_content_merge(struct merge_options *opt,
647647
static int process_renames(struct merge_options *opt,
648648
struct diff_queue_struct *renames)
649649
{
650-
die("Not yet implemented.");
650+
int clean_merge = 1, i;
651+
652+
for (i = 0; i < renames->nr; ++i) {
653+
const char *oldpath = NULL, *newpath;
654+
struct diff_filepair *pair = renames->queue[i];
655+
struct conflict_info *oldinfo = NULL, *newinfo = NULL;
656+
struct strmap_entry *old_ent, *new_ent;
657+
unsigned int old_sidemask;
658+
int target_index, other_source_index;
659+
int source_deleted, collision, type_changed;
660+
661+
old_ent = strmap_get_entry(&opt->priv->paths, pair->one->path);
662+
oldpath = old_ent->key;
663+
oldinfo = old_ent->value;
664+
665+
new_ent = strmap_get_entry(&opt->priv->paths, pair->two->path);
666+
newpath = new_ent->key;
667+
newinfo = new_ent->value;
668+
669+
/*
670+
* diff_filepairs have copies of pathnames, thus we have to
671+
* use standard 'strcmp()' (negated) instead of '=='.
672+
*/
673+
if (i + 1 < renames->nr &&
674+
!strcmp(oldpath, renames->queue[i+1]->one->path)) {
675+
/* Handle rename/rename(1to2) or rename/rename(1to1) */
676+
const char *pathnames[3];
677+
678+
pathnames[0] = oldpath;
679+
pathnames[1] = newpath;
680+
pathnames[2] = renames->queue[i+1]->two->path;
681+
682+
if (!strcmp(pathnames[1], pathnames[2])) {
683+
/* Both sides renamed the same way. */
684+
die("Not yet implemented");
685+
686+
/* We handled both renames, i.e. i+1 handled */
687+
i++;
688+
/* Move to next rename */
689+
continue;
690+
}
691+
692+
/* This is a rename/rename(1to2) */
693+
die("Not yet implemented");
694+
695+
i++; /* We handled both renames, i.e. i+1 handled */
696+
continue;
697+
}
698+
699+
VERIFY_CI(oldinfo);
700+
VERIFY_CI(newinfo);
701+
target_index = pair->score; /* from collect_renames() */
702+
assert(target_index == 1 || target_index == 2);
703+
other_source_index = 3 - target_index;
704+
old_sidemask = (1 << other_source_index); /* 2 or 4 */
705+
source_deleted = (oldinfo->filemask == 1);
706+
collision = ((newinfo->filemask & old_sidemask) != 0);
707+
type_changed = !source_deleted &&
708+
(S_ISREG(oldinfo->stages[other_source_index].mode) !=
709+
S_ISREG(newinfo->stages[target_index].mode));
710+
if (type_changed && collision) {
711+
/* special handling so later blocks can handle this */
712+
die("Not yet implemented");
713+
}
714+
715+
assert(source_deleted || oldinfo->filemask & old_sidemask);
716+
717+
/* Need to check for special types of rename conflicts... */
718+
if (collision && !source_deleted) {
719+
/* collision: rename/add or rename/rename(2to1) */
720+
die("Not yet implemented");
721+
} else if (collision && source_deleted) {
722+
/* rename/add/delete or rename/rename(2to1)/delete */
723+
die("Not yet implemented");
724+
} else {
725+
/* a few different cases... */
726+
if (type_changed) {
727+
/* rename vs. typechange */
728+
die("Not yet implemented");
729+
} else if (source_deleted) {
730+
/* rename/delete */
731+
die("Not yet implemented");
732+
} else {
733+
/* normal rename */
734+
die("Not yet implemented");
735+
}
736+
}
737+
738+
if (!type_changed) {
739+
/* Mark the original as resolved by removal */
740+
oldinfo->merged.is_null = 1;
741+
oldinfo->merged.clean = 1;
742+
}
743+
744+
}
745+
746+
return clean_merge;
651747
}
652748

653749
static int compare_pairs(const void *a_, const void *b_)

0 commit comments

Comments
 (0)