Re: [PATCH] notes: Disallow reusing non-blob as a note object
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Feb 14, 2014, 15:19 UTC
- Message-ID
- <CAPig+cSQ12Ga4kEnNrspzru2F3p0jWb2i=1GRX84k0am5AA6Bw@mail.gmail.com>
- In-Reply-To
- <1392198856-3908-1-git-send-email-johan@herland.net>
On Wed, Feb 12, 2014 at 4:54 AM, Johan Herland <johan@herland.net> wrote:
Show 37 quoted lines
> Currently "git notes add -C $object" will read the raw bytes from $object,
> and then copy those bytes into the note object, which is hardcoded to be
> of type blob. This means that if the given $object is a non-blob (e.g.
> tree or commit), the raw bytes from that object is copied into a blob
> object. This is probably not useful, and certainly not what any sane
> user would expect. So disallow it, by erroring out if the $object passed
> to the -C option is not a blob.
>
> The fix also applies to the -c option (in which the user is prompted to
> edit/verify the note contents in a text editor), and also when -c/-C is
> passed to "git notes append" (which appends the $object contents to an
> existing note object). In both cases, passing a non-blob $object does not
> make sense.
>
> Also add a couple of tests demonstrating expected behavior.
>
> Suggested-by: Junio C Hamano <gitster@pobox.com>
> Signed-off-by: Johan Herland <johan@herland.net>
> ---
> builtin/notes.c | 6 +++++-
> t/t3301-notes.sh | 27 +++++++++++++++++++++++++++
> 2 files changed, 32 insertions(+), 1 deletion(-)
>
> diff --git a/builtin/notes.c b/builtin/notes.c
> index 2b24d05..bb89930 100644
> --- a/builtin/notes.c
> +++ b/builtin/notes.c
> @@ -269,7 +269,11 @@ static int parse_reuse_arg(const struct option *opt, const char *arg, int unset)
> die(_("Failed to resolve '%s' as a valid ref."), arg);
> if (!(buf = read_sha1_file(object, &type, &len)) || !len) {
> free(buf);
> - die(_("Failed to read object '%s'."), arg);;
> + die(_("Failed to read object '%s'."), arg);
> + }
> + if (type != OBJ_BLOB) {
> + free(buf);
> + die(_("Cannot read note data from non-blob object '%s'."), arg);The way this diagnostic is worded, it sound as if the 'read' failed rather than that the user specified an incorrect object type. Perhaps "Object is not a blob '%s'" or "Expected blob but '%s' has type '%s'" or something along those lines?
> } > strbuf_add(&(msg->buf), buf, len); > free(buf);