Skip to content

Commit cedc61a

Browse files
rscharfegitster
authored andcommitted
strbuf: use strbuf_addstr() for adding C strings
Avoid code duplication and let strbuf_addstr() call strlen() for us. Signed-off-by: Rene Scharfe <[email protected]> Reviewed-by: Jonathan Nieder <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9d02150 commit cedc61a

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

builtin/commit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
707707
char *buffer;
708708
buffer = strstr(use_message_buffer, "\n\n");
709709
if (buffer)
710-
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
710+
strbuf_addstr(&sb, buffer + 2);
711711
hook_arg1 = "commit";
712712
hook_arg2 = use_message;
713713
} else if (fixup_message) {

diff.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,9 +525,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
525525
ep += 2; /* skip over @@ */
526526

527527
/* The hunk header in fraginfo color */
528-
strbuf_add(&msgbuf, frag, strlen(frag));
528+
strbuf_addstr(&msgbuf, frag);
529529
strbuf_add(&msgbuf, line, ep - line);
530-
strbuf_add(&msgbuf, reset, strlen(reset));
530+
strbuf_addstr(&msgbuf, reset);
531531

532532
/*
533533
* trailing "\r\n"
@@ -541,15 +541,15 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
541541
if (*ep != ' ' && *ep != '\t')
542542
break;
543543
if (ep != cp) {
544-
strbuf_add(&msgbuf, plain, strlen(plain));
544+
strbuf_addstr(&msgbuf, plain);
545545
strbuf_add(&msgbuf, cp, ep - cp);
546-
strbuf_add(&msgbuf, reset, strlen(reset));
546+
strbuf_addstr(&msgbuf, reset);
547547
}
548548

549549
if (ep < line + len) {
550-
strbuf_add(&msgbuf, func, strlen(func));
550+
strbuf_addstr(&msgbuf, func);
551551
strbuf_add(&msgbuf, ep, line + len - ep);
552-
strbuf_add(&msgbuf, reset, strlen(reset));
552+
strbuf_addstr(&msgbuf, reset);
553553
}
554554

555555
strbuf_add(&msgbuf, line + len, org_len - len);

path.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,16 +277,16 @@ char *expand_user_path(const char *path)
277277
const char *home = getenv("HOME");
278278
if (!home)
279279
goto return_null;
280-
strbuf_add(&user_path, home, strlen(home));
280+
strbuf_addstr(&user_path, home);
281281
} else {
282282
struct passwd *pw = getpw_str(username, username_len);
283283
if (!pw)
284284
goto return_null;
285-
strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
285+
strbuf_addstr(&user_path, pw->pw_dir);
286286
}
287287
to_copy = first_slash;
288288
}
289-
strbuf_add(&user_path, to_copy, strlen(to_copy));
289+
strbuf_addstr(&user_path, to_copy);
290290
return strbuf_detach(&user_path, NULL);
291291
return_null:
292292
strbuf_release(&user_path);

0 commit comments

Comments
 (0)