1515#include "utf8.h"
1616
1717static const char * const repo_usage [] = {
18- "git repo info [--format=(keyvalue|nul)] [-z] [<key>...]" ,
18+ "git repo info [--format=(keyvalue|nul)] [-z] [--all | <key>...]" ,
1919 "git repo structure [--format=(table|keyvalue|nul)]" ,
2020 NULL
2121};
@@ -85,6 +85,24 @@ static get_value_fn *get_value_fn_for_key(const char *key)
8585 return found ? found -> get_value : NULL ;
8686}
8787
88+ static void print_field (enum output_format format , const char * key ,
89+ struct strbuf * valbuf , struct strbuf * quotbuf )
90+ {
91+ strbuf_reset (quotbuf );
92+
93+ switch (format ) {
94+ case FORMAT_KEYVALUE :
95+ quote_c_style (valbuf -> buf , quotbuf , NULL , 0 );
96+ printf ("%s=%s\n" , key , quotbuf -> buf );
97+ break ;
98+ case FORMAT_NUL_TERMINATED :
99+ printf ("%s\n%s%c" , key , valbuf -> buf , '\0' );
100+ break ;
101+ default :
102+ BUG ("not a valid output format: %d" , format );
103+ }
104+ }
105+
88106static int print_fields (int argc , const char * * argv ,
89107 struct repository * repo ,
90108 enum output_format format )
@@ -105,28 +123,33 @@ static int print_fields(int argc, const char **argv,
105123 }
106124
107125 strbuf_reset (& valbuf );
108- strbuf_reset (& quotbuf );
109-
110126 get_value (repo , & valbuf );
111-
112- switch (format ) {
113- case FORMAT_KEYVALUE :
114- quote_c_style (valbuf .buf , & quotbuf , NULL , 0 );
115- printf ("%s=%s\n" , key , quotbuf .buf );
116- break ;
117- case FORMAT_NUL_TERMINATED :
118- printf ("%s\n%s%c" , key , valbuf .buf , '\0' );
119- break ;
120- default :
121- BUG ("not a valid output format: %d" , format );
122- }
127+ print_field (format , key , & valbuf , & quotbuf );
123128 }
124129
125130 strbuf_release (& valbuf );
126131 strbuf_release (& quotbuf );
127132 return ret ;
128133}
129134
135+ static void print_all_fields (struct repository * repo ,
136+ enum output_format format )
137+ {
138+ struct strbuf valbuf = STRBUF_INIT ;
139+ struct strbuf quotbuf = STRBUF_INIT ;
140+
141+ for (unsigned long i = 0 ; i < ARRAY_SIZE (repo_info_fields ); i ++ ) {
142+ struct field field = repo_info_fields [i ];
143+
144+ strbuf_reset (& valbuf );
145+ field .get_value (repo , & valbuf );
146+ print_field (format , field .key , & valbuf , & quotbuf );
147+ }
148+
149+ strbuf_release (& valbuf );
150+ strbuf_release (& quotbuf );
151+ }
152+
130153static int parse_format_cb (const struct option * opt ,
131154 const char * arg , int unset UNUSED )
132155{
@@ -150,6 +173,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
150173 struct repository * repo )
151174{
152175 enum output_format format = FORMAT_KEYVALUE ;
176+ int all_keys = 0 ;
153177 struct option options [] = {
154178 OPT_CALLBACK_F (0 , "format" , & format , N_ ("format" ),
155179 N_ ("output format" ),
@@ -158,13 +182,22 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
158182 N_ ("synonym for --format=nul" ),
159183 PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
160184 parse_format_cb ),
185+ OPT_BOOL (0 , "all" , & all_keys , N_ ("return all keys" )),
161186 OPT_END ()
162187 };
163188
164189 argc = parse_options (argc , argv , prefix , options , repo_usage , 0 );
165190 if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED )
166191 die (_ ("unsupported output format" ));
167192
193+ if (all_keys ) {
194+ if (argc )
195+ die (_ ("--all and <key> cannot be used together" ));
196+
197+ print_all_fields (repo , format );
198+ return 0 ;
199+ }
200+
168201 return print_fields (argc , argv , repo , format );
169202}
170203
0 commit comments