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 <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Aug 11, 2011 at 23:20 UTC
4f66dade81c2ebc6e1143b6c116960bfcd837067
1 file changed
+66
-68
merge-recursive.c
+66
-68
@@ -66,10 +66,11 @@ static int sha_eq(const unsigned char *a, const unsigned char *b)
66
enum rename_type {
67
RENAME_NORMAL = 0,
68
RENAME_DELETE,
69
+ RENAME_ONE_FILE_TO_ONE,
70
RENAME_ONE_FILE_TO_TWO
71
};
72
72
-struct rename_df_conflict_info {
73
+struct rename_conflict_info {
74
enum rename_type rename_type;
75
struct diff_filepair *pair1;
76
struct diff_filepair *pair2;
@@ -88,34 +89,33 @@ struct stage_data {
89
unsigned mode;
90
unsigned char sha[20];
91
} stages[4];
91
- struct rename_df_conflict_info *rename_df_conflict_info;
92
+ struct rename_conflict_info *rename_conflict_info;
93
unsigned processed:1;
93
- unsigned involved_in_rename:1;
94
};
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
{
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
ci->rename_type = rename_type;
106
ci->pair1 = pair1;
107
ci->branch1 = branch1;
108
ci->branch2 = branch2;
109
110
ci->dst_entry1 = dst_entry1;
111
- dst_entry1->rename_df_conflict_info = ci;
111
+ dst_entry1->rename_conflict_info = ci;
112
dst_entry1->processed = 0;
113
114
assert(!pair2 == !dst_entry2);
115
if (dst_entry2) {
116
ci->dst_entry2 = dst_entry2;
117
ci->pair2 = pair2;
118
- dst_entry2->rename_df_conflict_info = ci;
118
+ dst_entry2->rename_conflict_info = ci;
119
}
120
}
121
@@ -952,10 +952,29 @@ static void conflict_rename_rename_1to2(struct merge_options *o,
952
/* One file was renamed in both branches, but to different names. */
953
char *del[2];
954
int delp = 0;
955
+ const char *src = pair1->one->path;
956
const char *ren1_dst = pair1->two->path;
957
const char *ren2_dst = pair2->two->path;
958
const char *dst_name1 = ren1_dst;
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
+
978
if (dir_in_way(ren1_dst, !o->call_depth)) {
979
dst_name1 = del[delp++] = unique_path(o, ren1_dst, branch1);
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,
1115
if (ren2) {
1116
const char *ren2_src = ren2->pair->one->path;
1117
const char *ren2_dst = ren2->pair->two->path;
1118
+ enum rename_type rename_type;
1119
/* Renamed in 1 and renamed in 2 */
1120
if (strcmp(ren1_src, ren2_src) != 0)
1121
die("ren1.src != ren2.src");
1122
ren2->dst_entry->processed = 1;
1123
ren2->processed = 1;
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;
1126
} else {
1127
+ rename_type = RENAME_ONE_FILE_TO_ONE;
1128
/* BUG: We should only remove ren1_src in
1129
* the base stage (think of rename +
1130
* add-source cases).
@@ -1119,8 +1134,14 @@ static int process_renames(struct merge_options *o,
1134
ren1->pair->one,
1135
ren1->pair->two,
1136
ren2->pair->two);
1122
- ren1->dst_entry->involved_in_rename = 1;
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);
1145
} else {
1146
/* Renamed in 1, maybe changed in 2 */
1147
struct string_list_item *item;
@@ -1151,19 +1172,13 @@ static int process_renames(struct merge_options *o,
1172
try_merge = 0;
1173
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);
1182
} else if ((item = string_list_lookup(renames2Dst, ren1_dst))) {
1183
char *ren2_src, *ren2_dst;
1184
ren2 = item->util;
@@ -1237,16 +1252,13 @@ static int process_renames(struct merge_options *o,
1252
a = &src_other;
1253
}
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);
1262
}
1263
}
1264
}
@@ -1334,12 +1346,11 @@ static void handle_delete_modify(struct merge_options *o,
1346
}
1347
1348
static int merge_content(struct merge_options *o,
1337
- unsigned involved_in_rename,
1349
const char *path,
1350
unsigned char *o_sha, int o_mode,
1351
unsigned char *a_sha, int a_mode,
1352
unsigned char *b_sha, int b_mode,
1342
- const char *df_rename_conflict_branch)
1353
+ struct rename_conflict_info *rename_conflict_info)
1354
{
1355
const char *reason = "content";
1356
struct merge_file_info mfi;
@@ -1359,8 +1370,7 @@ static int merge_content(struct merge_options *o,
1370
b.mode = b_mode;
1371
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)) {
1374
df_conflict_remains = 1;
1375
}
1376
@@ -1375,7 +1385,7 @@ static int merge_content(struct merge_options *o,
1385
reason = "submodule";
1386
output(o, 1, "CONFLICT (%s): Merge conflict in %s",
1387
reason, path);
1378
- if (involved_in_rename && !df_conflict_remains)
1388
+ if (rename_conflict_info && !df_conflict_remains)
1389
update_stages(path, &one, &a, &b);
1390
}
1391
@@ -1398,7 +1408,7 @@ static int merge_content(struct merge_options *o,
1408
}
1409
1410
}
1401
- new_path = unique_path(o, path, df_rename_conflict_branch);
1411
+ new_path = unique_path(o, path, rename_conflict_info->branch1);
1412
output(o, 1, "Adding as %s instead", new_path);
1413
update_file(o, 0, mfi.sha, mfi.mode, new_path);
1414
free(new_path);
@@ -1428,14 +1438,14 @@ static int process_entry(struct merge_options *o,
1438
unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);
1439
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;
1443
switch (conflict_info->rename_type) {
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,
1447
o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
1438
- conflict_info->branch1);
1448
+ conflict_info);
1449
break;
1450
case RENAME_DELETE:
1451
clean_merge = 0;
@@ -1444,19 +1454,7 @@ static int process_entry(struct merge_options *o,
1454
conflict_info->branch2);
1455
break;
1456
case RENAME_ONE_FILE_TO_TWO:
1447
- src = conflict_info->pair1->one->path;
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
- }
1458
conflict_rename_rename_1to2(o, conflict_info->pair1,
1459
conflict_info->branch1,
1460
conflict_info->pair2,
@@ -1531,7 +1529,7 @@ static int process_entry(struct merge_options *o,
1529
} else if (a_sha && b_sha) {
1530
/* Case C: Added in both (check for same permissions) and */
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,
1533
o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
1534
NULL);
1535
} else if (!o_sha && !a_sha && !b_sha) {