{"thread":{"id":"37144","subject":"[PATCH] strbuf: use strbuf_addstr() for adding C strings","startedAt":"2014-07-16T23:38:18Z","lastAt":"2014-07-16T23:41:51Z","messageCount":2,"participants":["René Scharfe","Jonathan Nieder"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"246209","messageId":"53C70CEA.8000000@web.de","threadId":"37144","inReplyTo":null,"subject":"[PATCH] strbuf: use strbuf_addstr() for adding C strings","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2014-07-16T23:38:18Z","receivedAt":"2014-07-16T23:38:18Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Avoid code duplication and let strbuf_addstr() call strlen() for us.\n\nSigned-off-by: Rene Scharfe <l.s.r@web.de>\n---\n builtin/commit.c |  2 +-\n diff.c           | 12 ++++++------\n path.c           |  6 +++---\n 3 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 72eb3be..f2d7979 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -702,7 +702,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\tchar *buffer;\n \t\tbuffer = strstr(use_message_buffer, \"\\n\\n\");\n \t\tif (buffer)\n-\t\t\tstrbuf_add(&sb, buffer + 2, strlen(buffer + 2));\n+\t\t\tstrbuf_addstr(&sb, buffer + 2);\n \t\thook_arg1 = \"commit\";\n \t\thook_arg2 = use_message;\n \t} else if (fixup_message) {\ndiff --git a/diff.c b/diff.c\nindex 06bdfb8..867f034 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -525,9 +525,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,\n \tep += 2; /* skip over @@ */\n \n \t/* The hunk header in fraginfo color */\n-\tstrbuf_add(&msgbuf, frag, strlen(frag));\n+\tstrbuf_addstr(&msgbuf, frag);\n \tstrbuf_add(&msgbuf, line, ep - line);\n-\tstrbuf_add(&msgbuf, reset, strlen(reset));\n+\tstrbuf_addstr(&msgbuf, reset);\n \n \t/*\n \t * trailing \"\\r\\n\"\n@@ -541,15 +541,15 @@ static void emit_hunk_header(struct emit_callback *ecbdata,\n \t\tif (*ep != ' ' && *ep != '\\t')\n \t\t\tbreak;\n \tif (ep != cp) {\n-\t\tstrbuf_add(&msgbuf, plain, strlen(plain));\n+\t\tstrbuf_addstr(&msgbuf, plain);\n \t\tstrbuf_add(&msgbuf, cp, ep - cp);\n-\t\tstrbuf_add(&msgbuf, reset, strlen(reset));\n+\t\tstrbuf_addstr(&msgbuf, reset);\n \t}\n \n \tif (ep < line + len) {\n-\t\tstrbuf_add(&msgbuf, func, strlen(func));\n+\t\tstrbuf_addstr(&msgbuf, func);\n \t\tstrbuf_add(&msgbuf, ep, line + len - ep);\n-\t\tstrbuf_add(&msgbuf, reset, strlen(reset));\n+\t\tstrbuf_addstr(&msgbuf, reset);\n \t}\n \n \tstrbuf_add(&msgbuf, line + len, org_len - len);\ndiff --git a/path.c b/path.c\nindex bc804a3..c3883d4 100644\n--- a/path.c\n+++ b/path.c\n@@ -277,16 +277,16 @@ char *expand_user_path(const char *path)\n \t\t\tconst char *home = getenv(\"HOME\");\n \t\t\tif (!home)\n \t\t\t\tgoto return_null;\n-\t\t\tstrbuf_add(&user_path, home, strlen(home));\n+\t\t\tstrbuf_addstr(&user_path, home);\n \t\t} else {\n \t\t\tstruct passwd *pw = getpw_str(username, username_len);\n \t\t\tif (!pw)\n \t\t\t\tgoto return_null;\n-\t\t\tstrbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));\n+\t\t\tstrbuf_addstr(&user_path, pw->pw_dir);\n \t\t}\n \t\tto_copy = first_slash;\n \t}\n-\tstrbuf_add(&user_path, to_copy, strlen(to_copy));\n+\tstrbuf_addstr(&user_path, to_copy);\n \treturn strbuf_detach(&user_path, NULL);\n return_null:\n \tstrbuf_release(&user_path);\n-- \n2.0.2\n"},{"id":"246210","messageId":"20140716234151.GN12427@google.com","threadId":"37144","inReplyTo":"53C70CEA.8000000@web.de","subject":"Re: [PATCH] strbuf: use strbuf_addstr() for adding C strings","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-07-16T23:41:51Z","receivedAt":"2014-07-16T23:41:51Z","isPatch":true,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"René Scharfe wrote:\n\n> Avoid code duplication and let strbuf_addstr() call strlen() for us.\n\nNice.\n\n> Signed-off-by: Rene Scharfe <l.s.r@web.de>\n> ---\n>  builtin/commit.c |  2 +-\n>  diff.c           | 12 ++++++------\n>  path.c           |  6 +++---\n>  3 files changed, 10 insertions(+), 10 deletions(-)\n\nReviewed-by: Jonathan Nieder <jrnieder@gmail.com>\n"}]}