summaryrefslogtreecommitdiff
path: root/builtin-commit.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2009-09-05 04:59:56 -0400
committerJunio C Hamano <gitster@pobox.com>2009-09-05 23:16:32 -0700
commit7c9f7038e923e6eb135b27c6fca9a010b034bc27 (patch)
treee123bfb2fe90b490cf5fcb89c5ff5db03cc3451b /builtin-commit.c
parent6f15787181a163e158c6fee1d79085b97692ac2f (diff)
downloadgit-7c9f7038e923e6eb135b27c6fca9a010b034bc27.tar.gz
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>
Diffstat (limited to 'builtin-commit.c')
-rw-r--r--builtin-commit.c39
1 files changed, 32 insertions, 7 deletions
diff --git a/builtin-commit.c b/builtin-commit.c
index ffdee31bbf..f2fd0a4580 100644
--- a/builtin-commit.c
+++ b/builtin-commit.c
@@ -72,6 +72,15 @@ static int use_editor = 1, initial_commit, in_merge;
static const char *only_include_assumed;
static struct strbuf message;
+static int null_termination;
+static enum {
+ STATUS_FORMAT_LONG,
+ STATUS_FORMAT_SHORT,
+ STATUS_FORMAT_PORCELAIN,
+} status_format = STATUS_FORMAT_LONG;
+
+static void short_print(struct wt_status *s, int null_termination);
+
static int opt_parse_m(const struct option *opt, const char *arg, int unset)
{
struct strbuf *buf = opt->value;
@@ -105,6 +114,12 @@ static struct option builtin_commit_options[] = {
OPT_BOOLEAN('o', "only", &only, "commit only specified files"),
OPT_BOOLEAN('n', "no-verify", &no_verify, "bypass pre-commit hook"),
OPT_BOOLEAN(0, "dry-run", &dry_run, "show what would be committed"),
+ OPT_SET_INT(0, "short", &status_format, "show status concisely",
+ STATUS_FORMAT_SHORT),
+ OPT_SET_INT(0, "porcelain", &status_format,
+ "show porcelain output format", STATUS_FORMAT_PORCELAIN),
+ OPT_BOOLEAN('z', "null", &null_termination,
+ "terminate entries with NUL"),
OPT_BOOLEAN(0, "amend", &amend, "amend previous commit"),
{ 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" },
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
s->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;
wt_status_collect(s);
- wt_status_print(s);
+
+ switch (status_format) {
+ case STATUS_FORMAT_SHORT:
+ short_print(s, null_termination);
+ break;
+ case STATUS_FORMAT_PORCELAIN:
+ short_print(s, null_termination);
+ break;
+ case STATUS_FORMAT_LONG:
+ wt_status_print(s);
+ break;
+ }
return s->commitable;
}
@@ -821,6 +847,11 @@ static int parse_and_validate_options(int argc, const char *argv[],
else if (interactive && argc > 0)
die("Paths with --interactive does not make sense.");
+ if (null_termination && status_format == STATUS_FORMAT_LONG)
+ status_format = STATUS_FORMAT_PORCELAIN;
+ if (status_format != STATUS_FORMAT_LONG)
+ dry_run = 1;
+
return argc;
}
@@ -991,12 +1022,6 @@ static void short_print(struct wt_status *s, int null_termination)
int cmd_status(int argc, const char **argv, const char *prefix)
{
struct wt_status s;
- static int null_termination;
- static enum {
- STATUS_FORMAT_LONG,
- STATUS_FORMAT_SHORT,
- STATUS_FORMAT_PORCELAIN,
- } status_format = STATUS_FORMAT_LONG;
unsigned char sha1[20];
static struct option builtin_status_options[] = {
OPT__VERBOSE(&verbose),