@@ -64,6 +64,73 @@ static void add_entry(struct unpack_trees_options *o, struct cache_entry *ce,
6464 add_index_entry (& o -> result , new , ADD_CACHE_OK_TO_ADD |ADD_CACHE_OK_TO_REPLACE );
6565}
6666
67+ /*
68+ * add error messages on path <path>
69+ * corresponding to the type <e> with the message <msg>
70+ * indicating if it should be display in porcelain or not
71+ */
72+ static int add_rejected_path (struct unpack_trees_options * o ,
73+ enum unpack_trees_error_types e ,
74+ const char * path )
75+ {
76+ struct rejected_paths_list * newentry ;
77+ int porcelain = o && (o )-> msgs [e ];
78+ /*
79+ * simply display the given error message if in plumbing mode
80+ */
81+ if (!porcelain )
82+ o -> show_all_errors = 0 ;
83+ if (!o -> show_all_errors )
84+ return error (ERRORMSG (o , e ), path );
85+
86+ /*
87+ * Otherwise, insert in a list for future display by
88+ * display_error_msgs()
89+ */
90+ newentry = xmalloc (sizeof (struct rejected_paths_list ));
91+ newentry -> path = (char * )path ;
92+ newentry -> next = o -> unpack_rejects [e ];
93+ o -> unpack_rejects [e ] = newentry ;
94+ return -1 ;
95+ }
96+
97+ /*
98+ * free all the structures allocated for the error <e>
99+ */
100+ static void free_rejected_paths (struct unpack_trees_options * o ,
101+ enum unpack_trees_error_types e )
102+ {
103+ while (o -> unpack_rejects [e ]) {
104+ struct rejected_paths_list * del = o -> unpack_rejects [e ];
105+ o -> unpack_rejects [e ] = o -> unpack_rejects [e ]-> next ;
106+ free (del );
107+ }
108+ free (o -> unpack_rejects [e ]);
109+ }
110+
111+ /*
112+ * display all the error messages stored in a nice way
113+ */
114+ static void display_error_msgs (struct unpack_trees_options * o )
115+ {
116+ int e ;
117+ int something_displayed = 0 ;
118+ for (e = 0 ; e < NB_UNPACK_TREES_ERROR_TYPES ; e ++ ) {
119+ if (o -> unpack_rejects [e ]) {
120+ struct rejected_paths_list * rp ;
121+ struct strbuf path = STRBUF_INIT ;
122+ something_displayed = 1 ;
123+ for (rp = o -> unpack_rejects [e ]; rp ; rp = rp -> next )
124+ strbuf_addf (& path , "\t%s\n" , rp -> path );
125+ error (ERRORMSG (o , e ), path .buf );
126+ strbuf_release (& path );
127+ free_rejected_paths (o , e );
128+ }
129+ }
130+ if (something_displayed )
131+ printf ("Aborting\n" );
132+ }
133+
67134/*
68135 * Unlink the last component and schedule the leading directories for
69136 * removal, such that empty directories get removed.
@@ -755,6 +822,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
755822 setup_traverse_info (& info , prefix );
756823 info .fn = unpack_callback ;
757824 info .data = o ;
825+ info .show_all_errors = o -> show_all_errors ;
758826
759827 if (o -> prefix ) {
760828 /*
@@ -834,6 +902,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
834902 return ret ;
835903
836904return_failed :
905+ if (o -> show_all_errors )
906+ display_error_msgs (o );
837907 mark_all_ce_unused (o -> src_index );
838908 ret = unpack_failed (o , NULL );
839909 goto done ;
@@ -843,7 +913,7 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
843913
844914static int reject_merge (struct cache_entry * ce , struct unpack_trees_options * o )
845915{
846- return error ( ERRORMSG ( o , ERROR_WOULD_OVERWRITE ) , ce -> name );
916+ return add_rejected_path ( o , ERROR_WOULD_OVERWRITE , ce -> name );
847917}
848918
849919static int same (struct cache_entry * a , struct cache_entry * b )
@@ -890,7 +960,7 @@ static int verify_uptodate_1(struct cache_entry *ce,
890960 if (errno == ENOENT )
891961 return 0 ;
892962 return o -> gently ? -1 :
893- error ( ERRORMSG ( o , error_type ) , ce -> name );
963+ add_rejected_path ( o , error_type , ce -> name );
894964}
895965
896966static int verify_uptodate (struct cache_entry * ce ,
@@ -993,7 +1063,7 @@ static int verify_clean_subdirectory(struct cache_entry *ce,
9931063 i = read_directory (& d , pathbuf , namelen + 1 , NULL );
9941064 if (i )
9951065 return o -> gently ? -1 :
996- error ( ERRORMSG ( o , ERROR_NOT_UPTODATE_DIR ) , ce -> name );
1066+ add_rejected_path ( o , ERROR_NOT_UPTODATE_DIR , ce -> name );
9971067 free (pathbuf );
9981068 return cnt ;
9991069}
@@ -1075,7 +1145,7 @@ static int verify_absent_1(struct cache_entry *ce,
10751145 }
10761146
10771147 return o -> gently ? -1 :
1078- error ( ERRORMSG ( o , error_type ) , ce -> name );
1148+ add_rejected_path ( o , error_type , ce -> name );
10791149 }
10801150 return 0 ;
10811151}
0 commit comments