@matheusbsbs / matheus-bagliano / commits / 7c9f7038e9
Fork 0

commit: support alternate status formats

The status command recently grew "short" and "porcelain" options for alternate output formats. Since status is no longer "commit --dry-run", these formats are inaccessible to people who do want to see a dry-run in a parseable form. This patch makes those formats available to "git commit", implying the "dry-run" option when they are used. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 5, 2009 at 04:59 UTC 7c9f7038e923e6eb135b27c6fca9a010b034bc27
2 files changed +46 -7
Documentation/git-commit.txt
+14
@@ -75,6 +75,20 @@ OPTIONS
75 and paths that are untracked, similar to the one that is given
76 in the commit log editor.
77
78 +--short::
79 + When doing a dry-run, give the output in the short-format. See
80 + linkgit:git-status[1] for details. Implies `--dry-run`.
81 +
82 +--porcelain::
83 + When doing a dry-run, give the output in a porcelain-ready
84 + format. See linkgit:git-status[1] for details. Implies
85 + `--dry-run`.
86 +
87 +-z::
88 + When showing `short` or `porcelain` status output, terminate
89 + entries in the status output with NUL, instead of LF. If no
90 + format is given, implies the `--porcelain` output format.
91 +
92 -F <file>::
93 --file=<file>::
94 Take the commit message from the given file. Use '-' to
builtin-commit.c
+32 -7
@@ -72,6 +72,15 @@ static int use_editor = 1, initial_commit, in_merge;
72 static const char *only_include_assumed;
73 static struct strbuf message;
74
75 +static int null_termination;
76 +static enum {
77 + STATUS_FORMAT_LONG,
78 + STATUS_FORMAT_SHORT,
79 + STATUS_FORMAT_PORCELAIN,
80 +} status_format = STATUS_FORMAT_LONG;
81 +
82 +static void short_print(struct wt_status *s, int null_termination);
83 +
84 static int opt_parse_m(const struct option *opt, const char *arg, int unset)
85 {
86 struct strbuf *buf = opt->value;
@@ -105,6 +114,12 @@ static struct option builtin_commit_options[] = {
114 OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
115 OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
116 OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
117 + OPT_SET_INT(0, "short", &status_format, "show status concisely",
118 + STATUS_FORMAT_SHORT),
119 + OPT_SET_INT(0, "porcelain", &status_format,
120 + "show porcelain output format", STATUS_FORMAT_PORCELAIN),
121 + OPT_BOOLEAN('z', "null", &null_termination,
122 + "terminate entries with NUL"),
123 OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
124 { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg, "mode", "show untracked files, optional modes: all, normal, no. (Default: all)", PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
125 OPT_BOOLEAN(0, "allow-empty", &allow_empty, "ok to record an empty change"),
@@ -363,7 +378,18 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int
378 s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
379
380 wt_status_collect(s);
366 - wt_status_print(s);
381 +
382 + switch (status_format) {
383 + case STATUS_FORMAT_SHORT:
384 + short_print(s, null_termination);
385 + break;
386 + case STATUS_FORMAT_PORCELAIN:
387 + short_print(s, null_termination);
388 + break;
389 + case STATUS_FORMAT_LONG:
390 + wt_status_print(s);
391 + break;
392 + }
393
394 return s->commitable;
395 }
@@ -821,6 +847,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
847 else if (interactive && argc > 0)
848 die("Paths with --interactive does not make sense.");
849
850 + if (null_termination && status_format == STATUS_FORMAT_LONG)
851 + status_format = STATUS_FORMAT_PORCELAIN;
852 + if (status_format != STATUS_FORMAT_LONG)
853 + dry_run = 1;
854 +
855 return argc;
856 }
857
@@ -991,12 +1022,6 @@ static void short_print(struct wt_status *s, int null_termination)
1022 int cmd_status(int argc, const char **argv, const char *prefix)
1023 {
1024 struct wt_status s;
994 - static int null_termination;
995 - static enum {
996 - STATUS_FORMAT_LONG,
997 - STATUS_FORMAT_SHORT,
998 - STATUS_FORMAT_PORCELAIN,
999 - } status_format = STATUS_FORMAT_LONG;
1025 unsigned char sha1[20];
1026 static struct option builtin_status_options[] = {
1027 OPT__VERBOSE(&verbose),