From 6897be8f14fb97e7ee4f9d5543af4320bb8039ee Mon Sep 17 00:00:00 2001 From: Calvin Wan Date: Fri, 12 May 2023 17:15:16 +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 --- builtin/notes.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'builtin/notes.c') diff --git a/builtin/notes.c b/builtin/notes.c index d5788352b6..3bad5b458b 100644 --- a/builtin/notes.c +++ b/builtin/notes.c @@ -11,6 +11,7 @@ #include "config.h" #include "builtin.h" #include "editor.h" +#include "environment.h" #include "gettext.h" #include "hex.h" #include "notes.h" @@ -157,7 +158,7 @@ static void write_commented_object(int fd, const struct object_id *object) if (strbuf_read(&buf, show.out, 0) < 0) die_errno(_("could not read 'show' output")); - strbuf_add_commented_lines(&cbuf, buf.buf, buf.len); + strbuf_add_commented_lines(&cbuf, buf.buf, buf.len, comment_line_char); write_or_die(fd, cbuf.buf, cbuf.len); strbuf_release(&cbuf); @@ -185,9 +186,10 @@ static void prepare_note_data(const struct object_id *object, struct note_data * copy_obj_to_fd(fd, old_note); strbuf_addch(&buf, '\n'); - strbuf_add_commented_lines(&buf, "\n", strlen("\n")); - strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template))); - strbuf_add_commented_lines(&buf, "\n", strlen("\n")); + strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char); + strbuf_add_commented_lines(&buf, _(note_template), strlen(_(note_template)), + comment_line_char); + strbuf_add_commented_lines(&buf, "\n", strlen("\n"), comment_line_char); write_or_die(fd, buf.buf, buf.len); write_commented_object(fd, object); @@ -199,7 +201,7 @@ static void prepare_note_data(const struct object_id *object, struct note_data * if (launch_editor(d->edit_path, &d->buf, NULL)) { die(_("please supply the note contents using either -m or -F option")); } - strbuf_stripspace(&d->buf, 1); + strbuf_stripspace(&d->buf, comment_line_char); } } @@ -225,7 +227,7 @@ static int parse_msg_arg(const struct option *opt, const char *arg, int unset) if (d->buf.len) strbuf_addch(&d->buf, '\n'); strbuf_addstr(&d->buf, arg); - strbuf_stripspace(&d->buf, 0); + strbuf_stripspace(&d->buf, '\0'); d->given = 1; return 0; @@ -244,7 +246,7 @@ static int parse_file_arg(const struct option *opt, const char *arg, int unset) die_errno(_("cannot read '%s'"), arg); } else if (strbuf_read_file(&d->buf, arg, 1024) < 0) die_errno(_("could not open or read '%s'"), arg); - strbuf_stripspace(&d->buf, 0); + strbuf_stripspace(&d->buf, '\0'); d->given = 1; return 0; -- cgit v1.2.1