status: disable color for porcelain format
[gitweb.git] / builtin-commit.c
index 5e23ef1f0a67bed7088a0eaacc9ac9b36555843b..ded58984ac983fe09b817c2c2b0af386266f6fe3 100644 (file)
@@ -36,11 +36,6 @@ static const char * const builtin_status_usage[] = {
        NULL
 };
 
-static const char * const builtin_stat_usage[] = {
-       "git stat [options]",
-       NULL
-};
-
 static unsigned char head_sha1[20], merge_head_sha1[20];
 static char *use_message_buffer;
 static const char commit_editmsg[] = "COMMIT_EDITMSG";
@@ -77,6 +72,13 @@ 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 int opt_parse_m(const struct option *opt, const char *arg, int unset)
 {
        struct strbuf *buf = opt->value;
@@ -110,6 +112,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"),
@@ -368,7 +376,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:
+               wt_shortstatus_print(s, null_termination);
+               break;
+       case STATUS_FORMAT_PORCELAIN:
+               wt_porcelain_print(s, null_termination);
+               break;
+       case STATUS_FORMAT_LONG:
+               wt_status_print(s);
+               break;
+       }
 
        return s->commitable;
 }
@@ -826,6 +845,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;
 }
 
@@ -902,12 +926,19 @@ static int git_status_config(const char *k, const char *v, void *cb)
        return git_diff_ui_config(k, v, NULL);
 }
 
-int cmd_stat(int argc, const char **argv, const char *prefix)
+int cmd_status(int argc, const char **argv, const char *prefix)
 {
        struct wt_status s;
        unsigned char sha1[20];
-       static struct option builtin_stat_options[] = {
+       static struct option builtin_status_options[] = {
                OPT__VERBOSE(&verbose),
+               OPT_SET_INT('s', "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"),
                { OPTION_STRING, 'u', "untracked-files", &untracked_files_arg,
                  "mode",
                  "show untracked files, optional modes: all, normal, no. (Default: all)",
@@ -915,11 +946,14 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
                OPT_END(),
        };
 
+       if (null_termination && status_format == STATUS_FORMAT_LONG)
+               status_format = STATUS_FORMAT_PORCELAIN;
+
        wt_status_prepare(&s);
        git_config(git_status_config, &s);
        argc = parse_options(argc, argv, prefix,
-                            builtin_stat_options,
-                            builtin_stat_usage, 0);
+                            builtin_status_options,
+                            builtin_status_usage, 0);
        handle_untracked_files_arg(&s);
 
        if (*argv)
@@ -930,33 +964,33 @@ int cmd_stat(int argc, const char **argv, const char *prefix)
        s.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;
        wt_status_collect(&s);
 
-       s.verbose = verbose;
-       if (s.relative_paths)
-               s.prefix = prefix;
-       if (s.use_color == -1)
-               s.use_color = git_use_color_default;
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
-       wt_status_print(&s);
+       switch (status_format) {
+       case STATUS_FORMAT_SHORT:
+               if (s.relative_paths)
+                       s.prefix = prefix;
+               if (s.use_color == -1)
+                       s.use_color = git_use_color_default;
+               if (diff_use_color_default == -1)
+                       diff_use_color_default = git_use_color_default;
+               wt_shortstatus_print(&s, null_termination);
+               break;
+       case STATUS_FORMAT_PORCELAIN:
+               wt_porcelain_print(&s, null_termination);
+               break;
+       case STATUS_FORMAT_LONG:
+               s.verbose = verbose;
+               if (s.relative_paths)
+                       s.prefix = prefix;
+               if (s.use_color == -1)
+                       s.use_color = git_use_color_default;
+               if (diff_use_color_default == -1)
+                       diff_use_color_default = git_use_color_default;
+               wt_status_print(&s);
+               break;
+       }
        return 0;
 }
 
-int cmd_status(int argc, const char **argv, const char *prefix)
-{
-       struct wt_status s;
-
-       wt_status_prepare(&s);
-       git_config(git_status_config, &s);
-       if (s.use_color == -1)
-               s.use_color = git_use_color_default;
-       if (diff_use_color_default == -1)
-               diff_use_color_default = git_use_color_default;
-
-       argc = parse_and_validate_options(argc, argv, builtin_status_usage,
-                                         prefix, &s);
-       return dry_run_commit(argc, argv, prefix, &s);
-}
-
 static void print_summary(const char *prefix, const unsigned char *sha1)
 {
        struct rev_info rev;