@@ -66,10 +66,11 @@ static int sha_eq(const unsigned char *a, const unsigned char *b)
66
66
enum rename_type {
67
67
RENAME_NORMAL = 0 ,
68
68
RENAME_DELETE ,
69
+ RENAME_ONE_FILE_TO_ONE ,
69
70
RENAME_ONE_FILE_TO_TWO
70
71
};
71
72
72
- struct rename_df_conflict_info {
73
+ struct rename_conflict_info {
73
74
enum rename_type rename_type ;
74
75
struct diff_filepair * pair1 ;
75
76
struct diff_filepair * pair2 ;
@@ -88,34 +89,33 @@ struct stage_data {
88
89
unsigned mode ;
89
90
unsigned char sha [20 ];
90
91
} stages [4 ];
91
- struct rename_df_conflict_info * rename_df_conflict_info ;
92
+ struct rename_conflict_info * rename_conflict_info ;
92
93
unsigned processed :1 ;
93
- unsigned involved_in_rename :1 ;
94
94
};
95
95
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 )
103
103
{
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 ));
105
105
ci -> rename_type = rename_type ;
106
106
ci -> pair1 = pair1 ;
107
107
ci -> branch1 = branch1 ;
108
108
ci -> branch2 = branch2 ;
109
109
110
110
ci -> dst_entry1 = dst_entry1 ;
111
- dst_entry1 -> rename_df_conflict_info = ci ;
111
+ dst_entry1 -> rename_conflict_info = ci ;
112
112
dst_entry1 -> processed = 0 ;
113
113
114
114
assert (!pair2 == !dst_entry2 );
115
115
if (dst_entry2 ) {
116
116
ci -> dst_entry2 = dst_entry2 ;
117
117
ci -> pair2 = pair2 ;
118
- dst_entry2 -> rename_df_conflict_info = ci ;
118
+ dst_entry2 -> rename_conflict_info = ci ;
119
119
}
120
120
}
121
121
@@ -952,10 +952,29 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
952
952
/* One file was renamed in both branches, but to different names. */
953
953
char * del [2 ];
954
954
int delp = 0 ;
955
+ const char * src = pair1 -> one -> path ;
955
956
const char * ren1_dst = pair1 -> two -> path ;
956
957
const char * ren2_dst = pair2 -> two -> path ;
957
958
const char * dst_name1 = ren1_dst ;
958
959
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
+
959
978
if (dir_in_way (ren1_dst , !o -> call_depth )) {
960
979
dst_name1 = del [delp ++ ] = unique_path (o , ren1_dst , branch1 );
961
980
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,
1096
1115
if (ren2 ) {
1097
1116
const char * ren2_src = ren2 -> pair -> one -> path ;
1098
1117
const char * ren2_dst = ren2 -> pair -> two -> path ;
1118
+ enum rename_type rename_type ;
1099
1119
/* Renamed in 1 and renamed in 2 */
1100
1120
if (strcmp (ren1_src , ren2_src ) != 0 )
1101
1121
die ("ren1.src != ren2.src" );
1102
1122
ren2 -> dst_entry -> processed = 1 ;
1103
1123
ren2 -> processed = 1 ;
1104
1124
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 ;
1112
1126
} else {
1127
+ rename_type = RENAME_ONE_FILE_TO_ONE ;
1113
1128
/* BUG: We should only remove ren1_src in
1114
1129
* the base stage (think of rename +
1115
1130
* add-source cases).
@@ -1119,8 +1134,14 @@ static int process_renames(struct merge_options *o,
1119
1134
ren1 -> pair -> one ,
1120
1135
ren1 -> pair -> two ,
1121
1136
ren2 -> pair -> two );
1122
- ren1 -> dst_entry -> involved_in_rename = 1 ;
1123
1137
}
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 );
1124
1145
} else {
1125
1146
/* Renamed in 1, maybe changed in 2 */
1126
1147
struct string_list_item * item ;
@@ -1151,19 +1172,13 @@ static int process_renames(struct merge_options *o,
1151
1172
try_merge = 0 ;
1152
1173
1153
1174
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 );
1167
1182
} else if ((item = string_list_lookup (renames2Dst , ren1_dst ))) {
1168
1183
char * ren2_src , * ren2_dst ;
1169
1184
ren2 = item -> util ;
@@ -1237,16 +1252,13 @@ static int process_renames(struct merge_options *o,
1237
1252
a = & src_other ;
1238
1253
}
1239
1254
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 );
1250
1262
}
1251
1263
}
1252
1264
}
@@ -1334,12 +1346,11 @@ static void handle_delete_modify(struct merge_options *o,
1334
1346
}
1335
1347
1336
1348
static int merge_content (struct merge_options * o ,
1337
- unsigned involved_in_rename ,
1338
1349
const char * path ,
1339
1350
unsigned char * o_sha , int o_mode ,
1340
1351
unsigned char * a_sha , int a_mode ,
1341
1352
unsigned char * b_sha , int b_mode ,
1342
- const char * df_rename_conflict_branch )
1353
+ struct rename_conflict_info * rename_conflict_info )
1343
1354
{
1344
1355
const char * reason = "content" ;
1345
1356
struct merge_file_info mfi ;
@@ -1359,8 +1370,7 @@ static int merge_content(struct merge_options *o,
1359
1370
b .mode = b_mode ;
1360
1371
1361
1372
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 )) {
1364
1374
df_conflict_remains = 1 ;
1365
1375
}
1366
1376
@@ -1375,7 +1385,7 @@ static int merge_content(struct merge_options *o,
1375
1385
reason = "submodule" ;
1376
1386
output (o , 1 , "CONFLICT (%s): Merge conflict in %s" ,
1377
1387
reason , path );
1378
- if (involved_in_rename && !df_conflict_remains )
1388
+ if (rename_conflict_info && !df_conflict_remains )
1379
1389
update_stages (path , & one , & a , & b );
1380
1390
}
1381
1391
@@ -1398,7 +1408,7 @@ static int merge_content(struct merge_options *o,
1398
1408
}
1399
1409
1400
1410
}
1401
- new_path = unique_path (o , path , df_rename_conflict_branch );
1411
+ new_path = unique_path (o , path , rename_conflict_info -> branch1 );
1402
1412
output (o , 1 , "Adding as %s instead" , new_path );
1403
1413
update_file (o , 0 , mfi .sha , mfi .mode , new_path );
1404
1414
free (new_path );
@@ -1428,14 +1438,14 @@ static int process_entry(struct merge_options *o,
1428
1438
unsigned char * b_sha = stage_sha (entry -> stages [3 ].sha , b_mode );
1429
1439
1430
1440
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 ;
1434
1443
switch (conflict_info -> rename_type ) {
1435
1444
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 ,
1437
1447
o_sha , o_mode , a_sha , a_mode , b_sha , b_mode ,
1438
- conflict_info -> branch1 );
1448
+ conflict_info );
1439
1449
break ;
1440
1450
case RENAME_DELETE :
1441
1451
clean_merge = 0 ;
@@ -1444,19 +1454,7 @@ static int process_entry(struct merge_options *o,
1444
1454
conflict_info -> branch2 );
1445
1455
break ;
1446
1456
case RENAME_ONE_FILE_TO_TWO :
1447
- src = conflict_info -> pair1 -> one -> path ;
1448
1457
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
- }
1460
1458
conflict_rename_rename_1to2 (o , conflict_info -> pair1 ,
1461
1459
conflict_info -> branch1 ,
1462
1460
conflict_info -> pair2 ,
@@ -1531,7 +1529,7 @@ static int process_entry(struct merge_options *o,
1531
1529
} else if (a_sha && b_sha ) {
1532
1530
/* Case C: Added in both (check for same permissions) and */
1533
1531
/* 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 ,
1535
1533
o_sha , o_mode , a_sha , a_mode , b_sha , b_mode ,
1536
1534
NULL );
1537
1535
} else if (!o_sha && !a_sha && !b_sha ) {
0 commit comments