merge-recursive: i18n submodule merge output and respect verbosity

The submodule merge code now uses the output() function that is used by all the rest of the merge-recursive-code. This allows for respecting internationalisation as well as the verbosity setting. Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Stefan Beller committed May 15, 2018 at 13:00 UTC 325f3a8e077c1992a3cc6ff957811e3154edc554
1 file changed +15 -18
merge-recursive.c
+15 -18
@@ -1048,18 +1048,17 @@ static void print_commit(struct commit *commit)
1048 strbuf_release(&sb);
1049 }
1050
1051 -#define MERGE_WARNING(path, msg) \
1052 - warning("Failed to merge submodule %s (%s)", path, msg);
1053 -
1054 -static int merge_submodule(struct object_id *result, const char *path,
1051 +static int merge_submodule(struct merge_options *o,
1052 + struct object_id *result, const char *path,
1053 const struct object_id *base, const struct object_id *a,
1056 - const struct object_id *b, int search)
1054 + const struct object_id *b)
1055 {
1056 struct commit *commit_base, *commit_a, *commit_b;
1057 int parent_count;
1058 struct object_array merges;
1059
1060 int i;
1061 + int search = !o->call_depth;
1062
1063 /* store a in result in case we fail */
1064 oidcpy(result, a);
@@ -1073,21 +1072,21 @@ static int merge_submodule(struct object_id *result, const char *path,
1072 return 0;
1073
1074 if (add_submodule_odb(path)) {
1076 - MERGE_WARNING(path, "not checked out");
1075 + output(o, 1, _("Failed to merge submodule %s (not checked out)"), path);
1076 return 0;
1077 }
1078
1079 if (!(commit_base = lookup_commit_reference(base)) ||
1080 !(commit_a = lookup_commit_reference(a)) ||
1081 !(commit_b = lookup_commit_reference(b))) {
1083 - MERGE_WARNING(path, "commits not present");
1082 + output(o, 1, _("Failed to merge submodule %s (commits not present)"), path);
1083 return 0;
1084 }
1085
1086 /* check whether both changes are forward */
1087 if (!in_merge_bases(commit_base, commit_a) ||
1088 !in_merge_bases(commit_base, commit_b)) {
1090 - MERGE_WARNING(path, "commits don't follow merge-base");
1089 + output(o, 1, _("Failed to merge submodule %s (commits don't follow merge-base)"), path);
1090 return 0;
1091 }
1092
@@ -1116,25 +1115,24 @@ static int merge_submodule(struct object_id *result, const char *path,
1115 parent_count = find_first_merges(&merges, path, commit_a, commit_b);
1116 switch (parent_count) {
1117 case 0:
1119 - MERGE_WARNING(path, "merge following commits not found");
1118 + output(o, 1, _("Failed to merge submodule %s (merge following commits not found)"), path);
1119 break;
1120
1121 case 1:
1123 - MERGE_WARNING(path, "not fast-forward");
1124 - fprintf(stderr, "Found a possible merge resolution "
1125 - "for the submodule:\n");
1122 + output(o, 1, _("Failed to merge submodule %s (not fast-forward)"), path);
1123 + output(o, 2, _("Found a possible merge resolution for the submodule:\n"));
1124 print_commit((struct commit *) merges.objects[0].item);
1127 - fprintf(stderr,
1125 + output(o, 2, _(
1126 "If this is correct simply add it to the index "
1127 "for example\n"
1128 "by using:\n\n"
1129 " git update-index --cacheinfo 160000 %s \"%s\"\n\n"
1132 - "which will accept this suggestion.\n",
1130 + "which will accept this suggestion.\n"),
1131 oid_to_hex(&merges.objects[0].item->oid), path);
1132 break;
1133
1134 default:
1137 - MERGE_WARNING(path, "multiple merges found");
1135 + output(o, 1, _("Failed to merge submodule %s (multiple merges found)"), path);
1136 for (i = 0; i < merges.nr; i++)
1137 print_commit((struct commit *) merges.objects[i].item);
1138 }
@@ -1205,12 +1203,11 @@ static int merge_file_1(struct merge_options *o,
1203 return ret;
1204 result->clean = (merge_status == 0);
1205 } else if (S_ISGITLINK(a->mode)) {
1208 - result->clean = merge_submodule(&result->oid,
1206 + result->clean = merge_submodule(o, &result->oid,
1207 one->path,
1208 &one->oid,
1209 &a->oid,
1212 - &b->oid,
1213 - !o->call_depth);
1210 + &b->oid);
1211 } else if (S_ISLNK(a->mode)) {
1212 switch (o->recursive_variant) {
1213 case MERGE_RECURSIVE_NORMAL: