Skip to content

Commit 2402082

Browse files
lucasoshirogitster
authored andcommitted
repo: add a default output format to enum output_format
Add a `FORMAT_DEFAULT` value to `enum output_format`. Change the initial value of `format` to `FORMAT_DEFAULT` in cmd_repo_info, indicating that the initial value hasn't been changed. Also map the string "default" to this new value in `parse_format_cb`, allowing future patches to add support to --format=default. Signed-off-by: Lucas Seiki Oshiro <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a92df5a commit 2402082

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

builtin/repo.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static const char *const repo_usage[] = {
2323
typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
2424

2525
enum output_format {
26+
FORMAT_DEFAULT,
2627
FORMAT_TABLE,
2728
FORMAT_KEYVALUE,
2829
FORMAT_NUL_TERMINATED,
@@ -159,6 +160,8 @@ static int parse_format_cb(const struct option *opt,
159160
*format = FORMAT_KEYVALUE;
160161
else if (!strcmp(arg, "table"))
161162
*format = FORMAT_TABLE;
163+
else if (!strcmp(arg, "default"))
164+
*format = FORMAT_DEFAULT;
162165
else
163166
die(_("invalid format '%s'"), arg);
164167

@@ -168,7 +171,7 @@ static int parse_format_cb(const struct option *opt,
168171
static int cmd_repo_info(int argc, const char **argv, const char *prefix,
169172
struct repository *repo)
170173
{
171-
enum output_format format = FORMAT_KEYVALUE;
174+
enum output_format format = FORMAT_DEFAULT;
172175
int all_keys = 0;
173176
struct option options[] = {
174177
OPT_CALLBACK_F(0, "format", &format, N_("format"),
@@ -183,6 +186,10 @@ static int cmd_repo_info(int argc, const char **argv, const char *prefix,
183186
};
184187

185188
argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
189+
190+
if (format == FORMAT_DEFAULT)
191+
format = FORMAT_KEYVALUE;
192+
186193
if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
187194
die(_("unsupported output format"));
188195

0 commit comments

Comments
 (0)