From 787cb8a48ae24ff07fa7c763909bb204bfdc84a7 Mon Sep 17 00:00:00 2001 From: Calvin Wan Date: Tue, 6 Jun 2023 19:48:43 +0000 Subject: 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 Signed-off-by: Junio C Hamano --- strbuf.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 5d97e27b99..da91c17257 100644 --- a/strbuf.h +++ b/strbuf.h @@ -291,7 +291,8 @@ void strbuf_splice(struct strbuf *sb, size_t pos, size_t len, * by a comment character and a blank. */ void strbuf_add_commented_lines(struct strbuf *out, - const char *buf, size_t size); + const char *buf, size_t size, + char comment_line_char); /** @@ -420,8 +421,8 @@ void strbuf_addf(struct strbuf *sb, const char *fmt, ...); * Add a formatted string prepended by a comment character and a * blank to the buffer. */ -__attribute__((format (printf, 2, 3))) -void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...); +__attribute__((format (printf, 3, 4))) +void strbuf_commented_addf(struct strbuf *sb, char comment_line_char, const char *fmt, ...); __attribute__((format (printf,2,0))) void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); @@ -543,10 +544,11 @@ int strbuf_getcwd(struct strbuf *sb); int strbuf_normalize_path(struct strbuf *sb); /** - * Strip whitespace from a buffer. The second parameter controls if - * comments are considered contents to be removed or not. + * Strip whitespace from a buffer. If comment_line_char is non-NUL, + * then lines beginning with that character are considered comments, + * thus removed. */ -void strbuf_stripspace(struct strbuf *buf, int skip_comments); +void strbuf_stripspace(struct strbuf *buf, char comment_line_char); static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix) { -- cgit v1.2.3