{"thread":{"id":"52400","subject":"[PATCH] commit: use strbuf_add() to add a length-limited string","startedAt":"2019-12-07T11:16:11Z","lastAt":"2019-12-09T19:24:39Z","messageCount":3,"participants":["René Scharfe","Derrick Stolee","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"387673","messageId":"f4c7d65f-d7bb-c574-fe48-8d2df0c2907a@web.de","threadId":"52400","inReplyTo":null,"subject":"[PATCH] commit: use strbuf_add() to add a length-limited string","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-12-07T11:16:04Z","receivedAt":"2019-12-07T11:16:11Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"This is shorter and simpler.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/commit.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 294dc574cd..35a1fb9ad6 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -537,7 +537,7 @@ static void export_one(const char *var, const char *s, const char *e, int hack)\n \tstruct strbuf buf = STRBUF_INIT;\n \tif (hack)\n \t\tstrbuf_addch(&buf, hack);\n-\tstrbuf_addf(&buf, \"%.*s\", (int)(e - s), s);\n+\tstrbuf_add(&buf, s, e - s);\n \tsetenv(var, buf.buf, 1);\n \tstrbuf_release(&buf);\n }\n--\n2.24.0\n"},{"id":"387699","messageId":"5bc19b91-7579-357f-e241-32d3a763d9c5@gmail.com","threadId":"52400","inReplyTo":"f4c7d65f-d7bb-c574-fe48-8d2df0c2907a@web.de","subject":"Re: [PATCH] commit: use strbuf_add() to add a length-limited string","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-12-07T20:17:29Z","receivedAt":"2019-12-07T20:22:15Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 12/7/2019 6:16 AM, René Scharfe wrote:\n> This is shorter and simpler.\n> \n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n>  builtin/commit.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n> \n> diff --git a/builtin/commit.c b/builtin/commit.c\n> index 294dc574cd..35a1fb9ad6 100644\n> --- a/builtin/commit.c\n> +++ b/builtin/commit.c\n> @@ -537,7 +537,7 @@ static void export_one(const char *var, const char *s, const char *e, int hack)\n>  \tstruct strbuf buf = STRBUF_INIT;\n>  \tif (hack)\n>  \t\tstrbuf_addch(&buf, hack);\n> -\tstrbuf_addf(&buf, \"%.*s\", (int)(e - s), s);\n> +\tstrbuf_add(&buf, s, e - s);\n\nI had to look up what \"%.*s\" does [1, 2] but this looks like\na behavior-equivalent (and possibly faster) way to do it.\n\n-Stolee\n\n[1] https://stackoverflow.com/a/49580164\n[2] https://en.cppreference.com/w/c/io/fprintf\n\n\n"},{"id":"387822","messageId":"xmqqh829uwsu.fsf@gitster-ct.c.googlers.com","threadId":"52400","inReplyTo":"f4c7d65f-d7bb-c574-fe48-8d2df0c2907a@web.de","subject":"Re: [PATCH] commit: use strbuf_add() to add a length-limited string","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-12-09T19:24:33Z","receivedAt":"2019-12-09T19:24:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"René Scharfe <l.s.r@web.de> writes:\n\n> This is shorter and simpler.\n>\n> Signed-off-by: René Scharfe <l.s.r@web.de>\n> ---\n\nAck (this was from me abck in 2012).\n\n>  builtin/commit.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/builtin/commit.c b/builtin/commit.c\n> index 294dc574cd..35a1fb9ad6 100644\n> --- a/builtin/commit.c\n> +++ b/builtin/commit.c\n> @@ -537,7 +537,7 @@ static void export_one(const char *var, const char *s, const char *e, int hack)\n>  \tstruct strbuf buf = STRBUF_INIT;\n>  \tif (hack)\n>  \t\tstrbuf_addch(&buf, hack);\n> -\tstrbuf_addf(&buf, \"%.*s\", (int)(e - s), s);\n> +\tstrbuf_add(&buf, s, e - s);\n>  \tsetenv(var, buf.buf, 1);\n>  \tstrbuf_release(&buf);\n>  }\n> --\n> 2.24.0\n"}]}