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

[PATCH 1/2] trace: add trace_print_string_list_key

From
Stefan Beller <sbeller@google.com>
Date
Sep 10, 2018, 21:58 UTC
Message-ID
<20180910215831.17608-1-sbeller@google.com>
In-Reply-To
<CAGZ79kbObDXyaRLADQpvMMSitOLCDwb030Q6UBiX-7Y-XWnqog@mail.gmail.com>

Similar to trace_strbuf or trace_argv_printf, we might want to output a string list in tracing. Add such a function.

Signed-off-by: Stefan Beller <sbeller@google.com>
---

I separated this from the other series, making it into 2 patches: This first patch adds tracing for string lists and the next patch that removes the unused function from the string list API. That way we can decide on these two patches separately if needed.

 Documentation/technical/api-trace.txt |  8 ++++++
 trace.c                               | 39 +++++++++++++++++++++++++++
 trace.h                               | 16 +++++++++++
 3 files changed, 63 insertions(+)
diff --git a/Documentation/technical/api-trace.txt b/Documentation/technical/api-trace.txt
index fadb5979c48..ad0ea99d930 100644
--- a/Documentation/technical/api-trace.txt
+++ b/Documentation/technical/api-trace.txt
@@ -62,6 +62,14 @@ Functions
 	Prints the strbuf, without additional formatting (i.e. doesn't
 	choke on `%` or even `\0`).
 
+`void trace_print_string_list_key(struct trace_key *key, const struct string_list *p, const char *text)::
+
+	Print the string-pointer pairs of the string_list,
+	each one in its own line.
+	It takes an optional key and header argument.
+	If the tracing key is not given, use the default key.
+	The header text is printed before the list itself.
+
 `uint64_t getnanotime(void)`::
 
 	Returns nanoseconds since the epoch (01/01/1970), typically used
diff --git a/trace.c b/trace.c
index fc623e91fdd..e3a12a092f9 100644
--- a/trace.c
+++ b/trace.c
@@ -176,6 +176,38 @@ void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
 	strbuf_release(&buf);
 }
 
+void trace_print_string_list_key_fl(const char *file, int line,
+				    struct trace_key *key,
+				    const struct string_list *p,
+				    const char *text)
+{
+	int i, buf_prefix;
+	struct strbuf buf = STRBUF_INIT;
+
+	if (!key)
+		key = &trace_default_key;
+
+	if (!prepare_trace_line(file, line, key, &buf))
+		return;
+
+	buf_prefix = buf.len;
+
+	if (text) {
+		strbuf_addstr(&buf, text);
+		print_trace_line(key, &buf);
+	}
+
+	for (i = 0; i < p->nr; i++) {
+		strbuf_setlen(&buf, buf_prefix);
+		strbuf_addf(&buf, "%s:%p\n",
+			    p->items[i].string,
+			    p->items[i].util);
+		print_trace_line(key, &buf);
+	}
+
+	strbuf_release(&buf);
+}
+
 static void trace_performance_vprintf_fl(const char *file, int line,
 					 uint64_t nanos, const char *format,
 					 va_list ap)
@@ -227,6 +259,13 @@ void trace_strbuf(struct trace_key *key, const struct strbuf *data)
 	trace_strbuf_fl(NULL, 0, key, data);
 }
 
+void trace_print_string_list_key(struct trace_key *key,
+				 const struct string_list *p,
+				 const char *text)
+{
+	trace_print_string_list_key_fl(NULL, 0, key, p, list);
+}
+
 void trace_performance(uint64_t nanos, const char *format, ...)
 {
 	va_list ap;
diff --git a/trace.h b/trace.h
index 2b6a1bc17c2..0e083891e1f 100644
--- a/trace.h
+++ b/trace.h
@@ -37,6 +37,10 @@ extern void trace_argv_printf(const char **argv, const char *format, ...);
 
 extern void trace_strbuf(struct trace_key *key, const struct strbuf *data);
 
+extern void trace_print_string_list_key(struct trace_key *key,
+					const struct string_list *p,
+					const char *text);
+
 /* Prints elapsed time (in nanoseconds) if GIT_TRACE_PERFORMANCE is enabled. */
 __attribute__((format (printf, 2, 3)))
 extern void trace_performance(uint64_t nanos, const char *format, ...);
@@ -103,6 +107,13 @@ extern void trace_performance_since(uint64_t start, const char *format, ...);
 			trace_strbuf_fl(TRACE_CONTEXT, __LINE__, key, data);\
 	} while (0)
 
+#define trace_print_string_list_key(key, list, text) 			    \
+	do {								    \
+		if (trace_pass_fl(key))					    \
+			trace_print_string_list_key_fl(TRACE_CONTEXT,	    \
+						       __LINE__, key, data);\
+	} while (0)
+
 #define trace_performance(nanos, ...)					    \
 	do {								    \
 		if (trace_pass_fl(&trace_perf_key))			    \
@@ -127,6 +138,11 @@ extern void trace_argv_printf_fl(const char *file, int line, const char **argv,
 				 const char *format, ...);
 extern void trace_strbuf_fl(const char *file, int line, struct trace_key *key,
 			    const struct strbuf *data);
+extern void trace_print_string_list_key_fl(const char *file, int line,
+					   struct trace_key *key,
+					   const struct string_list *p,
+					   const char *text);
+
 __attribute__((format (printf, 4, 5)))
 extern void trace_performance_fl(const char *file, int line,
 				 uint64_t nanos, const char *fmt, ...);
-- 
2.19.0.rc2.392.g5ba43deb5a-goog
Previous: Stefan BellerNext: Stefan Beller
Message 9 of 39 in “fetch: make sure submodule oids are fetched”
  1. 00/11 fetch: make sure submodule oids are fetchedStefan Beller, Sep 4, 2018
  2. 01/11 string_list: print_string_list to use trace_printfStefan Beller, Sep 4, 2018
  3. Junio C HamanoSep 6, 2018
  4. Jeff KingSep 6, 2018
  5. Stefan BellerSep 6, 2018
  6. Jeff KingSep 7, 2018
  7. Junio C HamanoSep 7, 2018
  8. Stefan BellerSep 7, 2018
  9. 1/2 trace: add trace_print_string_list_keyStefan Beller, Sep 10, 2018
  10. 2/2 string-list: remove unused function print_string_listStefan Beller, Sep 10, 2018
  11. Junio C HamanoSep 10, 2018
  12. Stefan BellerSep 10, 2018
  13. Junio C HamanoSep 11, 2018
  14. Stefan BellerSep 11, 2018
  15. Jeff KingSep 11, 2018
  16. string-list: remove unused function print_string_listStefan Beller, Sep 11, 2018
  17. Junio C HamanoSep 11, 2018
  18. Junio C HamanoSep 11, 2018
  19. Stefan BellerSep 11, 2018
  20. Junio C HamanoSep 11, 2018
  21. 02/11 string-list.h: add string_list_{pop, last} functionsStefan Beller, Sep 4, 2018
  22. Junio C HamanoSep 6, 2018
  23. Stefan BellerSep 6, 2018
  24. 03/11 sha1-array: provide oid_array_filterStefan Beller, Sep 4, 2018
  25. Junio C HamanoSep 6, 2018
  26. 04/11 submodule.c: convert submodule_move_head new argument to object idStefan Beller, Sep 4, 2018
  27. Junio C HamanoSep 6, 2018
  28. 05/11 submodule.c: fix indentationStefan Beller, Sep 4, 2018
  29. Junio C HamanoSep 6, 2018
  30. 06/11 submodule.c: sort changed_submodule_names before searching itStefan Beller, Sep 4, 2018
  31. Junio C HamanoSep 6, 2018
  32. Stefan BellerSep 11, 2018
  33. 07/11 submodule: move global changed_submodule_names into fetch submodule structStefan Beller, Sep 4, 2018
  34. Junio C HamanoSep 6, 2018
  35. 08/11 submodule.c: do not copy around submodule listStefan Beller, Sep 4, 2018
  36. Junio C HamanoSep 6, 2018
  37. 09/11 submodule: fetch in submodules git directory instead of in worktreeStefan Beller, Sep 4, 2018
  38. 10/11 fetch: retry fetching submodules if sha1 were not fetchedStefan Beller, Sep 4, 2018
  39. 11/11 builtin/fetch: check for submodule updates for non branch fetchesStefan Beller, Sep 4, 2018

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.