@@ -545,17 +545,35 @@ enum conflict_and_info_types {
545
545
CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE ,
546
546
CONFLICT_SUBMODULE_MAY_HAVE_REWINDS ,
547
547
CONFLICT_SUBMODULE_NULL_MERGE_BASE ,
548
- CONFLICT_SUBMODULE_CORRUPT ,
548
+
549
+ /* INSERT NEW ENTRIES HERE */
550
+
551
+ /*
552
+ * Keep this entry after all regular conflict and info types; only
553
+ * errors (failures causing immediate abort of the merge) should
554
+ * come after this.
555
+ */
556
+ NB_REGULAR_CONFLICT_TYPES ,
557
+
558
+ /*
559
+ * Something is seriously wrong; cannot even perform merge;
560
+ * Keep this group _last_ other than NB_TOTAL_TYPES
561
+ */
562
+ ERROR_SUBMODULE_CORRUPT ,
563
+ ERROR_THREEWAY_CONTENT_MERGE_FAILED ,
564
+ ERROR_OBJECT_WRITE_FAILED ,
565
+ ERROR_OBJECT_READ_FAILED ,
566
+ ERROR_OBJECT_NOT_A_BLOB ,
549
567
550
568
/* Keep this entry _last_ in the list */
551
- NB_CONFLICT_TYPES ,
569
+ NB_TOTAL_TYPES ,
552
570
};
553
571
554
572
/*
555
573
* Short description of conflict type, relied upon by external tools.
556
574
*
557
575
* We can add more entries, but DO NOT change any of these strings. Also,
558
- * Order MUST match conflict_info_and_types.
576
+ * please ensure the order matches what is used in conflict_info_and_types.
559
577
*/
560
578
static const char * type_short_descriptions [] = {
561
579
/*** "Simple" conflicts and informational messages ***/
@@ -599,8 +617,18 @@ static const char *type_short_descriptions[] = {
599
617
"CONFLICT (submodule may have rewinds)" ,
600
618
[CONFLICT_SUBMODULE_NULL_MERGE_BASE ] =
601
619
"CONFLICT (submodule lacks merge base)" ,
602
- [CONFLICT_SUBMODULE_CORRUPT ] =
603
- "CONFLICT (submodule corrupt)"
620
+
621
+ /* Something is seriously wrong; cannot even perform merge */
622
+ [ERROR_SUBMODULE_CORRUPT ] =
623
+ "ERROR (submodule corrupt)" ,
624
+ [ERROR_THREEWAY_CONTENT_MERGE_FAILED ] =
625
+ "ERROR (three-way content merge failed)" ,
626
+ [ERROR_OBJECT_WRITE_FAILED ] =
627
+ "ERROR (object write failed)" ,
628
+ [ERROR_OBJECT_READ_FAILED ] =
629
+ "ERROR (object read failed)" ,
630
+ [ERROR_OBJECT_NOT_A_BLOB ] =
631
+ "ERROR (object is not a blob)" ,
604
632
};
605
633
606
634
struct logical_conflict_info {
@@ -764,7 +792,8 @@ static void path_msg(struct merge_options *opt,
764
792
765
793
/* Sanity checks */
766
794
assert (omittable_hint ==
767
- !starts_with (type_short_descriptions [type ], "CONFLICT" ) ||
795
+ (!starts_with (type_short_descriptions [type ], "CONFLICT" ) &&
796
+ !starts_with (type_short_descriptions [type ], "ERROR" )) ||
768
797
type == CONFLICT_DIR_RENAME_SUGGESTED );
769
798
if (opt -> record_conflict_msgs_as_headers && omittable_hint )
770
799
return ; /* Do not record mere hints in headers */
@@ -1819,9 +1848,9 @@ static int merge_submodule(struct merge_options *opt,
1819
1848
/* check whether both changes are forward */
1820
1849
ret2 = repo_in_merge_bases (& subrepo , commit_o , commit_a );
1821
1850
if (ret2 < 0 ) {
1822
- path_msg (opt , CONFLICT_SUBMODULE_CORRUPT , 0 ,
1851
+ path_msg (opt , ERROR_SUBMODULE_CORRUPT , 0 ,
1823
1852
path , NULL , NULL , NULL ,
1824
- _ ("Failed to merge submodule %s "
1853
+ _ ("error: failed to merge submodule %s "
1825
1854
"(repository corrupt)" ),
1826
1855
path );
1827
1856
ret = -1 ;
@@ -1830,9 +1859,9 @@ static int merge_submodule(struct merge_options *opt,
1830
1859
if (ret2 > 0 )
1831
1860
ret2 = repo_in_merge_bases (& subrepo , commit_o , commit_b );
1832
1861
if (ret2 < 0 ) {
1833
- path_msg (opt , CONFLICT_SUBMODULE_CORRUPT , 0 ,
1862
+ path_msg (opt , ERROR_SUBMODULE_CORRUPT , 0 ,
1834
1863
path , NULL , NULL , NULL ,
1835
- _ ("Failed to merge submodule %s "
1864
+ _ ("error: failed to merge submodule %s "
1836
1865
"(repository corrupt)" ),
1837
1866
path );
1838
1867
ret = -1 ;
@@ -1850,9 +1879,9 @@ static int merge_submodule(struct merge_options *opt,
1850
1879
/* Case #1: a is contained in b or vice versa */
1851
1880
ret2 = repo_in_merge_bases (& subrepo , commit_a , commit_b );
1852
1881
if (ret2 < 0 ) {
1853
- path_msg (opt , CONFLICT_SUBMODULE_CORRUPT , 0 ,
1882
+ path_msg (opt , ERROR_SUBMODULE_CORRUPT , 0 ,
1854
1883
path , NULL , NULL , NULL ,
1855
- _ ("Failed to merge submodule %s "
1884
+ _ ("error: failed to merge submodule %s "
1856
1885
"(repository corrupt)" ),
1857
1886
path );
1858
1887
ret = -1 ;
@@ -1869,9 +1898,9 @@ static int merge_submodule(struct merge_options *opt,
1869
1898
}
1870
1899
ret2 = repo_in_merge_bases (& subrepo , commit_b , commit_a );
1871
1900
if (ret2 < 0 ) {
1872
- path_msg (opt , CONFLICT_SUBMODULE_CORRUPT , 0 ,
1901
+ path_msg (opt , ERROR_SUBMODULE_CORRUPT , 0 ,
1873
1902
path , NULL , NULL , NULL ,
1874
- _ ("Failed to merge submodule %s "
1903
+ _ ("error: failed to merge submodule %s "
1875
1904
"(repository corrupt)" ),
1876
1905
path );
1877
1906
ret = -1 ;
@@ -1903,9 +1932,9 @@ static int merge_submodule(struct merge_options *opt,
1903
1932
& merges );
1904
1933
switch (parent_count ) {
1905
1934
case -1 :
1906
- path_msg (opt , CONFLICT_SUBMODULE_CORRUPT , 0 ,
1935
+ path_msg (opt , ERROR_SUBMODULE_CORRUPT , 0 ,
1907
1936
path , NULL , NULL , NULL ,
1908
- _ ("Failed to merge submodule %s "
1937
+ _ ("error: failed to merge submodule %s "
1909
1938
"(repository corrupt)" ),
1910
1939
path );
1911
1940
ret = -1 ;
@@ -2111,7 +2140,7 @@ static int handle_content_merge(struct merge_options *opt,
2111
2140
* merges, which happens for example with rename/rename(2to1) and
2112
2141
* rename/add conflicts.
2113
2142
*/
2114
- unsigned clean = 1 ;
2143
+ int clean = 1 ;
2115
2144
2116
2145
/*
2117
2146
* handle_content_merge() needs both files to be of the same type, i.e.
@@ -2175,25 +2204,37 @@ static int handle_content_merge(struct merge_options *opt,
2175
2204
pathnames , extra_marker_size ,
2176
2205
& result_buf );
2177
2206
2178
- if ((merge_status < 0 ) || !result_buf .ptr )
2179
- ret = error (_ ("failed to execute internal merge" ));
2207
+ if ((merge_status < 0 ) || !result_buf .ptr ) {
2208
+ path_msg (opt , ERROR_THREEWAY_CONTENT_MERGE_FAILED , 0 ,
2209
+ pathnames [0 ], pathnames [1 ], pathnames [2 ], NULL ,
2210
+ _ ("error: failed to execute internal merge for %s" ),
2211
+ path );
2212
+ ret = -1 ;
2213
+ }
2180
2214
2181
2215
if (!ret &&
2182
2216
write_object_file (result_buf .ptr , result_buf .size ,
2183
- OBJ_BLOB , & result -> oid ))
2184
- ret = error (_ ("unable to add %s to database" ), path );
2185
-
2217
+ OBJ_BLOB , & result -> oid )) {
2218
+ path_msg (opt , ERROR_OBJECT_WRITE_FAILED , 0 ,
2219
+ pathnames [0 ], pathnames [1 ], pathnames [2 ], NULL ,
2220
+ _ ("error: unable to add %s to database" ), path );
2221
+ ret = -1 ;
2222
+ }
2186
2223
free (result_buf .ptr );
2224
+
2187
2225
if (ret )
2188
2226
return -1 ;
2189
- clean &= (merge_status == 0 );
2227
+ if (merge_status > 0 )
2228
+ clean = 0 ;
2190
2229
path_msg (opt , INFO_AUTO_MERGING , 1 , path , NULL , NULL , NULL ,
2191
2230
_ ("Auto-merging %s" ), path );
2192
2231
} else if (S_ISGITLINK (a -> mode )) {
2193
2232
int two_way = ((S_IFMT & o -> mode ) != (S_IFMT & a -> mode ));
2194
2233
clean = merge_submodule (opt , pathnames [0 ],
2195
2234
two_way ? null_oid () : & o -> oid ,
2196
2235
& a -> oid , & b -> oid , & result -> oid );
2236
+ if (clean < 0 )
2237
+ return -1 ;
2197
2238
if (opt -> priv -> call_depth && two_way && !clean ) {
2198
2239
result -> mode = o -> mode ;
2199
2240
oidcpy (& result -> oid , & o -> oid );
@@ -3559,18 +3600,27 @@ static int sort_dirs_next_to_their_children(const char *one, const char *two)
3559
3600
return c1 - c2 ;
3560
3601
}
3561
3602
3562
- static int read_oid_strbuf (const struct object_id * oid ,
3563
- struct strbuf * dst )
3603
+ static int read_oid_strbuf (struct merge_options * opt ,
3604
+ const struct object_id * oid ,
3605
+ struct strbuf * dst ,
3606
+ const char * path )
3564
3607
{
3565
3608
void * buf ;
3566
3609
enum object_type type ;
3567
3610
unsigned long size ;
3568
3611
buf = repo_read_object_file (the_repository , oid , & type , & size );
3569
- if (!buf )
3570
- return error (_ ("cannot read object %s" ), oid_to_hex (oid ));
3612
+ if (!buf ) {
3613
+ path_msg (opt , ERROR_OBJECT_READ_FAILED , 0 ,
3614
+ path , NULL , NULL , NULL ,
3615
+ _ ("error: cannot read object %s" ), oid_to_hex (oid ));
3616
+ return -1 ;
3617
+ }
3571
3618
if (type != OBJ_BLOB ) {
3572
3619
free (buf );
3573
- return error (_ ("object %s is not a blob" ), oid_to_hex (oid ));
3620
+ path_msg (opt , ERROR_OBJECT_NOT_A_BLOB , 0 ,
3621
+ path , NULL , NULL , NULL ,
3622
+ _ ("error: object %s is not a blob" ), oid_to_hex (oid ));
3623
+ return -1 ;
3574
3624
}
3575
3625
strbuf_attach (dst , buf , size , size + 1 );
3576
3626
return 0 ;
@@ -3594,8 +3644,8 @@ static int blob_unchanged(struct merge_options *opt,
3594
3644
if (oideq (& base -> oid , & side -> oid ))
3595
3645
return 1 ;
3596
3646
3597
- if (read_oid_strbuf (& base -> oid , & basebuf ) ||
3598
- read_oid_strbuf (& side -> oid , & sidebuf ))
3647
+ if (read_oid_strbuf (opt , & base -> oid , & basebuf , path ) ||
3648
+ read_oid_strbuf (opt , & side -> oid , & sidebuf , path ))
3599
3649
goto error_return ;
3600
3650
/*
3601
3651
* Note: binary | is used so that both renormalizations are
@@ -4645,6 +4695,7 @@ void merge_display_update_messages(struct merge_options *opt,
4645
4695
struct hashmap_iter iter ;
4646
4696
struct strmap_entry * e ;
4647
4697
struct string_list olist = STRING_LIST_INIT_NODUP ;
4698
+ FILE * o = stdout ;
4648
4699
4649
4700
if (opt -> record_conflict_msgs_as_headers )
4650
4701
BUG ("Either display conflict messages or record them as headers, not both" );
@@ -4661,32 +4712,42 @@ void merge_display_update_messages(struct merge_options *opt,
4661
4712
}
4662
4713
string_list_sort (& olist );
4663
4714
4715
+ /* Print to stderr if we hit errors rather than just conflicts */
4716
+ if (result -> clean < 0 )
4717
+ o = stderr ;
4718
+
4664
4719
/* Iterate over the items, printing them */
4665
4720
for (int path_nr = 0 ; path_nr < olist .nr ; ++ path_nr ) {
4666
4721
struct string_list * conflicts = olist .items [path_nr ].util ;
4667
4722
for (int i = 0 ; i < conflicts -> nr ; i ++ ) {
4668
4723
struct logical_conflict_info * info =
4669
4724
conflicts -> items [i ].util ;
4670
4725
4726
+ /* On failure, ignore regular conflict types */
4727
+ if (result -> clean < 0 &&
4728
+ info -> type < NB_REGULAR_CONFLICT_TYPES )
4729
+ continue ;
4730
+
4671
4731
if (detailed ) {
4672
- printf ( "%lu" , (unsigned long )info -> paths .nr );
4673
- putchar ('\0' );
4732
+ fprintf ( o , "%lu" , (unsigned long )info -> paths .nr );
4733
+ fputc ('\0' , o );
4674
4734
for (int n = 0 ; n < info -> paths .nr ; n ++ ) {
4675
- fputs (info -> paths .v [n ], stdout );
4676
- putchar ('\0' );
4735
+ fputs (info -> paths .v [n ], o );
4736
+ fputc ('\0' , o );
4677
4737
}
4678
- fputs (type_short_descriptions [info -> type ],
4679
- stdout );
4680
- putchar ('\0' );
4738
+ fputs (type_short_descriptions [info -> type ], o );
4739
+ fputc ('\0' , o );
4681
4740
}
4682
- puts (conflicts -> items [i ].string );
4741
+ fputs (conflicts -> items [i ].string , o );
4742
+ fputc ('\n' , o );
4683
4743
if (detailed )
4684
- putchar ('\0' );
4744
+ fputc ('\0' , o );
4685
4745
}
4686
4746
}
4687
4747
string_list_clear (& olist , 0 );
4688
4748
4689
- print_submodule_conflict_suggestion (& opti -> conflicted_submodules );
4749
+ if (result -> clean >= 0 )
4750
+ print_submodule_conflict_suggestion (& opti -> conflicted_submodules );
4690
4751
4691
4752
/* Also include needed rename limit adjustment now */
4692
4753
diff_warn_rename_limit ("merge.renamelimit" ,
@@ -5002,6 +5063,26 @@ static void merge_check_renames_reusable(struct merge_result *result,
5002
5063
5003
5064
/*** Function Grouping: merge_incore_*() and their internal variants ***/
5004
5065
5066
+ static void move_opt_priv_to_result_priv (struct merge_options * opt ,
5067
+ struct merge_result * result )
5068
+ {
5069
+ /*
5070
+ * opt->priv and result->priv are a bit weird. opt->priv contains
5071
+ * information that we can re-use in subsequent merge operations to
5072
+ * enable our cached renames optimization. The best way to provide
5073
+ * that to subsequent merges is putting it in result->priv.
5074
+ * However, putting it directly there would mean retrofitting lots
5075
+ * of functions in this file to also take a merge_result pointer,
5076
+ * which is ugly and annoying. So, we just make sure at the end of
5077
+ * the merge (the outer merge if there are internal recursive ones)
5078
+ * to move it.
5079
+ */
5080
+ assert (opt -> priv && !result -> priv );
5081
+ result -> priv = opt -> priv ;
5082
+ result -> _properly_initialized = RESULT_INITIALIZED ;
5083
+ opt -> priv = NULL ;
5084
+ }
5085
+
5005
5086
/*
5006
5087
* Originally from merge_trees_internal(); heavily adapted, though.
5007
5088
*/
@@ -5032,6 +5113,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
5032
5113
oid_to_hex (& side1 -> object .oid ),
5033
5114
oid_to_hex (& side2 -> object .oid ));
5034
5115
result -> clean = -1 ;
5116
+ move_opt_priv_to_result_priv (opt , result );
5035
5117
return ;
5036
5118
}
5037
5119
trace2_region_leave ("merge" , "collect_merge_info" , opt -> repo );
@@ -5062,11 +5144,8 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
5062
5144
/* existence of conflicted entries implies unclean */
5063
5145
result -> clean &= strmap_empty (& opt -> priv -> conflicted );
5064
5146
}
5065
- if (!opt -> priv -> call_depth ) {
5066
- result -> priv = opt -> priv ;
5067
- result -> _properly_initialized = RESULT_INITIALIZED ;
5068
- opt -> priv = NULL ;
5069
- }
5147
+ if (!opt -> priv -> call_depth || result -> clean < 0 )
5148
+ move_opt_priv_to_result_priv (opt , result );
5070
5149
}
5071
5150
5072
5151
/*
0 commit comments