merge-recursive: shrink rename_conflict_info

The rename_conflict_info struct used both a pair and a stage_data which were taken from a rename struct. Just use the original rename struct. This will also allow us to start making other simplifications to the code. 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 e9cd1b5ca4438769c369126f1d9f963fc93bb471
1 file changed +50 -70
merge-recursive.c
+50 -70
@@ -238,24 +238,20 @@ struct rename {
238
239 struct rename_conflict_info {
240 enum rename_type rename_type;
241 - struct diff_filepair *pair1;
242 - struct diff_filepair *pair2;
241 + struct rename *ren1;
242 + struct rename *ren2;
243 const char *branch1;
244 const char *branch2;
245 - struct stage_data *dst_entry1;
246 - struct stage_data *dst_entry2;
245 struct diff_filespec ren1_other;
246 struct diff_filespec ren2_other;
247 };
248
249 static inline void setup_rename_conflict_info(enum rename_type rename_type,
252 - struct diff_filepair *pair1,
253 - struct diff_filepair *pair2,
250 + struct merge_options *opt,
251 + struct rename *ren1,
252 + struct rename *ren2,
253 const char *branch1,
254 const char *branch2,
256 - struct stage_data *dst_entry1,
257 - struct stage_data *dst_entry2,
258 - struct merge_options *opt,
255 struct stage_data *src_entry1,
256 struct stage_data *src_entry2)
257 {
@@ -269,31 +265,27 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
265 * ensure that branch1 == opt->branch1. So, simply flip arguments
266 * around if we don't have that.
267 */
272 - if (dst_entry2 && branch1 != opt->branch1) {
268 + if (ren2 && branch1 != opt->branch1) {
269 setup_rename_conflict_info(rename_type,
274 - pair2, pair1,
275 - branch2, branch1,
276 - dst_entry2, dst_entry1,
270 opt,
271 + ren2, ren1,
272 + branch2, branch1,
273 src_entry2, src_entry1);
274 return;
275 }
276
277 ci = xcalloc(1, sizeof(struct rename_conflict_info));
278 ci->rename_type = rename_type;
284 - ci->pair1 = pair1;
279 + ci->ren1 = ren1;
280 + ci->ren2 = ren2;
281 ci->branch1 = branch1;
282 ci->branch2 = branch2;
283
288 - ci->dst_entry1 = dst_entry1;
289 - dst_entry1->rename_conflict_info = ci;
290 - dst_entry1->processed = 0;
284 + ci->ren1->dst_entry->processed = 0;
285 + ci->ren1->dst_entry->rename_conflict_info = ci;
286
292 - assert(!pair2 == !dst_entry2);
293 - if (dst_entry2) {
294 - ci->dst_entry2 = dst_entry2;
295 - ci->pair2 = pair2;
296 - dst_entry2->rename_conflict_info = ci;
287 + if (ren2) {
288 + ci->ren2->dst_entry->rename_conflict_info = ci;
289 }
290
291 /*
@@ -305,7 +297,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
297 rename_type == RENAME_TWO_FILES_TO_ONE) {
298 ostage1 = opt->branch1 == branch1 ? 3 : 2;
299
308 - ci->ren1_other.path = pair1->one->path;
300 + ci->ren1_other.path = ren1->pair->one->path;
301 oidcpy(&ci->ren1_other.oid, &src_entry1->stages[ostage1].oid);
302 ci->ren1_other.mode = src_entry1->stages[ostage1].mode;
303 }
@@ -313,7 +305,7 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
305 if (rename_type == RENAME_TWO_FILES_TO_ONE) {
306 ostage2 = ostage1 ^ 1;
307
316 - ci->ren2_other.path = pair2->one->path;
308 + ci->ren2_other.path = ren2->pair->one->path;
309 oidcpy(&ci->ren2_other.oid, &src_entry2->stages[ostage2].oid);
310 ci->ren2_other.mode = src_entry2->stages[ostage2].mode;
311 }
@@ -1694,8 +1686,8 @@ static int handle_rename_add(struct merge_options *opt,
1686 struct rename_conflict_info *ci)
1687 {
1688 /* a was renamed to c, and a separate c was added. */
1697 - struct diff_filespec *a = ci->pair1->one;
1698 - struct diff_filespec *c = ci->pair1->two;
1689 + struct diff_filespec *a = ci->ren1->pair->one;
1690 + struct diff_filespec *c = ci->ren1->pair->two;
1691 char *path = c->path;
1692 char *prev_path_desc;
1693 struct merge_file_info mfi;
@@ -1718,8 +1710,8 @@ static int handle_rename_add(struct merge_options *opt,
1710 c->path, a->path, NULL,
1711 ci->branch1, ci->branch2,
1712 &mfi.oid, mfi.mode,
1721 - &ci->dst_entry1->stages[other_stage].oid,
1722 - ci->dst_entry1->stages[other_stage].mode);
1713 + &ci->ren1->dst_entry->stages[other_stage].oid,
1714 + ci->ren1->dst_entry->stages[other_stage].mode);
1715 }
1716
1717 static char *find_path_for_conflict(struct merge_options *opt,
@@ -1750,9 +1742,9 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1742 struct merge_file_info mfi;
1743 struct diff_filespec other;
1744 struct diff_filespec *add;
1753 - struct diff_filespec *o = ci->pair1->one;
1754 - struct diff_filespec *a = ci->pair1->two;
1755 - struct diff_filespec *b = ci->pair2->two;
1745 + struct diff_filespec *o = ci->ren1->pair->one;
1746 + struct diff_filespec *a = ci->ren1->pair->two;
1747 + struct diff_filespec *b = ci->ren2->pair->two;
1748 char *path_desc;
1749
1750 output(opt, 1, _("CONFLICT (rename/rename): "
@@ -1788,14 +1780,14 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1780 * such cases, we should keep the added file around,
1781 * resolving the conflict at that path in its favor.
1782 */
1791 - add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
1783 + add = filespec_from_entry(&other, ci->ren1->dst_entry, 2 ^ 1);
1784 if (add) {
1785 if (update_file(opt, 0, &add->oid, add->mode, a->path))
1786 return -1;
1787 }
1788 else
1789 remove_file_from_index(opt->repo->index, a->path);
1798 - add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
1790 + add = filespec_from_entry(&other, ci->ren2->dst_entry, 3 ^ 1);
1791 if (add) {
1792 if (update_file(opt, 0, &add->oid, add->mode, b->path))
1793 return -1;
@@ -1808,7 +1800,7 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1800 * rename/add collision. If not, we can write the file out
1801 * to the specified location.
1802 */
1811 - add = filespec_from_entry(&other, ci->dst_entry1, 2 ^ 1);
1803 + add = filespec_from_entry(&other, ci->ren1->dst_entry, 2 ^ 1);
1804 if (add) {
1805 if (handle_file_collision(opt, a->path,
1806 NULL, NULL,
@@ -1827,7 +1819,7 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1819 return -1;
1820 }
1821
1830 - add = filespec_from_entry(&other, ci->dst_entry2, 3 ^ 1);
1822 + add = filespec_from_entry(&other, ci->ren2->dst_entry, 3 ^ 1);
1823 if (add) {
1824 if (handle_file_collision(opt, b->path,
1825 NULL, NULL,
@@ -1854,10 +1846,10 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
1846 struct rename_conflict_info *ci)
1847 {
1848 /* Two files, a & b, were renamed to the same thing, c. */
1857 - struct diff_filespec *a = ci->pair1->one;
1858 - struct diff_filespec *b = ci->pair2->one;
1859 - struct diff_filespec *c1 = ci->pair1->two;
1860 - struct diff_filespec *c2 = ci->pair2->two;
1849 + struct diff_filespec *a = ci->ren1->pair->one;
1850 + struct diff_filespec *b = ci->ren2->pair->one;
1851 + struct diff_filespec *c1 = ci->ren1->pair->two;
1852 + struct diff_filespec *c2 = ci->ren2->pair->two;
1853 char *path = c1->path; /* == c2->path */
1854 char *path_side_1_desc;
1855 char *path_side_2_desc;
@@ -2732,13 +2724,11 @@ static int process_renames(struct merge_options *opt,
2724 ren2->pair->two);
2725 }
2726 setup_rename_conflict_info(rename_type,
2735 - ren1->pair,
2736 - ren2->pair,
2727 + opt,
2728 + ren1,
2729 + ren2,
2730 branch1,
2731 branch2,
2739 - ren1->dst_entry,
2740 - ren2->dst_entry,
2741 - opt,
2732 NULL,
2733 NULL);
2734 } else if ((lookup = string_list_lookup(renames2Dst, ren1_dst))) {
@@ -2759,13 +2749,11 @@ static int process_renames(struct merge_options *opt,
2749 ren2->src_entry->processed = 1;
2750
2751 setup_rename_conflict_info(RENAME_TWO_FILES_TO_ONE,
2762 - ren1->pair,
2763 - ren2->pair,
2752 + opt,
2753 + ren1,
2754 + ren2,
2755 branch1,
2756 branch2,
2766 - ren1->dst_entry,
2767 - ren2->dst_entry,
2768 - opt,
2757 ren1->src_entry,
2758 ren2->src_entry);
2759
@@ -2802,24 +2790,20 @@ static int process_renames(struct merge_options *opt,
2790 if (oid_eq(&src_other.oid, &null_oid) &&
2791 ren1->add_turned_into_rename) {
2792 setup_rename_conflict_info(RENAME_VIA_DIR,
2805 - ren1->pair,
2793 + opt,
2794 + ren1,
2795 NULL,
2796 branch1,
2797 branch2,
2809 - ren1->dst_entry,
2810 - NULL,
2811 - opt,
2798 NULL,
2799 NULL);
2800 } else if (oid_eq(&src_other.oid, &null_oid)) {
2801 setup_rename_conflict_info(RENAME_DELETE,
2816 - ren1->pair,
2802 + opt,
2803 + ren1,
2804 NULL,
2805 branch1,
2806 branch2,
2820 - ren1->dst_entry,
2821 - NULL,
2822 - opt,
2807 NULL,
2808 NULL);
2809 } else if ((dst_other.mode == ren1->pair->two->mode) &&
@@ -2848,13 +2832,11 @@ static int process_renames(struct merge_options *opt,
2832 * file, then the merge will be clean.
2833 */
2834 setup_rename_conflict_info(RENAME_ADD,
2851 - ren1->pair,
2835 + opt,
2836 + ren1,
2837 NULL,
2838 branch1,
2839 branch2,
2855 - ren1->dst_entry,
2856 - NULL,
2857 - opt,
2840 ren1->src_entry,
2841 NULL);
2842 } else
@@ -2876,13 +2858,11 @@ static int process_renames(struct merge_options *opt,
2858 }
2859 update_entry(ren1->dst_entry, o, a, b);
2860 setup_rename_conflict_info(RENAME_NORMAL,
2879 - ren1->pair,
2861 + opt,
2862 + ren1,
2863 NULL,
2864 branch1,
2865 NULL,
2883 - ren1->dst_entry,
2884 - NULL,
2885 - opt,
2866 NULL,
2867 NULL);
2868 }
@@ -3119,15 +3099,15 @@ static int handle_content_merge(struct merge_options *opt,
3099 b.mode = b_mode;
3100
3101 if (ci) {
3122 - struct diff_filepair *pair1 = ci->pair1;
3102 + struct diff_filepair *pair1 = ci->ren1->pair;
3103
3104 path1 = (opt->branch1 == ci->branch1) ?
3105 pair1->two->path : pair1->one->path;
3126 - /* If ci->pair2 != NULL, we are in
3106 + /* If ci->ren2->pair != NULL, we are in
3107 * RENAME_ONE_FILE_TO_ONE case. Otherwise, we have a
3108 * normal rename.
3109 */
3130 - path2 = (ci->pair2 ||
3110 + path2 = ((ci->ren2 && ci->ren2->pair) ||
3111 opt->branch2 == ci->branch1) ?
3112 pair1->two->path : pair1->one->path;
3113 one.path = pair1->one->path;
@@ -3264,7 +3244,7 @@ static int process_entry(struct merge_options *opt,
3244 break;
3245 case RENAME_VIA_DIR:
3246 clean_merge = 1;
3267 - if (handle_rename_via_dir(opt, ci->pair1, ci->branch1))
3247 + if (handle_rename_via_dir(opt, ci->ren1->pair, ci->branch1))
3248 clean_merge = -1;
3249 break;
3250 case RENAME_ADD:
@@ -3278,7 +3258,7 @@ static int process_entry(struct merge_options *opt,
3258 break;
3259 case RENAME_DELETE:
3260 clean_merge = 0;
3281 - if (handle_rename_delete(opt, ci->pair1,
3261 + if (handle_rename_delete(opt, ci->ren1->pair,
3262 ci->branch1, ci->branch2))
3263 clean_merge = -1;
3264 break;