@matheusbsbs / matheus-bagliano / commits / 6271d77cb1
Fork 0

unpack-trees: split display_error_msgs() into two

display_error_msgs() is never called to show messages of both ERROR_* and WARNING_* types at the same time; it is instead called multiple times, separately for each type. Since we want to display these types differently, make two slightly different versions of this function. A subsequent commit will further modify unpack_trees() and how it calls the new display_warning_msgs(). Reviewed-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Elijah Newren committed Mar 27, 2020 at 00:48 UTC 6271d77cb1ccfb7e4124593b4463446fe1188cda
3 files changed +49 -13
t/t1091-sparse-checkout-builtin.sh
+2 -2
@@ -328,10 +328,10 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status'
328 echo dirty >dirty/folder1/a &&
329
330 git -C dirty sparse-checkout init 2>err &&
331 - test_i18ngrep "error.*Cannot update sparse checkout" err &&
331 + test_i18ngrep "warning.*Cannot update sparse checkout" err &&
332
333 git -C dirty sparse-checkout set /folder2/* /deep/deeper1/* 2>err &&
334 - test_i18ngrep "error.*Cannot update sparse checkout" err &&
334 + test_i18ngrep "warning.*Cannot update sparse checkout" err &&
335 test_path_is_file dirty/folder1/a &&
336
337 git -C dirty sparse-checkout disable 2>err &&
unpack-trees.c
+42 -8
@@ -24,7 +24,7 @@
24 * situation better. See how "git checkout" and "git merge" replaces
25 * them using setup_unpack_trees_porcelain(), for example.
26 */
27 -static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
27 +static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = {
28 /* ERROR_WOULD_OVERWRITE */
29 "Entry '%s' would be overwritten by merge. Cannot merge.",
30
@@ -46,6 +46,9 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
46 /* ERROR_WOULD_LOSE_SUBMODULE */
47 "Submodule '%s' cannot checkout new HEAD.",
48
49 + /* NB_UNPACK_TREES_ERROR_TYPES; just a meta value */
50 + "",
51 +
52 /* WARNING_SPARSE_NOT_UPTODATE_FILE */
53 "Entry '%s' not uptodate. Cannot update sparse checkout.",
54
@@ -222,7 +225,7 @@ static int add_rejected_path(struct unpack_trees_options *o,
225
226 /*
227 * Otherwise, insert in a list for future display by
225 - * display_error_msgs()
228 + * display_(error|warning)_msgs()
229 */
230 string_list_append(&o->unpack_rejects[e], path);
231 return -1;
@@ -233,13 +236,16 @@ static int add_rejected_path(struct unpack_trees_options *o,
236 */
237 static void display_error_msgs(struct unpack_trees_options *o)
238 {
236 - int e, i;
237 - int something_displayed = 0;
239 + int e;
240 + unsigned error_displayed = 0;
241 for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) {
242 struct string_list *rejects = &o->unpack_rejects[e];
243 +
244 if (rejects->nr > 0) {
245 + int i;
246 struct strbuf path = STRBUF_INIT;
242 - something_displayed = 1;
247 +
248 + error_displayed = 1;
249 for (i = 0; i < rejects->nr; i++)
250 strbuf_addf(&path, "\t%s\n", rejects->items[i].string);
251 error(ERRORMSG(o, e), super_prefixed(path.buf));
@@ -247,10 +253,36 @@ static void display_error_msgs(struct unpack_trees_options *o)
253 }
254 string_list_clear(rejects, 0);
255 }
250 - if (something_displayed)
256 + if (error_displayed)
257 fprintf(stderr, _("Aborting\n"));
258 }
259
260 +/*
261 + * display all the warning messages stored in a nice way
262 + */
263 +static void display_warning_msgs(struct unpack_trees_options *o)
264 +{
265 + int e;
266 + unsigned warning_displayed = 0;
267 + for (e = NB_UNPACK_TREES_ERROR_TYPES + 1;
268 + e < NB_UNPACK_TREES_WARNING_TYPES; e++) {
269 + struct string_list *rejects = &o->unpack_rejects[e];
270 +
271 + if (rejects->nr > 0) {
272 + int i;
273 + struct strbuf path = STRBUF_INIT;
274 +
275 + warning_displayed = 1;
276 + for (i = 0; i < rejects->nr; i++)
277 + strbuf_addf(&path, "\t%s\n", rejects->items[i].string);
278 + warning(ERRORMSG(o, e), super_prefixed(path.buf));
279 + strbuf_release(&path);
280 + }
281 + string_list_clear(rejects, 0);
282 + }
283 + if (warning_displayed)
284 + fprintf(stderr, _("After fixing the above paths, you may want to run `git sparse-checkout reapply`.\n"));
285 +}
286 static int check_submodule_move_head(const struct cache_entry *ce,
287 const char *old_id,
288 const char *new_id,
@@ -1705,8 +1737,10 @@ done:
1737 return ret;
1738
1739 return_failed:
1708 - if (o->show_all_errors)
1740 + if (o->show_all_errors) {
1741 display_error_msgs(o);
1742 + display_warning_msgs(o);
1743 + }
1744 mark_all_ce_unused(o->src_index);
1745 ret = unpack_failed(o, NULL);
1746 if (o->exiting_early)
@@ -1783,7 +1817,7 @@ skip_sparse_checkout:
1817 ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES;
1818
1819 done:
1786 - display_error_msgs(o);
1820 + display_warning_msgs(o);
1821 o->show_all_errors = old_show_all_errors;
1822 if (free_pattern_list)
1823 clear_pattern_list(&pl);
unpack-trees.h
+5 -3
@@ -24,10 +24,12 @@ enum unpack_trees_error_types {
24 ERROR_BIND_OVERLAP,
25 ERROR_WOULD_LOSE_SUBMODULE,
26
27 + NB_UNPACK_TREES_ERROR_TYPES,
28 +
29 WARNING_SPARSE_NOT_UPTODATE_FILE,
30 WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN,
31
30 - NB_UNPACK_TREES_ERROR_TYPES,
32 + NB_UNPACK_TREES_WARNING_TYPES,
33 };
34
35 /*
@@ -66,13 +68,13 @@ struct unpack_trees_options {
68 struct dir_struct *dir;
69 struct pathspec *pathspec;
70 merge_fn_t fn;
69 - const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];
71 + const char *msgs[NB_UNPACK_TREES_WARNING_TYPES];
72 struct argv_array msgs_to_free;
73 /*
74 * Store error messages in an array, each case
75 * corresponding to a error message type
76 */
75 - struct string_list unpack_rejects[NB_UNPACK_TREES_ERROR_TYPES];
77 + struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES];
78
79 int head_idx;
80 int merge_size;