Re: [PATCH 5/7] object.c: add a utility function for "expected type X, got Y"

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Ævar Arnfjörð Bjarmason  <avarab@xxxxxxxxx> writes:

> Refactor various "Object X is not Y" error messages so that they use
> the same message as the long-standing object_as_type() error
> message. Now we'll consistently report e.g. that we got a commit when
> we expected a tag, not just that the object is not a tag.

This one is quite nice.  There might be some i18n fallout to do this
at this low layer, but everything should be manageable (i.e. we can
just tell the users "don't parse the die() message---they are meant
for humans") immediately, and in the longer term, we probably would
want to move away from dying at this low level anyway and instead
return an error for the higher layer to deal with.

> +static const char *oid_is_a_X_not_a_Y = N_("object %s is a %s, not a %s");
> +
>  const char *type_name(unsigned int type)
>  {
>  	if (type >= ARRAY_SIZE(object_type_strings))
> @@ -159,6 +161,36 @@ void *create_object(struct repository *r, const struct object_id *oid, void *o)
>  	return obj;
>  }
>  
> +static int oid_is_type_or(const struct object_id *oid,
> +			  enum object_type want,
> +			  enum object_type type,
> +			  int err)

"err" is usually called "gently" in this codebase, isn't it?

> +{
> +	if (want == type)
> +		return 0;
> +	if (err)
> +		return error(_(oid_is_a_X_not_a_Y),
> +			     oid_to_hex(oid), type_name(type),
> +			     type_name(want));

Just a style thing, but breaking line after oid like you did on the
other "!err" side makes it a lot more readable.

> +	else
> +		die(_(oid_is_a_X_not_a_Y), oid_to_hex(oid),
> +		    type_name(type), type_name(want));
> +}




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux