9
9
#include "shallow.h"
10
10
11
11
static const char * const repo_usage [] = {
12
- "git repo info [--format=(keyvalue|nul)] [<key>...]" ,
12
+ "git repo info [--format=(keyvalue|nul)] [-z] [ <key>...]" ,
13
13
NULL
14
14
};
15
15
@@ -38,6 +38,12 @@ static int get_layout_shallow(struct repository *repo, struct strbuf *buf)
38
38
return 0 ;
39
39
}
40
40
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
+
41
47
static int get_references_format (struct repository * repo , struct strbuf * buf )
42
48
{
43
49
strbuf_addstr (buf ,
@@ -49,6 +55,7 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
49
55
static const struct field repo_info_fields [] = {
50
56
{ "layout.bare" , get_layout_bare },
51
57
{ "layout.shallow" , get_layout_shallow },
58
+ { "object.format" , get_object_format },
52
59
{ "references.format" , get_references_format },
53
60
};
54
61
@@ -112,26 +119,40 @@ static int print_fields(int argc, const char **argv,
112
119
return ret ;
113
120
}
114
121
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
+
115
139
static int repo_info (int argc , const char * * argv , const char * prefix ,
116
140
struct repository * repo )
117
141
{
118
- const char * format_str = "keyvalue" ;
119
- enum output_format format ;
142
+ enum output_format format = FORMAT_KEYVALUE ;
120
143
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 ),
123
151
OPT_END ()
124
152
};
125
153
126
154
argc = parse_options (argc , argv , prefix , options , repo_usage , 0 );
127
155
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
-
135
156
return print_fields (argc , argv , repo , format );
136
157
}
137
158
0 commit comments