Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Apr 27, 2012
1 parent ebe31ef commit 323d053
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Documentation/config.txt
Expand Up @@ -866,6 +866,10 @@ column.branch::
Specify whether to output branch listing in `git branch` in columns.
See `column.ui` for details.

column.status::
Specify whether to output untracked files in `git status` in columns.
See `column.ui` for details.

commit.status::
A boolean to enable/disable inclusion of status information in the
commit message template when using an editor to prepare the commit
Expand Down
7 changes: 7 additions & 0 deletions Documentation/git-status.txt
Expand Up @@ -77,6 +77,13 @@ configuration variable documented in linkgit:git-config[1].
Terminate entries with NUL, instead of LF. This implies
the `--porcelain` output format if no other format is given.

--column[=<options>]::
--no-column::
Display untracked files in columns. See configuration variable
column.status for option syntax.`--column` and `--no-column`
without options are equivalent to 'always' and 'never'
respectively.


OUTPUT
------
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -2168,7 +2168,7 @@ builtin/prune.o builtin/reflog.o reachable.o: reachable.h
builtin/commit.o builtin/revert.o wt-status.o: wt-status.h
builtin/tar-tree.o archive-tar.o: tar.h
connect.o transport.o url.o http-backend.o: url.h
builtin/branch.o column.o help.o pager.o: column.h
builtin/branch.o builtin/commit.o column.o help.o pager.o: column.h
http-fetch.o http-walker.o remote-curl.o transport.o walker.o: walker.h
http.o http-walker.o http-push.o http-fetch.o remote-curl.o: http.h url.h

Expand Down
7 changes: 7 additions & 0 deletions builtin/commit.c
Expand Up @@ -27,6 +27,7 @@
#include "quote.h"
#include "submodule.h"
#include "gpg-interface.h"
#include "column.h"

static const char * const builtin_commit_usage[] = {
"git commit [options] [--] <filepattern>...",
Expand Down Expand Up @@ -88,6 +89,7 @@ static int quiet, verbose, no_verify, allow_empty, dry_run, renew_authorship;
static int no_post_rewrite, allow_empty_message;
static char *untracked_files_arg, *force_date, *ignore_submodule_arg;
static char *sign_commit;
static unsigned int colopts;

/*
* The default commit message cleanup mode will remove the lines
Expand Down Expand Up @@ -1145,6 +1147,8 @@ static int git_status_config(const char *k, const char *v, void *cb)
{
struct wt_status *s = cb;

if (!prefixcmp(k, "column."))
return git_column_config(k, v, "status", &colopts);
if (!strcmp(k, "status.submodulesummary")) {
int is_bool;
s->submodule_summary = git_config_bool_or_int(k, v, &is_bool);
Expand Down Expand Up @@ -1210,6 +1214,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)
{ OPTION_STRING, 0, "ignore-submodules", &ignore_submodule_arg, "when",
"ignore changes to submodules, optional when: all, dirty, untracked. (Default: all)",
PARSE_OPT_OPTARG, NULL, (intptr_t)"all" },
OPT_COLUMN(0, "column", &colopts, "list untracked files in columns"),
OPT_END(),
};

Expand All @@ -1223,6 +1228,8 @@ int cmd_status(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix,
builtin_status_options,
builtin_status_usage, 0);
finalize_colopts(&colopts, -1);
s.colopts = colopts;

if (null_termination && status_format == STATUS_FORMAT_LONG)
status_format = STATUS_FORMAT_PORCELAIN;
Expand Down
24 changes: 24 additions & 0 deletions t/t7508-status.sh
Expand Up @@ -59,6 +59,30 @@ test_expect_success 'status (1)' '
test_i18ngrep "use \"git rm --cached <file>\.\.\.\" to unstage" output
'

test_expect_success 'status --column' '
COLUMNS=50 git status --column="column dense" >output &&
cat >expect <<\EOF &&
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# new file: dir2/added
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: dir1/modified
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# dir1/untracked dir2/untracked untracked
# dir2/modified output
EOF
test_cmp expect output
'

cat >expect <<\EOF
# On branch master
# Changes to be committed:
Expand Down
28 changes: 26 additions & 2 deletions wt-status.c
Expand Up @@ -11,6 +11,7 @@
#include "remote.h"
#include "refs.h"
#include "submodule.h"
#include "column.h"

static char default_wt_status_colors[][COLOR_MAXLEN] = {
GIT_COLOR_NORMAL, /* WT_STATUS_HEADER */
Expand Down Expand Up @@ -641,6 +642,8 @@ static void wt_status_print_other(struct wt_status *s,
{
int i;
struct strbuf buf = STRBUF_INIT;
static struct string_list output = STRING_LIST_INIT_DUP;
struct column_options copts;

if (!l->nr)
return;
Expand All @@ -649,12 +652,33 @@ static void wt_status_print_other(struct wt_status *s,

for (i = 0; i < l->nr; i++) {
struct string_list_item *it;
const char *path;
it = &(l->items[i]);
path = quote_path(it->string, strlen(it->string),
&buf, s->prefix);
if (column_active(s->colopts)) {
string_list_append(&output, path);
continue;
}
status_printf(s, color(WT_STATUS_HEADER, s), "\t");
status_printf_more(s, color(WT_STATUS_UNTRACKED, s),
"%s\n", quote_path(it->string, strlen(it->string),
&buf, s->prefix));
"%s\n", path);
}

strbuf_release(&buf);
if (!column_active(s->colopts))
return;

strbuf_addf(&buf, "%s#\t%s",
color(WT_STATUS_HEADER, s),
color(WT_STATUS_UNTRACKED, s));
memset(&copts, 0, sizeof(copts));
copts.padding = 1;
copts.indent = buf.buf;
if (want_color(s->use_color))
copts.nl = GIT_COLOR_RESET "\n";
print_columns(&output, s->colopts, &copts);
string_list_clear(&output, 0);
strbuf_release(&buf);
}

Expand Down
1 change: 1 addition & 0 deletions wt-status.h
Expand Up @@ -56,6 +56,7 @@ struct wt_status {
enum untracked_status_type show_untracked_files;
const char *ignore_submodule_arg;
char color_palette[WT_STATUS_MAXSLOT][COLOR_MAXLEN];
int colopts;

/* These are computed during processing of the individual sections */
int commitable;
Expand Down

0 comments on commit 323d053

Please sign in to comment.