Skip to content

Commit 14949d9

Browse files
newrengitster
authored andcommitted
merge-ort: upon merge abort, only show messages causing the abort
When something goes wrong enough that we need to abort early and not even attempt merging the remaining files, it probably does not make sense to report conflicts messages for the subset of files we processed before hitting the fatal error. Instead, only show the messages associated with paths where we hit the fatal error. Also, print these messages to stderr rather than stdout. Signed-off-by: Elijah Newren <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c55c3f2 commit 14949d9

File tree

1 file changed

+53
-25
lines changed

1 file changed

+53
-25
lines changed

merge-ort.c

Lines changed: 53 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -543,10 +543,24 @@ enum conflict_and_info_types {
543543
CONFLICT_SUBMODULE_HISTORY_NOT_AVAILABLE,
544544
CONFLICT_SUBMODULE_MAY_HAVE_REWINDS,
545545
CONFLICT_SUBMODULE_NULL_MERGE_BASE,
546-
CONFLICT_SUBMODULE_CORRUPT,
546+
547+
/* INSERT NEW ENTRIES HERE */
548+
549+
/*
550+
* Keep this entry after all regular conflict and info types; only
551+
* errors (failures causing immediate abort of the merge) should
552+
* come after this.
553+
*/
554+
NB_REGULAR_CONFLICT_TYPES,
555+
556+
/*
557+
* Something is seriously wrong; cannot even perform merge;
558+
* Keep this group _last_ other than NB_TOTAL_TYPES
559+
*/
560+
ERROR_SUBMODULE_CORRUPT,
547561

548562
/* Keep this entry _last_ in the list */
549-
NB_CONFLICT_TYPES,
563+
NB_TOTAL_TYPES,
550564
};
551565

552566
/*
@@ -597,8 +611,10 @@ static const char *type_short_descriptions[] = {
597611
"CONFLICT (submodule may have rewinds)",
598612
[CONFLICT_SUBMODULE_NULL_MERGE_BASE] =
599613
"CONFLICT (submodule lacks merge base)",
600-
[CONFLICT_SUBMODULE_CORRUPT] =
601-
"CONFLICT (submodule corrupt)"
614+
615+
/* Something is seriously wrong; cannot even perform merge */
616+
[ERROR_SUBMODULE_CORRUPT] =
617+
"ERROR (submodule corrupt)",
602618
};
603619

604620
struct logical_conflict_info {
@@ -762,7 +778,8 @@ static void path_msg(struct merge_options *opt,
762778

763779
/* Sanity checks */
764780
assert(omittable_hint ==
765-
!starts_with(type_short_descriptions[type], "CONFLICT") ||
781+
(!starts_with(type_short_descriptions[type], "CONFLICT") &&
782+
!starts_with(type_short_descriptions[type], "ERROR")) ||
766783
type == CONFLICT_DIR_RENAME_SUGGESTED);
767784
if (opt->record_conflict_msgs_as_headers && omittable_hint)
768785
return; /* Do not record mere hints in headers */
@@ -1817,9 +1834,9 @@ static int merge_submodule(struct merge_options *opt,
18171834
/* check whether both changes are forward */
18181835
ret2 = repo_in_merge_bases(&subrepo, commit_o, commit_a);
18191836
if (ret2 < 0) {
1820-
path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
1837+
path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0,
18211838
path, NULL, NULL, NULL,
1822-
_("Failed to merge submodule %s "
1839+
_("error: failed to merge submodule %s "
18231840
"(repository corrupt)"),
18241841
path);
18251842
ret = -1;
@@ -1828,9 +1845,9 @@ static int merge_submodule(struct merge_options *opt,
18281845
if (ret2 > 0)
18291846
ret2 = repo_in_merge_bases(&subrepo, commit_o, commit_b);
18301847
if (ret2 < 0) {
1831-
path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
1848+
path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0,
18321849
path, NULL, NULL, NULL,
1833-
_("Failed to merge submodule %s "
1850+
_("error: failed to merge submodule %s "
18341851
"(repository corrupt)"),
18351852
path);
18361853
ret = -1;
@@ -1848,9 +1865,9 @@ static int merge_submodule(struct merge_options *opt,
18481865
/* Case #1: a is contained in b or vice versa */
18491866
ret2 = repo_in_merge_bases(&subrepo, commit_a, commit_b);
18501867
if (ret2 < 0) {
1851-
path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
1868+
path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0,
18521869
path, NULL, NULL, NULL,
1853-
_("Failed to merge submodule %s "
1870+
_("error: failed to merge submodule %s "
18541871
"(repository corrupt)"),
18551872
path);
18561873
ret = -1;
@@ -1867,9 +1884,9 @@ static int merge_submodule(struct merge_options *opt,
18671884
}
18681885
ret2 = repo_in_merge_bases(&subrepo, commit_b, commit_a);
18691886
if (ret2 < 0) {
1870-
path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
1887+
path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0,
18711888
path, NULL, NULL, NULL,
1872-
_("Failed to merge submodule %s "
1889+
_("error: failed to merge submodule %s "
18731890
"(repository corrupt)"),
18741891
path);
18751892
ret = -1;
@@ -1901,9 +1918,9 @@ static int merge_submodule(struct merge_options *opt,
19011918
&merges);
19021919
switch (parent_count) {
19031920
case -1:
1904-
path_msg(opt, CONFLICT_SUBMODULE_CORRUPT, 0,
1921+
path_msg(opt, ERROR_SUBMODULE_CORRUPT, 0,
19051922
path, NULL, NULL, NULL,
1906-
_("Failed to merge submodule %s "
1923+
_("error: failed to merge submodule %s "
19071924
"(repository corrupt)"),
19081925
path);
19091926
ret = -1;
@@ -4646,6 +4663,7 @@ void merge_display_update_messages(struct merge_options *opt,
46464663
struct hashmap_iter iter;
46474664
struct strmap_entry *e;
46484665
struct string_list olist = STRING_LIST_INIT_NODUP;
4666+
FILE *o = stdout;
46494667

46504668
if (opt->record_conflict_msgs_as_headers)
46514669
BUG("Either display conflict messages or record them as headers, not both");
@@ -4662,32 +4680,42 @@ void merge_display_update_messages(struct merge_options *opt,
46624680
}
46634681
string_list_sort(&olist);
46644682

4683+
/* Print to stderr if we hit errors rather than just conflicts */
4684+
if (result->clean < 0)
4685+
o = stderr;
4686+
46654687
/* Iterate over the items, printing them */
46664688
for (int path_nr = 0; path_nr < olist.nr; ++path_nr) {
46674689
struct string_list *conflicts = olist.items[path_nr].util;
46684690
for (int i = 0; i < conflicts->nr; i++) {
46694691
struct logical_conflict_info *info =
46704692
conflicts->items[i].util;
46714693

4694+
/* On failure, ignore regular conflict types */
4695+
if (result->clean < 0 &&
4696+
info->type < NB_REGULAR_CONFLICT_TYPES)
4697+
continue;
4698+
46724699
if (detailed) {
4673-
printf("%lu", (unsigned long)info->paths.nr);
4674-
putchar('\0');
4700+
fprintf(o, "%lu", (unsigned long)info->paths.nr);
4701+
fputc('\0', o);
46754702
for (int n = 0; n < info->paths.nr; n++) {
4676-
fputs(info->paths.v[n], stdout);
4677-
putchar('\0');
4703+
fputs(info->paths.v[n], o);
4704+
fputc('\0', o);
46784705
}
4679-
fputs(type_short_descriptions[info->type],
4680-
stdout);
4681-
putchar('\0');
4706+
fputs(type_short_descriptions[info->type], o);
4707+
fputc('\0', o);
46824708
}
4683-
puts(conflicts->items[i].string);
4709+
fputs(conflicts->items[i].string, o);
4710+
fputc('\n', o);
46844711
if (detailed)
4685-
putchar('\0');
4712+
fputc('\0', o);
46864713
}
46874714
}
46884715
string_list_clear(&olist, 0);
46894716

4690-
print_submodule_conflict_suggestion(&opti->conflicted_submodules);
4717+
if (result->clean >= 0)
4718+
print_submodule_conflict_suggestion(&opti->conflicted_submodules);
46914719

46924720
/* Also include needed rename limit adjustment now */
46934721
diff_warn_rename_limit("merge.renamelimit",

0 commit comments

Comments
 (0)