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 <lucasseikioshiro@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Lucas Seiki Oshiro 2025-12-09 16:36:02 -03:00 committed by Junio C Hamano
parent a92df5a0de
commit 240208233c

View File

@ -23,6 +23,7 @@ static const char *const repo_usage[] = {
typedef int get_value_fn(struct repository *repo, struct strbuf *buf);
enum output_format {
FORMAT_DEFAULT,
FORMAT_TABLE,
FORMAT_KEYVALUE,
FORMAT_NUL_TERMINATED,
@ -159,6 +160,8 @@ static int parse_format_cb(const struct option *opt,
*format = FORMAT_KEYVALUE;
else if (!strcmp(arg, "table"))
*format = FORMAT_TABLE;
else if (!strcmp(arg, "default"))
*format = FORMAT_DEFAULT;
else
die(_("invalid format '%s'"), arg);
@ -168,7 +171,7 @@ static int parse_format_cb(const struct option *opt,
static int cmd_repo_info(int argc, const char **argv, const char *prefix,
struct repository *repo)
{
enum output_format format = FORMAT_KEYVALUE;
enum output_format format = FORMAT_DEFAULT;
int all_keys = 0;
struct option options[] = {
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,
};
argc = parse_options(argc, argv, prefix, options, repo_usage, 0);
if (format == FORMAT_DEFAULT)
format = FORMAT_KEYVALUE;
if (format != FORMAT_KEYVALUE && format != FORMAT_NUL_TERMINATED)
die(_("unsupported output format"));