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

[GSoC PATCH v10 2/5] repo: add the field references.format

From
Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Date
Aug 15, 2025, 13:55 UTC
Message-ID
<20250815135521.44044-3-lucasseikioshiro@gmail.com>
In-Reply-To
<20250815135521.44044-1-lucasseikioshiro@gmail.com>

This commit is part of the series that introduces the new subcommand git-repo-info.

The flag `--show-ref-format` from git-rev-parse is used for retrieving the reference format (i.e. `files` or `reftable`). This way, it is used for querying repository metadata, fitting in the purpose of git-repo-info.

Add a new field `references.format` to the repo-info subcommand containing that information.

Helped-by: Phillip Wood <phillip.wood@dunelm.org.uk>
Helped-by: Junio C Hamano <gitster@pobox.com>
Helped-by: Justin Tobler <jltobler@gmail.com>
Helped-by: Eric Sunshine <sunshine@sunshineco.com>
Mentored-by: Karthik Nayak <karthik.188@gmail.com>
Mentored-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
---
 Documentation/git-repo.adoc | 20 ++++++++++
 builtin/repo.c              | 74 ++++++++++++++++++++++++++++++++++++-
 t/meson.build               |  1 +
 t/t1900-repo.sh             | 50 +++++++++++++++++++++++++
 4 files changed, 143 insertions(+), 2 deletions(-)
 create mode 100755 t/t1900-repo.sh
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index 68c706f5a0..a708c70a3d 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -22,6 +22,26 @@ COMMANDS
 	Retrieve metadata-related information about the current repository. Only
 	the requested data will be returned based on their keys (see "INFO KEYS"
 	section below).
++
+The values are returned in the same order in which their respective keys were
+requested.
++
+The output format consists of key-value pairs one per line using the `=`
+character as the delimiter between the key and the value. Values containing
+"unusual" characters are quoted as explained for the configuration variable
+`core.quotePath` (see linkgit:git-config[1]).
+
+INFO KEYS
+---------
+
+In order to obtain a set of values from `git repo info`, you should provide
+the keys that identify them. Here's a list of the available keys and the
+values that they return:
+
+`references.format`::
+The reference storage format. The valid values are:
++
+include::ref-storage-format.adoc[]
 
 SEE ALSO
 --------
diff --git a/builtin/repo.c b/builtin/repo.c
index fd2a9b4216..73d4e27a16 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -1,17 +1,87 @@
 #include "builtin.h"
 #include "parse-options.h"
+#include "quote.h"
+#include "refs.h"
+#include "strbuf.h"
 
 static const char *const repo_usage[] = {
 	"git repo info [<key>...]",
 	NULL
 };
 
-static int repo_info(int argc UNUSED, const char **argv UNUSED,
-		     const char *prefix UNUSED, struct repository *repo UNUSED)
+typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
+
+struct field {
+	const char *key;
+	get_value_fn *get_value;
+};
+
+static int get_references_format(struct repository *repo, struct strbuf *buf)
 {
+	strbuf_addstr(buf,
+		      ref_storage_format_to_name(repo->ref_storage_format));
 	return 0;
 }
 
+/* repo_info_fields keys must be in lexicographical order */
+static const struct field repo_info_fields[] = {
+	{ "references.format", get_references_format },
+};
+
+static int repo_info_fields_cmp(const void *va, const void *vb)
+{
+	const struct field *a = va;
+	const struct field *b = vb;
+
+	return strcmp(a->key, b->key);
+}
+
+static get_value_fn *get_value_fn_for_key(const char *key)
+{
+	const struct field search_key = { key, NULL };
+	const struct field *found = bsearch(&search_key, repo_info_fields,
+					    ARRAY_SIZE(repo_info_fields),
+					    sizeof(*found),
+					    repo_info_fields_cmp);
+	return found ? found->get_value : NULL;
+}
+
+static int print_fields(int argc, const char **argv, struct repository *repo)
+{
+	int ret = 0;
+	struct strbuf valbuf = STRBUF_INIT;
+	struct strbuf quotbuf = STRBUF_INIT;
+
+	for (int i = 0; i < argc; i++) {
+		get_value_fn *get_value;
+		const char *key = argv[i];
+
+		get_value = get_value_fn_for_key(key);
+
+		if (!get_value) {
+			ret = error(_("key '%s' not found"), key);
+			continue;
+		}
+
+		strbuf_reset(&valbuf);
+		strbuf_reset(&quotbuf);
+
+		get_value(repo, &valbuf);
+		quote_c_style(valbuf.buf, &quotbuf, NULL, 0);
+		printf("%s=%s\n", key, quotbuf.buf);
+	}
+
+	strbuf_release(&valbuf);
+	strbuf_release(&quotbuf);
+	return ret;
+}
+
+static int repo_info(int argc, const char **argv, const char *prefix UNUSED,
+		     struct repository *repo)
+{
+	return print_fields(argc - 1, argv + 1, repo);
+}
+
 int cmd_repo(int argc, const char **argv, const char *prefix,
 	     struct repository *repo)
 {
diff --git a/t/meson.build b/t/meson.build
index 983245501c..7555d52917 100644
--- a/t/meson.build
+++ b/t/meson.build
@@ -231,6 +231,7 @@ integration_tests = [
   't1700-split-index.sh',
   't1701-racy-split-index.sh',
   't1800-hook.sh',
+  't1900-repo.sh',
   't2000-conflict-when-checking-files-out.sh',
   't2002-checkout-cache-u.sh',
   't2003-checkout-cache-mkdir.sh',
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
new file mode 100755
index 0000000000..dca4023a00
--- /dev/null
+++ b/t/t1900-repo.sh
@@ -0,0 +1,50 @@
+#!/bin/sh
+
+test_description='test git repo-info'
+
+. ./test-lib.sh
+
+# Test whether a key-value pair is correctly returned
+#
+# Usage: test_repo_info <label> <init command> <repo_name> <key> <expected value>
+#
+# Arguments:
+#   label: the label of the test
+#   init_command: a command which creates a repository
+#   repo_name: the name of the repository that will be created in init_command
+#   key: the key of the field that is being tested
+#   expected_value: the value that the field should contain
+test_repo_info () {
+	label=$1
+	init_command=$2
+	repo_name=$3
+	key=$4
+	expected_value=$5
+
+	test_expect_success "$label" '
+		eval "$init_command $repo_name" &&
+		echo "$key=$expected_value" >expected &&
+		git -C $repo_name repo info "$key" >actual &&
+		test_cmp expected actual
+	'
+}
+
+test_repo_info 'ref format files is retrieved correctly' \
+	'git init --ref-format=files' 'format-files' 'references.format' 'files'
+
+test_repo_info 'ref format reftable is retrieved correctly' \
+	'git init --ref-format=reftable' 'format-reftable' 'references.format' 'reftable'
+
+test_expect_success 'git-repo-info fails if an invalid key is requested' '
+	echo "error: key ${SQ}foo${SQ} not found" >expected_err &&
+	test_must_fail git repo info foo 2>actual_err &&
+	test_cmp expected_err actual_err
+'
+
+test_expect_success 'git-repo-info outputs data even if there is an invalid field' '
+	echo "references.format=$(test_detect_ref_format)" >expected &&
+	test_must_fail git repo info foo references.format bar >actual &&
+	test_cmp expected actual
+'
+
+test_done
-- 
2.39.5 (Apple Git-154)
Previous: Lucas Seiki OshiroNext: Junio C Hamano
Message 212 of 226 in “repo-info: add new command for retrieving repository info”
  1. 0/5 repo-info: add new command for retrieving repository infoLucas Seiki Oshiro, Jun 10, 2025
  2. 1/5 repo-info: declare the repo-info commandLucas Seiki Oshiro, Jun 10, 2025
  3. Karthik NayakJun 11, 2025
  4. 2/5 repo-info: add the --format flagLucas Seiki Oshiro, Jun 10, 2025
  5. Karthik NayakJun 11, 2025
  6. Lucas Seiki OshiroJun 12, 2025
  7. Karthik NayakJun 13, 2025
  8. 3/5 repo-info: add the field references.formatLucas Seiki Oshiro, Jun 10, 2025
  9. Karthik NayakJun 11, 2025
  10. Junio C HamanoJun 12, 2025
  11. 5/5 repo-info: add field layout.shallowLucas Seiki Oshiro, Jun 10, 2025
  12. 4/5 repo-info: add field layout.bareLucas Seiki Oshiro, Jun 10, 2025
  13. Karthik NayakJun 11, 2025
  14. Lucas Seiki OshiroJun 12, 2025
  15. Junio C HamanoJun 12, 2025
  16. Kristoffer HaugsbakkJun 10, 2025
  17. Junio C HamanoJun 10, 2025
  18. Lucas Seiki OshiroJun 12, 2025
  19. Junio C HamanoJun 12, 2025
  20. Lucas Seiki OshiroJun 16, 2025
  21. Junio C HamanoJun 16, 2025
  22. Lucas Seiki OshiroJun 19, 2025
  23. Karthik NayakJun 11, 2025
  24. 0/7 repo-info: add new command for retrieving repository infoLucas Seiki Oshiro, Jun 19, 2025
  25. 1/7 repo-info: declare the repo-info commandLucas Seiki Oshiro, Jun 19, 2025
  26. Karthik NayakJun 20, 2025
  27. Junio C HamanoJun 20, 2025
  28. Karthik NayakJun 23, 2025
  29. Lucas Seiki OshiroJun 23, 2025
  30. Karthik NayakJun 20, 2025
  31. Phillip WoodJun 24, 2025
  32. Patrick SteinhardtJul 3, 2025
  33. Lucas Seiki OshiroJul 4, 2025
  34. Patrick SteinhardtJul 7, 2025
  35. Justin ToblerJul 9, 2025
  36. 2/7 repo-info: add the --format flagLucas Seiki Oshiro, Jun 19, 2025
  37. Karthik NayakJun 20, 2025
  38. Junio C HamanoJun 20, 2025
  39. Patrick SteinhardtJul 3, 2025
  40. 3/7 repo-info: add plaintext as an output formatLucas Seiki Oshiro, Jun 19, 2025
  41. Junio C HamanoJun 20, 2025
  42. Patrick SteinhardtJul 3, 2025
  43. 4/7 repo-info: add the --allow-empty flagLucas Seiki Oshiro, Jun 19, 2025
  44. Karthik NayakJun 20, 2025
  45. Lucas Seiki OshiroJun 23, 2025
  46. Junio C HamanoJun 20, 2025
  47. Karthik NayakJun 23, 2025
  48. Lucas Seiki OshiroJun 23, 2025
  49. 5/7 repo-info: add the field references.formatLucas Seiki Oshiro, Jun 19, 2025
  50. Junio C HamanoJun 20, 2025
  51. Phillip WoodJun 24, 2025
  52. Junio C HamanoJun 24, 2025
  53. Phillip WoodJun 25, 2025
  54. Patrick SteinhardtJul 3, 2025
  55. Lucas Seiki OshiroJul 4, 2025
  56. 6/7 repo-info: add field layout.bareLucas Seiki Oshiro, Jun 19, 2025
  57. Patrick SteinhardtJul 3, 2025
  58. Lucas Seiki OshiroJul 3, 2025
  59. Phillip WoodJul 4, 2025
  60. 7/7 repo-info: add field layout.shallowLucas Seiki Oshiro, Jun 19, 2025
  61. Phillip WoodJun 23, 2025
  62. Lucas Seiki OshiroJun 23, 2025
  63. Phillip WoodJun 24, 2025
  64. Junio C HamanoJun 24, 2025
  65. Lucas Seiki OshiroJul 1, 2025
  66. phillip.wood123@gmail.comJul 2, 2025
  67. 0/5 repo-info: add new command for retrieving repository infoLucas Seiki Oshiro, Jul 6, 2025
  68. 1/5 repo-info: declare the repo-info commandLucas Seiki Oshiro, Jul 6, 2025
  69. 2/5 repo-info: add the --format flagLucas Seiki Oshiro, Jul 6, 2025
  70. 3/5 repo-info: add the field references.formatLucas Seiki Oshiro, Jul 6, 2025
  71. 4/5 repo-info: add field layout.bareLucas Seiki Oshiro, Jul 6, 2025
  72. 5/5 repo-info: add field layout.shallowLucas Seiki Oshiro, Jul 6, 2025
  73. Phillip WoodJul 8, 2025
  74. Lucas Seiki OshiroJul 8, 2025
  75. Phillip WoodJul 10, 2025
  76. Lucas Seiki OshiroJul 11, 2025
  77. Justin ToblerJul 11, 2025
  78. 0/4 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Jul 14, 2025
  79. 1/4 repo: declare the repo commandLucas Seiki Oshiro, Jul 14, 2025
  80. Karthik NayakJul 15, 2025
  81. Patrick SteinhardtJul 15, 2025
  82. Justin ToblerJul 15, 2025
  83. Lucas Seiki OshiroJul 20, 2025
  84. Justin ToblerJul 15, 2025
  85. 2/4 repo: add the field references.formatLucas Seiki Oshiro, Jul 14, 2025
  86. Patrick SteinhardtJul 15, 2025
  87. Lucas Seiki OshiroJul 18, 2025
  88. Karthik NayakJul 15, 2025
  89. Justin ToblerJul 15, 2025
  90. Patrick SteinhardtJul 16, 2025
  91. Justin ToblerJul 16, 2025
  92. Patrick SteinhardtJul 17, 2025
  93. Justin ToblerJul 17, 2025
  94. Lucas Seiki OshiroJul 18, 2025
  95. Justin ToblerJul 21, 2025
  96. 3/4 repo: add field layout.bareLucas Seiki Oshiro, Jul 14, 2025
  97. 4/4 repo: add field layout.shallowLucas Seiki Oshiro, Jul 14, 2025
  98. Oswald BuddenhagenJul 15, 2025
  99. Patrick SteinhardtJul 15, 2025
  100. Oswald BuddenhagenJul 15, 2025
  101. Justin ToblerJul 15, 2025
  102. Junio C HamanoJul 15, 2025
  103. Oswald BuddenhagenJul 17, 2025
  104. Patrick SteinhardtJul 17, 2025
  105. Junio C HamanoJul 16, 2025
  106. Junio C HamanoJul 16, 2025
  107. Lucas Seiki OshiroJul 21, 2025
  108. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Jul 22, 2025
  109. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Jul 22, 2025
  110. Karthik NayakJul 22, 2025
  111. Junio C HamanoJul 22, 2025
  112. Lucas Seiki OshiroJul 23, 2025
  113. Junio C HamanoJul 23, 2025
  114. Patrick SteinhardtJul 24, 2025
  115. Junio C HamanoJul 24, 2025
  116. Patrick SteinhardtJul 25, 2025
  117. Lucas Seiki OshiroJul 26, 2025
  118. Junio C HamanoJul 28, 2025
  119. Lucas Seiki OshiroJul 23, 2025
  120. Jean-Noël AVILAJul 23, 2025
  121. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Jul 22, 2025
  122. Karthik NayakJul 22, 2025
  123. Justin ToblerJul 22, 2025
  124. Phillip WoodJul 23, 2025
  125. Lucas Seiki OshiroJul 23, 2025
  126. Lucas Seiki OshiroJul 23, 2025
  127. Patrick SteinhardtJul 24, 2025
  128. 3/5 repo: add field layout.bareLucas Seiki Oshiro, Jul 22, 2025
  129. 4/5 repo: add field layout.shallowLucas Seiki Oshiro, Jul 22, 2025
  130. 5/5 repo: add the --format flagLucas Seiki Oshiro, Jul 22, 2025
  131. Karthik NayakJul 22, 2025
  132. Patrick SteinhardtJul 24, 2025
  133. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Jul 27, 2025
  134. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Jul 27, 2025
  135. Eric SunshineJul 27, 2025
  136. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Jul 27, 2025
  137. Eric SunshineJul 27, 2025
  138. Lucas Seiki OshiroJul 31, 2025
  139. Patrick SteinhardtJul 29, 2025
  140. Lucas Seiki OshiroJul 31, 2025
  141. 3/5 repo: add field layout.bareLucas Seiki Oshiro, Jul 27, 2025
  142. 4/5 repo: add field layout.shallowLucas Seiki Oshiro, Jul 27, 2025
  143. Eric SunshineJul 27, 2025
  144. 5/5 repo: add the --format flagLucas Seiki Oshiro, Jul 27, 2025
  145. Eric SunshineJul 27, 2025
  146. Ben KnobleJul 29, 2025
  147. Eric SunshineJul 29, 2025
  148. Ben KnobleJul 29, 2025
  149. Eric SunshineJul 29, 2025
  150. Lucas Seiki OshiroJul 31, 2025
  151. Lucas Seiki OshiroJul 31, 2025
  152. Eric SunshineJul 27, 2025
  153. Patrick SteinhardtJul 29, 2025
  154. Lucas Seiki OshiroJul 30, 2025
  155. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Aug 1, 2025
  156. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 1, 2025
  157. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 1, 2025
  158. Eric SunshineAug 1, 2025
  159. Lucas Seiki OshiroAug 3, 2025
  160. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 1, 2025
  161. Eric SunshineAug 1, 2025
  162. Lucas Seiki OshiroAug 3, 2025
  163. Eric SunshineAug 3, 2025
  164. Patrick SteinhardtAug 5, 2025
  165. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 1, 2025
  166. Patrick SteinhardtAug 5, 2025
  167. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 1, 2025
  168. Junio C HamanoAug 1, 2025
  169. Jean-Noël AVILAAug 1, 2025
  170. Eric SunshineAug 1, 2025
  171. Patrick SteinhardtAug 5, 2025
  172. Patrick SteinhardtAug 5, 2025
  173. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Aug 6, 2025
  174. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 6, 2025
  175. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 6, 2025
  176. Karthik NayakAug 7, 2025
  177. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 6, 2025
  178. Patrick SteinhardtAug 7, 2025
  179. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 6, 2025
  180. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 6, 2025
  181. Patrick SteinhardtAug 7, 2025
  182. Junio C HamanoAug 7, 2025
  183. Junio C HamanoAug 6, 2025
  184. Karthik NayakAug 7, 2025
  185. 0/5 repo: add new command for retrieving repository infoLucas Seiki Oshiro, Aug 7, 2025
  186. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 7, 2025
  187. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 7, 2025
  188. Eric SunshineAug 11, 2025
  189. Phillip WoodAug 11, 2025
  190. Junio C HamanoAug 11, 2025
  191. Lucas Seiki OshiroAug 13, 2025
  192. Eric SunshineAug 13, 2025
  193. Lucas Seiki OshiroAug 13, 2025
  194. Phillip WoodAug 14, 2025
  195. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 7, 2025
  196. Eric SunshineAug 11, 2025
  197. Lucas Seiki OshiroAug 14, 2025
  198. Eric SunshineAug 14, 2025
  199. Junio C HamanoAug 14, 2025
  200. Eric SunshineAug 14, 2025
  201. Junio C HamanoAug 15, 2025
  202. Lucas Seiki OshiroAug 14, 2025
  203. Eric SunshineAug 14, 2025
  204. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 7, 2025
  205. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 7, 2025
  206. Eric SunshineAug 11, 2025
  207. Patrick SteinhardtAug 8, 2025
  208. Junio C HamanoAug 8, 2025
  209. Karthik NayakAug 8, 2025
  210. 0/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 15, 2025
  211. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 15, 2025
  212. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 15, 2025
  213. Junio C HamanoAug 15, 2025
  214. Lucas Seiki OshiroAug 15, 2025
  215. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 15, 2025
  216. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 15, 2025
  217. Junio C HamanoAug 15, 2025
  218. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 15, 2025
  219. Junio C HamanoAug 15, 2025
  220. 0/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 16, 2025
  221. 1/5 repo: declare the repo commandLucas Seiki Oshiro, Aug 16, 2025
  222. 2/5 repo: add the field references.formatLucas Seiki Oshiro, Aug 16, 2025
  223. 3/5 repo: add the field layout.bareLucas Seiki Oshiro, Aug 16, 2025
  224. 4/5 repo: add the field layout.shallowLucas Seiki Oshiro, Aug 16, 2025
  225. 5/5 repo: add the --format flagLucas Seiki Oshiro, Aug 16, 2025
  226. Junio C HamanoAug 17, 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.