@@ -2971,9 +2971,11 @@ static int read_oid_strbuf(struct merge_options *opt,
if (!buf)
return err(opt, _("cannot read object %s"), oid_to_hex(oid));
if (type != OBJ_BLOB) {
- const char* msg = oid_is_type_or_die_msg(oid, OBJ_BLOB, &type);
+ char *msg = oid_is_type_or_die_msg(oid, OBJ_BLOB, &type);
+ int ret = err(opt, msg);
free(buf);
- return err(opt, _("object %s is not a blob"), oid_to_hex(oid));
+ free(msg);
+ return ret;
}
strbuf_attach(dst, buf, size, size + 1);
return 0;
@@ -182,6 +182,18 @@ int oid_is_type_or_error(const struct object_id *oid,
type_name(want));
}
+char* oid_is_type_or_die_msg(const struct object_id *oid,
+ enum object_type want,
+ enum object_type *type)
+{
+ struct strbuf sb = STRBUF_INIT;
+ if (want == *type)
+ BUG("call this just to get the message!");
+ strbuf_addf(&sb, _(object_type_mismatch_msg), oid_to_hex(oid),
+ type_name(*type), type_name(want));
+ return strbuf_detach(&sb, NULL);
+}
+
void *object_as_type(struct object *obj, enum object_type type, int quiet)
{
if (obj->type == type)
@@ -128,6 +128,9 @@ void oid_is_type_or_die(const struct object_id *oid, enum object_type want,
enum object_type *type);
int oid_is_type_or_error(const struct object_id *oid, enum object_type want,
enum object_type *type);
+char* oid_is_type_or_die_msg(const struct object_id *oid,
+ enum object_type want,
+ enum object_type *type);
/*
* Returns the object, having parsed it to find out what it is.
Add a oid_is_type_or_die_msg() function to go with the "error" and "die" forms for emitting "expected type X, got Y" messages. This is useful for callers that want the message itself as a char *. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- merge-recursive.c | 6 ++++-- object.c | 12 ++++++++++++ object.h | 3 +++ 3 files changed, 19 insertions(+), 2 deletions(-)