Skip to content

Commit 96a093d

Browse files
Seija KijinAZero13
authored andcommitted
git: replace strbuf_addstr with strbuf_addch for all strings of length 2
Adding the char directly instead of a string of length 2 is clearer and more efficient. Signed-off-by: Seija Kijin <[email protected]>
1 parent d882f38 commit 96a093d

File tree

10 files changed

+13
-17
lines changed

10 files changed

+13
-17
lines changed

bisect.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ static int register_ref(const char *refname, const char *referent UNUSED, const
454454
{
455455
struct strbuf good_prefix = STRBUF_INIT;
456456
strbuf_addstr(&good_prefix, term_good);
457-
strbuf_addstr(&good_prefix, "-");
457+
strbuf_addch(&good_prefix, '-');
458458

459459
if (!strcmp(refname, term_bad)) {
460460
free(current_bad_oid);

builtin/am.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,13 +341,11 @@ static void write_author_script(const struct am_state *state)
341341

342342
strbuf_addstr(&sb, "GIT_AUTHOR_NAME=");
343343
sq_quote_buf(&sb, state->author_name);
344-
strbuf_addch(&sb, '\n');
345344

346-
strbuf_addstr(&sb, "GIT_AUTHOR_EMAIL=");
345+
strbuf_addstr(&sb, "\nGIT_AUTHOR_EMAIL=");
347346
sq_quote_buf(&sb, state->author_email);
348-
strbuf_addch(&sb, '\n');
349347

350-
strbuf_addstr(&sb, "GIT_AUTHOR_DATE=");
348+
strbuf_addstr(&sb, "\nGIT_AUTHOR_DATE=");
351349
sq_quote_buf(&sb, state->author_date);
352350
strbuf_addch(&sb, '\n');
353351

builtin/blame.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,9 @@ static void get_ac_line(const char *inbuf, const char *what,
148148

149149
if (split_ident_line(&ident, tmp, len)) {
150150
error_out:
151-
/* Ugh */
152-
tmp = "(unknown)";
153-
strbuf_addstr(name, tmp);
154-
strbuf_addstr(mail, tmp);
155-
strbuf_addstr(tz, tmp);
151+
strbuf_addstr(name, "(unknown)");
152+
strbuf_addstr(mail, "(unknown)");
153+
strbuf_addstr(tz, "(unknown)");
156154
*time = 0;
157155
return;
158156
}

builtin/ls-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static void expand_objectsize(struct strbuf *line, const struct object_id *oid,
3737
} else if (padded) {
3838
strbuf_addf(line, "%7s", "-");
3939
} else {
40-
strbuf_addstr(line, "-");
40+
strbuf_addch(line, '-');
4141
}
4242
}
4343

diff.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1763,7 +1763,7 @@ static void add_line_count(struct strbuf *out, int count)
17631763
strbuf_addstr(out, "0,0");
17641764
break;
17651765
case 1:
1766-
strbuf_addstr(out, "1");
1766+
strbuf_addch(out, '1');
17671767
break;
17681768
default:
17691769
strbuf_addf(out, "1,%d", count);

log-tree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,7 @@ void fmt_output_subject(struct strbuf *filename,
452452

453453
strbuf_addf(&temp, "v%s", info->reroll_count);
454454
format_sanitized_subject(filename, temp.buf, temp.len);
455-
strbuf_addstr(filename, "-");
455+
strbuf_addch(filename, '-');
456456
strbuf_release(&temp);
457457
}
458458
strbuf_addf(filename, "%04d-%s", nr, subject);

path.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,7 @@ const char *remove_leading_path(const char *in, const char *prefix)
982982

983983
strbuf_reset(&buf);
984984
if (!in[j])
985-
strbuf_addstr(&buf, ".");
985+
strbuf_addch(&buf, '.');
986986
else
987987
strbuf_addstr(&buf, in + j);
988988
return buf.buf;

protocol-caps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ static void send_info(struct repository *r, struct packet_writer *writer,
6565

6666
if (info->size) {
6767
if (oid_object_info(r, &oid, &object_size) < 0) {
68-
strbuf_addstr(&send_buffer, " ");
68+
strbuf_addch(&send_buffer, ' ');
6969
} else {
7070
strbuf_addf(&send_buffer, " %lu", object_size);
7171
}

setup.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1550,7 +1550,7 @@ static enum discovery_result setup_git_directory_gently_1(struct strbuf *dir,
15501550
return GIT_DIR_DISALLOWED_BARE;
15511551
if (!ensure_valid_ownership(NULL, NULL, dir->buf, report))
15521552
return GIT_DIR_INVALID_OWNERSHIP;
1553-
strbuf_addstr(gitdir, ".");
1553+
strbuf_addch(gitdir, '.');
15541554
return GIT_DIR_BARE;
15551555
}
15561556

trace2/tr2_tgt_normal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static void fn_child_start_fl(const char *file, int line,
226226
if (cmd->dir) {
227227
strbuf_addstr(&buf_payload, " cd ");
228228
sq_quote_buf_pretty(&buf_payload, cmd->dir);
229-
strbuf_addstr(&buf_payload, ";");
229+
strbuf_addch(&buf_payload, ';');
230230
}
231231

232232
/*

0 commit comments

Comments
 (0)