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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jeff King committed
Mar 12, 2024 at 05:17 UTC
2786d058b6b25ab5f8d0994d24f4f4dc9442a41a
2 files changed
+12
-12
strbuf.c
+8
-8
@@ -359,16 +359,16 @@ static void add_lines(struct strbuf *out,
359
}
360
361
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)
363
{
364
char prefix[2];
365
366
- prefix[0] = comment_line_char;
366
+ prefix[0] = comment_prefix;
367
prefix[1] = '\0';
368
add_lines(out, prefix, buf, size, 1);
369
}
370
371
-void strbuf_commented_addf(struct strbuf *sb, char comment_line_char,
371
+void strbuf_commented_addf(struct strbuf *sb, char comment_prefix,
372
const char *fmt, ...)
373
{
374
va_list params;
@@ -379,7 +379,7 @@ void strbuf_commented_addf(struct strbuf *sb, char comment_line_char,
379
strbuf_vaddf(&buf, fmt, params);
380
va_end(params);
381
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);
383
if (incomplete_line)
384
sb->buf[--sb->len] = '\0';
385
@@ -1001,10 +1001,10 @@ static size_t cleanup(char *line, size_t len)
1001
*
1002
* If last line does not have a newline at the end, one is added.
1003
*
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
1005
* with it.
1006
*/
1007
-void strbuf_stripspace(struct strbuf *sb, char comment_line_char)
1007
+void strbuf_stripspace(struct strbuf *sb, char comment_prefix)
1008
{
1009
size_t empties = 0;
1010
size_t i, j, len, newlen;
@@ -1017,8 +1017,8 @@ void strbuf_stripspace(struct strbuf *sb, char comment_line_char)
1017
eol = memchr(sb->buf + i, '\n', sb->len - i);
1018
len = eol ? eol - (sb->buf + i) + 1 : sb->len - i;
1019
1020
- if (comment_line_char && len &&
1021
- sb->buf[i] == comment_line_char) {
1020
+ if (comment_prefix && len &&
1021
+ sb->buf[i] == comment_prefix) {
1022
newlen = 0;
1023
continue;
1024
}
strbuf.h
+4
-4
@@ -288,7 +288,7 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len,
288
*/
289
void strbuf_add_commented_lines(struct strbuf *out,
290
const char *buf, size_t size,
291
- char comment_line_char);
291
+ char comment_prefix);
292
293
294
/**
@@ -379,7 +379,7 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...);
379
* blank to the buffer.
380
*/
381
__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, ...);
383
384
__attribute__((format (printf,2,0)))
385
void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap);
@@ -513,11 +513,11 @@ int strbuf_getcwd(struct strbuf *sb);
513
int strbuf_normalize_path(struct strbuf *sb);
514
515
/**
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,
517
* then lines beginning with that character are considered comments,
518
* thus removed.
519
*/
520
-void strbuf_stripspace(struct strbuf *buf, char comment_line_char);
520
+void strbuf_stripspace(struct strbuf *buf, char comment_prefix);
521
522
static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
523
{