status: add --long output format option

You can currently set the output format to --short or --porcelain. There is no --long, because we default to it already. However, you may want to override an alias that uses "--short" to get back to the default. This requires a little bit of refactoring, because currently we use STATUS_FORMAT_LONG internally to mean the same as "the user did not specify anything". By expanding the enum to include STATUS_FORMAT_NONE, we can distinguish between the implicit and explicit cases. This effects these conditions: 1. The user has asked for NUL termination. With NONE, we currently default to turning on the porcelain mode. With an explicit --long, we would in theory use NUL termination with the long mode, but it does not support it. So we can just complain and die. 2. When an output format is given to "git commit", we default to "--dry-run". This behavior would now kick in when "--long" is given, too. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 18, 2012 at 21:15 UTC f3f47a1e8ddbecb0865be3d4c5dfef609cb58867
3 files changed +30 -6
Documentation/git-commit.txt
+4
@@ -109,6 +109,10 @@ OPTIONS
109 format. See linkgit:git-status[1] for details. Implies
110 `--dry-run`.
111
112 +--long::
113 + When doing a dry-run, give the output in a the long-format.
114 + Implies `--dry-run`.
115 +
116 -z::
117 --null::
118 When showing `short` or `porcelain` status output, terminate
Documentation/git-status.txt
+3
@@ -38,6 +38,9 @@ OPTIONS
38 across git versions and regardless of user configuration. See
39 below for details.
40
41 +--long::
42 + Give the output in the long-format. This is the default.
43 +
44 -u[<mode>]::
45 --untracked-files[=<mode>]::
46 Show untracked files.
builtin/commit.c
+23 -6
@@ -112,10 +112,11 @@ static const char *only_include_assumed;
112 static struct strbuf message = STRBUF_INIT;
113
114 static enum {
115 + STATUS_FORMAT_NONE = 0,
116 STATUS_FORMAT_LONG,
117 STATUS_FORMAT_SHORT,
118 STATUS_FORMAT_PORCELAIN
118 -} status_format = STATUS_FORMAT_LONG;
119 +} status_format;
120
121 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
122 {
@@ -454,6 +455,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
455 case STATUS_FORMAT_PORCELAIN:
456 wt_porcelain_print(s);
457 break;
458 + case STATUS_FORMAT_NONE:
459 case STATUS_FORMAT_LONG:
460 wt_status_print(s);
461 break;
@@ -1058,9 +1060,13 @@ static int parse_and_validate_options(int argc, const char *argv[],
1060 if (all && argc > 0)
1061 die(_("Paths with -a does not make sense."));
1062
1061 - if (s->null_termination && status_format == STATUS_FORMAT_LONG)
1062 - status_format = STATUS_FORMAT_PORCELAIN;
1063 - if (status_format != STATUS_FORMAT_LONG)
1063 + if (s->null_termination) {
1064 + if (status_format == STATUS_FORMAT_NONE)
1065 + status_format = STATUS_FORMAT_PORCELAIN;
1066 + else if (status_format == STATUS_FORMAT_LONG)
1067 + die(_("--long and -z are incompatible"));
1068 + }
1069 + if (status_format != STATUS_FORMAT_NONE)
1070 dry_run = 1;
1071
1072 return argc;
@@ -1159,6 +1165,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1165 OPT_SET_INT(0, "porcelain", &status_format,
1166 N_("machine-readable output"),
1167 STATUS_FORMAT_PORCELAIN),
1168 + OPT_SET_INT(0, "long", &status_format,
1169 + N_("show status in long format (default)"),
1170 + STATUS_FORMAT_LONG),
1171 OPT_BOOLEAN('z', "null", &s.null_termination,
1172 N_("terminate entries with NUL")),
1173 { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
@@ -1186,8 +1195,12 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1195 builtin_status_usage, 0);
1196 finalize_colopts(&s.colopts, -1);
1197
1189 - if (s.null_termination && status_format == STATUS_FORMAT_LONG)
1190 - status_format = STATUS_FORMAT_PORCELAIN;
1198 + if (s.null_termination) {
1199 + if (status_format == STATUS_FORMAT_NONE)
1200 + status_format = STATUS_FORMAT_PORCELAIN;
1201 + else if (status_format == STATUS_FORMAT_LONG)
1202 + die(_("--long and -z are incompatible"));
1203 + }
1204
1205 handle_untracked_files_arg(&s);
1206 if (show_ignored_in_status)
@@ -1216,6 +1229,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1229 case STATUS_FORMAT_PORCELAIN:
1230 wt_porcelain_print(&s);
1231 break;
1232 + case STATUS_FORMAT_NONE:
1233 case STATUS_FORMAT_LONG:
1234 s.verbose = verbose;
1235 s.ignore_submodule_arg = ignore_submodule_arg;
@@ -1386,6 +1400,9 @@ int cmd_commit(int argc, const char **argv, const char *prefix)
1400 OPT_BOOLEAN(0, "branch", &s.show_branch, N_("show branch information")),
1401 OPT_SET_INT(0, "porcelain", &status_format,
1402 N_("machine-readable output"), STATUS_FORMAT_PORCELAIN),
1403 + OPT_SET_INT(0, "long", &status_format,
1404 + N_("show status in long format (default)"),
1405 + STATUS_FORMAT_LONG),
1406 OPT_BOOLEAN('z', "null", &s.null_termination,
1407 N_("terminate entries with NUL")),
1408 OPT_BOOLEAN(0, "amend", &amend, N_("amend previous commit")),