merge-recursive: track branch where rename occurred in rename struct

We previously tracked the branch associated with a rename in a separate field in rename_conflict_info, but since it is directly associated with the rename it makes more sense to move it into the rename struct. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Apr 5, 2019 at 08:00 UTC c336ab859347036eb5d538a9bd741fb9a95da36a
1 file changed +42 -71
merge-recursive.c
+42 -71
@@ -211,6 +211,7 @@ struct stage_data {
211
212 struct rename {
213 struct diff_filepair *pair;
214 + const char *branch; /* branch that the rename occurred on */
215 /*
216 * Purpose of src_entry and dst_entry:
217 *
@@ -240,16 +241,12 @@ struct rename_conflict_info {
241 enum rename_type rename_type;
242 struct rename *ren1;
243 struct rename *ren2;
243 - const char *branch1;
244 - const char *branch2;
244 };
245
246 static inline void setup_rename_conflict_info(enum rename_type rename_type,
247 struct merge_options *opt,
248 struct rename *ren1,
250 - struct rename *ren2,
251 - const char *branch1,
252 - const char *branch2)
249 + struct rename *ren2)
250 {
251 struct rename_conflict_info *ci;
252
@@ -260,11 +257,8 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
257 * ensure that branch1 == opt->branch1. So, simply flip arguments
258 * around if we don't have that.
259 */
263 - if (ren2 && branch1 != opt->branch1) {
264 - setup_rename_conflict_info(rename_type,
265 - opt,
266 - ren2, ren1,
267 - branch2, branch1);
260 + if (ren2 && ren1->branch != opt->branch1) {
261 + setup_rename_conflict_info(rename_type, opt, ren2, ren1);
262 return;
263 }
264
@@ -272,8 +266,6 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
266 ci->rename_type = rename_type;
267 ci->ren1 = ren1;
268 ci->ren2 = ren2;
275 - ci->branch1 = branch1;
276 - ci->branch2 = branch2;
269
270 ci->ren1->dst_entry->processed = 0;
271 ci->ren1->dst_entry->rename_conflict_info = ci;
@@ -1665,12 +1657,15 @@ static int handle_rename_add(struct merge_options *opt,
1657 char *prev_path_desc;
1658 struct merge_file_info mfi;
1659
1668 - int other_stage = (ci->branch1 == opt->branch1 ? 3 : 2);
1660 + const char *rename_branch = ci->ren1->branch;
1661 + const char *add_branch = (opt->branch1 == rename_branch ?
1662 + opt->branch2 : opt->branch1);
1663 + int other_stage = (ci->ren1->branch == opt->branch1 ? 3 : 2);
1664
1665 output(opt, 1, _("CONFLICT (rename/add): "
1666 "Rename %s->%s in %s. Added %s in %s"),
1672 - a->path, c->path, ci->branch1,
1673 - c->path, ci->branch2);
1667 + a->path, c->path, rename_branch,
1668 + c->path, add_branch);
1669
1670 filespec_from_entry(&tmp, ci->ren1->src_entry, other_stage);
1671 tmp.path = a->path;
@@ -1685,7 +1680,7 @@ static int handle_rename_add(struct merge_options *opt,
1680
1681 return handle_file_collision(opt,
1682 c->path, a->path, NULL,
1688 - ci->branch1, ci->branch2,
1683 + rename_branch, add_branch,
1684 &mfi.oid, mfi.mode,
1685 &ci->ren1->dst_entry->stages[other_stage].oid,
1686 ci->ren1->dst_entry->stages[other_stage].mode);
@@ -1727,14 +1722,14 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1722 output(opt, 1, _("CONFLICT (rename/rename): "
1723 "Rename \"%s\"->\"%s\" in branch \"%s\" "
1724 "rename \"%s\"->\"%s\" in \"%s\"%s"),
1730 - o->path, a->path, ci->branch1,
1731 - o->path, b->path, ci->branch2,
1725 + o->path, a->path, ci->ren1->branch,
1726 + o->path, b->path, ci->ren2->branch,
1727 opt->call_depth ? _(" (left unresolved)") : "");
1728
1729 path_desc = xstrfmt("%s and %s, both renamed from %s",
1730 a->path, b->path, o->path);
1731 if (merge_mode_and_contents(opt, o, a, b, path_desc,
1737 - ci->branch1, ci->branch2,
1732 + ci->ren1->branch, ci->ren2->branch,
1733 opt->call_depth * 2, &mfi))
1734 return -1;
1735 free(path_desc);
@@ -1781,14 +1776,15 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1776 if (add) {
1777 if (handle_file_collision(opt, a->path,
1778 NULL, NULL,
1784 - ci->branch1, ci->branch2,
1779 + ci->ren1->branch,
1780 + ci->ren2->branch,
1781 &mfi.oid, mfi.mode,
1782 &add->oid, add->mode) < 0)
1783 return -1;
1784 } else {
1785 char *new_path = find_path_for_conflict(opt, a->path,
1790 - ci->branch1,
1791 - ci->branch2);
1786 + ci->ren1->branch,
1787 + ci->ren2->branch);
1788 if (update_file(opt, 0, &mfi.oid, mfi.mode, new_path ? new_path : a->path))
1789 return -1;
1790 free(new_path);
@@ -1800,14 +1796,15 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1796 if (add) {
1797 if (handle_file_collision(opt, b->path,
1798 NULL, NULL,
1803 - ci->branch1, ci->branch2,
1799 + ci->ren1->branch,
1800 + ci->ren2->branch,
1801 &add->oid, add->mode,
1802 &mfi.oid, mfi.mode) < 0)
1803 return -1;
1804 } else {
1805 char *new_path = find_path_for_conflict(opt, b->path,
1809 - ci->branch2,
1810 - ci->branch1);
1806 + ci->ren2->branch,
1807 + ci->ren1->branch);
1808 if (update_file(opt, 0, &mfi.oid, mfi.mode, new_path ? new_path : b->path))
1809 return -1;
1810 free(new_path);
@@ -1837,8 +1834,8 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
1834 output(opt, 1, _("CONFLICT (rename/rename): "
1835 "Rename %s->%s in %s. "
1836 "Rename %s->%s in %s"),
1840 - a->path, c1->path, ci->branch1,
1841 - b->path, c2->path, ci->branch2);
1837 + a->path, c1->path, ci->ren1->branch,
1838 + b->path, c2->path, ci->ren2->branch);
1839
1840 filespec_from_entry(&tmp1, ci->ren1->src_entry, 3);
1841 tmp1.path = a->path;
@@ -1858,7 +1855,7 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
1855 free(path_side_2_desc);
1856
1857 return handle_file_collision(opt, path, a->path, b->path,
1861 - ci->branch1, ci->branch2,
1858 + ci->ren1->branch, ci->ren2->branch,
1859 &mfi_c1.oid, mfi_c1.mode,
1860 &mfi_c2.oid, mfi_c2.mode);
1861 }
@@ -2542,6 +2539,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
2539 * information; tree is always equal to either a_tree or b_tree.
2540 */
2541 static struct string_list *get_renames(struct merge_options *opt,
2542 + const char *branch,
2543 struct diff_queue_struct *pairs,
2544 struct hashmap *dir_renames,
2545 struct hashmap *dir_rename_exclusions,
@@ -2585,6 +2583,7 @@ static struct string_list *get_renames(struct merge_options *opt,
2583 re->processed = 0;
2584 re->add_turned_into_rename = 0;
2585 re->pair = pair;
2586 + re->branch = branch;
2587 item = string_list_lookup(entries, re->pair->one->path);
2588 if (!item)
2589 re->src_entry = insert_stage_data(re->pair->one->path,
@@ -2639,7 +2638,6 @@ static int process_renames(struct merge_options *opt,
2638 for (i = 0, j = 0; i < a_renames->nr || j < b_renames->nr;) {
2639 struct string_list *renames1, *renames2Dst;
2640 struct rename *ren1 = NULL, *ren2 = NULL;
2642 - const char *branch1, *branch2;
2641 const char *ren1_src, *ren1_dst;
2642 struct string_list_item *lookup;
2643
@@ -2660,13 +2658,9 @@ static int process_renames(struct merge_options *opt,
2658 if (ren1) {
2659 renames1 = a_renames;
2660 renames2Dst = &b_by_dst;
2663 - branch1 = opt->branch1;
2664 - branch2 = opt->branch2;
2661 } else {
2662 renames1 = b_renames;
2663 renames2Dst = &a_by_dst;
2668 - branch1 = opt->branch2;
2669 - branch2 = opt->branch1;
2664 SWAP(ren2, ren1);
2665 }
2666
@@ -2706,12 +2700,7 @@ static int process_renames(struct merge_options *opt,
2700 ren1->pair->two,
2701 ren2->pair->two);
2702 }
2709 - setup_rename_conflict_info(rename_type,
2710 - opt,
2711 - ren1,
2712 - ren2,
2713 - branch1,
2714 - branch2);
2703 + setup_rename_conflict_info(rename_type, opt, ren1, ren2);
2704 } else if ((lookup = string_list_lookup(renames2Dst, ren1_dst))) {
2705 /* Two different files renamed to the same thing */
2706 char *ren2_dst;
@@ -2730,11 +2719,7 @@ static int process_renames(struct merge_options *opt,
2719 ren2->src_entry->processed = 1;
2720
2721 setup_rename_conflict_info(RENAME_TWO_FILES_TO_ONE,
2733 - opt,
2734 - ren1,
2735 - ren2,
2736 - branch1,
2737 - branch2);
2722 + opt, ren1, ren2);
2723
2724 } else {
2725 /* Renamed in 1, maybe changed in 2 */
@@ -2769,18 +2754,10 @@ static int process_renames(struct merge_options *opt,
2754 if (oid_eq(&src_other.oid, &null_oid) &&
2755 ren1->add_turned_into_rename) {
2756 setup_rename_conflict_info(RENAME_VIA_DIR,
2772 - opt,
2773 - ren1,
2774 - NULL,
2775 - branch1,
2776 - branch2);
2757 + opt, ren1, NULL);
2758 } else if (oid_eq(&src_other.oid, &null_oid)) {
2759 setup_rename_conflict_info(RENAME_DELETE,
2779 - opt,
2780 - ren1,
2781 - NULL,
2782 - branch1,
2783 - branch2);
2760 + opt, ren1, NULL);
2761 } else if ((dst_other.mode == ren1->pair->two->mode) &&
2762 oid_eq(&dst_other.oid, &ren1->pair->two->oid)) {
2763 /*
@@ -2807,11 +2784,7 @@ static int process_renames(struct merge_options *opt,
2784 * file, then the merge will be clean.
2785 */
2786 setup_rename_conflict_info(RENAME_ADD,
2810 - opt,
2811 - ren1,
2812 - NULL,
2813 - branch1,
2814 - branch2);
2787 + opt, ren1, NULL);
2788 } else
2789 try_merge = 1;
2790
@@ -2831,11 +2804,7 @@ static int process_renames(struct merge_options *opt,
2804 }
2805 update_entry(ren1->dst_entry, o, a, b);
2806 setup_rename_conflict_info(RENAME_NORMAL,
2834 - opt,
2835 - ren1,
2836 - NULL,
2837 - branch1,
2838 - NULL);
2807 + opt, ren1, NULL);
2808 }
2809 }
2810 }
@@ -2904,13 +2873,13 @@ static int detect_and_process_renames(struct merge_options *opt,
2873 dir_rename_init(dir_re_merge);
2874 }
2875
2907 - ri->head_renames = get_renames(opt, head_pairs,
2876 + ri->head_renames = get_renames(opt, opt->branch1, head_pairs,
2877 dir_re_merge, dir_re_head, head,
2878 common, head, merge, entries,
2879 &clean);
2880 if (clean < 0)
2881 goto cleanup;
2913 - ri->merge_renames = get_renames(opt, merge_pairs,
2882 + ri->merge_renames = get_renames(opt, opt->branch2, merge_pairs,
2883 dir_re_head, dir_re_merge, merge,
2884 common, head, merge, entries,
2885 &clean);
@@ -3072,14 +3041,14 @@ static int handle_content_merge(struct merge_options *opt,
3041 if (ci) {
3042 struct diff_filepair *pair1 = ci->ren1->pair;
3043
3075 - path1 = (opt->branch1 == ci->branch1) ?
3044 + path1 = (opt->branch1 == ci->ren1->branch) ?
3045 pair1->two->path : pair1->one->path;
3046 /* If ci->ren2->pair != NULL, we are in
3047 * RENAME_ONE_FILE_TO_ONE case. Otherwise, we have a
3048 * normal rename.
3049 */
3050 path2 = ((ci->ren2 && ci->ren2->pair) ||
3082 - opt->branch2 == ci->branch1) ?
3051 + opt->branch2 == ci->ren1->branch) ?
3052 pair1->two->path : pair1->one->path;
3053 one.path = pair1->one->path;
3054 a.path = (char *)path1;
@@ -3157,7 +3126,7 @@ static int handle_content_merge(struct merge_options *opt,
3126 }
3127
3128 }
3160 - new_path = unique_path(opt, path, ci->branch1);
3129 + new_path = unique_path(opt, path, ci->ren1->branch);
3130 if (is_dirty) {
3131 output(opt, 1, _("Refusing to lose dirty file at %s"),
3132 path);
@@ -3215,7 +3184,8 @@ static int process_entry(struct merge_options *opt,
3184 break;
3185 case RENAME_VIA_DIR:
3186 clean_merge = 1;
3218 - if (handle_rename_via_dir(opt, ci->ren1->pair, ci->branch1))
3187 + if (handle_rename_via_dir(opt, ci->ren1->pair,
3188 + ci->ren1->branch))
3189 clean_merge = -1;
3190 break;
3191 case RENAME_ADD:
@@ -3230,7 +3200,8 @@ static int process_entry(struct merge_options *opt,
3200 case RENAME_DELETE:
3201 clean_merge = 0;
3202 if (handle_rename_delete(opt, ci->ren1->pair,
3233 - ci->branch1, ci->branch2))
3203 + ci->ren1->branch,
3204 + ci->ren1->branch == opt->branch1 ? opt->branch2 : opt->branch1))
3205 clean_merge = -1;
3206 break;
3207 case RENAME_ONE_FILE_TO_TWO: