Re: [PATCH v2 1/3] notes.c: introduce "--blank-line" option
- From
Ævar Arnfjörð Bjarmason <avarab@gmail.com>
- Date
- Nov 7, 2022, 15:06 UTC
- Message-ID
- <221107.86v8nqvlla.gmgdl@evledraar.gmail.com>
- In-Reply-To
- <2381947abdd6b965c02e114af297fc908ed3132b.1667828335.git.dyroneteng@gmail.com>
On Mon, Nov 07 2022, Teng Long wrote:
> From: Teng Long <dyroneteng@gmail.com>
Something I didn't notice on the first reading:
> @@ -619,7 +622,7 @@ static int append_edit(int argc, const char **argv, const char *prefix) > char *prev_buf = read_object_file(note, &type, &size); > > strbuf_grow(&d.buf, size + 1);
Here we're growing it to add the size plus the \n.
> - if (d.buf.len && prev_buf && size) > + if (blankline && d.buf.len && prev_buf && size) > strbuf_insertstr(&d.buf, 0, "\n");
But now we're not going to make use of that "+ 1" anymore...
> if (prev_buf && size) > strbuf_insert(&d.buf, 0, prev_buf, size);
..and here the prev_buf && size condition is duplicated.
I think the right thin to do is to just drop the strbuf_grow() here altogether, since strbuf_insert() will handle it for us, but that would make sense before this change, so maybe in pre-cleanup?