99#include "shallow.h"
1010
1111static const char * const repo_usage [] = {
12- "git repo info [--format=(keyvalue|nul)] [<key>...]" ,
12+ "git repo info [--format=(keyvalue|nul)] [-z] [ <key>...]" ,
1313 NULL
1414};
1515
@@ -38,6 +38,12 @@ static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
3838 return 0 ;
3939}
4040
41+ static int get_object_format (struct repository * repo , struct strbuf * buf )
42+ {
43+ strbuf_addstr (buf , repo -> hash_algo -> name );
44+ return 0 ;
45+ }
46+
4147static int get_references_format (struct repository * repo , struct strbuf * buf )
4248{
4349 strbuf_addstr (buf ,
@@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
4955static const struct field repo_info_fields [] = {
5056 { "layout.bare" , get_layout_bare },
5157 { "layout.shallow" , get_layout_shallow },
58+ { "object.format" , get_object_format },
5259 { "references.format" , get_references_format },
5360};
5461
@@ -112,26 +119,40 @@ static int print_fields(int argc, const char **argv,
112119 return ret ;
113120}
114121
122+ static int parse_format_cb (const struct option * opt ,
123+ const char * arg , int unset UNUSED )
124+ {
125+ enum output_format * format = opt -> value ;
126+
127+ if (opt -> short_name == 'z' )
128+ * format = FORMAT_NUL_TERMINATED ;
129+ else if (!strcmp (arg , "nul" ))
130+ * format = FORMAT_NUL_TERMINATED ;
131+ else if (!strcmp (arg , "keyvalue" ))
132+ * format = FORMAT_KEYVALUE ;
133+ else
134+ die (_ ("invalid format '%s'" ), arg );
135+
136+ return 0 ;
137+ }
138+
115139static int repo_info (int argc , const char * * argv , const char * prefix ,
116140 struct repository * repo )
117141{
118- const char * format_str = "keyvalue" ;
119- enum output_format format ;
142+ enum output_format format = FORMAT_KEYVALUE ;
120143 struct option options [] = {
121- OPT_STRING (0 , "format" , & format_str , N_ ("format" ),
122- N_ ("output format" )),
144+ OPT_CALLBACK_F (0 , "format" , & format , N_ ("format" ),
145+ N_ ("output format" ),
146+ PARSE_OPT_NONEG , parse_format_cb ),
147+ OPT_CALLBACK_F ('z' , NULL , & format , NULL ,
148+ N_ ("synonym for --format=nul" ),
149+ PARSE_OPT_NONEG | PARSE_OPT_NOARG ,
150+ parse_format_cb ),
123151 OPT_END ()
124152 };
125153
126154 argc = parse_options (argc , argv , prefix , options , repo_usage , 0 );
127155
128- if (!strcmp (format_str , "keyvalue" ))
129- format = FORMAT_KEYVALUE ;
130- else if (!strcmp (format_str , "nul" ))
131- format = FORMAT_NUL_TERMINATED ;
132- else
133- die (_ ("invalid format '%s'" ), format_str );
134-
135156 return print_fields (argc , argv , repo , format );
136157}
137158
0 commit comments