strbuf: use strbuf_addstr() for adding C strings

Avoid code duplication and let strbuf_addstr() call strlen() for us. Signed-off-by: Rene Scharfe <l.s.r@web.de> Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

René Scharfe committed Jul 17, 2014 at 01:38 UTC cedc61a99804db99f9a658c3cccd5c2786a28501
3 files changed +10 -10
builtin/commit.c
+1 -1
@@ -707,7 +707,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
707 char *buffer;
708 buffer = strstr(use_message_buffer, "\n\n");
709 if (buffer)
710 - strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
710 + strbuf_addstr(&sb, buffer + 2);
711 hook_arg1 = "commit";
712 hook_arg2 = use_message;
713 } else if (fixup_message) {
diff.c
+6 -6
@@ -525,9 +525,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
525 ep += 2; /* skip over @@ */
526
527 /* The hunk header in fraginfo color */
528 - strbuf_add(&msgbuf, frag, strlen(frag));
528 + strbuf_addstr(&msgbuf, frag);
529 strbuf_add(&msgbuf, line, ep - line);
530 - strbuf_add(&msgbuf, reset, strlen(reset));
530 + strbuf_addstr(&msgbuf, reset);
531
532 /*
533 * trailing "\r\n"
@@ -541,15 +541,15 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
541 if (*ep != ' ' && *ep != '\t')
542 break;
543 if (ep != cp) {
544 - strbuf_add(&msgbuf, plain, strlen(plain));
544 + strbuf_addstr(&msgbuf, plain);
545 strbuf_add(&msgbuf, cp, ep - cp);
546 - strbuf_add(&msgbuf, reset, strlen(reset));
546 + strbuf_addstr(&msgbuf, reset);
547 }
548
549 if (ep < line + len) {
550 - strbuf_add(&msgbuf, func, strlen(func));
550 + strbuf_addstr(&msgbuf, func);
551 strbuf_add(&msgbuf, ep, line + len - ep);
552 - strbuf_add(&msgbuf, reset, strlen(reset));
552 + strbuf_addstr(&msgbuf, reset);
553 }
554
555 strbuf_add(&msgbuf, line + len, org_len - len);
path.c
+3 -3
@@ -277,16 +277,16 @@ char *expand_user_path(const char *path)
277 const char *home = getenv("HOME");
278 if (!home)
279 goto return_null;
280 - strbuf_add(&user_path, home, strlen(home));
280 + strbuf_addstr(&user_path, home);
281 } else {
282 struct passwd *pw = getpw_str(username, username_len);
283 if (!pw)
284 goto return_null;
285 - strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
285 + strbuf_addstr(&user_path, pw->pw_dir);
286 }
287 to_copy = first_slash;
288 }
289 - strbuf_add(&user_path, to_copy, strlen(to_copy));
289 + strbuf_addstr(&user_path, to_copy);
290 return strbuf_detach(&user_path, NULL);
291 return_null:
292 strbuf_release(&user_path);