|
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 |
|
@@ -112,26 +112,40 @@ static int print_fields(int argc, const char **argv,
|
112 | 112 | return ret;
|
113 | 113 | }
|
114 | 114 |
|
| 115 | +static int parse_format_cb(const struct option *opt, |
| 116 | + const char *arg, int unset UNUSED) |
| 117 | +{ |
| 118 | + enum output_format *format = opt->value; |
| 119 | + |
| 120 | + if (opt->short_name == 'z') |
| 121 | + *format = FORMAT_NUL_TERMINATED; |
| 122 | + else if (!strcmp(arg, "nul")) |
| 123 | + *format = FORMAT_NUL_TERMINATED; |
| 124 | + else if (!strcmp(arg, "keyvalue")) |
| 125 | + *format = FORMAT_KEYVALUE; |
| 126 | + else |
| 127 | + die(_("invalid format '%s'"), arg); |
| 128 | + |
| 129 | + return 0; |
| 130 | +} |
| 131 | + |
115 | 132 | static int repo_info(int argc, const char **argv, const char *prefix,
|
116 | 133 | struct repository *repo)
|
117 | 134 | {
|
118 |
| - const char *format_str = "keyvalue"; |
119 |
| - enum output_format format; |
| 135 | + enum output_format format = FORMAT_KEYVALUE; |
120 | 136 | struct option options[] = {
|
121 |
| - OPT_STRING(0, "format", &format_str, N_("format"), |
122 |
| - N_("output format")), |
| 137 | + OPT_CALLBACK_F(0, "format", &format, N_("format"), |
| 138 | + N_("output format"), |
| 139 | + PARSE_OPT_NONEG, parse_format_cb), |
| 140 | + OPT_CALLBACK_F('z', NULL, &format, NULL, |
| 141 | + N_("synonym for --format=nul"), |
| 142 | + PARSE_OPT_NONEG | PARSE_OPT_NOARG, |
| 143 | + parse_format_cb), |
123 | 144 | OPT_END()
|
124 | 145 | };
|
125 | 146 |
|
126 | 147 | argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
|
127 | 148 |
|
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 | 149 | return print_fields(argc, argv, repo, format);
|
136 | 150 | }
|
137 | 151 |
|
|
0 commit comments