commit: use strbuf_add() to add a length-limited string
PATCH 1/1 commit: use strbuf_add() to add a length-limited string
This is shorter and simpler.
Signed-off-by René Scharfe <[email protected]>
--- builtin/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
builtin/commit.c +1 -1
@@ -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
Quoted 12 lines · René Scharfe
This is shorter and simpler.
Signed-off-by René Scharfe <[email protected]>--- builtin/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)builtin/commit.c +0
-0
builtin/commit.c static void export_one(const char *var, const char *s, const char *e, int hack) · line 540
Quoted 5 lines
builtin/commit.c +1
-1@@ -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
Quoted 4 lines · René Scharfe
This is shorter and simpler.
Signed-off-by René Scharfe <[email protected]>---
Ack (this was from me abck in 2012).
Quoted 18 lines
builtin/commit.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)builtin/commit.c +1
-2@@ -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