merge-recursive: Structure process_df_entry() to handle more cases
Modify process_df_entry() (mostly just indentation level changes) to get it ready for handling more D/F conflict type cases. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Sep 20, 2010 at 02:28 UTC
9c0bbb50f0dd916fe1684991d10d93f3c67311ba
1 file changed
+47
-36
merge-recursive.c
+47
-36
@@ -1336,13 +1336,19 @@ static int process_entry(struct merge_options *o,
1336
}
1337
1338
/*
1339
- * Per entry merge function for D/F conflicts, to be called only after
1340
- * all files below dir have been processed. We do this because in the
1341
- * cases we can cleanly resolve D/F conflicts, process_entry() can clean
1342
- * out all the files below the directory for us.
1339
+ * Per entry merge function for D/F (and/or rename) conflicts. In the
1340
+ * cases we can cleanly resolve D/F conflicts, process_entry() can
1341
+ * clean out all the files below the directory for us. All D/F
1342
+ * conflict cases must be handled here at the end to make sure any
1343
+ * directories that can be cleaned out, are.
1344
+ *
1345
+ * Some rename conflicts may also be handled here that don't necessarily
1346
+ * involve D/F conflicts, since the code to handle them is generic enough
1347
+ * to handle those rename conflicts with or without D/F conflicts also
1348
+ * being involved.
1349
*/
1350
static int process_df_entry(struct merge_options *o,
1345
- const char *path, struct stage_data *entry)
1351
+ const char *path, struct stage_data *entry)
1352
{
1353
int clean_merge = 1;
1354
unsigned o_mode = entry->stages[1].mode;
@@ -1351,42 +1357,47 @@ static int process_df_entry(struct merge_options *o,
1357
unsigned char *o_sha = stage_sha(entry->stages[1].sha, o_mode);
1358
unsigned char *a_sha = stage_sha(entry->stages[2].sha, a_mode);
1359
unsigned char *b_sha = stage_sha(entry->stages[3].sha, b_mode);
1354
- const char *add_branch;
1355
- const char *other_branch;
1356
- unsigned mode;
1357
- const unsigned char *sha;
1358
- const char *conf;
1360
struct stat st;
1361
1361
- if (!((!o_sha && a_sha && !b_sha) || (!o_sha && !a_sha && b_sha)))
1362
- return 1; /* we don't handle non D-F cases */
1363
-
1362
entry->processed = 1;
1363
+ if (entry->rename_df_conflict_info) {
1364
+ die("Not yet implemented.");
1365
+ } else if (!o_sha && !!a_sha != !!b_sha) {
1366
+ /* directory -> (directory, file) */
1367
+ const char *add_branch;
1368
+ const char *other_branch;
1369
+ unsigned mode;
1370
+ const unsigned char *sha;
1371
+ const char *conf;
1372
1366
- if (a_sha) {
1367
- add_branch = o->branch1;
1368
- other_branch = o->branch2;
1369
- mode = a_mode;
1370
- sha = a_sha;
1371
- conf = "file/directory";
1372
- } else {
1373
- add_branch = o->branch2;
1374
- other_branch = o->branch1;
1375
- mode = b_mode;
1376
- sha = b_sha;
1377
- conf = "directory/file";
1378
- }
1379
- if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
1380
- const char *new_path = unique_path(o, path, add_branch);
1381
- clean_merge = 0;
1382
- output(o, 1, "CONFLICT (%s): There is a directory with name %s in %s. "
1383
- "Adding %s as %s",
1384
- conf, path, other_branch, path, new_path);
1385
- remove_file(o, 0, path, 0);
1386
- update_file(o, 0, sha, mode, new_path);
1373
+ if (a_sha) {
1374
+ add_branch = o->branch1;
1375
+ other_branch = o->branch2;
1376
+ mode = a_mode;
1377
+ sha = a_sha;
1378
+ conf = "file/directory";
1379
+ } else {
1380
+ add_branch = o->branch2;
1381
+ other_branch = o->branch1;
1382
+ mode = b_mode;
1383
+ sha = b_sha;
1384
+ conf = "directory/file";
1385
+ }
1386
+ if (lstat(path, &st) == 0 && S_ISDIR(st.st_mode)) {
1387
+ const char *new_path = unique_path(o, path, add_branch);
1388
+ clean_merge = 0;
1389
+ output(o, 1, "CONFLICT (%s): There is a directory with name %s in %s. "
1390
+ "Adding %s as %s",
1391
+ conf, path, other_branch, path, new_path);
1392
+ remove_file(o, 0, path, 0);
1393
+ update_file(o, 0, sha, mode, new_path);
1394
+ } else {
1395
+ output(o, 2, "Adding %s", path);
1396
+ update_file(o, 1, sha, mode, path);
1397
+ }
1398
} else {
1388
- output(o, 2, "Adding %s", path);
1389
- update_file(o, 1, sha, mode, path);
1399
+ entry->processed = 0;
1400
+ return 1; /* not handled; assume clean until processed */
1401
}
1402
1403
return clean_merge;