1818
1919static const char * const repo_usage [] = {
2020 "git repo info [--format=(keyvalue|nul) | -z] [--all | <key>...]" ,
21+ "git repo info --keys [--format=(default|nul) | -z]" ,
2122 "git repo structure [--format=(table|keyvalue|nul) | -z]" ,
2223 NULL
2324};
2425
2526typedef int get_value_fn (struct repository * repo , struct strbuf * buf );
2627
2728enum output_format {
29+ FORMAT_DEFAULT ,
2830 FORMAT_TABLE ,
2931 FORMAT_KEYVALUE ,
3032 FORMAT_NUL_TERMINATED ,
@@ -148,6 +150,29 @@ static int print_all_fields(struct repository *repo,
148150 return 0 ;
149151}
150152
153+ static int print_keys (enum output_format format )
154+ {
155+ char sep ;
156+
157+ switch (format ) {
158+ case FORMAT_DEFAULT :
159+ sep = '\n' ;
160+ break ;
161+ case FORMAT_NUL_TERMINATED :
162+ sep = '\0' ;
163+ break ;
164+ default :
165+ die (_ ("--keys can only be used with --format=default or --format=nul" ));
166+ }
167+
168+ for (size_t i = 0 ; i < ARRAY_SIZE (repo_info_fields ); i ++ ) {
169+ const struct field * field = & repo_info_fields [i ];
170+ printf ("%s%c" , field -> key , sep );
171+ }
172+
173+ return 0 ;
174+ }
175+
151176static int parse_format_cb (const struct option * opt ,
152177 const char * arg , int unset UNUSED )
153178{
@@ -161,6 +186,8 @@ static int parse_format_cb(const struct option *opt,
161186 * format = FORMAT_KEYVALUE ;
162187 else if (!strcmp (arg , "table" ))
163188 * format = FORMAT_TABLE ;
189+ else if (!strcmp (arg , "default" ))
190+ * format = FORMAT_DEFAULT ;
164191 else
165192 die (_ ("invalid format '%s'" ), arg );
166193
@@ -170,8 +197,9 @@ static int parse_format_cb(const struct option *opt,
170197static int cmd_repo_info (int argc , const char * * argv , const char * prefix ,
171198 struct repository * repo )
172199{
173- enum output_format format = FORMAT_KEYVALUE ;
200+ enum output_format format = FORMAT_DEFAULT ;
174201 int all_keys = 0 ;
202+ int show_keys = 0 ;
175203 struct option options [] = {
176204 OPT_CALLBACK_F (0 , "format" , & format , N_ ("format" ),
177205 N_ ("output format" ),
@@ -181,10 +209,21 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
181209 PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
182210 parse_format_cb ),
183211 OPT_BOOL (0 , "all" , & all_keys , N_ ("print all keys/values" )),
212+ OPT_BOOL (0 , "keys" , & show_keys , N_ ("show keys" )),
184213 OPT_END ()
185214 };
186215
187216 argc = parse_options (argc , argv , prefix , options , repo_usage , 0 );
217+
218+ if (show_keys && (all_keys || argc ))
219+ die (_ ("--keys cannot be used with a <key> or --all" ));
220+
221+ if (show_keys )
222+ return print_keys (format );
223+
224+ if (format == FORMAT_DEFAULT )
225+ format = FORMAT_KEYVALUE ;
226+
188227 if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED )
189228 die (_ ("unsupported output format" ));
190229
0 commit comments