@@ -696,27 +696,6 @@ static int update_stages(struct merge_options *opt, const char *path,
696
696
return 0 ;
697
697
}
698
698
699
- static int update_stages_for_stage_data (struct merge_options * opt ,
700
- const char * path ,
701
- const struct stage_data * stage_data )
702
- {
703
- struct diff_filespec o , a , b ;
704
-
705
- o .mode = stage_data -> stages [1 ].mode ;
706
- oidcpy (& o .oid , & stage_data -> stages [1 ].oid );
707
-
708
- a .mode = stage_data -> stages [2 ].mode ;
709
- oidcpy (& a .oid , & stage_data -> stages [2 ].oid );
710
-
711
- b .mode = stage_data -> stages [3 ].mode ;
712
- oidcpy (& b .oid , & stage_data -> stages [3 ].oid );
713
-
714
- return update_stages (opt , path ,
715
- is_null_oid (& o .oid ) ? NULL : & o ,
716
- is_null_oid (& a .oid ) ? NULL : & a ,
717
- is_null_oid (& b .oid ) ? NULL : & b );
718
- }
719
-
720
699
static void update_entry (struct stage_data * entry ,
721
700
struct diff_filespec * o ,
722
701
struct diff_filespec * a ,
@@ -1870,89 +1849,29 @@ static int handle_rename_rename_2to1(struct merge_options *o,
1870
1849
char * path_side_2_desc ;
1871
1850
struct merge_file_info mfi_c1 ;
1872
1851
struct merge_file_info mfi_c2 ;
1873
- int ret ;
1874
1852
1875
1853
output (o , 1 , _ ("CONFLICT (rename/rename): "
1876
1854
"Rename %s->%s in %s. "
1877
1855
"Rename %s->%s in %s" ),
1878
1856
a -> path , c1 -> path , ci -> branch1 ,
1879
1857
b -> path , c2 -> path , ci -> branch2 );
1880
1858
1881
- remove_file (o , 1 , a -> path , o -> call_depth || would_lose_untracked (a -> path ));
1882
- remove_file (o , 1 , b -> path , o -> call_depth || would_lose_untracked (b -> path ));
1883
-
1884
1859
path_side_1_desc = xstrfmt ("version of %s from %s" , path , a -> path );
1885
1860
path_side_2_desc = xstrfmt ("version of %s from %s" , path , b -> path );
1886
1861
if (merge_mode_and_contents (o , a , c1 , & ci -> ren1_other , path_side_1_desc ,
1887
1862
o -> branch1 , o -> branch2 ,
1888
- o -> call_depth * 2 , & mfi_c1 ) ||
1863
+ 1 + o -> call_depth * 2 , & mfi_c1 ) ||
1889
1864
merge_mode_and_contents (o , b , & ci -> ren2_other , c2 , path_side_2_desc ,
1890
1865
o -> branch1 , o -> branch2 ,
1891
- o -> call_depth * 2 , & mfi_c2 ))
1866
+ 1 + o -> call_depth * 2 , & mfi_c2 ))
1892
1867
return -1 ;
1893
1868
free (path_side_1_desc );
1894
1869
free (path_side_2_desc );
1895
1870
1896
- if (o -> call_depth ) {
1897
- /*
1898
- * If mfi_c1.clean && mfi_c2.clean, then it might make
1899
- * sense to do a two-way merge of those results. But, I
1900
- * think in all cases, it makes sense to have the virtual
1901
- * merge base just undo the renames; they can be detected
1902
- * again later for the non-recursive merge.
1903
- */
1904
- remove_file (o , 0 , path , 0 );
1905
- ret = update_file (o , 0 , & mfi_c1 .oid , mfi_c1 .mode , a -> path );
1906
- if (!ret )
1907
- ret = update_file (o , 0 , & mfi_c2 .oid , mfi_c2 .mode ,
1908
- b -> path );
1909
- } else {
1910
- char * new_path1 = unique_path (o , path , ci -> branch1 );
1911
- char * new_path2 = unique_path (o , path , ci -> branch2 );
1912
- output (o , 1 , _ ("Renaming %s to %s and %s to %s instead" ),
1913
- a -> path , new_path1 , b -> path , new_path2 );
1914
- if (was_dirty (o , path ))
1915
- output (o , 1 , _ ("Refusing to lose dirty file at %s" ),
1916
- path );
1917
- else if (would_lose_untracked (path ))
1918
- /*
1919
- * Only way we get here is if both renames were from
1920
- * a directory rename AND user had an untracked file
1921
- * at the location where both files end up after the
1922
- * two directory renames. See testcase 10d of t6043.
1923
- */
1924
- output (o , 1 , _ ("Refusing to lose untracked file at "
1925
- "%s, even though it's in the way." ),
1926
- path );
1927
- else
1928
- remove_file (o , 0 , path , 0 );
1929
- ret = update_file (o , 0 , & mfi_c1 .oid , mfi_c1 .mode , new_path1 );
1930
- if (!ret )
1931
- ret = update_file (o , 0 , & mfi_c2 .oid , mfi_c2 .mode ,
1932
- new_path2 );
1933
- /*
1934
- * unpack_trees() actually populates the index for us for
1935
- * "normal" rename/rename(2to1) situtations so that the
1936
- * correct entries are at the higher stages, which would
1937
- * make the call below to update_stages_for_stage_data
1938
- * unnecessary. However, if either of the renames came
1939
- * from a directory rename, then unpack_trees() will not
1940
- * have gotten the right data loaded into the index, so we
1941
- * need to do so now. (While it'd be tempting to move this
1942
- * call to update_stages_for_stage_data() to
1943
- * apply_directory_rename_modifications(), that would break
1944
- * our intermediate calls to would_lose_untracked() since
1945
- * those rely on the current in-memory index. See also the
1946
- * big "NOTE" in update_stages()).
1947
- */
1948
- if (update_stages_for_stage_data (o , path , ci -> dst_entry1 ))
1949
- ret = -1 ;
1950
-
1951
- free (new_path2 );
1952
- free (new_path1 );
1953
- }
1954
-
1955
- return ret ;
1871
+ return handle_file_collision (o , path , a -> path , b -> path ,
1872
+ ci -> branch1 , ci -> branch2 ,
1873
+ & mfi_c1 .oid , mfi_c1 .mode ,
1874
+ & mfi_c2 .oid , mfi_c2 .mode );
1956
1875
}
1957
1876
1958
1877
/*
@@ -3361,9 +3280,14 @@ static int process_entry(struct merge_options *o,
3361
3280
clean_merge = -1 ;
3362
3281
break ;
3363
3282
case RENAME_TWO_FILES_TO_ONE :
3364
- clean_merge = 0 ;
3365
- if (handle_rename_rename_2to1 (o , conflict_info ))
3366
- clean_merge = -1 ;
3283
+ /*
3284
+ * Probably unclean merge, but if the two renamed
3285
+ * files merge cleanly and the two resulting files
3286
+ * can then be two-way merged cleanly, I guess it's
3287
+ * a clean merge?
3288
+ */
3289
+ clean_merge = handle_rename_rename_2to1 (o ,
3290
+ conflict_info );
3367
3291
break ;
3368
3292
default :
3369
3293
entry -> processed = 0 ;
0 commit comments