Skip to content

Commit 2786d05

Browse files
peffgitster
authored andcommitted
strbuf: avoid shadowing global comment_line_char name
Several comment-related strbuf functions take a comment_line_char parameter. There's also a global comment_line_char variable, which is closely related (most callers pass it in as this parameter). Let's avoid shadowing the global name. This makes it more obvious that we're not using the global value, and it will be especially helpful as we refactor the global in future patches (in particular, any macro trickery wouldn't work because the preprocessor doesn't respect scope). We'll use "comment_prefix". That should be descriptive enough, and as a bonus is more neutral with respect to the "char" type (since we'll eventually swap it out for a string). Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1751e58 commit 2786d05

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

strbuf.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -359,16 +359,16 @@ static void add_lines(struct strbuf *out,
359359
}
360360

361361
void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
362-
size_t size, char comment_line_char)
362+
size_t size, char comment_prefix)
363363
{
364364
char prefix[2];
365365

366-
prefix[0] = comment_line_char;
366+
prefix[0] = comment_prefix;
367367
prefix[1] = '\0';
368368
add_lines(out, prefix, buf, size, 1);
369369
}
370370

371-
void strbuf_commented_addf(struct strbuf *sb, char comment_line_char,
371+
void strbuf_commented_addf(struct strbuf *sb, char comment_prefix,
372372
const char *fmt, ...)
373373
{
374374
va_list params;
@@ -379,7 +379,7 @@ void strbuf_commented_addf(struct strbuf *sb, char comment_line_char,
379379
strbuf_vaddf(&buf, fmt, params);
380380
va_end(params);
381381

382-
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_line_char);
382+
strbuf_add_commented_lines(sb, buf.buf, buf.len, comment_prefix);
383383
if (incomplete_line)
384384
sb->buf[--sb->len] = '\0';
385385

@@ -1001,10 +1001,10 @@ static size_t cleanup(char *line, size_t len)
10011001
*
10021002
* If last line does not have a newline at the end, one is added.
10031003
*
1004-
* Pass a non-NUL comment_line_char to skip every line starting
1004+
* Pass a non-NUL comment_prefix to skip every line starting
10051005
* with it.
10061006
*/
1007-
void strbuf_stripspace(struct strbuf *sb, char comment_line_char)
1007+
void strbuf_stripspace(struct strbuf *sb, char comment_prefix)
10081008
{
10091009
size_t empties = 0;
10101010
size_t i, j, len, newlen;
@@ -1017,8 +1017,8 @@ void strbuf_stripspace(struct strbuf *sb, char comment_line_char)
10171017
eol = memchr(sb->buf + i, '\n', sb->len - i);
10181018
len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
10191019

1020-
if (comment_line_char && len &&
1021-
sb->buf[i] == comment_line_char) {
1020+
if (comment_prefix && len &&
1021+
sb->buf[i] == comment_prefix) {
10221022
newlen = 0;
10231023
continue;
10241024
}

strbuf.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
288288
*/
289289
void strbuf_add_commented_lines(struct strbuf *out,
290290
const char *buf, size_t size,
291-
char comment_line_char);
291+
char comment_prefix);
292292

293293

294294
/**
@@ -379,7 +379,7 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
379379
* blank to the buffer.
380380
*/
381381
__attribute__((format (printf, 3, 4)))
382-
void strbuf_commented_addf(struct strbuf *sb, char comment_line_char, const char *fmt, ...);
382+
void strbuf_commented_addf(struct strbuf *sb, char comment_prefix, const char *fmt, ...);
383383

384384
__attribute__((format (printf,2,0)))
385385
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
@@ -513,11 +513,11 @@ int strbuf_getcwd(struct strbuf *sb);
513513
int strbuf_normalize_path(struct strbuf *sb);
514514

515515
/**
516-
* Strip whitespace from a buffer. If comment_line_char is non-NUL,
516+
* Strip whitespace from a buffer. If comment_prefix is non-NUL,
517517
* then lines beginning with that character are considered comments,
518518
* thus removed.
519519
*/
520-
void strbuf_stripspace(struct strbuf *buf, char comment_line_char);
520+
void strbuf_stripspace(struct strbuf *buf, char comment_prefix);
521521

522522
static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
523523
{

0 commit comments

Comments
 (0)