Skip to content

Commit 808e83f

Browse files
peffgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent d6c5197 commit 808e83f

File tree

2 files changed

+7
-24
lines changed

2 files changed

+7
-24
lines changed

merge-ort.c

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -721,23 +721,6 @@ static void clear_or_reinit_internal_opts(struct merge_options_internal *opti,
721721
renames->callback_data_nr = renames->callback_data_alloc = 0;
722722
}
723723

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-
741724
static void format_commit(struct strbuf *sb,
742725
int indent,
743726
struct repository *repo,
@@ -2122,13 +2105,12 @@ static int handle_content_merge(struct merge_options *opt,
21222105
&result_buf);
21232106

21242107
if ((merge_status < 0) || !result_buf.ptr)
2125-
ret = err(opt, _("Failed to execute internal merge"));
2108+
ret = error(_("Failed to execute internal merge"));
21262109

21272110
if (!ret &&
21282111
write_object_file(result_buf.ptr, result_buf.size,
21292112
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);
21322114

21332115
free(result_buf.ptr);
21342116
if (ret)
@@ -3518,10 +3500,10 @@ static int read_oid_strbuf(struct merge_options *opt,
35183500
unsigned long size;
35193501
buf = repo_read_object_file(the_repository, oid, &type, &size);
35203502
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));
35223504
if (type != OBJ_BLOB) {
35233505
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));
35253507
}
35263508
strbuf_attach(dst, buf, size, size + 1);
35273509
return 0;
@@ -4973,7 +4955,7 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt,
49734955
* TRANSLATORS: The %s arguments are: 1) tree hash of a merge
49744956
* base, and 2-3) the trees for the two trees we're merging.
49754957
*/
4976-
err(opt, _("collecting merge info failed for trees %s, %s, %s"),
4958+
error(_("collecting merge info failed for trees %s, %s, %s"),
49774959
oid_to_hex(&merge_base->object.oid),
49784960
oid_to_hex(&side1->object.oid),
49794961
oid_to_hex(&side2->object.oid));

t/t6406-merge-attr.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ test_expect_success !WINDOWS 'custom merge driver that is killed with a signal'
179179
180180
>./please-abort &&
181181
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 &&
183184
git ls-files -u >output &&
184185
git diff --name-only HEAD >>output &&
185186
test_must_be_empty output

0 commit comments

Comments
 (0)