merge-ort: drop custom err() function

The merge-ort code has an err() function, but it's really just error() in disguise. It differs in two ways: 1. It takes a "struct merge_options" argument. But the function completely ignores it! We can simply remove it. 2. It formats the error string into a strbuf, prepending "error: ", and then feeds the result into error(). But this is wrong! The error() function already adds the prefix, so we end up with: error: error: Failed to execute internal merge So let's just drop this function entirely and call error() directly, as the functions are otherwise identical (note that they both always return -1). Presumably nobody noticed the bogus messages because they are quite hard to trigger (they are mostly internal errors reading and writing objects). However, one easy trigger is a custom merge driver which dies by signal; we have a test already here, but we were not checking the contents of stderr. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 14, 2023 at 05:39 UTC 808e83f2667e4b442a8f58f0c7ef55feb6864f65
2 files changed +7 -24
merge-ort.c
+5 -23
@@ -721,23 +721,6 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
721 renames->callback_data_nr = renames->callback_data_alloc = 0;
722 }
723
724 -__attribute__((format (printf, 2, 3)))
725 -static int err(struct merge_options *opt, const char *err, ...)
726 -{
727 - va_list params;
728 - struct strbuf sb = STRBUF_INIT;
729 -
730 - strbuf_addstr(&sb, "error: ");
731 - va_start(params, err);
732 - strbuf_vaddf(&sb, err, params);
733 - va_end(params);
734 -
735 - error("%s", sb.buf);
736 - strbuf_release(&sb);
737 -
738 - return -1;
739 -}
740 -
724 static void format_commit(struct strbuf *sb,
725 int indent,
726 struct repository *repo,
@@ -2122,13 +2105,12 @@ static int handle_content_merge(struct merge_options *opt,
2105 &result_buf);
2106
2107 if ((merge_status < 0) || !result_buf.ptr)
2125 - ret = err(opt, _("Failed to execute internal merge"));
2108 + ret = error(_("Failed to execute internal merge"));
2109
2110 if (!ret &&
2111 write_object_file(result_buf.ptr, result_buf.size,
2112 OBJ_BLOB, &result->oid))
2130 - ret = err(opt, _("Unable to add %s to database"),
2131 - path);
2113 + ret = error(_("Unable to add %s to database"), path);
2114
2115 free(result_buf.ptr);
2116 if (ret)
@@ -3518,10 +3500,10 @@ static int read_oid_strbuf(struct merge_options *opt,
3500 unsigned long size;
3501 buf = repo_read_object_file(the_repository, oid, &type, &size);
3502 if (!buf)
3521 - return err(opt, _("cannot read object %s"), oid_to_hex(oid));
3503 + return error(_("cannot read object %s"), oid_to_hex(oid));
3504 if (type != OBJ_BLOB) {
3505 free(buf);
3524 - return err(opt, _("object %s is not a blob"), oid_to_hex(oid));
3506 + return error(_("object %s is not a blob"), oid_to_hex(oid));
3507 }
3508 strbuf_attach(dst, buf, size, size + 1);
3509 return 0;
@@ -4973,7 +4955,7 @@ redo:
4955 * TRANSLATORS: The %s arguments are: 1) tree hash of a merge
4956 * base, and 2-3) the trees for the two trees we're merging.
4957 */
4976 - err(opt, _("collecting merge info failed for trees %s, %s, %s"),
4958 + error(_("collecting merge info failed for trees %s, %s, %s"),
4959 oid_to_hex(&merge_base->object.oid),
4960 oid_to_hex(&side1->object.oid),
4961 oid_to_hex(&side2->object.oid));
t/t6406-merge-attr.sh
+2 -1
@@ -179,7 +179,8 @@ test_expect_success !WINDOWS 'custom merge driver that is killed with a signal'
179
180 >./please-abort &&
181 echo "* merge=custom" >.gitattributes &&
182 - test_must_fail git merge main &&
182 + test_must_fail git merge main 2>err &&
183 + grep "^error: Failed to execute internal merge" err &&
184 git ls-files -u >output &&
185 git diff --name-only HEAD >>output &&
186 test_must_be_empty output