Re: [PATCH v4 7/7] strbuf: remove global variable

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Calvin

On 08/05/2023 17:59, Calvin Wan wrote:
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.

I find the revised subject and commit message much easier to understand.

diff --git a/strbuf.c b/strbuf.c
index d5978fee4e..eba65ca421 100644
--- a/strbuf.c
+++ b/strbuf.c
@@ -1,6 +1,5 @@
  #include "git-compat-util.h"
  #include "alloc.h"
-#include "environment.h"
  #include "gettext.h"
  #include "hex.h"
  #include "strbuf.h"
@@ -362,7 +361,8 @@ static void add_lines(struct strbuf *out,
  	strbuf_complete_line(out);
  }
-void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size)
+void strbuf_add_commented_lines(struct strbuf *out, const char *buf,
+				size_t size, char comment_line_char)

I don't really object to this change as I can understand why you are making it, but it does make this function more cumbersome to use within git itself where we now have to pass the global comment_line_char explicitly.

@@ -1054,7 +1055,8 @@ static size_t cleanup(char *line, size_t len)
   * Enable skip_comments to skip every line starting with comment
   * character.
   */
-void strbuf_stripspace(struct strbuf *sb, int skip_comments)
+void strbuf_stripspace(struct strbuf *sb, int skip_comments,
+		       char comment_line_char)

Rather than adding a new parameter here could we change the signature to

	void strbuf_stripspace(struct strbuf *sb, char comment_char)

and not strip comments if comment_char == '\0'? There doesn't seem much point in forcing callers to pass comment_line_char when they don't want to strip comments.

Best Wishes

Phillip



[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux