Skip to content

Commit 6271d77

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1ac83f4 commit 6271d77

File tree

3 files changed

+49
-13
lines changed

3 files changed

+49
-13
lines changed

t/t1091-sparse-checkout-builtin.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,10 +328,10 @@ test_expect_success 'sparse-checkout (init|set|disable) warns with dirty status'
328328
echo dirty >dirty/folder1/a &&
329329
330330
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 &&
332332
333333
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 &&
335335
test_path_is_file dirty/folder1/a &&
336336
337337
git -C dirty sparse-checkout disable 2>err &&

unpack-trees.c

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
* situation better. See how "git checkout" and "git merge" replaces
2525
* them using setup_unpack_trees_porcelain(), for example.
2626
*/
27-
static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
27+
static const char *unpack_plumbing_errors[NB_UNPACK_TREES_WARNING_TYPES] = {
2828
/* ERROR_WOULD_OVERWRITE */
2929
"Entry '%s' would be overwritten by merge. Cannot merge.",
3030

@@ -46,6 +46,9 @@ static const char *unpack_plumbing_errors[NB_UNPACK_TREES_ERROR_TYPES] = {
4646
/* ERROR_WOULD_LOSE_SUBMODULE */
4747
"Submodule '%s' cannot checkout new HEAD.",
4848

49+
/* NB_UNPACK_TREES_ERROR_TYPES; just a meta value */
50+
"",
51+
4952
/* WARNING_SPARSE_NOT_UPTODATE_FILE */
5053
"Entry '%s' not uptodate. Cannot update sparse checkout.",
5154

@@ -222,7 +225,7 @@ static int add_rejected_path(struct unpack_trees_options *o,
222225

223226
/*
224227
* Otherwise, insert in a list for future display by
225-
* display_error_msgs()
228+
* display_(error|warning)_msgs()
226229
*/
227230
string_list_append(&o->unpack_rejects[e], path);
228231
return -1;
@@ -233,24 +236,53 @@ static int add_rejected_path(struct unpack_trees_options *o,
233236
*/
234237
static void display_error_msgs(struct unpack_trees_options *o)
235238
{
236-
int e, i;
237-
int something_displayed = 0;
239+
int e;
240+
unsigned error_displayed = 0;
238241
for (e = 0; e < NB_UNPACK_TREES_ERROR_TYPES; e++) {
239242
struct string_list *rejects = &o->unpack_rejects[e];
243+
240244
if (rejects->nr > 0) {
245+
int i;
241246
struct strbuf path = STRBUF_INIT;
242-
something_displayed = 1;
247+
248+
error_displayed = 1;
243249
for (i = 0; i < rejects->nr; i++)
244250
strbuf_addf(&path, "\t%s\n", rejects->items[i].string);
245251
error(ERRORMSG(o, e), super_prefixed(path.buf));
246252
strbuf_release(&path);
247253
}
248254
string_list_clear(rejects, 0);
249255
}
250-
if (something_displayed)
256+
if (error_displayed)
251257
fprintf(stderr, _("Aborting\n"));
252258
}
253259

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+
}
254286
static int check_submodule_move_head(const struct cache_entry *ce,
255287
const char *old_id,
256288
const char *new_id,
@@ -1705,8 +1737,10 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options
17051737
return ret;
17061738

17071739
return_failed:
1708-
if (o->show_all_errors)
1740+
if (o->show_all_errors) {
17091741
display_error_msgs(o);
1742+
display_warning_msgs(o);
1743+
}
17101744
mark_all_ce_unused(o->src_index);
17111745
ret = unpack_failed(o, NULL);
17121746
if (o->exiting_early)
@@ -1783,7 +1817,7 @@ enum update_sparsity_result update_sparsity(struct unpack_trees_options *o)
17831817
ret = UPDATE_SPARSITY_WORKTREE_UPDATE_FAILURES;
17841818

17851819
done:
1786-
display_error_msgs(o);
1820+
display_warning_msgs(o);
17871821
o->show_all_errors = old_show_all_errors;
17881822
if (free_pattern_list)
17891823
clear_pattern_list(&pl);

unpack-trees.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,12 @@ enum unpack_trees_error_types {
2424
ERROR_BIND_OVERLAP,
2525
ERROR_WOULD_LOSE_SUBMODULE,
2626

27+
NB_UNPACK_TREES_ERROR_TYPES,
28+
2729
WARNING_SPARSE_NOT_UPTODATE_FILE,
2830
WARNING_SPARSE_ORPHANED_NOT_OVERWRITTEN,
2931

30-
NB_UNPACK_TREES_ERROR_TYPES,
32+
NB_UNPACK_TREES_WARNING_TYPES,
3133
};
3234

3335
/*
@@ -66,13 +68,13 @@ struct unpack_trees_options {
6668
struct dir_struct *dir;
6769
struct pathspec *pathspec;
6870
merge_fn_t fn;
69-
const char *msgs[NB_UNPACK_TREES_ERROR_TYPES];
71+
const char *msgs[NB_UNPACK_TREES_WARNING_TYPES];
7072
struct argv_array msgs_to_free;
7173
/*
7274
* Store error messages in an array, each case
7375
* corresponding to a error message type
7476
*/
75-
struct string_list unpack_rejects[NB_UNPACK_TREES_ERROR_TYPES];
77+
struct string_list unpack_rejects[NB_UNPACK_TREES_WARNING_TYPES];
7678

7779
int head_idx;
7880
int merge_size;

0 commit comments

Comments
 (0)