Skip to content

Commit 4f66dad

Browse files
newrengitster
authored andcommitted
merge-recursive: Cleanup and consolidation of rename_conflict_info
The consolidation of process_entry() and process_df_entry() allows us to consolidate more code paths concerning rename conflicts, and to do a few additional related cleanups. It also means we are using rename_df_conflict_info in some cases where there is no D/F conflict; rename it to rename_conflict_info. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent edd2faf commit 4f66dad

File tree

1 file changed

+66
-68
lines changed

1 file changed

+66
-68
lines changed

merge-recursive.c

Lines changed: 66 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,11 @@ static int sha_eq(const unsigned char *a, const unsigned char *b)
6666
enum rename_type {
6767
RENAME_NORMAL = 0,
6868
RENAME_DELETE,
69+
RENAME_ONE_FILE_TO_ONE,
6970
RENAME_ONE_FILE_TO_TWO
7071
};
7172

72-
struct rename_df_conflict_info {
73+
struct rename_conflict_info {
7374
enum rename_type rename_type;
7475
struct diff_filepair *pair1;
7576
struct diff_filepair *pair2;
@@ -88,34 +89,33 @@ struct stage_data {
8889
unsigned mode;
8990
unsigned char sha[20];
9091
} stages[4];
91-
struct rename_df_conflict_info *rename_df_conflict_info;
92+
struct rename_conflict_info *rename_conflict_info;
9293
unsigned processed:1;
93-
unsigned involved_in_rename:1;
9494
};
9595

96-
static inline void setup_rename_df_conflict_info(enum rename_type rename_type,
97-
struct diff_filepair *pair1,
98-
struct diff_filepair *pair2,
99-
const char *branch1,
100-
const char *branch2,
101-
struct stage_data *dst_entry1,
102-
struct stage_data *dst_entry2)
96+
static inline void setup_rename_conflict_info(enum rename_type rename_type,
97+
struct diff_filepair *pair1,
98+
struct diff_filepair *pair2,
99+
const char *branch1,
100+
const char *branch2,
101+
struct stage_data *dst_entry1,
102+
struct stage_data *dst_entry2)
103103
{
104-
struct rename_df_conflict_info *ci = xcalloc(1, sizeof(struct rename_df_conflict_info));
104+
struct rename_conflict_info *ci = xcalloc(1, sizeof(struct rename_conflict_info));
105105
ci->rename_type = rename_type;
106106
ci->pair1 = pair1;
107107
ci->branch1 = branch1;
108108
ci->branch2 = branch2;
109109

110110
ci->dst_entry1 = dst_entry1;
111-
dst_entry1->rename_df_conflict_info = ci;
111+
dst_entry1->rename_conflict_info = ci;
112112
dst_entry1->processed = 0;
113113

114114
assert(!pair2 == !dst_entry2);
115115
if (dst_entry2) {
116116
ci->dst_entry2 = dst_entry2;
117117
ci->pair2 = pair2;
118-
dst_entry2->rename_df_conflict_info = ci;
118+
dst_entry2->rename_conflict_info = ci;
119119
}
120120
}
121121

@@ -952,10 +952,29 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
952952
/* One file was renamed in both branches, but to different names. */
953953
char *del[2];
954954
int delp = 0;
955+
const char *src = pair1->one->path;
955956
const char *ren1_dst = pair1->two->path;
956957
const char *ren2_dst = pair2->two->path;
957958
const char *dst_name1 = ren1_dst;
958959
const char *dst_name2 = ren2_dst;
960+
961+
output(o, 1, "CONFLICT (rename/rename): "
962+
"Rename \"%s\"->\"%s\" in branch \"%s\" "
963+
"rename \"%s\"->\"%s\" in \"%s\"%s",
964+
src, pair1->two->path, branch1,
965+
src, pair2->two->path, branch2,
966+
o->call_depth ? " (left unresolved)" : "");
967+
if (o->call_depth) {
968+
/*
969+
* FIXME: Why remove file from cache, and then
970+
* immediately readd it? Why not just overwrite using
971+
* update_file only? Also...this is buggy for
972+
* rename/add-source situations...
973+
*/
974+
remove_file_from_cache(src);
975+
update_file(o, 0, pair1->one->sha1, pair1->one->mode, src);
976+
}
977+
959978
if (dir_in_way(ren1_dst, !o->call_depth)) {
960979
dst_name1 = del[delp++] = unique_path(o, ren1_dst, branch1);
961980
output(o, 1, "%s is a directory in %s adding as %s instead",
@@ -1096,20 +1115,16 @@ static int process_renames(struct merge_options *o,
10961115
if (ren2) {
10971116
const char *ren2_src = ren2->pair->one->path;
10981117
const char *ren2_dst = ren2->pair->two->path;
1118+
enum rename_type rename_type;
10991119
/* Renamed in 1 and renamed in 2 */
11001120
if (strcmp(ren1_src, ren2_src) != 0)
11011121
die("ren1.src != ren2.src");
11021122
ren2->dst_entry->processed = 1;
11031123
ren2->processed = 1;
11041124
if (strcmp(ren1_dst, ren2_dst) != 0) {
1105-
setup_rename_df_conflict_info(RENAME_ONE_FILE_TO_TWO,
1106-
ren1->pair,
1107-
ren2->pair,
1108-
branch1,
1109-
branch2,
1110-
ren1->dst_entry,
1111-
ren2->dst_entry);
1125+
rename_type = RENAME_ONE_FILE_TO_TWO;
11121126
} else {
1127+
rename_type = RENAME_ONE_FILE_TO_ONE;
11131128
/* BUG: We should only remove ren1_src in
11141129
* the base stage (think of rename +
11151130
* add-source cases).
@@ -1119,8 +1134,14 @@ static int process_renames(struct merge_options *o,
11191134
ren1->pair->one,
11201135
ren1->pair->two,
11211136
ren2->pair->two);
1122-
ren1->dst_entry->involved_in_rename = 1;
11231137
}
1138+
setup_rename_conflict_info(rename_type,
1139+
ren1->pair,
1140+
ren2->pair,
1141+
branch1,
1142+
branch2,
1143+
ren1->dst_entry,
1144+
ren2->dst_entry);
11241145
} else {
11251146
/* Renamed in 1, maybe changed in 2 */
11261147
struct string_list_item *item;
@@ -1151,19 +1172,13 @@ static int process_renames(struct merge_options *o,
11511172
try_merge = 0;
11521173

11531174
if (sha_eq(src_other.sha1, null_sha1)) {
1154-
if (dir_in_way(ren1_dst, 0 /*check_wc*/)) {
1155-
ren1->dst_entry->processed = 0;
1156-
setup_rename_df_conflict_info(RENAME_DELETE,
1157-
ren1->pair,
1158-
NULL,
1159-
branch1,
1160-
branch2,
1161-
ren1->dst_entry,
1162-
NULL);
1163-
} else {
1164-
clean_merge = 0;
1165-
conflict_rename_delete(o, ren1->pair, branch1, branch2);
1166-
}
1175+
setup_rename_conflict_info(RENAME_DELETE,
1176+
ren1->pair,
1177+
NULL,
1178+
branch1,
1179+
branch2,
1180+
ren1->dst_entry,
1181+
NULL);
11671182
} else if ((item = string_list_lookup(renames2Dst, ren1_dst))) {
11681183
char *ren2_src, *ren2_dst;
11691184
ren2 = item->util;
@@ -1237,16 +1252,13 @@ static int process_renames(struct merge_options *o,
12371252
a = &src_other;
12381253
}
12391254
update_entry(ren1->dst_entry, one, a, b);
1240-
ren1->dst_entry->involved_in_rename = 1;
1241-
if (dir_in_way(ren1_dst, 0 /*check_wc*/)) {
1242-
setup_rename_df_conflict_info(RENAME_NORMAL,
1243-
ren1->pair,
1244-
NULL,
1245-
branch1,
1246-
NULL,
1247-
ren1->dst_entry,
1248-
NULL);
1249-
}
1255+
setup_rename_conflict_info(RENAME_NORMAL,
1256+
ren1->pair,
1257+
NULL,
1258+
branch1,
1259+
NULL,
1260+
ren1->dst_entry,
1261+
NULL);
12501262
}
12511263
}
12521264
}
@@ -1334,12 +1346,11 @@ static void handle_delete_modify(struct merge_options *o,
13341346
}
13351347

13361348
static int merge_content(struct merge_options *o,
1337-
unsigned involved_in_rename,
13381349
const char *path,
13391350
unsigned char *o_sha, int o_mode,
13401351
unsigned char *a_sha, int a_mode,
13411352
unsigned char *b_sha, int b_mode,
1342-
const char *df_rename_conflict_branch)
1353+
struct rename_conflict_info *rename_conflict_info)
13431354
{
13441355
const char *reason = "content";
13451356
struct merge_file_info mfi;
@@ -1359,8 +1370,7 @@ static int merge_content(struct merge_options *o,
13591370
b.mode = b_mode;
13601371

13611372
mfi = merge_file(o, &one, &a, &b, o->branch1, o->branch2);
1362-
if (df_rename_conflict_branch &&
1363-
dir_in_way(path, !o->call_depth)) {
1373+
if (rename_conflict_info && dir_in_way(path, !o->call_depth)) {
13641374
df_conflict_remains = 1;
13651375
}
13661376

@@ -1375,7 +1385,7 @@ static int merge_content(struct merge_options *o,
13751385
reason = "submodule";
13761386
output(o, 1, "CONFLICT (%s): Merge conflict in %s",
13771387
reason, path);
1378-
if (involved_in_rename && !df_conflict_remains)
1388+
if (rename_conflict_info && !df_conflict_remains)
13791389
update_stages(path, &one, &a, &b);
13801390
}
13811391

@@ -1398,7 +1408,7 @@ static int merge_content(struct merge_options *o,
13981408
}
13991409

14001410
}
1401-
new_path = unique_path(o, path, df_rename_conflict_branch);
1411+
new_path = unique_path(o, path, rename_conflict_info->branch1);
14021412
output(o, 1, "Adding as %s instead", new_path);
14031413
update_file(o, 0, mfi.sha, mfi.mode, new_path);
14041414
free(new_path);
@@ -1428,14 +1438,14 @@ static int process_entry(struct merge_options *o,
14281438
unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);
14291439

14301440
entry->processed = 1;
1431-
if (entry->rename_df_conflict_info) {
1432-
struct rename_df_conflict_info *conflict_info = entry->rename_df_conflict_info;
1433-
char *src;
1441+
if (entry->rename_conflict_info) {
1442+
struct rename_conflict_info *conflict_info = entry->rename_conflict_info;
14341443
switch (conflict_info->rename_type) {
14351444
case RENAME_NORMAL:
1436-
clean_merge = merge_content(o, entry->involved_in_rename, path,
1445+
case RENAME_ONE_FILE_TO_ONE:
1446+
clean_merge = merge_content(o, path,
14371447
o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
1438-
conflict_info->branch1);
1448+
conflict_info);
14391449
break;
14401450
case RENAME_DELETE:
14411451
clean_merge = 0;
@@ -1444,19 +1454,7 @@ static int process_entry(struct merge_options *o,
14441454
conflict_info->branch2);
14451455
break;
14461456
case RENAME_ONE_FILE_TO_TWO:
1447-
src = conflict_info->pair1->one->path;
14481457
clean_merge = 0;
1449-
output(o, 1, "CONFLICT (rename/rename): "
1450-
"Rename \"%s\"->\"%s\" in branch \"%s\" "
1451-
"rename \"%s\"->\"%s\" in \"%s\"%s",
1452-
src, conflict_info->pair1->two->path, conflict_info->branch1,
1453-
src, conflict_info->pair2->two->path, conflict_info->branch2,
1454-
o->call_depth ? " (left unresolved)" : "");
1455-
if (o->call_depth) {
1456-
remove_file_from_cache(src);
1457-
update_file(o, 0, conflict_info->pair1->one->sha1,
1458-
conflict_info->pair1->one->mode, src);
1459-
}
14601458
conflict_rename_rename_1to2(o, conflict_info->pair1,
14611459
conflict_info->branch1,
14621460
conflict_info->pair2,
@@ -1531,7 +1529,7 @@ static int process_entry(struct merge_options *o,
15311529
} else if (a_sha && b_sha) {
15321530
/* Case C: Added in both (check for same permissions) and */
15331531
/* case D: Modified in both, but differently. */
1534-
clean_merge = merge_content(o, entry->involved_in_rename, path,
1532+
clean_merge = merge_content(o, path,
15351533
o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
15361534
NULL);
15371535
} else if (!o_sha && !a_sha && !b_sha) {

0 commit comments

Comments
 (0)