strbuf: remove global variable

As a library that only interacts with other primitives, strbuf should
not utilize the comment_line_char global variable within its
functions. Therefore, add an additional parameter for functions that use
comment_line_char and refactor callers to pass it in instead.
strbuf_stripspace() removes the skip_comments boolean and checks if
comment_line_char is a non-NUL character to determine whether to skip
comments or not.

Signed-off-by: Calvin Wan <calvinwan@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Calvin Wan
2023-06-06 19:48:43 +00:00
committed by Junio C Hamano
parent aba0706832
commit 787cb8a48a
16 changed files with 90 additions and 64 deletions

View File

@ -1,6 +1,7 @@
#include "builtin.h"
#include "cache.h"
#include "config.h"
#include "environment.h"
#include "gettext.h"
#include "parse-options.h"
#include "setup.h"
@ -13,7 +14,7 @@ static void comment_lines(struct strbuf *buf)
size_t len;
msg = strbuf_detach(buf, &len);
strbuf_add_commented_lines(buf, msg, len);
strbuf_add_commented_lines(buf, msg, len, comment_line_char);
free(msg);
}
@ -58,7 +59,8 @@ int cmd_stripspace(int argc, const char **argv, const char *prefix)
die_errno("could not read the input");
if (mode == STRIP_DEFAULT || mode == STRIP_COMMENTS)
strbuf_stripspace(&buf, mode == STRIP_COMMENTS);
strbuf_stripspace(&buf,
mode == STRIP_COMMENTS ? comment_line_char : '\0');
else
comment_lines(&buf);