Thread (178 messages) 178 messages, 10 authors, 2025-08-16

Re: [GSoC RFC PATCH v4 2/4] repo: add the field references.format

From: Patrick Steinhardt <hidden>
Date: 2025-07-16 05:38:31

On Tue, Jul 15, 2025 at 02:15:07PM -0500, Justin Tobler wrote:
On 25/07/14 08:52PM, Lucas Seiki Oshiro wrote:
quoted
diff --git a/builtin/repo.c b/builtin/repo.c
index a1787a3cc5..dcda0d6d61 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -1,11 +1,95 @@
 #include "builtin.h"
 #include "parse-options.h"
+#include "strbuf.h"
+#include "refs.h"
 
-static int repo_info(int argc UNUSED,
-		     const char **argv UNUSED,
+typedef void add_field_fn(struct strbuf *buf, struct repository *repo);
+
+struct field {
+	const char *key;
+	add_field_fn *add_field_callback;
+};
+
+static void add_string(struct strbuf *buf,
+		       const char *key, const char *value)
+{
+	strbuf_addf(buf, "%s\n%s%c", key, value, '\0');
+}
Any reason we add each key/value pair to a buffer instead of just
printing it?

Also, as mentioned in a comment for the previous patch, maybe we should
support printing two output modes. For the default output, maybe a
simple `<key>=<value>\n` where the any value containing special
characters is quoted via `quote_c_style()`.

A null-terminated output, such as the one proposed in this patch, could
be enabled via a `-z` flag similar to how its done in other commands.
Agreed in general, but instead of using `-z` I wonder whether it would
make sense to use something like `--format=key-value` and `--format=nul`
instead. This gives us more room to introduce additional formats in the
future, like for example the JSON format that was scrapped for now.

Patrick
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help