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,35 @@ 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+ get_value_fn * get_value = field .get_value ;
144+ const char * key = field .key ;
145+
146+ strbuf_reset (& valbuf );
147+ get_value (repo , & valbuf );
148+ print_field (format , key , & valbuf , & quotbuf );
149+ }
150+
151+ strbuf_release (& valbuf );
152+ strbuf_release (& quotbuf );
153+ }
154+
130155static int parse_format_cb (const struct option * opt ,
131156 const char * arg , int unset UNUSED )
132157{
@@ -150,6 +175,7 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
150175 struct repository * repo )
151176{
152177 enum output_format format = FORMAT_KEYVALUE ;
178+ int all_keys = 0 ;
153179 struct option options [] = {
154180 OPT_CALLBACK_F (0 , "format" , & format , N_ ("format" ),
155181 N_ ("output format" ),
@@ -158,13 +184,17 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
158184 N_ ("synonym for --format=nul" ),
159185 PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
160186 parse_format_cb ),
187+ OPT_BOOL (0 , "all" , & all_keys , N_ ("return all keys" )),
161188 OPT_END ()
162189 };
163190
164191 argc = parse_options (argc , argv , prefix , options , repo_usage , 0 );
165192 if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED )
166193 die (_ ("unsupported output format" ));
167194
195+ if (all_keys )
196+ print_all_fields (repo , format );
197+
168198 return print_fields (argc , argv , repo , format );
169199}
170200
0 commit comments