From 5e8617f560968567c285bc2e9b0674f8f9d535cb Mon Sep 17 00:00:00 2001 From: Thomas Rast Date: Wed, 22 Feb 2012 20:34:22 +0100 Subject: bundle: put strbuf_readline_fd in strbuf.c with adjustments The comment even said that it should eventually go there. While at it, match the calling convention and name of the function to the strbuf_get*line family. So it now is strbuf_getwholeline_fd. Signed-off-by: Thomas Rast Signed-off-by: Junio C Hamano --- strbuf.h | 1 + 1 file changed, 1 insertion(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 46a33f8c46..e42dbe5ac8 100644 --- a/strbuf.h +++ b/strbuf.h @@ -108,6 +108,7 @@ extern int strbuf_readlink(struct strbuf *sb, const char *path, size_t hint); extern int strbuf_getwholeline(struct strbuf *, FILE *, int); extern int strbuf_getline(struct strbuf *, FILE *, int); +extern int strbuf_getwholeline_fd(struct strbuf *, int, int); extern void stripspace(struct strbuf *buf, int skip_comments); extern int launch_editor(const char *path, struct strbuf *buffer, const char *const *env); -- cgit v1.2.1 From 9a0a30aa4b92a69f63275680820b81c7e34629c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Mon, 23 Apr 2012 19:30:22 +0700 Subject: strbuf: convenience format functions with \n automatically appended MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These functions are helpful when we do not want to expose \n to translators. For example printf("hello world\n"); can be converted to printf_ln(_("hello world")); Signed-off-by: Nguyễn Thái Ngọc Duy Signed-off-by: Junio C Hamano --- strbuf.h | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 3effaa86b6..b888d405db 100644 --- a/strbuf.h +++ b/strbuf.h @@ -99,6 +99,8 @@ __attribute__((format (printf,2,3))) extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); __attribute__((format (printf,2,0))) extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); +__attribute__((format (printf,2,3))) +extern void strbuf_addf_ln(struct strbuf *sb, const char *fmt, ...); extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size); @@ -129,4 +131,9 @@ extern void strbuf_add_urlencode(struct strbuf *, const char *, size_t, extern void strbuf_addstr_urlencode(struct strbuf *, const char *, int reserved); +__attribute__((format (printf,1,2))) +extern int printf_ln(const char *fmt, ...); +__attribute__((format (printf,2,3))) +extern int fprintf_ln(FILE *fp, const char *fmt, ...); + #endif /* STRBUF_H */ -- cgit v1.2.1 From ea03a8e181261b5efda10376ff160dc8df084104 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 15 Sep 2012 22:43:15 -0700 Subject: strbuf.c: mark a private file-scope symbol as static Also remove an unused function. Signed-off-by: Junio C Hamano --- strbuf.h | 4 ---- 1 file changed, 4 deletions(-) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index b888d405db..be941ee481 100644 --- a/strbuf.h +++ b/strbuf.h @@ -99,8 +99,6 @@ __attribute__((format (printf,2,3))) extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); __attribute__((format (printf,2,0))) extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); -__attribute__((format (printf,2,3))) -extern void strbuf_addf_ln(struct strbuf *sb, const char *fmt, ...); extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size); @@ -126,8 +124,6 @@ extern int launch_editor(const char *path, struct strbuf *buffer, const char *co extern int strbuf_branchname(struct strbuf *sb, const char *name); extern int strbuf_check_branch_ref(struct strbuf *sb, const char *name); -extern void strbuf_add_urlencode(struct strbuf *, const char *, size_t, - int reserved); extern void strbuf_addstr_urlencode(struct strbuf *, const char *, int reserved); -- cgit v1.2.1 From 17b73dc699c46d7af5d29d2f3813e7addafdce0d Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Sun, 4 Nov 2012 07:46:53 +0100 Subject: strbuf_split*(): rename "delim" parameter to "terminator" The word "delimiter" suggests that the argument separates the substrings, whereas in fact (1) the delimiter characters are included in the output, and (2) if the input string ends with the delimiter, then the output does not include a final empty string. So rename the "delim" arguments of the strbuf_split() family of functions to "terminator", which is more suggestive of how it is used. Signed-off-by: Michael Haggerty Signed-off-by: Jeff King --- strbuf.h | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index be941ee481..c896a47bfd 100644 --- a/strbuf.h +++ b/strbuf.h @@ -45,20 +45,21 @@ extern void strbuf_ltrim(struct strbuf *); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); extern struct strbuf **strbuf_split_buf(const char *, size_t, - int delim, int max); + int terminator, int max); static inline struct strbuf **strbuf_split_str(const char *str, - int delim, int max) + int terminator, int max) { - return strbuf_split_buf(str, strlen(str), delim, max); + return strbuf_split_buf(str, strlen(str), terminator, max); } static inline struct strbuf **strbuf_split_max(const struct strbuf *sb, - int delim, int max) + int terminator, int max) { - return strbuf_split_buf(sb->buf, sb->len, delim, max); + return strbuf_split_buf(sb->buf, sb->len, terminator, max); } -static inline struct strbuf **strbuf_split(const struct strbuf *sb, int delim) +static inline struct strbuf **strbuf_split(const struct strbuf *sb, + int terminator) { - return strbuf_split_max(sb, delim, 0); + return strbuf_split_max(sb, terminator, 0); } extern void strbuf_list_free(struct strbuf **); -- cgit v1.2.1 From 06379a65098212aef05010598ba3a8549bd78474 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Sun, 4 Nov 2012 07:46:54 +0100 Subject: strbuf_split*(): document functions Document strbuf_split_buf(), strbuf_split_str(), strbuf_split_max(), strbuf_split(), and strbuf_list_free() in the header file and in api-strbuf.txt. (These functions were previously completely undocumented.) Signed-off-by: Michael Haggerty Signed-off-by: Jeff King --- strbuf.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index c896a47bfd..aa386c6074 100644 --- a/strbuf.h +++ b/strbuf.h @@ -44,23 +44,56 @@ extern void strbuf_rtrim(struct strbuf *); extern void strbuf_ltrim(struct strbuf *); extern int strbuf_cmp(const struct strbuf *, const struct strbuf *); +/* + * Split str (of length slen) at the specified terminator character. + * Return a null-terminated array of pointers to strbuf objects + * holding the substrings. The substrings include the terminator, + * except for the last substring, which might be unterminated if the + * original string did not end with a terminator. If max is positive, + * then split the string into at most max substrings (with the last + * substring containing everything following the (max-1)th terminator + * character). + * + * For lighter-weight alternatives, see string_list_split() and + * string_list_split_in_place(). + */ extern struct strbuf **strbuf_split_buf(const char *, size_t, int terminator, int max); + +/* + * Split a NUL-terminated string at the specified terminator + * character. See strbuf_split_buf() for more information. + */ static inline struct strbuf **strbuf_split_str(const char *str, int terminator, int max) { return strbuf_split_buf(str, strlen(str), terminator, max); } + +/* + * Split a strbuf at the specified terminator character. See + * strbuf_split_buf() for more information. + */ static inline struct strbuf **strbuf_split_max(const struct strbuf *sb, int terminator, int max) { return strbuf_split_buf(sb->buf, sb->len, terminator, max); } + +/* + * Split a strbuf at the specified terminator character. See + * strbuf_split_buf() for more information. + */ static inline struct strbuf **strbuf_split(const struct strbuf *sb, int terminator) { return strbuf_split_max(sb, terminator, 0); } + +/* + * Free a NULL-terminated list of strbufs (for example, the return + * values of the strbuf_split*() functions). + */ extern void strbuf_list_free(struct strbuf **); /*----- add data in your buffer -----*/ -- cgit v1.2.1 From 5963c0367f00df0e5eeb761f1ef77a33c8f54c40 Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Sun, 25 Nov 2012 12:08:34 +0100 Subject: Add new function strbuf_add_xml_quoted() Substantially the same code is present in http-push.c and imap-send.c, so make a library function out of it. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- strbuf.h | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index be941ee481..65aa2a032f 100644 --- a/strbuf.h +++ b/strbuf.h @@ -102,6 +102,12 @@ extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); extern void strbuf_add_lines(struct strbuf *sb, const char *prefix, const char *buf, size_t size); +/* + * Append s to sb, with the characters '<', '>', '&' and '"' converted + * into XML entities. + */ +extern void strbuf_addstr_xml_quoted(struct strbuf *sb, const char *s); + static inline void strbuf_complete_line(struct strbuf *sb) { if (sb->len && sb->buf[sb->len - 1] != '\n') -- cgit v1.2.1 From eff80a9fd990de3605063050dae32f969ef18ba8 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Wed, 16 Jan 2013 20:18:48 +0100 Subject: Allow custom "comment char" Some users do want to write a line that begin with a pound sign, #, in their commit log message. Many tracking system recognise a token of # form, for example. The support we offer these use cases is not very friendly to the end users. They have a choice between - Don't do it. Avoid such a line by rewrapping or indenting; and - Use --cleanup=whitespace but remove all the hint lines we add. Give them a way to set a custom comment char, e.g. $ git -c core.commentchar="%" commit so that they do not have to do either of the two workarounds. [jc: although I started the topic, all the tests and documentation updates, many of the call sites of the new strbuf_add_commented_*() functions, and the change to git-submodule.sh scripted Porcelain are from Ralf.] Signed-off-by: Junio C Hamano Signed-off-by: Ralf Thielow Signed-off-by: Junio C Hamano --- strbuf.h | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index ecae4e215f..958822c2dd 100644 --- a/strbuf.h +++ b/strbuf.h @@ -110,6 +110,8 @@ extern void strbuf_remove(struct strbuf *, size_t pos, size_t len); extern void strbuf_splice(struct strbuf *, size_t pos, size_t len, const void *, size_t); +extern void strbuf_add_commented_lines(struct strbuf *out, const char *buf, size_t size); + extern void strbuf_add(struct strbuf *, const void *, size_t); static inline void strbuf_addstr(struct strbuf *sb, const char *s) { strbuf_add(sb, s, strlen(s)); @@ -131,6 +133,8 @@ extern void strbuf_addbuf_percentquote(struct strbuf *dst, const struct strbuf * __attribute__((format (printf,2,3))) extern void strbuf_addf(struct strbuf *sb, const char *fmt, ...); +__attribute__((format (printf, 2, 3))) +extern void strbuf_commented_addf(struct strbuf *sb, const char *fmt, ...); __attribute__((format (printf,2,0))) extern void strbuf_vaddf(struct strbuf *sb, const char *fmt, va_list ap); -- cgit v1.2.1 From 079b546a2940a84989893254a318c8414e13a13e Mon Sep 17 00:00:00 2001 From: Antoine Pelisse Date: Wed, 10 Apr 2013 21:03:23 +0200 Subject: strbuf: create strbuf_humanise_bytes() to show byte sizes Humanization of downloaded size is done in the same function as text formatting in 'process.c'. The code cannot be reused easily elsewhere. Separate text formatting from size simplification and make the function public in strbuf so that it can easily be used by other callers. We now can use strbuf_humanise_bytes() for both downloaded size and download speed calculation. One of the drawbacks is that speed will now look like this when download is stalled: "0 bytes/s" instead of "0 KiB/s". Signed-off-by: Antoine Pelisse Signed-off-by: Junio C Hamano --- strbuf.h | 1 + 1 file changed, 1 insertion(+) (limited to 'strbuf.h') diff --git a/strbuf.h b/strbuf.h index 958822c2dd..73e80cea69 100644 --- a/strbuf.h +++ b/strbuf.h @@ -170,6 +170,7 @@ extern int strbuf_check_branch_ref(struct strbuf *sb, const char *name); extern void strbuf_addstr_urlencode(struct strbuf *, const char *, int reserved); +extern void strbuf_humanise_bytes(struct strbuf *buf, off_t bytes); __attribute__((format (printf,1,2))) extern int printf_ln(const char *fmt, ...); -- cgit v1.2.1