Subject: Re: [RFC PATCH 2/2] notes.c: fixed tip when target and append note are both empty

From: Ævar Arnfjörð Bjarmason <[email-masked]>
Date: Thu, 13 Oct 2022 11:36:42 +0200

On Thu, Oct 13 2022, Teng Long wrote:

> From: Teng Long <[email-masked]>
>
> When "git notes append <object>" is executed, if there is no note in
> the given object and the appended note is empty, the command line
> prompt will be as follows:
>
>      "Removing note for object <object>"
>
> Actually, this tip is not that accurate, because there is no note in
> the original <object>, and it also does no remove work on the notes
> reference, so let's fix this and give the correct tip.
>
> Signed-off-by: Teng Long <[email-masked]>
> ---
>  builtin/notes.c  | 13 +++++++++++--
>  t/t3301-notes.sh |  3 ++-
>  2 files changed, 13 insertions(+), 3 deletions(-)
>
> diff --git a/builtin/notes.c b/builtin/notes.c
> index 1ca0476a27..cc1e3aa2b6 100644
> --- a/builtin/notes.c
> +++ b/builtin/notes.c
> @@ -567,9 +567,10 @@ static int append_edit(int argc, const char **argv, const char *prefix)
>  	struct notes_tree *t;
>  	struct object_id object, new_note;
>  	const struct object_id *note;
> -	char *logmsg;
> +	char *logmsg = NULL;

Hrm, interesting that (at least my) gcc doesn't catch if we don't
NULL-initialize this, but -fanalyzer does (usually it's not needed for
such trivial cases0. Anyawy...

>  	const char * const *usage;
>  	struct note_data d = { 0, 0, NULL, STRBUF_INIT };
> +	struct note_data cp = { 0, 0, NULL, STRBUF_INIT };

This is probably better "fixed while at it" to set both to use "{ .buf =
STRBUF_INIT }", rather than copying the pre-C99 pattern.