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

[PATCH v2 1/2] repo: factor out field printing to dedicated function

From
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Date
Oct 20, 2025, 16:19 UTC
Message-ID
<20251020181943.6314-2-lucasseikioshiro@gmail.com>
In-Reply-To
<20251020181943.6314-1-lucasseikioshiro@gmail.com>

Move the field printing in git-repo-info to a new function called `print_field`, allowing it to be called by functions other than `print_fields`.

Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 builtin/repo.c | 33 +++++++++++++++++++--------------
 1 file changed, 19 insertions(+), 14 deletions(-)
diff --git a/builtin/repo.c b/builtin/repo.c
index bbb0966f2d..3b071e9a50 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -77,6 +77,24 @@ static get_value_fn *get_value_fn_for_key(const char *key)
 	return found ? found->get_value : NULL;
 }
 
+static void print_field(enum output_format format, const char *key,
+			struct strbuf *valbuf, struct strbuf *quotbuf)
+{
+	strbuf_reset(quotbuf);
+
+	switch (format) {
+	case FORMAT_KEYVALUE:
+		quote_c_style(valbuf->buf, quotbuf, NULL, 0);
+		printf("%s=%s\n", key, quotbuf->buf);
+		break;
+	case FORMAT_NUL_TERMINATED:
+		printf("%s\n%s%c", key, valbuf->buf, '\0');
+		break;
+	default:
+		BUG("not a valid output format: %d", format);
+	}
+}
+
 static int print_fields(int argc, const char **argv,
 			struct repository *repo,
 			enum output_format format)
@@ -97,21 +115,8 @@ static int print_fields(int argc, const char **argv,
 		}
 
 		strbuf_reset(&valbuf);
-		strbuf_reset(&quotbuf);
-
 		get_value(repo, &valbuf);
-
-		switch (format) {
-		case FORMAT_KEYVALUE:
-			quote_c_style(valbuf.buf, &quotbuf, NULL, 0);
-			printf("%s=%s\n", key, quotbuf.buf);
-			break;
-		case FORMAT_NUL_TERMINATED:
-			printf("%s\n%s%c", key, valbuf.buf, '\0');
-			break;
-		default:
-			BUG("not a valid output format: %d", format);
-		}
+		print_field(format, key, &valbuf, &quotbuf);
 	}
 
 	strbuf_release(&valbuf);
-- 
2.50.1 (Apple Git-155)
Previous: Lucas Seiki OshiroNext: Lucas Seiki Oshiro
Message 2 of 6 in “repo: add --all to repo-info”
  1. 0/2 repo: add --all to repo-infoLucas Seiki Oshiro, Oct 20, 2025
  2. 1/2 repo: factor out field printing to dedicated functionLucas Seiki Oshiro, Oct 20, 2025
  3. 2/2 repo: add --all to git-repo-infoLucas Seiki Oshiro, Oct 20, 2025
  4. Patrick SteinhardtOct 21, 2025
  5. Junio C HamanoOct 21, 2025
  6. Lucas Seiki OshiroOct 24, 2025

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.