From: Jeff King <peff@peff.net>
To: git@vger.kernel.org
Cc: Elijah Newren <newren@gmail.com>
Subject: [PATCH 1/4] merge-ort: drop custom err() function
Date: Thu, 14 Sep 2023 05:39:48 -0400 [thread overview]
Message-ID: <20230914093948.GA2254894@coredump.intra.peff.net> (raw)
In-Reply-To: <20230914093409.GA2254811@coredump.intra.peff.net>
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>
---
A few of these messages starts with capital letters, which is unlike our
usual error message style. I didn't clean that up here. We could do so
on top, but I actually wonder if some of these ought to be using
path_msg() and continuing instead, to give output closer to other
conflict or error cases (e.g., conflicts caused by missing submodule
objects). But I dunno. I guess these are all more clearly "woah,
something is totally wrong" that we do not expect to happen, so it
probably isn't a big deal to just abort.
merge-ort.c | 28 +++++-----------------------
t/t6406-merge-attr.sh | 3 ++-
2 files changed, 7 insertions(+), 24 deletions(-)
diff --git a/merge-ort.c b/merge-ort.c
index 8631c99700..027ecc7f78 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -721,23 +721,6 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
renames->callback_data_nr = renames->callback_data_alloc = 0;
}
-__attribute__((format (printf, 2, 3)))
-static int err(struct merge_options *opt, const char *err, ...)
-{
- va_list params;
- struct strbuf sb = STRBUF_INIT;
-
- strbuf_addstr(&sb, "error: ");
- va_start(params, err);
- strbuf_vaddf(&sb, err, params);
- va_end(params);
-
- error("%s", sb.buf);
- strbuf_release(&sb);
-
- return -1;
-}
-
static void format_commit(struct strbuf *sb,
int indent,
struct repository *repo,
@@ -2122,13 +2105,12 @@ static int handle_content_merge(struct merge_options *opt,
&result_buf);
if ((merge_status < 0) || !result_buf.ptr)
- ret = err(opt, _("Failed to execute internal merge"));
+ ret = error(_("Failed to execute internal merge"));
if (!ret &&
write_object_file(result_buf.ptr, result_buf.size,
OBJ_BLOB, &result->oid))
- ret = err(opt, _("Unable to add %s to database"),
- path);
+ ret = error(_("Unable to add %s to database"), path);
free(result_buf.ptr);
if (ret)
@@ -3518,10 +3500,10 @@ static int read_oid_strbuf(struct merge_options *opt,
unsigned long size;
buf = repo_read_object_file(the_repository, oid, &type, &size);
if (!buf)
- return err(opt, _("cannot read object %s"), oid_to_hex(oid));
+ return error(_("cannot read object %s"), oid_to_hex(oid));
if (type != OBJ_BLOB) {
free(buf);
- return err(opt, _("object %s is not a blob"), oid_to_hex(oid));
+ return error(_("object %s is not a blob"), oid_to_hex(oid));
}
strbuf_attach(dst, buf, size, size + 1);
return 0;
@@ -4973,7 +4955,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
* TRANSLATORS: The %s arguments are: 1) tree hash of a merge
* base, and 2-3) the trees for the two trees we're merging.
*/
- err(opt, _("collecting merge info failed for trees %s, %s, %s"),
+ error(_("collecting merge info failed for trees %s, %s, %s"),
oid_to_hex(&merge_base->object.oid),
oid_to_hex(&side1->object.oid),
oid_to_hex(&side2->object.oid));
diff --git a/t/t6406-merge-attr.sh b/t/t6406-merge-attr.sh
index 9677180a5b..05ad13b23e 100755
--- a/t/t6406-merge-attr.sh
+++ b/t/t6406-merge-attr.sh
@@ -179,7 +179,8 @@ test_expect_success !WINDOWS 'custom merge driver that is killed with a signal'
>./please-abort &&
echo "* merge=custom" >.gitattributes &&
- test_must_fail git merge main &&
+ test_must_fail git merge main 2>err &&
+ grep "^error: Failed to execute internal merge" err &&
git ls-files -u >output &&
git diff --name-only HEAD >>output &&
test_must_be_empty output
--
2.42.0.628.g8a27295885
next prev parent reply other threads:[~2023-09-14 9:44 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-14 9:34 [PATCH 0/4] merge-ort unused parameter cleanups Jeff King
2023-09-14 9:39 ` Jeff King [this message]
2023-09-16 2:54 ` [PATCH 1/4] merge-ort: drop custom err() function Elijah Newren
2023-09-16 5:50 ` Jeff King
2023-09-14 9:39 ` [PATCH 2/4] merge-ort: stop passing "opt" to read_oid_strbuf() Jeff King
2023-09-14 9:39 ` [PATCH 3/4] merge-ort: drop unused parameters from detect_and_process_renames() Jeff King
2023-09-16 3:04 ` Elijah Newren
2023-09-14 9:40 ` [PATCH 4/4] merge-ort: drop unused "opt" parameter from merge_check_renames_reusable() Jeff King
2023-09-16 3:09 ` Elijah Newren
2023-09-16 5:52 ` Jeff King
2023-09-16 2:56 ` [PATCH 0/4] merge-ort unused parameter cleanups Elijah Newren
2023-09-16 6:00 ` [PATCH 5/4] merge-ort: lowercase a few error messages Jeff King
2023-09-16 7:29 ` Jeff King
2023-09-16 21:49 ` Junio C Hamano
2023-09-16 22:11 ` Jeff King
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230914093948.GA2254894@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=newren@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).