@@ -211,6 +211,7 @@ struct stage_data {
211
211
212
212
struct rename {
213
213
struct diff_filepair * pair ;
214
+ const char * branch ; /* branch that the rename occurred on */
214
215
/*
215
216
* Purpose of src_entry and dst_entry:
216
217
*
@@ -240,16 +241,12 @@ struct rename_conflict_info {
240
241
enum rename_type rename_type ;
241
242
struct rename * ren1 ;
242
243
struct rename * ren2 ;
243
- const char * branch1 ;
244
- const char * branch2 ;
245
244
};
246
245
247
246
static inline void setup_rename_conflict_info (enum rename_type rename_type ,
248
247
struct merge_options * opt ,
249
248
struct rename * ren1 ,
250
- struct rename * ren2 ,
251
- const char * branch1 ,
252
- const char * branch2 )
249
+ struct rename * ren2 )
253
250
{
254
251
struct rename_conflict_info * ci ;
255
252
@@ -260,20 +257,15 @@ static inline void setup_rename_conflict_info(enum rename_type rename_type,
260
257
* ensure that branch1 == opt->branch1. So, simply flip arguments
261
258
* around if we don't have that.
262
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 );
268
262
return ;
269
263
}
270
264
271
265
ci = xcalloc (1 , sizeof (struct rename_conflict_info ));
272
266
ci -> rename_type = rename_type ;
273
267
ci -> ren1 = ren1 ;
274
268
ci -> ren2 = ren2 ;
275
- ci -> branch1 = branch1 ;
276
- ci -> branch2 = branch2 ;
277
269
278
270
ci -> ren1 -> dst_entry -> processed = 0 ;
279
271
ci -> ren1 -> dst_entry -> rename_conflict_info = ci ;
@@ -1665,12 +1657,15 @@ static int handle_rename_add(struct merge_options *opt,
1665
1657
char * prev_path_desc ;
1666
1658
struct merge_file_info mfi ;
1667
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 );
1669
1664
1670
1665
output (opt , 1 , _ ("CONFLICT (rename/add): "
1671
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 );
1674
1669
1675
1670
filespec_from_entry (& tmp , ci -> ren1 -> src_entry , other_stage );
1676
1671
tmp .path = a -> path ;
@@ -1685,7 +1680,7 @@ static int handle_rename_add(struct merge_options *opt,
1685
1680
1686
1681
return handle_file_collision (opt ,
1687
1682
c -> path , a -> path , NULL ,
1688
- ci -> branch1 , ci -> branch2 ,
1683
+ rename_branch , add_branch ,
1689
1684
& mfi .oid , mfi .mode ,
1690
1685
& ci -> ren1 -> dst_entry -> stages [other_stage ].oid ,
1691
1686
ci -> ren1 -> dst_entry -> stages [other_stage ].mode );
@@ -1727,14 +1722,14 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1727
1722
output (opt , 1 , _ ("CONFLICT (rename/rename): "
1728
1723
"Rename \"%s\"->\"%s\" in branch \"%s\" "
1729
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 ,
1732
1727
opt -> call_depth ? _ (" (left unresolved)" ) : "" );
1733
1728
1734
1729
path_desc = xstrfmt ("%s and %s, both renamed from %s" ,
1735
1730
a -> path , b -> path , o -> path );
1736
1731
if (merge_mode_and_contents (opt , o , a , b , path_desc ,
1737
- ci -> branch1 , ci -> branch2 ,
1732
+ ci -> ren1 -> branch , ci -> ren2 -> branch ,
1738
1733
opt -> call_depth * 2 , & mfi ))
1739
1734
return -1 ;
1740
1735
free (path_desc );
@@ -1781,14 +1776,15 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1781
1776
if (add ) {
1782
1777
if (handle_file_collision (opt , a -> path ,
1783
1778
NULL , NULL ,
1784
- ci -> branch1 , ci -> branch2 ,
1779
+ ci -> ren1 -> branch ,
1780
+ ci -> ren2 -> branch ,
1785
1781
& mfi .oid , mfi .mode ,
1786
1782
& add -> oid , add -> mode ) < 0 )
1787
1783
return -1 ;
1788
1784
} else {
1789
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 );
1792
1788
if (update_file (opt , 0 , & mfi .oid , mfi .mode , new_path ? new_path : a -> path ))
1793
1789
return -1 ;
1794
1790
free (new_path );
@@ -1800,14 +1796,15 @@ static int handle_rename_rename_1to2(struct merge_options *opt,
1800
1796
if (add ) {
1801
1797
if (handle_file_collision (opt , b -> path ,
1802
1798
NULL , NULL ,
1803
- ci -> branch1 , ci -> branch2 ,
1799
+ ci -> ren1 -> branch ,
1800
+ ci -> ren2 -> branch ,
1804
1801
& add -> oid , add -> mode ,
1805
1802
& mfi .oid , mfi .mode ) < 0 )
1806
1803
return -1 ;
1807
1804
} else {
1808
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 );
1811
1808
if (update_file (opt , 0 , & mfi .oid , mfi .mode , new_path ? new_path : b -> path ))
1812
1809
return -1 ;
1813
1810
free (new_path );
@@ -1837,8 +1834,8 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
1837
1834
output (opt , 1 , _ ("CONFLICT (rename/rename): "
1838
1835
"Rename %s->%s in %s. "
1839
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 );
1842
1839
1843
1840
filespec_from_entry (& tmp1 , ci -> ren1 -> src_entry , 3 );
1844
1841
tmp1 .path = a -> path ;
@@ -1858,7 +1855,7 @@ static int handle_rename_rename_2to1(struct merge_options *opt,
1858
1855
free (path_side_2_desc );
1859
1856
1860
1857
return handle_file_collision (opt , path , a -> path , b -> path ,
1861
- ci -> branch1 , ci -> branch2 ,
1858
+ ci -> ren1 -> branch , ci -> ren2 -> branch ,
1862
1859
& mfi_c1 .oid , mfi_c1 .mode ,
1863
1860
& mfi_c2 .oid , mfi_c2 .mode );
1864
1861
}
@@ -2542,6 +2539,7 @@ static void apply_directory_rename_modifications(struct merge_options *opt,
2542
2539
* information; tree is always equal to either a_tree or b_tree.
2543
2540
*/
2544
2541
static struct string_list * get_renames (struct merge_options * opt ,
2542
+ const char * branch ,
2545
2543
struct diff_queue_struct * pairs ,
2546
2544
struct hashmap * dir_renames ,
2547
2545
struct hashmap * dir_rename_exclusions ,
@@ -2585,6 +2583,7 @@ static struct string_list *get_renames(struct merge_options *opt,
2585
2583
re -> processed = 0 ;
2586
2584
re -> add_turned_into_rename = 0 ;
2587
2585
re -> pair = pair ;
2586
+ re -> branch = branch ;
2588
2587
item = string_list_lookup (entries , re -> pair -> one -> path );
2589
2588
if (!item )
2590
2589
re -> src_entry = insert_stage_data (re -> pair -> one -> path ,
@@ -2639,7 +2638,6 @@ static int process_renames(struct merge_options *opt,
2639
2638
for (i = 0 , j = 0 ; i < a_renames -> nr || j < b_renames -> nr ;) {
2640
2639
struct string_list * renames1 , * renames2Dst ;
2641
2640
struct rename * ren1 = NULL , * ren2 = NULL ;
2642
- const char * branch1 , * branch2 ;
2643
2641
const char * ren1_src , * ren1_dst ;
2644
2642
struct string_list_item * lookup ;
2645
2643
@@ -2660,13 +2658,9 @@ static int process_renames(struct merge_options *opt,
2660
2658
if (ren1 ) {
2661
2659
renames1 = a_renames ;
2662
2660
renames2Dst = & b_by_dst ;
2663
- branch1 = opt -> branch1 ;
2664
- branch2 = opt -> branch2 ;
2665
2661
} else {
2666
2662
renames1 = b_renames ;
2667
2663
renames2Dst = & a_by_dst ;
2668
- branch1 = opt -> branch2 ;
2669
- branch2 = opt -> branch1 ;
2670
2664
SWAP (ren2 , ren1 );
2671
2665
}
2672
2666
@@ -2706,12 +2700,7 @@ static int process_renames(struct merge_options *opt,
2706
2700
ren1 -> pair -> two ,
2707
2701
ren2 -> pair -> two );
2708
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 );
2715
2704
} else if ((lookup = string_list_lookup (renames2Dst , ren1_dst ))) {
2716
2705
/* Two different files renamed to the same thing */
2717
2706
char * ren2_dst ;
@@ -2730,11 +2719,7 @@ static int process_renames(struct merge_options *opt,
2730
2719
ren2 -> src_entry -> processed = 1 ;
2731
2720
2732
2721
setup_rename_conflict_info (RENAME_TWO_FILES_TO_ONE ,
2733
- opt ,
2734
- ren1 ,
2735
- ren2 ,
2736
- branch1 ,
2737
- branch2 );
2722
+ opt , ren1 , ren2 );
2738
2723
2739
2724
} else {
2740
2725
/* Renamed in 1, maybe changed in 2 */
@@ -2769,18 +2754,10 @@ static int process_renames(struct merge_options *opt,
2769
2754
if (oid_eq (& src_other .oid , & null_oid ) &&
2770
2755
ren1 -> add_turned_into_rename ) {
2771
2756
setup_rename_conflict_info (RENAME_VIA_DIR ,
2772
- opt ,
2773
- ren1 ,
2774
- NULL ,
2775
- branch1 ,
2776
- branch2 );
2757
+ opt , ren1 , NULL );
2777
2758
} else if (oid_eq (& src_other .oid , & null_oid )) {
2778
2759
setup_rename_conflict_info (RENAME_DELETE ,
2779
- opt ,
2780
- ren1 ,
2781
- NULL ,
2782
- branch1 ,
2783
- branch2 );
2760
+ opt , ren1 , NULL );
2784
2761
} else if ((dst_other .mode == ren1 -> pair -> two -> mode ) &&
2785
2762
oid_eq (& dst_other .oid , & ren1 -> pair -> two -> oid )) {
2786
2763
/*
@@ -2807,11 +2784,7 @@ static int process_renames(struct merge_options *opt,
2807
2784
* file, then the merge will be clean.
2808
2785
*/
2809
2786
setup_rename_conflict_info (RENAME_ADD ,
2810
- opt ,
2811
- ren1 ,
2812
- NULL ,
2813
- branch1 ,
2814
- branch2 );
2787
+ opt , ren1 , NULL );
2815
2788
} else
2816
2789
try_merge = 1 ;
2817
2790
@@ -2831,11 +2804,7 @@ static int process_renames(struct merge_options *opt,
2831
2804
}
2832
2805
update_entry (ren1 -> dst_entry , o , a , b );
2833
2806
setup_rename_conflict_info (RENAME_NORMAL ,
2834
- opt ,
2835
- ren1 ,
2836
- NULL ,
2837
- branch1 ,
2838
- NULL );
2807
+ opt , ren1 , NULL );
2839
2808
}
2840
2809
}
2841
2810
}
@@ -2904,13 +2873,13 @@ static int detect_and_process_renames(struct merge_options *opt,
2904
2873
dir_rename_init (dir_re_merge );
2905
2874
}
2906
2875
2907
- ri -> head_renames = get_renames (opt , head_pairs ,
2876
+ ri -> head_renames = get_renames (opt , opt -> branch1 , head_pairs ,
2908
2877
dir_re_merge , dir_re_head , head ,
2909
2878
common , head , merge , entries ,
2910
2879
& clean );
2911
2880
if (clean < 0 )
2912
2881
goto cleanup ;
2913
- ri -> merge_renames = get_renames (opt , merge_pairs ,
2882
+ ri -> merge_renames = get_renames (opt , opt -> branch2 , merge_pairs ,
2914
2883
dir_re_head , dir_re_merge , merge ,
2915
2884
common , head , merge , entries ,
2916
2885
& clean );
@@ -3072,14 +3041,14 @@ static int handle_content_merge(struct merge_options *opt,
3072
3041
if (ci ) {
3073
3042
struct diff_filepair * pair1 = ci -> ren1 -> pair ;
3074
3043
3075
- path1 = (opt -> branch1 == ci -> branch1 ) ?
3044
+ path1 = (opt -> branch1 == ci -> ren1 -> branch ) ?
3076
3045
pair1 -> two -> path : pair1 -> one -> path ;
3077
3046
/* If ci->ren2->pair != NULL, we are in
3078
3047
* RENAME_ONE_FILE_TO_ONE case. Otherwise, we have a
3079
3048
* normal rename.
3080
3049
*/
3081
3050
path2 = ((ci -> ren2 && ci -> ren2 -> pair ) ||
3082
- opt -> branch2 == ci -> branch1 ) ?
3051
+ opt -> branch2 == ci -> ren1 -> branch ) ?
3083
3052
pair1 -> two -> path : pair1 -> one -> path ;
3084
3053
one .path = pair1 -> one -> path ;
3085
3054
a .path = (char * )path1 ;
@@ -3157,7 +3126,7 @@ static int handle_content_merge(struct merge_options *opt,
3157
3126
}
3158
3127
3159
3128
}
3160
- new_path = unique_path (opt , path , ci -> branch1 );
3129
+ new_path = unique_path (opt , path , ci -> ren1 -> branch );
3161
3130
if (is_dirty ) {
3162
3131
output (opt , 1 , _ ("Refusing to lose dirty file at %s" ),
3163
3132
path );
@@ -3215,7 +3184,8 @@ static int process_entry(struct merge_options *opt,
3215
3184
break ;
3216
3185
case RENAME_VIA_DIR :
3217
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 ))
3219
3189
clean_merge = -1 ;
3220
3190
break ;
3221
3191
case RENAME_ADD :
@@ -3230,7 +3200,8 @@ static int process_entry(struct merge_options *opt,
3230
3200
case RENAME_DELETE :
3231
3201
clean_merge = 0 ;
3232
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 ))
3234
3205
clean_merge = -1 ;
3235
3206
break ;
3236
3207
case RENAME_ONE_FILE_TO_TWO :
0 commit comments