Skip to content

Commit 6d169fd

Browse files
newrengitster
authored andcommitted
merge-recursive: track information associated with directory renames
Directory rename detection previously silently applied. In order to allow printing information about paths that changed or printing a conflict notification (and only doing so near other potential conflict messages associated with the paths), save this information inside the rename struct for later use. A subsequent patch will make use of the additional information. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent e0612a1 commit 6d169fd

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

merge-recursive.c

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,16 @@ struct stage_data {
207207
};
208208

209209
struct rename {
210+
unsigned processed:1;
210211
struct diff_filepair *pair;
211212
const char *branch; /* branch that the rename occurred on */
213+
/*
214+
* If directory rename detection affected this rename, what was its
215+
* original type ('A' or 'R') and it's original destination before
216+
* the directory rename (otherwise, '\0' and NULL for these two vars).
217+
*/
218+
char dir_rename_original_type;
219+
char *dir_rename_original_dest;
212220
/*
213221
* Purpose of src_entry and dst_entry:
214222
*
@@ -230,8 +238,6 @@ struct rename {
230238
*/
231239
struct stage_data *src_entry;
232240
struct stage_data *dst_entry;
233-
unsigned add_turned_into_rename:1;
234-
unsigned processed:1;
235241
};
236242

237243
struct rename_conflict_info {
@@ -2484,16 +2490,18 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
24842490
&re->dst_entry->stages[stage].oid,
24852491
&re->dst_entry->stages[stage].mode);
24862492

2487-
/* Update pair status */
2488-
if (pair->status == 'A') {
2489-
/*
2490-
* Recording rename information for this add makes it look
2491-
* like a rename/delete conflict. Make sure we can
2492-
* correctly handle this as an add that was moved to a new
2493-
* directory instead of reporting a rename/delete conflict.
2494-
*/
2495-
re->add_turned_into_rename = 1;
2496-
}
2493+
/*
2494+
* Record the original change status (or 'type' of change). If it
2495+
* was originally an add ('A'), this lets us differentiate later
2496+
* between a RENAME_DELETE conflict and RENAME_VIA_DIR (they
2497+
* otherwise look the same). If it was originally a rename ('R'),
2498+
* this lets us remember and report accurately about the transitive
2499+
* renaming that occurred via the directory rename detection. Also,
2500+
* record the original destination name.
2501+
*/
2502+
re->dir_rename_original_type = pair->status;
2503+
re->dir_rename_original_dest = pair->two->path;
2504+
24972505
/*
24982506
* We don't actually look at pair->status again, but it seems
24992507
* pedagogically correct to adjust it.
@@ -2556,9 +2564,10 @@ static struct string_list *get_renames(struct merge_options *opt,
25562564

25572565
re = xmalloc(sizeof(*re));
25582566
re->processed = 0;
2559-
re->add_turned_into_rename = 0;
25602567
re->pair = pair;
25612568
re->branch = branch;
2569+
re->dir_rename_original_type = '\0';
2570+
re->dir_rename_original_dest = NULL;
25622571
item = string_list_lookup(entries, re->pair->one->path);
25632572
if (!item)
25642573
re->src_entry = insert_stage_data(re->pair->one->path,
@@ -2726,7 +2735,7 @@ static int process_renames(struct merge_options *opt,
27262735
try_merge = 0;
27272736

27282737
if (oid_eq(&src_other.oid, &null_oid) &&
2729-
ren1->add_turned_into_rename) {
2738+
ren1->dir_rename_original_type == 'A') {
27302739
setup_rename_conflict_info(RENAME_VIA_DIR,
27312740
opt, ren1, NULL);
27322741
} else if (oid_eq(&src_other.oid, &null_oid)) {

0 commit comments

Comments
 (0)