Skip to content

Commit cf50d3d

Browse files
committed
Merge branch 'jc/strbuf-commented-something' into seen
Update two functions whose callers always pass the same global variable to omit the redundant parameter and use the global in the callee themselves. * jc/strbuf-commented-something: strbuf: retire strbuf_commented_lines() strbuf: retire strbuf_commented_addf()
2 parents b6310a6 + 19e27e2 commit cf50d3d

File tree

12 files changed

+56
-57
lines changed

12 files changed

+56
-57
lines changed

add-patch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1116,11 +1116,11 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
11161116
size_t i;
11171117

11181118
strbuf_reset(&s->buf);
1119-
strbuf_commented_addf(&s->buf, comment_line_str,
1119+
strbuf_comment_addf(&s->buf,
11201120
_("Manual hunk edit mode -- see bottom for "
11211121
"a quick guide.\n"));
11221122
render_hunk(s, hunk, 0, 0, &s->buf);
1123-
strbuf_commented_addf(&s->buf, comment_line_str,
1123+
strbuf_comment_addf(&s->buf,
11241124
_("---\n"
11251125
"To remove '%c' lines, make them ' ' lines "
11261126
"(context).\n"
@@ -1129,13 +1129,13 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
11291129
s->mode->is_reverse ? '+' : '-',
11301130
s->mode->is_reverse ? '-' : '+',
11311131
comment_line_str);
1132-
strbuf_commented_addf(&s->buf, comment_line_str, "%s",
1132+
strbuf_comment_addf(&s->buf, "%s",
11331133
_(s->mode->edit_hunk_hint));
11341134
/*
11351135
* TRANSLATORS: 'it' refers to the patch mentioned in the previous
11361136
* messages.
11371137
*/
1138-
strbuf_commented_addf(&s->buf, comment_line_str,
1138+
strbuf_comment_addf(&s->buf,
11391139
_("If it does not apply cleanly, you will be "
11401140
"given an opportunity to\n"
11411141
"edit again. If all lines of the hunk are "

builtin/branch.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,7 @@ static int edit_branch_description(const char *branch_name)
682682
exists = !read_branch_desc(&buf, branch_name);
683683
if (!buf.len || buf.buf[buf.len-1] != '\n')
684684
strbuf_addch(&buf, '\n');
685-
strbuf_commented_addf(&buf, comment_line_str,
685+
strbuf_comment_addf(&buf,
686686
_("Please edit the description for the branch\n"
687687
" %s\n"
688688
"Lines starting with '%s' will be stripped.\n"),

builtin/merge.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -868,15 +868,15 @@ static void prepare_to_commit(struct commit_list *remoteheads)
868868
strbuf_addch(&msg, '\n');
869869
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS) {
870870
wt_status_append_cut_line(&msg);
871-
strbuf_commented_addf(&msg, comment_line_str, "\n");
871+
strbuf_comment_addf(&msg, "\n");
872872
}
873-
strbuf_commented_addf(&msg, comment_line_str,
873+
strbuf_comment_addf(&msg,
874874
_(merge_editor_comment));
875875
if (cleanup_mode == COMMIT_MSG_CLEANUP_SCISSORS)
876-
strbuf_commented_addf(&msg, comment_line_str,
876+
strbuf_comment_addf(&msg,
877877
_(scissors_editor_comment));
878878
else
879-
strbuf_commented_addf(&msg, comment_line_str,
879+
strbuf_comment_addf(&msg,
880880
_(no_scissors_editor_comment), comment_line_str);
881881
}
882882
if (signoff)

builtin/notes.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ static void write_commented_object(int fd, const struct object_id *object)
178178

179179
if (strbuf_read(&buf, show.out, 0) < 0)
180180
die_errno(_("could not read 'show' output"));
181-
strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_str);
181+
strbuf_add_comment_lines(&cbuf, buf.buf, buf.len);
182182
write_or_die(fd, cbuf.buf, cbuf.len);
183183

184184
strbuf_release(&cbuf);
@@ -206,10 +206,10 @@ static void prepare_note_data(const struct object_id *object, struct note_data *
206206
copy_obj_to_fd(fd, old_note);
207207

208208
strbuf_addch(&buf, '\n');
209-
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_str);
210-
strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)),
211-
comment_line_str);
212-
strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_str);
209+
strbuf_add_comment_lines(&buf, "\n", strlen("\n"));
210+
strbuf_add_comment_lines(&buf, _(note_template),
211+
strlen(_(note_template)));
212+
strbuf_add_comment_lines(&buf, "\n", strlen("\n"));
213213
write_or_die(fd, buf.buf, buf.len);
214214

215215
write_commented_object(fd, object);

builtin/stripspace.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ static void comment_lines(struct strbuf *buf)
1414
size_t len;
1515

1616
msg = strbuf_detach(buf, &len);
17-
strbuf_add_commented_lines(buf, msg, len, comment_line_str);
17+
strbuf_add_comment_lines(buf, msg, len);
1818
free(msg);
1919
}
2020

builtin/tag.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,10 +335,10 @@ static void create_tag(const struct object_id *object, const char *object_ref,
335335
struct strbuf buf = STRBUF_INIT;
336336
strbuf_addch(&buf, '\n');
337337
if (opt->cleanup_mode == CLEANUP_ALL)
338-
strbuf_commented_addf(&buf, comment_line_str,
338+
strbuf_comment_addf(&buf,
339339
_(tag_template), tag, comment_line_str);
340340
else
341-
strbuf_commented_addf(&buf, comment_line_str,
341+
strbuf_comment_addf(&buf,
342342
_(tag_template_nocleanup), tag, comment_line_str);
343343
write_or_die(fd, buf.buf, buf.len);
344344
strbuf_release(&buf);

fmt-merge-msg.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -511,8 +511,7 @@ static void fmt_tag_signature(struct strbuf *tagbuf,
511511
strbuf_complete_line(tagbuf);
512512
if (sig->len) {
513513
strbuf_addch(tagbuf, '\n');
514-
strbuf_add_commented_lines(tagbuf, sig->buf, sig->len,
515-
comment_line_str);
514+
strbuf_add_comment_lines(tagbuf, sig->buf, sig->len);
516515
}
517516
}
518517

@@ -556,19 +555,17 @@ static void fmt_merge_msg_sigs(struct strbuf *out)
556555
if (tag_number == 2) {
557556
struct strbuf tagline = STRBUF_INIT;
558557
strbuf_addch(&tagline, '\n');
559-
strbuf_add_commented_lines(&tagline,
560-
origins.items[first_tag].string,
561-
strlen(origins.items[first_tag].string),
562-
comment_line_str);
558+
strbuf_add_comment_lines(&tagline,
559+
origins.items[first_tag].string,
560+
strlen(origins.items[first_tag].string));
563561
strbuf_insert(&tagbuf, 0, tagline.buf,
564562
tagline.len);
565563
strbuf_release(&tagline);
566564
}
567565
strbuf_addch(&tagbuf, '\n');
568-
strbuf_add_commented_lines(&tagbuf,
569-
origins.items[i].string,
570-
strlen(origins.items[i].string),
571-
comment_line_str);
566+
strbuf_add_comment_lines(&tagbuf,
567+
origins.items[i].string,
568+
strlen(origins.items[i].string));
572569
fmt_tag_signature(&tagbuf, &sig, buf, len);
573570
}
574571
strbuf_release(&payload);

rebase-interactive.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,14 @@ void append_todo_help(int command_count,
7373

7474
if (!edit_todo) {
7575
strbuf_addch(buf, '\n');
76-
strbuf_commented_addf(buf, comment_line_str,
76+
strbuf_comment_addf(buf,
7777
Q_("Rebase %s onto %s (%d command)",
7878
"Rebase %s onto %s (%d commands)",
7979
command_count),
8080
shortrevisions, shortonto, command_count);
8181
}
8282

83-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
83+
strbuf_add_comment_lines(buf, msg, strlen(msg));
8484

8585
if (get_missing_commit_check_level() == MISSING_COMMIT_CHECK_ERROR)
8686
msg = _("\nDo not remove any line. Use 'drop' "
@@ -89,7 +89,7 @@ void append_todo_help(int command_count,
8989
msg = _("\nIf you remove a line here "
9090
"THAT COMMIT WILL BE LOST.\n");
9191

92-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
92+
strbuf_add_comment_lines(buf, msg, strlen(msg));
9393

9494
if (edit_todo)
9595
msg = _("\nYou are editing the todo file "
@@ -100,7 +100,7 @@ void append_todo_help(int command_count,
100100
msg = _("\nHowever, if you remove everything, "
101101
"the rebase will be aborted.\n\n");
102102

103-
strbuf_add_commented_lines(buf, msg, strlen(msg), comment_line_str);
103+
strbuf_add_comment_lines(buf, msg, strlen(msg));
104104
}
105105

106106
int edit_todo_list(struct repository *r, struct replay_opts *opts,

sequencer.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,11 @@ void append_conflicts_hint(struct index_state *istate,
732732
}
733733

734734
strbuf_addch(msgbuf, '\n');
735-
strbuf_commented_addf(msgbuf, comment_line_str, "Conflicts:\n");
735+
strbuf_comment_addf(msgbuf, "Conflicts:\n");
736736
for (i = 0; i < istate->cache_nr;) {
737737
const struct cache_entry *ce = istate->cache[i++];
738738
if (ce_stage(ce)) {
739-
strbuf_commented_addf(msgbuf, comment_line_str,
739+
strbuf_comment_addf(msgbuf,
740740
"\t%s\n", ce->name);
741741
while (i < istate->cache_nr &&
742742
!strcmp(ce->name, istate->cache[i]->name))
@@ -1912,7 +1912,7 @@ static int is_fixup_flag(enum todo_command command, unsigned flag)
19121912
}
19131913

19141914
/*
1915-
* Wrapper around strbuf_add_commented_lines() which avoids double
1915+
* Wrapper around strbuf_add_comment_lines() which avoids double
19161916
* commenting commit subjects.
19171917
*/
19181918
static void add_commented_lines(struct strbuf *buf, const void *str, size_t len)
@@ -1929,7 +1929,7 @@ static void add_commented_lines(struct strbuf *buf, const void *str, size_t len)
19291929
s += count;
19301930
len -= count;
19311931
}
1932-
strbuf_add_commented_lines(buf, s, len, comment_line_str);
1932+
strbuf_add_comment_lines(buf, s, len);
19331933
}
19341934

19351935
/* Does the current fixup chain contain a squash command? */
@@ -2029,7 +2029,7 @@ static int append_squash_message(struct strbuf *buf, const char *body,
20292029
strbuf_addf(buf, _(nth_commit_msg_fmt),
20302030
++ctx->current_fixup_count + 1);
20312031
strbuf_addstr(buf, "\n\n");
2032-
strbuf_add_commented_lines(buf, body, commented_len, comment_line_str);
2032+
strbuf_add_comment_lines(buf, body, commented_len);
20332033
/* buf->buf may be reallocated so store an offset into the buffer */
20342034
fixup_off = buf->len;
20352035
strbuf_addstr(buf, body + commented_len);
@@ -2120,8 +2120,7 @@ static int update_squash_messages(struct repository *r,
21202120
_(first_commit_msg_str));
21212121
strbuf_addstr(&buf, "\n\n");
21222122
if (is_fixup_flag(command, flag))
2123-
strbuf_add_commented_lines(&buf, body, strlen(body),
2124-
comment_line_str);
2123+
strbuf_add_comment_lines(&buf, body, strlen(body));
21252124
else
21262125
strbuf_addstr(&buf, body);
21272126

@@ -2140,8 +2139,7 @@ static int update_squash_messages(struct repository *r,
21402139
strbuf_addf(&buf, _(skip_nth_commit_msg_fmt),
21412140
++ctx->current_fixup_count + 1);
21422141
strbuf_addstr(&buf, "\n\n");
2143-
strbuf_add_commented_lines(&buf, body, strlen(body),
2144-
comment_line_str);
2142+
strbuf_add_comment_lines(&buf, body, strlen(body));
21452143
} else
21462144
return error(_("unknown command: %d"), command);
21472145
repo_unuse_commit_buffer(r, commit, message);

strbuf.c

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
#include "git-compat-util.h"
2+
#include "environment.h"
23
#include "gettext.h"
34
#include "hex-ll.h"
45
#include "strbuf.h"
56
#include "string-list.h"
67
#include "utf8.h"
78
#include "date.h"
89

10+
/*
11+
* We do not need the_repository at all, but the comment_line_str
12+
* variable is hidden behind USE_THE_REPOSITORY_VARIABLE CPP macro.
13+
* We could #define it before including "envirnoment.h". Or we can
14+
* make an external declaration ourselves here.
15+
*/
16+
extern const char *comment_line_str;
17+
918
int starts_with(const char *str, const char *prefix)
1019
{
1120
for (; ; str++, prefix++)
@@ -385,14 +394,12 @@ static void add_lines(struct strbuf *out,
385394
strbuf_complete_line(out);
386395
}
387396

388-
void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
389-
size_t size, const char *comment_prefix)
397+
void strbuf_add_comment_lines(struct strbuf *out, const char *buf, size_t size)
390398
{
391-
add_lines(out, comment_prefix, buf, size, 1);
399+
add_lines(out, comment_line_str, buf, size, 1);
392400
}
393401

394-
void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
395-
const char *fmt, ...)
402+
void strbuf_comment_addf(struct strbuf *sb, const char *fmt, ...)
396403
{
397404
va_list params;
398405
struct strbuf buf = STRBUF_INIT;
@@ -402,7 +409,7 @@ void strbuf_commented_addf(struct strbuf *sb, const char *comment_prefix,
402409
strbuf_vaddf(&buf, fmt, params);
403410
va_end(params);
404411

405-
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix);
412+
strbuf_add_comment_lines(sb, buf.buf, buf.len);
406413
if (incomplete_line)
407414
sb->buf[--sb->len] = '\0';
408415

0 commit comments

Comments
 (0)