status: add --column

Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Apr 13, 2012 at 17:54 UTC 323d0530918f015fa28572f4477723b607bce000
7 files changed +70 -3
Documentation/config.txt
+4
@@ -866,6 +866,10 @@ column.branch::
866 Specify whether to output branch listing in `git branch` in columns.
867 See `column.ui` for details.
868
869 +column.status::
870 + Specify whether to output untracked files in `git status` in columns.
871 + See `column.ui` for details.
872 +
873 commit.status::
874 A boolean to enable/disable inclusion of status information in the
875 commit message template when using an editor to prepare the commit
Documentation/git-status.txt
+7
@@ -77,6 +77,13 @@ configuration variable documented in linkgit:git-config[1].
77 Terminate entries with NUL, instead of LF. This implies
78 the `--porcelain` output format if no other format is given.
79
80 +--column[=<options>]::
81 +--no-column::
82 + Display untracked files in columns. See configuration variable
83 + column.status for option syntax.`--column` and `--no-column`
84 + without options are equivalent to 'always' and 'never'
85 + respectively.
86 +
87
88 OUTPUT
89 ------
Makefile
+1 -1
@@ -2168,7 +2168,7 @@ builtin/prune.o builtin/reflog.o reachable.o: reachable.h
2168 builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
2169 builtin/tar-tree.o archive-tar.o: tar.h
2170 connect.o transport.o url.o http-backend.o: url.h
2171 -builtin/branch.o column.o help.o pager.o: column.h
2171 +builtin/branch.o builtin/commit.o column.o help.o pager.o: column.h
2172 http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
2173 http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.h
2174
builtin/commit.c
+7
@@ -27,6 +27,7 @@
27 #include "quote.h"
28 #include "submodule.h"
29 #include "gpg-interface.h"
30 +#include "column.h"
31
32 static const char * const builtin_commit_usage[] = {
33 "git commit [options] [--] <filepattern>...",
@@ -88,6 +89,7 @@ static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
89 static int no_post_rewrite, allow_empty_message;
90 static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
91 static char *sign_commit;
92 +static unsigned int colopts;
93
94 /*
95 * The default commit message cleanup mode will remove the lines
@@ -1145,6 +1147,8 @@ static int git_status_config(const char *k, const char *v, void *cb)
1147 {
1148 struct wt_status *s = cb;
1149
1150 + if (!prefixcmp(k, "column."))
1151 + return git_column_config(k, v, "status", &colopts);
1152 if (!strcmp(k, "status.submodulesummary")) {
1153 int is_bool;
1154 s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
@@ -1210,6 +1214,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1214 { OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, "when",
1215 "ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)",
1216 PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
1217 + OPT_COLUMN(0, "column", &colopts, "list untracked files in columns"),
1218 OPT_END(),
1219 };
1220
@@ -1223,6 +1228,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
1228 argc = parse_options(argc, argv, prefix,
1229 builtin_status_options,
1230 builtin_status_usage, 0);
1231 + finalize_colopts(&colopts, -1);
1232 + s.colopts = colopts;
1233
1234 if (null_termination && status_format == STATUS_FORMAT_LONG)
1235 status_format = STATUS_FORMAT_PORCELAIN;
t/t7508-status.sh
+24
@@ -59,6 +59,30 @@ test_expect_success 'status (1)' '
59 test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
60 '
61
62 +test_expect_success 'status --column' '
63 + COLUMNS=50 git status --column="column dense" >output &&
64 + cat >expect <<\EOF &&
65 +# On branch master
66 +# Changes to be committed:
67 +# (use "git reset HEAD <file>..." to unstage)
68 +#
69 +# new file: dir2/added
70 +#
71 +# Changes not staged for commit:
72 +# (use "git add <file>..." to update what will be committed)
73 +# (use "git checkout -- <file>..." to discard changes in working directory)
74 +#
75 +# modified: dir1/modified
76 +#
77 +# Untracked files:
78 +# (use "git add <file>..." to include in what will be committed)
79 +#
80 +# dir1/untracked dir2/untracked untracked
81 +# dir2/modified output
82 +EOF
83 + test_cmp expect output
84 +'
85 +
86 cat >expect <<\EOF
87 # On branch master
88 # Changes to be committed:
wt-status.c
+26 -2
@@ -11,6 +11,7 @@
11 #include "remote.h"
12 #include "refs.h"
13 #include "submodule.h"
14 +#include "column.h"
15
16 static char default_wt_status_colors[][COLOR_MAXLEN] = {
17 GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
@@ -641,6 +642,8 @@ static void wt_status_print_other(struct wt_status *s,
642 {
643 int i;
644 struct strbuf buf = STRBUF_INIT;
645 + static struct string_list output = STRING_LIST_INIT_DUP;
646 + struct column_options copts;
647
648 if (!l->nr)
649 return;
@@ -649,12 +652,33 @@ static void wt_status_print_other(struct wt_status *s,
652
653 for (i = 0; i < l->nr; i++) {
654 struct string_list_item *it;
655 + const char *path;
656 it = &(l->items[i]);
657 + path = quote_path(it->string, strlen(it->string),
658 + &buf, s->prefix);
659 + if (column_active(s->colopts)) {
660 + string_list_append(&output, path);
661 + continue;
662 + }
663 status_printf(s, color(WT_STATUS_HEADER, s), "\t");
664 status_printf_more(s, color(WT_STATUS_UNTRACKED, s),
655 - "%s\n", quote_path(it->string, strlen(it->string),
656 - &buf, s->prefix));
665 + "%s\n", path);
666 }
667 +
668 + strbuf_release(&buf);
669 + if (!column_active(s->colopts))
670 + return;
671 +
672 + strbuf_addf(&buf, "%s#\t%s",
673 + color(WT_STATUS_HEADER, s),
674 + color(WT_STATUS_UNTRACKED, s));
675 + memset(&copts, 0, sizeof(copts));
676 + copts.padding = 1;
677 + copts.indent = buf.buf;
678 + if (want_color(s->use_color))
679 + copts.nl = GIT_COLOR_RESET "\n";
680 + print_columns(&output, s->colopts, &copts);
681 + string_list_clear(&output, 0);
682 strbuf_release(&buf);
683 }
684
wt-status.h
+1
@@ -56,6 +56,7 @@ struct wt_status {
56 enum untracked_status_type show_untracked_files;
57 const char *ignore_submodule_arg;
58 char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
59 + int colopts;
60
61 /* These are computed during processing of the individual sections */
62 int commitable;