]> git.ipfire.org Git - thirdparty/git.git/commitdiff
repo: add a default output format to enum output_format
authorLucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Tue, 9 Dec 2025 19:36:02 +0000 (16:36 -0300)
committerJunio C Hamano <gitster@pobox.com>
Thu, 11 Dec 2025 05:43:17 +0000 (14:43 +0900)
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>
builtin/repo.c

index 0dd41b17783ed113a4c2e0ff36a8b67eb7b962e5..1cd12e7eea56199ed1285fd25a031e13e6b51192 100644 (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"));