merge-recursive: Split update_stages_and_entry; only update stages at end

Instead of having the process_renames logic update the stages in the index for the rename destination, have the index updated after process_entry or process_df_entry. This will also allow us to have process_entry determine whether a file was tracked and existed in the working copy before the merge started. 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 b8ddf16424f2d4f29a73b89dabbb764763744abe
1 file changed +17 -18
merge-recursive.c
+17 -18
@@ -90,6 +90,7 @@ struct stage_data {
90 } stages[4];
91 struct rename_df_conflict_info *rename_df_conflict_info;
92 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,
@@ -522,15 +523,11 @@ static int update_stages(const char *path, const struct diff_filespec *o,
523 return 0;
524 }
525
525 -static int update_stages_and_entry(const char *path,
526 - struct stage_data *entry,
527 - struct diff_filespec *o,
528 - struct diff_filespec *a,
529 - struct diff_filespec *b,
530 - int clear)
526 +static void update_entry(struct stage_data *entry,
527 + struct diff_filespec *o,
528 + struct diff_filespec *a,
529 + struct diff_filespec *b)
530 {
532 - int options;
533 -
531 entry->processed = 0;
532 entry->stages[1].mode = o->mode;
533 entry->stages[2].mode = a->mode;
@@ -538,7 +535,6 @@ static int update_stages_and_entry(const char *path,
535 hashcpy(entry->stages[1].sha, o->sha1);
536 hashcpy(entry->stages[2].sha, a->sha1);
537 hashcpy(entry->stages[3].sha, b->sha1);
541 - return update_stages(path, o, a, b);
538 }
539
540 static int remove_file(struct merge_options *o, int clean,
@@ -1097,12 +1093,11 @@ static int process_renames(struct merge_options *o,
1093 ren2->dst_entry);
1094 } else {
1095 remove_file(o, 1, ren1_src, 1);
1100 - update_stages_and_entry(ren1_dst,
1101 - ren1->dst_entry,
1102 - ren1->pair->one,
1103 - ren1->pair->two,
1104 - ren2->pair->two,
1105 - 1 /* clear */);
1096 + update_entry(ren1->dst_entry,
1097 + ren1->pair->one,
1098 + ren1->pair->two,
1099 + ren2->pair->two);
1100 + ren1->dst_entry->involved_in_rename = 1;
1101 }
1102 } else {
1103 /* Renamed in 1, maybe changed in 2 */
@@ -1207,7 +1202,8 @@ static int process_renames(struct merge_options *o,
1202 b = ren1->pair->two;
1203 a = &src_other;
1204 }
1210 - update_stages_and_entry(ren1_dst, ren1->dst_entry, one, a, b, 1);
1205 + update_entry(ren1->dst_entry, one, a, b);
1206 + ren1->dst_entry->involved_in_rename = 1;
1207 if (dir_in_way(ren1_dst, 0 /*check_wc*/)) {
1208 setup_rename_df_conflict_info(RENAME_NORMAL,
1209 ren1->pair,
@@ -1304,6 +1300,7 @@ static void handle_delete_modify(struct merge_options *o,
1300 }
1301
1302 static int merge_content(struct merge_options *o,
1303 + unsigned involved_in_rename,
1304 const char *path,
1305 unsigned char *o_sha, int o_mode,
1306 unsigned char *a_sha, int a_mode,
@@ -1344,6 +1341,8 @@ static int merge_content(struct merge_options *o,
1341 reason = "submodule";
1342 output(o, 1, "CONFLICT (%s): Merge conflict in %s",
1343 reason, path);
1344 + if (involved_in_rename)
1345 + update_stages(path, &one, &a, &b);
1346 }
1347
1348 if (df_conflict_remains) {
@@ -1428,7 +1427,7 @@ static int process_entry(struct merge_options *o,
1427 } else if (a_sha && b_sha) {
1428 /* Case C: Added in both (check for same permissions) and */
1429 /* case D: Modified in both, but differently. */
1431 - clean_merge = merge_content(o, path,
1430 + clean_merge = merge_content(o, entry->involved_in_rename, path,
1431 o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
1432 NULL);
1433 } else if (!o_sha && !a_sha && !b_sha) {
@@ -1472,7 +1471,7 @@ static int process_df_entry(struct merge_options *o,
1471 char *src;
1472 switch (conflict_info->rename_type) {
1473 case RENAME_NORMAL:
1475 - clean_merge = merge_content(o, path,
1474 + clean_merge = merge_content(o, entry->involved_in_rename, path,
1475 o_sha, o_mode, a_sha, a_mode, b_sha, b_mode,
1476 conflict_info->branch1);
1477 break;