* [PATCH] commit: use strbuf_add() to add a length-limited string
@ 2019-12-07 11:16 René Scharfe
2019-12-07 20:17 ` Derrick Stolee
2019-12-09 19:24 ` Junio C Hamano
0 siblings, 2 replies; 3+ messages in thread
From: René Scharfe @ 2019-12-07 11:16 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
This is shorter and simpler.
Signed-off-by: René Scharfe <l.s.r@web.de>
---
builtin/commit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/builtin/commit.c b/builtin/commit.c
index 294dc574cd..35a1fb9ad6 100644
--- a/builtin/commit.c
+++ b/builtin/commit.c
@@ -537,7 +537,7 @@ static void export_one(const char *var, const char *s, const char *e, int hack)
struct strbuf buf = STRBUF_INIT;
if (hack)
strbuf_addch(&buf, hack);
- strbuf_addf(&buf, "%.*s", (int)(e - s), s);
+ strbuf_add(&buf, s, e - s);
setenv(var, buf.buf, 1);
strbuf_release(&buf);
}
--
2.24.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] commit: use strbuf_add() to add a length-limited string
2019-12-07 11:16 [PATCH] commit: use strbuf_add() to add a length-limited string René Scharfe
@ 2019-12-07 20:17 ` Derrick Stolee
2019-12-09 19:24 ` Junio C Hamano
1 sibling, 0 replies; 3+ messages in thread
From: Derrick Stolee @ 2019-12-07 20:17 UTC (permalink / raw)
To: René Scharfe, Git Mailing List; +Cc: Junio C Hamano
On 12/7/2019 6:16 AM, René Scharfe wrote:
> This is shorter and simpler.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
> builtin/commit.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 294dc574cd..35a1fb9ad6 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -537,7 +537,7 @@ static void export_one(const char *var, const char *s, const char *e, int hack)
> struct strbuf buf = STRBUF_INIT;
> if (hack)
> strbuf_addch(&buf, hack);
> - strbuf_addf(&buf, "%.*s", (int)(e - s), s);
> + strbuf_add(&buf, s, e - s);
I had to look up what "%.*s" does [1, 2] but this looks like
a behavior-equivalent (and possibly faster) way to do it.
-Stolee
[1] https://stackoverflow.com/a/49580164
[2] https://en.cppreference.com/w/c/io/fprintf
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] commit: use strbuf_add() to add a length-limited string
2019-12-07 11:16 [PATCH] commit: use strbuf_add() to add a length-limited string René Scharfe
2019-12-07 20:17 ` Derrick Stolee
@ 2019-12-09 19:24 ` Junio C Hamano
1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2019-12-09 19:24 UTC (permalink / raw)
To: René Scharfe; +Cc: Git Mailing List
René Scharfe <l.s.r@web.de> writes:
> This is shorter and simpler.
>
> Signed-off-by: René Scharfe <l.s.r@web.de>
> ---
Ack (this was from me abck in 2012).
> builtin/commit.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 294dc574cd..35a1fb9ad6 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -537,7 +537,7 @@ static void export_one(const char *var, const char *s, const char *e, int hack)
> struct strbuf buf = STRBUF_INIT;
> if (hack)
> strbuf_addch(&buf, hack);
> - strbuf_addf(&buf, "%.*s", (int)(e - s), s);
> + strbuf_add(&buf, s, e - s);
> setenv(var, buf.buf, 1);
> strbuf_release(&buf);
> }
> --
> 2.24.0
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2019-12-09 19:24 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-07 11:16 [PATCH] commit: use strbuf_add() to add a length-limited string René Scharfe
2019-12-07 20:17 ` Derrick Stolee
2019-12-09 19:24 ` Junio C Hamano
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).