git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] document string_list_clear

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Dec 9, 2014, 20:17 UTC
Message-ID
<20141209201713.GY16345@google.com>
In-Reply-To
<CAGZ79kbk4SXEXKzn-V8c4zCQU8m8ub+VkKhmub-bFoLZT1WWpA@mail.gmail.com>
Stefan Beller wrote:
> On Tue, Dec 9, 2014 at 11:37 AM, Junio C Hamano <gitster@pobox.com> wrote:
Show 8 quoted lines
>> Perhaps the API doc that currently says "Free" is the only thing
>> that needs fixing?  And perhaps add "See $doc" at the beginning of
>> the header and remove duplicated comments we already have in the
>> file?
>
> The reason I wrote this patch originally was because I seem to forget we have
> more than one place to document our APIs. If there are comments in the header
> I seem to have thought it were the only place where we have documentation.
How about this patch?
-- >8 --
Subject: put strbuf API documentation in one place

v1.8.1-rc0~61^2 (strbuf_split*(): document functions, 2012-11-04) added some nice API documentation for a few functions to strbuf.h, to complement the documentation at Documentation/technical/api-strbuf. That was helpful because it meant one less hop for someone reading the header to find API documentation.

In practice, unfortunately, it is too hard to remember that there is documentation in two places. The longer documentation comments in the header made Documentation/technical/api-strbuf less discoverable. So move the information to Documentation/technical/api-strbuf and drop the long comments.

Hopefully in the long term we will find a good way to generate well organized Documentation/technical/api-* documents from comments in headers and this problem will be eliminated completely.

Short reminders in the header file are still okay.
Reported-by: Stefan Beller <sbeller@google.com>
Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
---
 Documentation/technical/api-strbuf.txt | 20 +++++++++++++++--
 strbuf.h                               | 40 ++--------------------------------
 2 files changed, 20 insertions(+), 40 deletions(-)
diff --git a/Documentation/technical/api-strbuf.txt b/Documentation/technical/api-strbuf.txt
index cca6543..a43facc 100644
--- a/Documentation/technical/api-strbuf.txt
+++ b/Documentation/technical/api-strbuf.txt
@@ -252,6 +252,11 @@ which can be used by the programmer of the callback as she sees fit.
 	destination. This is useful for literal data to be fed to either
 	strbuf_expand or to the *printf family of functions.
 
+`strbuf_addstr_xml_quoted`::
+
+	Append a string to a strbuf with the characters '<', '>', '&', and
+	'"' converted into XML entities.
+
 `strbuf_humanise_bytes`::
 
 	Append the given byte size as a human-readable string (i.e. 12.23 KiB,
@@ -266,6 +271,13 @@ which can be used by the programmer of the callback as she sees fit.
 	Add a formatted string prepended by a comment character and a
 	blank to the buffer.
 
+`xstrfmt`::
+`xstrvfmt`::
+
+	Create a newly allocated string using printf format.  You can do
+	this easily with a strbuf, but this provides a shortcut to save a
+	few lines.
+
 `strbuf_fread`::
 
 	Read a given size of data from a FILE* pointer to the buffer.
@@ -336,11 +348,15 @@ same behaviour as well.
 	terminator characters.  Some of these functions take a `max`
 	parameter, which, if positive, limits the output to that
 	number of substrings.
++
+For lighter-weight alternatives, see `string_list_split` and
+`string_list_split_in_place` from the
+link:api-string-list.html[string list API].
 
 `strbuf_list_free`::
 
-	Free a list of strbufs (for example, the return values of the
-	`strbuf_split()` functions).
+	Free a NULL-terminated list of strbufs (for example, the return
+	values of the `strbuf_split()` functions).
 
 `launch_editor`::
 
diff --git a/strbuf.h b/strbuf.h
index 652b6c4..f3c9bb6 100644
--- a/strbuf.h
+++ b/strbuf.h
@@ -58,56 +58,27 @@ static inline int strbuf_strip_suffix(struct strbuf *sb, const char *suffix)
 		return 0;
 }
 
-/*
- * 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,
+extern struct strbuf **strbuf_split_buf(const char *str, size_t slen,
 					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 -----*/
@@ -158,10 +129,7 @@ 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.
- */
+/* append s with <, >, &, and " converted to XML entities */
 extern void strbuf_addstr_xml_quoted(struct strbuf *sb, const char *s);
 
 static inline void strbuf_complete_line(struct strbuf *sb)
@@ -200,10 +168,6 @@ extern int fprintf_ln(FILE *fp, const char *fmt, ...);
 
 char *xstrdup_tolower(const char *);
 
-/*
- * Create a newly allocated string using printf format. You can do this easily
- * with a strbuf, but this provides a shortcut to save a few lines.
- */
 __attribute__((format (printf, 1, 0)))
 char *xstrvfmt(const char *fmt, va_list ap);
 __attribute__((format (printf, 1, 2)))
-- 
2.2.0.rc0.207.ga3a616c
Previous: Stefan BellerNext: Jeff King
Message 10 of 49 in “document string_list_clear”
  1. document string_list_clearStefan Beller, Dec 6, 2014
  2. Jonathan NiederDec 6, 2014
  3. Jeff KingDec 6, 2014
  4. Jeff KingDec 6, 2014
  5. Junio C HamanoDec 9, 2014
  6. Jeff KingDec 9, 2014
  7. Jonathan NiederDec 9, 2014
  8. Junio C HamanoDec 9, 2014
  9. Stefan BellerDec 9, 2014
  10. Jonathan NiederDec 9, 2014
  11. Jeff KingDec 9, 2014
  12. Stefan BellerDec 9, 2014
  13. Jeff KingDec 9, 2014
  14. Jonathan NiederDec 9, 2014
  15. Junio C HamanoDec 9, 2014
  16. Jeff KingDec 10, 2014
  17. Jeff KingDec 10, 2014
  18. Jonathan NiederDec 10, 2014
  19. Jeff KingDec 12, 2014
  20. Jonathan NiederDec 12, 2014
  21. Junio C HamanoDec 12, 2014
  22. Stefan BellerDec 12, 2014
  23. Jeff KingDec 12, 2014
  24. Jeff KingDec 12, 2014
  25. Jonathan NiederDec 12, 2014
  26. Jeff KingDec 12, 2014
  27. 1/4 strbuf: migrate api-strbuf.txt documentation to strbuf.hJeff King, Dec 12, 2014
  28. Jeff KingDec 12, 2014
  29. Junio C HamanoDec 12, 2014
  30. Jonathan NiederDec 12, 2014
  31. 2/4 strbuf.h: drop asciidoc list formatting from API docsJeff King, Dec 12, 2014
  32. Junio C HamanoDec 12, 2014
  33. Jonathan NiederDec 12, 2014
  34. 3/4 strbuf.h: format asciidoc code blocks as 4-space indentJeff King, Dec 12, 2014
  35. Jonathan NiederDec 12, 2014
  36. Michael HaggertyDec 14, 2014
  37. 4/4 strbuf.h: reorganize api function grouping headersJeff King, Dec 12, 2014
  38. Jonathan NiederDec 12, 2014
  39. Stefan BellerDec 12, 2014
  40. Michael HaggertyDec 10, 2014
  41. Jonathan NiederDec 10, 2014
  42. Junio C HamanoDec 10, 2014
  43. Jonathan NiederDec 10, 2014
  44. Junio C HamanoDec 10, 2014
  45. Jonathan NiederDec 10, 2014
  46. Jonathan NiederDec 9, 2014
  47. Stefan BellerDec 9, 2014
  48. Jonathan NiederDec 9, 2014
  49. Jonathan NiederDec 9, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.