From: Lucas Seiki Oshiro Date: Tue, 9 Dec 2025 19:36:02 +0000 (-0300) Subject: repo: add a default output format to enum output_format X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=240208233c496ef6013cc8aafd3db8c041cfa75d;p=thirdparty%2Fgit.git 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 Signed-off-by: Junio C Hamano --- diff --git a/builtin/repo.c b/builtin/repo.c index 0dd41b1778..1cd12e7eea 100644 --- a/builtin/repo.c +++ b/builtin/repo.c @@ -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"));