Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

Commit

Permalink
strbuf: use strbuf_addstr() for adding C strings
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
rscharfe authored and gitster committed Jul 17, 2014
1 parent 9d02150 commit cedc61a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion builtin/commit.c
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,
char *buffer;
buffer = strstr(use_message_buffer, "\n\n");
if (buffer)
strbuf_add(&sb, buffer + 2, strlen(buffer + 2));
strbuf_addstr(&sb, buffer + 2);
hook_arg1 = "commit";
hook_arg2 = use_message;
} else if (fixup_message) {
Expand Down
12 changes: 6 additions & 6 deletions diff.c
Original file line number Diff line number Diff line change
Expand Up @@ -525,9 +525,9 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
ep += 2; /* skip over @@ */

/* The hunk header in fraginfo color */
strbuf_add(&msgbuf, frag, strlen(frag));
strbuf_addstr(&msgbuf, frag);
strbuf_add(&msgbuf, line, ep - line);
strbuf_add(&msgbuf, reset, strlen(reset));
strbuf_addstr(&msgbuf, reset);

/*
* trailing "\r\n"
Expand All @@ -541,15 +541,15 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
if (*ep != ' ' && *ep != '\t')
break;
if (ep != cp) {
strbuf_add(&msgbuf, plain, strlen(plain));
strbuf_addstr(&msgbuf, plain);
strbuf_add(&msgbuf, cp, ep - cp);
strbuf_add(&msgbuf, reset, strlen(reset));
strbuf_addstr(&msgbuf, reset);
}

if (ep < line + len) {
strbuf_add(&msgbuf, func, strlen(func));
strbuf_addstr(&msgbuf, func);
strbuf_add(&msgbuf, ep, line + len - ep);
strbuf_add(&msgbuf, reset, strlen(reset));
strbuf_addstr(&msgbuf, reset);
}

strbuf_add(&msgbuf, line + len, org_len - len);
Expand Down
6 changes: 3 additions & 3 deletions path.c
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,16 @@ char *expand_user_path(const char *path)
const char *home = getenv("HOME");
if (!home)
goto return_null;
strbuf_add(&user_path, home, strlen(home));
strbuf_addstr(&user_path, home);
} else {
struct passwd *pw = getpw_str(username, username_len);
if (!pw)
goto return_null;
strbuf_add(&user_path, pw->pw_dir, strlen(pw->pw_dir));
strbuf_addstr(&user_path, pw->pw_dir);
}
to_copy = first_slash;
}
strbuf_add(&user_path, to_copy, strlen(to_copy));
strbuf_addstr(&user_path, to_copy);
return strbuf_detach(&user_path, NULL);
return_null:
strbuf_release(&user_path);
Expand Down

0 comments on commit cedc61a

Please sign in to comment.