Column display
Subsystems (2)
v9 cover Column display
Compared to v8 [1], the only change is "COL_ENABLE(c) == COL_ENABLED" becomes column_active(c). Oh the the experimental modes are dropped, obviously they are not ready.
[1] http://thread.gmane.org/gmane.comp.version-control.git/191522/focus=192997
Nguyễn Thái Ngọc Duy (9):
Add column layout skeleton and git-column
Stop starting pager recursively
column: add columnar layout
column: add dense layout support
help: reuse print_columns() for help -a
branch: add --column
status: add --column
column: support piping stdout to external git-column process
tag: add --column
.gitignore | 1 + Documentation/config.txt | 38 ++++ Documentation/git-branch.txt | 9 + Documentation/git-column.txt | 53 +++++ Documentation/git-status.txt | 7 + Documentation/git-tag.txt | 9 + Makefile | 3 + builtin.h | 1 + builtin/branch.c | 32 +++- builtin/column.c | 59 ++++++ builtin/commit.c | 7 + builtin/help.c | 7 +- builtin/tag.c | 27 +++- column.c | 435 ++++++++++++++++++++++++++++++++++++++++++ column.h | 45 +++++ command-list.txt | 1 + git.c | 1 + help.c | 59 +++---- help.h | 2 +- pager.c | 2 +- parse-options.h | 2 + t/t3200-branch.sh | 77 ++++++++ t/t7004-tag.sh | 44 +++++ t/t7508-status.sh | 24 +++ t/t9002-column.sh | 179 +++++++++++++++++ wt-status.c | 28 +++- wt-status.h | 1 + 27 files changed, 1105 insertions(+), 48 deletions(-) create mode 100644 Documentation/git-column.txt create mode 100644 builtin/column.c create mode 100644 column.c create mode 100644 column.h create mode 100755 t/t9002-column.sh
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH v9 1/9 Add column layout skeleton and git-column
A column option string consists of many token separated by either a space or a comma. A token belongs to one of three groups:
- enabling: always, never and auto
- layout mode: currently plain (which does not layout at all)
- other future tuning flags
git-column can be used to pipe output to from a command that wants column layout, but not to mess with its own output code. Simpler output code can be changed to use column layout code directly.
Thanks-to: Ramsay Jones <[email protected]>
--- .gitignore | 1 + Documentation/config.txt | 18 +++++ Documentation/git-column.txt | 53 +++++++++++++ Makefile | 3 + builtin.h | 1 + builtin/column.c | 59 +++++++++++++++ column.c | 170 ++++++++++++++++++++++++++++++++++++++++++ column.h | 38 +++++++++ command-list.txt | 1 + git.c | 1 + parse-options.h | 2 + t/t9002-column.sh | 45 +++++++++++ 12 files changed, 392 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-column.txt create mode 100644 builtin/column.c create mode 100644 column.c create mode 100644 column.h create mode 100755 t/t9002-column.sh
.gitignore +1 -0
@@ -26,6 +26,7 @@ /git-cherry-pick /git-clean /git-clone +/git-column /git-commit /git-commit-tree /git-config
Documentation/config.txt +18 -0
@@ -836,6 +836,24 @@ color.ui:: `never` if you prefer git commands not to use color unless enabled explicitly with some other configuration or the `--color` option. +column.ui:: + Specify whether supported commands should output in columns. + This variable consists of a list of tokens separated by spaces + or commas: ++ +-- +`always`;; + always show in columns +`never`;; + never show in columns +`auto`;; + show in columns if the output is to the terminal +`plain`;; + show in one column +-- ++ + This option defaults to 'never'. + commit.status:: A boolean to enable/disable inclusion of status information in the commit message template when using an editor to prepare the commit
Documentation/git-column.txt new file +53 -0
53 lines not on this page · raw message
Makefile +3 -0
@@ -646,6 +646,7 @@ LIB_OBJS += bulk-checkin.o LIB_OBJS += bundle.o LIB_OBJS += cache-tree.o LIB_OBJS += color.o +LIB_OBJS += column.o LIB_OBJS += combine-diff.o LIB_OBJS += commit.o LIB_OBJS += compat/obstack.o
@@ -774,6 +775,7 @@ BUILTIN_OBJS += builtin/checkout-index.o BUILTIN_OBJS += builtin/checkout.o BUILTIN_OBJS += builtin/clean.o BUILTIN_OBJS += builtin/clone.o +BUILTIN_OBJS += builtin/column.o BUILTIN_OBJS += builtin/commit-tree.o BUILTIN_OBJS += builtin/commit.o BUILTIN_OBJS += builtin/config.o
@@ -2166,6 +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 +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
builtin.h +1 -0
@@ -61,6 +61,7 @@ extern int cmd_cherry(int argc, const char **argv, const char *prefix);extern int cmd_cherry_pick (int argc,const char **argv,const char *prefix);extern int cmd_clone (int argc,const char **argv,const char *prefix);extern int cmd_clean (int argc,const char **argv,const char *prefix); +extern int cmd_column (int argc,const char **argv,const char *prefix);extern int cmd_commit (int argc,const char **argv,const char *prefix);extern int cmd_commit_tree (int argc,const char **argv,const char *prefix);extern int cmd_config (int argc,const char **argv,const char *prefix);
builtin/column.c new file +59 -0
59 lines not on this page · raw message
column.c new file +170 -0
170 lines not on this page · raw message
column.h new file +38 -0
@@ -0,0 +1,38 @@ +#ifndef COLUMN_H +#define COLUMN_H + +#define COL_LAYOUT_MASK 0x000F +#define COL_ENABLE_MASK 0x0030/* always, never or auto */ +#define COL_PARSEOPT 0x0040/* --column is given from cmdline */ + +#define COL_DISABLED 0x0000/* must be zero */ +#define COL_ENABLED 0x0010 +#define COL_AUTO 0x0020 + +#define COL_LAYOUT (c) ((c) & COL_LAYOUT_MASK) +#define COL_PLAIN 15/* one column */ + +#define explicitly_enable_column (c) \ + (((c) & COL_PARSEOPT) && column_active(c)) + +struct column_options { +int width; +int padding; +const char *indent; +const char *nl; +}; + +struct option ; +extern int parseopt_column_callback (const struct option *,const char *,int ); +extern int git_column_config (const char *var,const char *value, +const char *command,unsigned int *colopts); +extern int finalize_colopts (unsigned int *colopts,int stdout_is_tty); +static inline int column_active (unsigned int colopts) +{ +return (colopts &COL_ENABLE_MASK ) ==COL_ENABLED ; +} + +extern void print_columns (const struct string_list *list,unsigned int colopts, +const struct column_options *opts); + +#endif
command-list.txt +1 -0
@@ -20,6 +20,7 @@ git-cherry-pick mainporcelain git-citool mainporcelain git-clean mainporcelain git-clone mainporcelain common +git-column purehelpers git-commit mainporcelain common git-commit-tree plumbingmanipulators git-config ancillarymanipulators
git.c +1 -0
@@ -348,6 +348,7 @@ static void handle_internal_command(int argc, const char **argv) { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE }, { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE }, { "clone", cmd_clone }, + { "column", cmd_column, RUN_SETUP_GENTLY }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, { "commit-tree", cmd_commit_tree, RUN_SETUP }, { "config", cmd_config, RUN_SETUP_GENTLY },
parse-options.h +2 -0
@@ -238,5 +238,7 @@ extern int parse_opt_noop_cb(const struct option *, const char *, int); PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }#define OPT__COLOR (var, h) \ OPT_COLOR_FLAG(0, "color", (var), (h)) +#define OPT_COLUMN (s, l, v, h) \ + { OPTION_CALLBACK, (s), (l), (v), "style", (h), PARSE_OPT_OPTARG, parseopt_column_callback }#endif
t/t9002-column.sh new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
1.7.3.1.256.g2539c.dirty
Re: [PATCH v9 1/9] Add column layout skeleton and git-column
column.c line 141
Quoted 13 lines · Nguyễn Thái Ngọc Duy
column.c new file +13
-0+static int column_config (const char *var,const char *value, +const char *key,unsigned int *colopts) +{ +if (parse_config (colopts, value)) +return error ("invalid %s mode %s" , key, value); +return 0 ; +} + +int git_column_config (const char *var,const char *value, +const char *command,unsigned int *colopts) +{ +if (!strcmp (var,"column.ui" )) +return column_config (var, value,"column.ui" , colopts);
I do not think there is anything that reads column.ui from a configuration file (or "git -c column.ui") in this step, but later patches seem to use it from their configuration callback (e.g. git_branch_config()) and at that point you will segfault because you ignore the case where value is NULL.
column.c line 151
Quoted 9 lines
column.c new file +9
-0+if (command) { +struct strbuf sb =STRBUF_INIT ; +int ret =0 ; +strbuf_addf (&sb,"column.%s" , command); +if (!strcmp (var, sb.buf)) + ret =column_config (var, value, sb.buf, colopts); +strbuf_release (&sb); +return ret; + }
This whole thing looks overly wasteful. How about doing it this way?
const char *it = skip_prefix(var, "column.");
if (!it)
return 0;
if (!strcmp(it, "ui"))
parse "ui";
else if (!strcmp(it, command))
parse "command";and make the third parameter to column_config() be without the constant prefix "column."?
PATCH 1/1 Add column layout skeleton and git-column
A column option string consists of many token separated by either a space or a comma. A token belongs to one of three groups:
- enabling: always, never and auto
- layout mode: currently plain (which does not layout at all)
- other future tuning flags
git-column can be used to pipe output to from a command that wants column layout, but not to mess with its own output code. Simpler output code can be changed to use column layout code directly.
Thanks-to: Ramsay Jones <[email protected]>
---
2012/4/16 Junio C Hamano <[email protected]>:
Quoted 13 lines
Quoted 11 lines · Nguyễn Thái Ngọc Duy
(quoted diff) +11
-0+static int column_config(const char *var, const char *value, + const char *key, unsigned int *colopts) +{ + if (parse_config(colopts, value)) + return error("invalid %s mode %s", key, value); + return 0; +} + +int git_column_config(const char *var, const char *value, + const char *command, unsigned int *colopts) +{
Quoted 8 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!strcmp(var, "column.ui")) + return column_config(var, value, "column.ui", colopts);I do not think there is anything that reads column.ui from a configuration file (or "git -c column.ui") in this step, but later patches seem to use it from their configuration callback (e.g.
git_branch_config()) and at that point you will segfault because you ignore the case where value is NULL.
fixed
Quoted 20 lines
Review
Quoted 9 lines
(quoted diff) +9
-0+ if (command) { + struct strbuf sb = STRBUF_INIT; + int ret = 0; + strbuf_addf(&sb, "column.%s", command); + if (!strcmp(var, sb.buf)) + ret = column_config(var, value, sb.buf, colopts); + strbuf_release(&sb); + return ret; + }This whole thing looks overly wasteful. How about doing it this way?
const char *it = skip_prefix(var, "column."); if (!it) return 0; if (!strcmp(it, "ui")) parse "ui"; else if (!strcmp(it, command)) parse "command";
Quoted 2 lines
and make the third parameter to
column_config()be without the constant prefix "column."?
Nice, and thanks I didn't know about skip_prefix. How about this?
.gitignore | 1 + Documentation/config.txt | 18 +++++ Documentation/git-column.txt | 53 +++++++++++++ Makefile | 3 + builtin.h | 1 + builtin/column.c | 59 +++++++++++++++ column.c | 167 ++++++++++++++++++++++++++++++++++++++++++ column.h | 35 +++++++++ command-list.txt | 1 + git.c | 1 + parse-options.h | 2 + t/t9002-column.sh | 45 +++++++++++ 12 files changed, 386 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-column.txt create mode 100644 builtin/column.c create mode 100644 column.c create mode 100644 column.h create mode 100755 t/t9002-column.sh
.gitignore +1 -0
@@ -26,6 +26,7 @@ /git-cherry-pick /git-clean /git-clone +/git-column /git-commit /git-commit-tree /git-config
Documentation/config.txt +18 -0
@@ -821,6 +821,24 @@ color.ui:: `never` if you prefer git commands not to use color unless enabled explicitly with some other configuration or the `--color` option. +column.ui:: + Specify whether supported commands should output in columns. + This variable consists of a list of tokens separated by spaces + or commas: ++ +-- +`always`;; + always show in columns +`never`;; + never show in columns +`auto`;; + show in columns if the output is to the terminal +`plain`;; + show in one column +-- ++ + This option defaults to 'never'. + commit.status:: A boolean to enable/disable inclusion of status information in the commit message template when using an editor to prepare the commit
Documentation/git-column.txt new file +53 -0
53 lines not on this page · raw message
Makefile +3 -0
@@ -646,6 +646,7 @@ LIB_OBJS += bulk-checkin.o LIB_OBJS += bundle.o LIB_OBJS += cache-tree.o LIB_OBJS += color.o +LIB_OBJS += column.o LIB_OBJS += combine-diff.o LIB_OBJS += commit.o LIB_OBJS += compat/obstack.o
@@ -774,6 +775,7 @@ BUILTIN_OBJS += builtin/checkout-index.o BUILTIN_OBJS += builtin/checkout.o BUILTIN_OBJS += builtin/clean.o BUILTIN_OBJS += builtin/clone.o +BUILTIN_OBJS += builtin/column.o BUILTIN_OBJS += builtin/commit-tree.o BUILTIN_OBJS += builtin/commit.o BUILTIN_OBJS += builtin/config.o
@@ -2166,6 +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 +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
builtin.h +1 -0
@@ -61,6 +61,7 @@ extern int cmd_cherry(int argc, const char **argv, const char *prefix);extern int cmd_cherry_pick (int argc,const char **argv,const char *prefix);extern int cmd_clone (int argc,const char **argv,const char *prefix);extern int cmd_clean (int argc,const char **argv,const char *prefix); +extern int cmd_column (int argc,const char **argv,const char *prefix);extern int cmd_commit (int argc,const char **argv,const char *prefix);extern int cmd_commit_tree (int argc,const char **argv,const char *prefix);extern int cmd_config (int argc,const char **argv,const char *prefix);
builtin/column.c new file +59 -0
59 lines not on this page · raw message
column.c new file +167 -0
167 lines not on this page · raw message
column.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef COLUMN_H +#define COLUMN_H + +#define COL_LAYOUT_MASK 0x000F +#define COL_ENABLE_MASK 0x0030/* always, never or auto */ +#define COL_PARSEOPT 0x0040/* --column is given from cmdline */ + +#define COL_ENABLE (c) ((c) & COL_ENABLE_MASK) +#define COL_DISABLED 0x0000/* must be zero */ +#define COL_ENABLED 0x0010 +#define COL_AUTO 0x0020 + +#define COL_LAYOUT (c) ((c) & COL_LAYOUT_MASK) +#define COL_PLAIN 15/* one column */ + +#define explicitly_enable_column (c) \ + (((c) & COL_PARSEOPT) && COL_ENABLE(c) == COL_ENABLED) + +struct column_options { +int width; +int padding; +const char *indent; +const char *nl; +}; + +struct option ; +extern int parseopt_column_callback (const struct option *,const char *,int ); +extern int git_column_config (const char *var,const char *value, +const char *command,unsigned int *colopts); +extern int finalize_colopts (unsigned int *colopts,int stdout_is_tty); + +extern void print_columns (const struct string_list *list,unsigned int colopts, +const struct column_options *opts); + +#endif
command-list.txt +1 -0
@@ -20,6 +20,7 @@ git-cherry-pick mainporcelain git-citool mainporcelain git-clean mainporcelain git-clone mainporcelain common +git-column purehelpers git-commit mainporcelain common git-commit-tree plumbingmanipulators git-config ancillarymanipulators
git.c +1 -0
@@ -348,6 +348,7 @@ static void handle_internal_command(int argc, const char **argv) { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE }, { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE }, { "clone", cmd_clone }, + { "column", cmd_column, RUN_SETUP_GENTLY }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, { "commit-tree", cmd_commit_tree, RUN_SETUP }, { "config", cmd_config, RUN_SETUP_GENTLY },
parse-options.h +2 -0
@@ -238,5 +238,7 @@ extern int parse_opt_noop_cb(const struct option *, const char *, int); PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }#define OPT__COLOR (var, h) \ OPT_COLOR_FLAG(0, "color", (var), (h)) +#define OPT_COLUMN (s, l, v, h) \ + { OPTION_CALLBACK, (s), (l), (v), "style", (h), PARSE_OPT_OPTARG, parseopt_column_callback }#endif
t/t9002-column.sh new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
1.7.3.1.256.g2539c.dirty
Re: [PATCH] Add column layout skeleton and git-column
Quoted 23 lines · Nguyễn Thái Ngọc Duy
column.c new file +23
-0+static int parse_config (unsigned int *colopts,const char *value) +{ +const char *sep =" ," ; +int group_set =0 ; + +while (*value) { +int len =strcspn (value, sep); +if (len) { +if (parse_option (value, len, colopts, &group_set)) +return -1 ; + + value += len; + } + value +=strspn (value, sep); + } +/* +* Setting layout implies "always" if neither always, never +* nor auto is specified. +* +* Current COL_ENABLE() value is disregarded. This means if +* you set column.ui = auto and pass --column=row, then "auto" +* will become "always". +*/
column.c line 133
Quoted 10 lines
column.c new file +10
-0+if ((group_set &LAYOUT_SET ) && !(group_set &ENABLE_SET )) + *colopts = (*colopts & ~COL_ENABLE_MASK ) |COL_ENABLED ; +return 0 ; +} + +static int column_config (const char *var,const char *value, +const char *key,unsigned int *colopts) +{ +if (value &&parse_config (colopts, value)) +return error ("invalid column.%s mode %s" , key, value);
If column.* can never be a boolean, this code shouldn't silently ignore
[column]
ui
but explicitly error out. See git_config_string() for an example if you want to go this route.
On the other hand, it might make sense to equate a "true" with "a sane default" (i.e. the user declares that s/he trusts whatever default the Git implementation deems sane), in which case
if (!value)
value = "auto,whatever,column,default,mode";
if (parse_config(colopts, value))
return error("invalid column.%s mode...", ...);might be a better way to go. If you take this route, a single-token column.* becomes a variable that takes boolean and more, so the existing never has to gain no, false, etc. as synonyms, and true, 1, etc. needs to be interpreted the same as auto for consistency.
PATCH 1/1 Add column layout skeleton and git-column
A column option string consists of many token separated by either a space or a comma. A token belongs to one of three groups:
- enabling: always, never and auto
- layout mode: currently plain (which does not layout at all)
- other future tuning flags
git-column can be used to pipe output to from a command that wants column layout, but not to mess with its own output code. Simpler output code can be changed to use column layout code directly.
Thanks-to: Ramsay Jones <[email protected]>
---
2012/4/16 Junio C Hamano <[email protected]>:
Quoted 23 lines
Review
Quoted 5 lines
(quoted diff) +5
-0+static int column_config(const char *var, const char *value, + const char *key, unsigned int *colopts) +{ + if (value && parse_config(colopts, value)) + return error("invalid column.%s mode %s", key, value);If column.* can never be a boolean, this code shouldn't silently ignore
[column]
uibut explicitly error out. See
git_config_string()for an example if you want to go this route.On the other hand, it might make sense to equate a "true" with "a sane default" (i.e. the user declares that s/he trusts whatever default the Git implementation deems sane), in which case
if (!value) value = "auto,whatever,column,default,mode"; if (parse_config(colopts, value)) return error("invalid column.%s mode...", ...);
Quoted 4 lines
might be a better way to go. If you take this route, a single-token column.* becomes a variable that takes boolean and more, so the existing
neverhas to gainno,false, etc. as synonyms, andtrue,1, etc. needs to be interpreted the same asautofor consistency.
Thanks. I'll go with the simple way: error out.
.gitignore | 1 + Documentation/config.txt | 18 +++++ Documentation/git-column.txt | 53 +++++++++++++ Makefile | 3 + builtin.h | 1 + builtin/column.c | 59 +++++++++++++++ column.c | 169 ++++++++++++++++++++++++++++++++++++++++++ column.h | 35 +++++++++ command-list.txt | 1 + git.c | 1 + parse-options.h | 2 + t/t9002-column.sh | 45 +++++++++++ 12 files changed, 388 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-column.txt create mode 100644 builtin/column.c create mode 100644 column.c create mode 100644 column.h create mode 100755 t/t9002-column.sh
.gitignore +1 -0
@@ -26,6 +26,7 @@ /git-cherry-pick /git-clean /git-clone +/git-column /git-commit /git-commit-tree /git-config
Documentation/config.txt +18 -0
@@ -836,6 +836,24 @@ color.ui:: `never` if you prefer git commands not to use color unless enabled explicitly with some other configuration or the `--color` option. +column.ui:: + Specify whether supported commands should output in columns. + This variable consists of a list of tokens separated by spaces + or commas: ++ +-- +`always`;; + always show in columns +`never`;; + never show in columns +`auto`;; + show in columns if the output is to the terminal +`plain`;; + show in one column +-- ++ + This option defaults to 'never'. + commit.status:: A boolean to enable/disable inclusion of status information in the commit message template when using an editor to prepare the commit
Documentation/git-column.txt new file +53 -0
53 lines not on this page · raw message
Makefile +3 -0
@@ -646,6 +646,7 @@ LIB_OBJS += bulk-checkin.o LIB_OBJS += bundle.o LIB_OBJS += cache-tree.o LIB_OBJS += color.o +LIB_OBJS += column.o LIB_OBJS += combine-diff.o LIB_OBJS += commit.o LIB_OBJS += compat/obstack.o
@@ -774,6 +775,7 @@ BUILTIN_OBJS += builtin/checkout-index.o BUILTIN_OBJS += builtin/checkout.o BUILTIN_OBJS += builtin/clean.o BUILTIN_OBJS += builtin/clone.o +BUILTIN_OBJS += builtin/column.o BUILTIN_OBJS += builtin/commit-tree.o BUILTIN_OBJS += builtin/commit.o BUILTIN_OBJS += builtin/config.o
@@ -2166,6 +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 +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
builtin.h +1 -0
@@ -61,6 +61,7 @@ extern int cmd_cherry(int argc, const char **argv, const char *prefix);extern int cmd_cherry_pick (int argc,const char **argv,const char *prefix);extern int cmd_clone (int argc,const char **argv,const char *prefix);extern int cmd_clean (int argc,const char **argv,const char *prefix); +extern int cmd_column (int argc,const char **argv,const char *prefix);extern int cmd_commit (int argc,const char **argv,const char *prefix);extern int cmd_commit_tree (int argc,const char **argv,const char *prefix);extern int cmd_config (int argc,const char **argv,const char *prefix);
builtin/column.c new file +59 -0
59 lines not on this page · raw message
column.c new file +169 -0
169 lines not on this page · raw message
column.h new file +35 -0
@@ -0,0 +1,35 @@ +#ifndef COLUMN_H +#define COLUMN_H + +#define COL_LAYOUT_MASK 0x000F +#define COL_ENABLE_MASK 0x0030/* always, never or auto */ +#define COL_PARSEOPT 0x0040/* --column is given from cmdline */ + +#define COL_ENABLE (c) ((c) & COL_ENABLE_MASK) +#define COL_DISABLED 0x0000/* must be zero */ +#define COL_ENABLED 0x0010 +#define COL_AUTO 0x0020 + +#define COL_LAYOUT (c) ((c) & COL_LAYOUT_MASK) +#define COL_PLAIN 15/* one column */ + +#define explicitly_enable_column (c) \ + (((c) & COL_PARSEOPT) && COL_ENABLE(c) == COL_ENABLED) + +struct column_options { +int width; +int padding; +const char *indent; +const char *nl; +}; + +struct option ; +extern int parseopt_column_callback (const struct option *,const char *,int ); +extern int git_column_config (const char *var,const char *value, +const char *command,unsigned int *colopts); +extern int finalize_colopts (unsigned int *colopts,int stdout_is_tty); + +extern void print_columns (const struct string_list *list,unsigned int colopts, +const struct column_options *opts); + +#endif
command-list.txt +1 -0
@@ -20,6 +20,7 @@ git-cherry-pick mainporcelain git-citool mainporcelain git-clean mainporcelain git-clone mainporcelain common +git-column purehelpers git-commit mainporcelain common git-commit-tree plumbingmanipulators git-config ancillarymanipulators
git.c +1 -0
@@ -348,6 +348,7 @@ static void handle_internal_command(int argc, const char **argv) { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE }, { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE }, { "clone", cmd_clone }, + { "column", cmd_column, RUN_SETUP_GENTLY }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, { "commit-tree", cmd_commit_tree, RUN_SETUP }, { "config", cmd_config, RUN_SETUP_GENTLY },
parse-options.h +2 -0
@@ -238,5 +238,7 @@ extern int parse_opt_noop_cb(const struct option *, const char *, int); PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }#define OPT__COLOR (var, h) \ OPT_COLOR_FLAG(0, "color", (var), (h)) +#define OPT_COLUMN (s, l, v, h) \ + { OPTION_CALLBACK, (s), (l), (v), "style", (h), PARSE_OPT_OPTARG, parseopt_column_callback }#endif
t/t9002-column.sh new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
1.7.8.36.g69ee2
Re: [PATCH] Add column layout skeleton and git-column
Quoted 1 line · Nguyễn Thái Ngọc Duy
Thanks. I'll go with the simple way: error out.
OK.
Quoted 19 lines
column.c new file +13
-0@@ -0,0 +1,169 @@ +#include "cache.h" +#include "column.h" +#include "string-list.h" +#include "parse-options.h" + +/* Display without layout when not enabled */ +static void display_plain (const struct string_list *list, +const char *indent,const char *nl) +{ +int i; + +for (i =0 ; i < list->nr; i++) +printf ("%s%s%s" , indent, list->items[i].string, nl);
column.c line 23
Quoted 10 lines
column.c new file +10
-0+} + +void print_columns (const struct string_list *list,unsigned int colopts, +const struct column_options *opts) +{ +struct column_options nopts; + +if (!list->nr) +return ; +assert (COL_ENABLE (colopts) !=COL_AUTO );
Am I looking at the correct version? Somehow I thought you eliminated this confusingly named macro in the previous round. Two steps forward, one step backward???
PATCH 1/1 Add column layout skeleton and git-column
A column option string consists of many token separated by either a space or a comma. A token belongs to one of three groups:
- enabling: always, never and auto
- layout mode: currently plain (which does not layout at all)
- other future tuning flags
git-column can be used to pipe output to from a command that wants column layout, but not to mess with its own output code. Simpler output code can be changed to use column layout code directly.
Thanks-to: Ramsay Jones <[email protected]>
---
2012/4/21 Junio C Hamano <[email protected]>:
Quoted 3 lines
Am I looking at the correct version? Somehow I thought you eliminated this confusingly named macro in the previous round. Two steps forward, one step backward???
Aah.. the beautiful result of having the same series (but probably different versions) across several machines.. This version should be the right one with fixes.
.gitignore | 1 + Documentation/config.txt | 18 +++++ Documentation/git-column.txt | 53 +++++++++++++ Makefile | 3 + builtin.h | 1 + builtin/column.c | 59 +++++++++++++++ column.c | 169 ++++++++++++++++++++++++++++++++++++++++++ column.h | 38 ++++++++++ command-list.txt | 1 + git.c | 1 + parse-options.h | 2 + t/t9002-column.sh | 45 +++++++++++ 12 files changed, 391 insertions(+), 0 deletions(-) create mode 100644 Documentation/git-column.txt create mode 100644 builtin/column.c create mode 100644 column.c create mode 100644 column.h create mode 100755 t/t9002-column.sh
.gitignore +1 -0
@@ -26,6 +26,7 @@ /git-cherry-pick /git-clean /git-clone +/git-column /git-commit /git-commit-tree /git-config
Documentation/config.txt +18 -0
@@ -836,6 +836,24 @@ color.ui:: `never` if you prefer git commands not to use color unless enabled explicitly with some other configuration or the `--color` option. +column.ui:: + Specify whether supported commands should output in columns. + This variable consists of a list of tokens separated by spaces + or commas: ++ +-- +`always`;; + always show in columns +`never`;; + never show in columns +`auto`;; + show in columns if the output is to the terminal +`plain`;; + show in one column +-- ++ + This option defaults to 'never'. + commit.status:: A boolean to enable/disable inclusion of status information in the commit message template when using an editor to prepare the commit
Documentation/git-column.txt new file +53 -0
53 lines not on this page · raw message
Makefile +3 -0
@@ -646,6 +646,7 @@ LIB_OBJS += bulk-checkin.o LIB_OBJS += bundle.o LIB_OBJS += cache-tree.o LIB_OBJS += color.o +LIB_OBJS += column.o LIB_OBJS += combine-diff.o LIB_OBJS += commit.o LIB_OBJS += compat/obstack.o
@@ -774,6 +775,7 @@ BUILTIN_OBJS += builtin/checkout-index.o BUILTIN_OBJS += builtin/checkout.o BUILTIN_OBJS += builtin/clean.o BUILTIN_OBJS += builtin/clone.o +BUILTIN_OBJS += builtin/column.o BUILTIN_OBJS += builtin/commit-tree.o BUILTIN_OBJS += builtin/commit.o BUILTIN_OBJS += builtin/config.o
@@ -2166,6 +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 +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
builtin.h +1 -0
@@ -61,6 +61,7 @@ extern int cmd_cherry(int argc, const char **argv, const char *prefix);extern int cmd_cherry_pick (int argc,const char **argv,const char *prefix);extern int cmd_clone (int argc,const char **argv,const char *prefix);extern int cmd_clean (int argc,const char **argv,const char *prefix); +extern int cmd_column (int argc,const char **argv,const char *prefix);extern int cmd_commit (int argc,const char **argv,const char *prefix);extern int cmd_commit_tree (int argc,const char **argv,const char *prefix);extern int cmd_config (int argc,const char **argv,const char *prefix);
builtin/column.c new file +59 -0
59 lines not on this page · raw message
column.c new file +169 -0
169 lines not on this page · raw message
column.h new file +38 -0
@@ -0,0 +1,38 @@ +#ifndef COLUMN_H +#define COLUMN_H + +#define COL_LAYOUT_MASK 0x000F +#define COL_ENABLE_MASK 0x0030/* always, never or auto */ +#define COL_PARSEOPT 0x0040/* --column is given from cmdline */ + +#define COL_DISABLED 0x0000/* must be zero */ +#define COL_ENABLED 0x0010 +#define COL_AUTO 0x0020 + +#define COL_LAYOUT (c) ((c) & COL_LAYOUT_MASK) +#define COL_PLAIN 15/* one column */ + +#define explicitly_enable_column (c) \ + (((c) & COL_PARSEOPT) && column_active(c)) + +struct column_options { +int width; +int padding; +const char *indent; +const char *nl; +}; + +struct option ; +extern int parseopt_column_callback (const struct option *,const char *,int ); +extern int git_column_config (const char *var,const char *value, +const char *command,unsigned int *colopts); +extern int finalize_colopts (unsigned int *colopts,int stdout_is_tty); +static inline int column_active (unsigned int colopts) +{ +return (colopts &COL_ENABLE_MASK ) ==COL_ENABLED ; +} + +extern void print_columns (const struct string_list *list,unsigned int colopts, +const struct column_options *opts); + +#endif
command-list.txt +1 -0
@@ -20,6 +20,7 @@ git-cherry-pick mainporcelain git-citool mainporcelain git-clean mainporcelain git-clone mainporcelain common +git-column purehelpers git-commit mainporcelain common git-commit-tree plumbingmanipulators git-config ancillarymanipulators
git.c +1 -0
@@ -348,6 +348,7 @@ static void handle_internal_command(int argc, const char **argv) { "cherry-pick", cmd_cherry_pick, RUN_SETUP | NEED_WORK_TREE }, { "clean", cmd_clean, RUN_SETUP | NEED_WORK_TREE }, { "clone", cmd_clone }, + { "column", cmd_column, RUN_SETUP_GENTLY }, { "commit", cmd_commit, RUN_SETUP | NEED_WORK_TREE }, { "commit-tree", cmd_commit_tree, RUN_SETUP }, { "config", cmd_config, RUN_SETUP_GENTLY },
parse-options.h +2 -0
@@ -238,5 +238,7 @@ extern int parse_opt_noop_cb(const struct option *, const char *, int); PARSE_OPT_OPTARG, &parse_opt_abbrev_cb, 0 }#define OPT__COLOR (var, h) \ OPT_COLOR_FLAG(0, "color", (var), (h)) +#define OPT_COLUMN (s, l, v, h) \ + { OPTION_CALLBACK, (s), (l), (v), "style", (h), PARSE_OPT_OPTARG, parseopt_column_callback }#endif
t/t9002-column.sh new file +45 -0
45 lines not on this page · raw message
Signature · 1 line
1.7.8.36.g69ee2
Re: [PATCH] Add column layout skeleton and git-column
Quoted 8 lines · Nguyễn Thái Ngọc Duy
2012/4/21 Junio C Hamano <[email protected]>:
Quoted 3 lines
Am I looking at the correct version? Somehow I thought you eliminated this confusingly named macro in the previous round. Two steps forward, one step backward???
Aah.. the beautiful result of having the same series (but probably different versions) across several machines.. This version should be the right one with fixes.
Yeah, this looks more like it.
Will replace 1/9 with this and requeue.
PATCH v9 2/9 Stop starting pager recursively
In reply to Nguyễn Thái Ngọc Duygit-column can be used as a pager for other git commands, something like this:
GIT_PAGER="git -p column --mode='dense color'" git -p branch
The problem with this is that "git -p column" also has $GIT_PAGER set so the pager runs itself again as another pager. The end result is an infinite loop of forking. Other git commands have the same problem if being abused this way.
Check if $GIT_PAGER is already set and stop launching another pager.
--- pager.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
pager.c +1 -1
@@ -73,7 +73,7 @@ void setup_pager(void) {const char *pager =git_pager (isatty (1 )); -if (!pager) +if (!pager ||pager_in_use ())return ;/*
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH v9 3/9 column: add columnar layout
In reply to Nguyễn Thái Ngọc DuyCOL_COLUMN and COL_ROW fill column by column (or row by row respectively), given the terminal width and how many space between columns. All cells have equal width.
Strings are supposed to be in UTF-8. Valid ANSI escape strings are OK.
--- Documentation/config.txt | 4 ++ column.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++ column.h | 2 + t/t9002-column.sh | 86 ++++++++++++++++++++++++++++++++++ 4 files changed, 206 insertions(+), 0 deletions(-)
Documentation/config.txt +4 -0
@@ -848,6 +848,10 @@ column.ui:: never show in columns `auto`;; show in columns if the output is to the terminal +`column`;; + fill columns before rows (default) +`row`;; + fill rows before columns `plain`;; show in one column --
column.c +114 -0
138 lines not on this page · raw message
column.h +2 -0
@@ -10,6 +10,8 @@#define COL_AUTO 0x0020#define COL_LAYOUT (c) ((c) & COL_LAYOUT_MASK) +#define COL_COLUMN 0/* Fill columns before rows */ +#define COL_ROW 1/* Fill rows before columns */ #define COL_PLAIN 15/* one column */ #define explicitly_enable_column (c) \
t/t9002-column.sh +86 -0
90 lines not on this page · raw message
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH v9 4/9 column: add dense layout support
In reply to Nguyễn Thái Ngọc DuyNormally all cells (and in turn columns) share the same width. This layout mode can waste space because one long item can stretch our all columns.
With COL_DENSE enabled, column width is calculated indepdendently. All columns are shrunk to minimum, then it attempts to push cells of the last row over to the next column with hope that everything still fits even there's one row less. The process is repeated until the new layout cannot fit in given width any more, or there's only one row left (perfect!).
Apparently, this mode consumes more cpu than the old one, but it makes better use of terminal space. For layouting one or two screens, cpu usage should not be detectable.
This patch introduces option handling code besides layout modes and enable/disable to expose this feature as "dense". The feature can be turned off by specifying "nodense".
Thanks-to: Ramsay Jones <[email protected]>
--- Documentation/config.txt | 4 ++ column.c | 84 +++++++++++++++++++++++++++++++++++++++++++++- column.h | 2 + t/t9002-column.sh | 48 ++++++++++++++++++++++++++ 4 files changed, 137 insertions(+), 1 deletions(-)
Documentation/config.txt +4 -0
@@ -854,6 +854,10 @@ column.ui:: fill rows before columns `plain`;; show in one column +`dense`;; + make unequal size columns to utilize more space +`nodense`;; + make equal size columns -- + This option defaults to 'never'.
column.c +83 -1
133 lines not on this page · raw message
column.h +2 -0
@@ -4,6 +4,8 @@#define COL_LAYOUT_MASK 0x000F#define COL_ENABLE_MASK 0x0030/* always, never or auto */ #define COL_PARSEOPT 0x0040/* --column is given from cmdline */ +#define COL_DENSE 0x0080/* Shrink columns when possible, +making space for more columns */ #define COL_DISABLED 0x0000/* must be zero */ #define COL_ENABLED 0x0010
t/t9002-column.sh +48 -0
58 lines not on this page · raw message
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH v9 5/9 help: reuse print_columns() for help -a
In reply to Nguyễn Thái Ngọc Duy"help -a" also respects column.ui (and column.help if presents)
--- builtin/help.c | 7 +++++- help.c | 59 +++++++++++++++++++++---------------------------------- help.h | 2 +- 3 files changed, 30 insertions(+), 38 deletions(-)
builtin/help.c +6 -1
@@ -9,6 +9,7 @@#include "common-cmds.h" #include "parse-options.h" #include "run-command.h" +#include "column.h" #include "help.h" static struct man_viewer_list {
@@ -30,6 +31,7 @@ enum help_format { };static int show_all =0 ; +static unsigned int colopts;static enum help_format help_format =HELP_FORMAT_NONE ;static struct option builtin_help_options[] = {OPT_BOOLEAN ('a' ,"all" , &show_all,"print all available commands" ),
@@ -251,6 +253,8 @@ static int add_man_viewer_info(const char *var, const char *value)static int git_help_config (const char *var,const char *value,void *cb) { +if (!prefixcmp (var,"column." )) +return git_column_config (var, value,"help" , &colopts);if (!strcmp (var,"help.format" )) {if (!value)return config_error_nonbool (var);
@@ -424,8 +428,9 @@ int cmd_help(int argc, const char **argv, const char *prefix) parsed_help_format = help_format;if (show_all) { +git_config (git_help_config,NULL );printf ("usage: %s\n\n" , git_usage_string); -list_commands ("git commands" , &main_cmds, &other_cmds); +list_commands ("git commands" , colopts, &main_cmds, &other_cmds);printf ("%s\n" , git_more_info_string);return 0 ; }
help.c +23 -36
92 lines not on this page · raw message
help.h +1 -1
@@ -25,7 +25,7 @@ extern void add_cmdname(struct cmdnames *cmds, const char *name, int len);/* Here we require that excludes is a sorted list. */ extern void exclude_cmds (struct cmdnames *cmds,struct cmdnames *excludes);extern int is_in_cmdlist (struct cmdnames *cmds,const char *name); -extern void list_commands (const char *title, +extern void list_commands (const char *title,unsigned int colopts,struct cmdnames *main_cmds,struct cmdnames *other_cmds);
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH v9 6/9 branch: add --column
In reply to Nguyễn Thái Ngọc Duy--- Documentation/config.txt | 4 ++ Documentation/git-branch.txt | 9 +++++ Makefile | 2 +- builtin/branch.c | 32 +++++++++++++++-- t/t3200-branch.sh | 77 ++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 119 insertions(+), 5 deletions(-)
Documentation/config.txt +4 -0
@@ -862,6 +862,10 @@ column.ui:: + This option defaults to 'never'. +column.branch:: + Specify whether to output branch listing in `git branch` 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
Documentation/git-branch.txt +9 -0
@@ -10,6 +10,7 @@ SYNOPSIS [verse] 'git branch' [--color[=<when>] | --no-color] [-r | -a] [--list] [-v [--abbrev=<length> | --no-abbrev]] + [--column[=<options>] | --no-column] [(--merged | --no-merged | --contains) [<commit>]] [<pattern>...] 'git branch' [--set-upstream | --track | --no-track] [-l] [-f] <branchname> [<start-point>] 'git branch' (-m | -M) [<oldbranch>] <newbranch>
@@ -107,6 +108,14 @@ OPTIONS default to color output. Same as `--color=never`. +--column[=<options>]:: +--no-column:: + Display branch listing in columns. See configuration variable + column.branch for option syntax.`--column` and `--no-column` + without options are equivalent to 'always' and 'never' respectively. ++ +This option is only applicable in non-verbose mode. + -r:: --remotes:: List or delete (if used with -d) the remote-tracking branches.
Makefile +1 -1
@@ -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 -column.o help.o pager.o: column.h +builtin/branch.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
builtin/branch.c +28 -4
@@ -15,6 +15,8 @@#include "branch.h" #include "diff.h" #include "revision.h" +#include "string-list.h" +#include "column.h" static const char *const builtin_branch_usage[] = {"git branch [options] [-r | -a] [--merged | --no-merged]" ,
@@ -53,6 +55,9 @@ static enum merge_filter { } merge_filter;static unsigned char merge_filter_ref[20 ]; +static struct string_list output =STRING_LIST_INIT_DUP ; +static unsigned int colopts; +static int parse_branch_color_slot (const char *var,int ofs) {if (!strcasecmp (var+ofs,"plain" ))
@@ -70,6 +75,8 @@ static int parse_branch_color_slot(const char *var, int ofs)static int git_branch_config (const char *var,const char *value,void *cb) { +if (!prefixcmp (var,"column." )) +return git_column_config (var, value,"branch" , &colopts);if (!strcmp (var,"color.branch" )) { branch_use_color =git_config_colorbool (var, value);return 0 ;
@@ -474,7 +481,12 @@ static void print_ref_item(struct ref_item *item, int maxwidth, int verbose,else if (verbose)/* " f7c0c00 [ahead 58, behind 197] vcs-svn: drop obj_pool.h" */ add_verbose_info (&out, item, verbose, abbrev); -printf ("%s\n" , out.buf); +if (column_active (colopts)) { +assert (!verbose &&"--column and --verbose are incompatible" ); +string_list_append (&output, out.buf); + }else { +printf ("%s\n" , out.buf); + }strbuf_release (&name);strbuf_release (&out); }
@@ -727,6 +739,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) PARSE_OPT_LASTARG_DEFAULT | PARSE_OPT_NONEG, opt_parse_merge_filter, (intptr_t) "HEAD", }, + OPT_COLUMN(0, "column", &colopts, "list branches in columns"), OPT_END(), };
@@ -749,6 +762,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix) }hashcpy (merge_filter_ref, head_sha1); + argc =parse_options (argc, argv, prefix, options, builtin_branch_usage,0 );
@@ -760,12 +774,22 @@ int cmd_branch(int argc, const char **argv, const char *prefix)if (abbrev ==-1 ) abbrev =DEFAULT_ABBREV ; +finalize_colopts (&colopts,-1 ); +if (verbose) { +if (explicitly_enable_column (colopts)) +die (_ ("--column and --verbose are incompatible" )); + colopts =0 ; + }if (delete)return delete_branches (argc, argv, delete >1 , kinds); -else if (list) -return print_ref_list (kinds, detached, verbose, abbrev, - with_commit, argv); +else if (list) { +int ret =print_ref_list (kinds, detached, verbose, abbrev, + with_commit, argv); +print_columns (&output, colopts,NULL ); +string_list_clear (&output,0 ); +return ret; + }else if (edit_description) {const char *branch_name;struct strbuf branch_ref =STRBUF_INIT ;
t/t3200-branch.sh +77 -0
83 lines not on this page · raw message
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH v9 7/9 status: add --column
In reply to Nguyễn Thái Ngọc Duy--- Documentation/config.txt | 4 ++++ Documentation/git-status.txt | 7 +++++++ Makefile | 2 +- builtin/commit.c | 7 +++++++ t/t7508-status.sh | 24 ++++++++++++++++++++++++ wt-status.c | 28 ++++++++++++++++++++++++++-- wt-status.h | 1 + 7 files changed, 70 insertions(+), 3 deletions(-)
Documentation/config.txt +4 -0
@@ -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
Documentation/git-status.txt +7 -0
@@ -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 ------
Makefile +1 -1
@@ -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
builtin/commit.c +7 -0
@@ -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>..." ,
@@ -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
@@ -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);
@@ -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(), };
@@ -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 ;
t/t7508-status.sh +24 -0
@@ -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:
wt-status.c +26 -2
@@ -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 */
@@ -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 ;
@@ -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); }
wt-status.h +1 -0
@@ -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;
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH v9 8/9 column: support piping stdout to external git-column process
In reply to Nguyễn Thái Ngọc DuyFor too complicated output handling, it'd be easier to just spawn git-column and redirect stdout to it. This patch provides helpers to do that.
--- column.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ column.h | 3 ++ 2 files changed, 72 insertions(+), 0 deletions(-)
column.c +69 -0
@@ -2,6 +2,7 @@#include "column.h" #include "string-list.h" #include "parse-options.h" +#include "run-command.h" #include "utf8.h" #define XY2LINEAR (d, x, y) (COL_LAYOUT((d)->colopts) == COL_COLUMN ? \
@@ -364,3 +365,71 @@ int parseopt_column_callback(const struct option *opt,return 0 ; } + +static int fd_out =-1 ; +static struct child_process column_process; + +int run_column_filter (int colopts,const struct column_options *opts) +{ +const char *av[10 ]; +int ret, ac =0 ; +struct strbuf sb_colopt =STRBUF_INIT ; +struct strbuf sb_width =STRBUF_INIT ; +struct strbuf sb_padding =STRBUF_INIT ; + +if (fd_out !=-1 ) +return -1 ; + + av[ac++] ="column" ; +strbuf_addf (&sb_colopt,"--raw-mode=%d" , colopts); + av[ac++] = sb_colopt.buf; +if (opts && opts->width) { +strbuf_addf (&sb_width,"--width=%d" , opts->width); + av[ac++] = sb_width.buf; + } +if (opts && opts->indent) { + av[ac++] ="--indent" ; + av[ac++] = opts->indent; + } +if (opts && opts->padding) { +strbuf_addf (&sb_padding,"--padding=%d" , opts->padding); + av[ac++] = sb_padding.buf; + } + av[ac] =NULL ; + +fflush (stdout); +memset (&column_process,0 ,sizeof (column_process)); + column_process.in =-1 ; + column_process.out =dup (1 ); + column_process.git_cmd =1 ; + column_process.argv = av; + + ret =start_command (&column_process); + +strbuf_release (&sb_colopt); +strbuf_release (&sb_width); +strbuf_release (&sb_padding); + +if (ret) +return -2 ; + + fd_out =dup (1 ); +close (1 ); +dup2 (column_process.in,1 ); +close (column_process.in); +return 0 ; +} + +int stop_column_filter (void ) +{ +if (fd_out ==-1 ) +return -1 ; + +fflush (stdout); +close (1 ); +finish_command (&column_process); +dup2 (fd_out,1 ); +close (fd_out); + fd_out =-1 ; +return 0 ; +}
column.h +3 -0
@@ -39,4 +39,7 @@ static inline int column_active(unsigned int colopts)extern void print_columns (const struct string_list *list,unsigned int colopts,const struct column_options *opts); +extern int run_column_filter (int colopts,const struct column_options *); +extern int stop_column_filter (void ); +#endif
Signature · 1 line
1.7.3.1.256.g2539c.dirty
PATCH v9 9/9 tag: add --column
In reply to Nguyễn Thái Ngọc Duy--- Documentation/config.txt | 4 ++++ Documentation/git-tag.txt | 9 +++++++++ Makefile | 2 +- builtin/tag.c | 27 ++++++++++++++++++++++++--- t/t7004-tag.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 4 deletions(-)
Documentation/config.txt +4 -0
@@ -870,6 +870,10 @@ column.status:: Specify whether to output untracked files in `git status` in columns. See `column.ui` for details. +column.tag:: + Specify whether to output tag listing in `git tag` 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
Documentation/git-tag.txt +9 -0
@@ -13,6 +13,7 @@ SYNOPSIS <tagname> [<commit> | <object>] 'git tag' -d <tagname>... 'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>] + [--column[=<options>] | --no-column] [<pattern>...] [<pattern>...] 'git tag' -v <tagname>...
@@ -84,6 +85,14 @@ OPTIONS using fnmatch(3)). Multiple patterns may be given; if any of them matches, the tag is shown. +--column[=<options>]:: +--no-column:: + Display tag listing in columns. See configuration variable + column.tag for option syntax.`--column` and `--no-column` + without options are equivalent to 'always' and 'never' respectively. ++ +This option is only applicable when listing tags without annotation lines. + --contains <commit>:: Only list tags which contain the specified commit.
Makefile +1 -1
@@ -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 builtin/commit.o column.o help.o pager.o: column.h +builtin/branch.o builtin/commit.o builtin/tag.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
builtin/tag.c +24 -3
@@ -16,6 +16,7 @@#include "revision.h" #include "gpg-interface.h" #include "sha1-array.h" +#include "column.h" static const char *const git_tag_usage[] = {"git tag [-a|-s|-u <key-id>] [-f] [-m <msg>|-F <file>] <tagname> [<head>]" ,
@@ -33,6 +34,7 @@ struct tag_filter { };static struct sha1_array points_at; +static unsigned int colopts;static int match_pattern (const char **patterns,const char *ref) {
@@ -263,6 +265,8 @@ static int git_tag_config(const char *var, const char *value, void *cb)int status =git_gpg_config (var, value, cb);if (status)return status; +if (!prefixcmp (var,"column." )) +return git_column_config (var, value,"tag" , &colopts);return git_default_config (var, value, cb); }
@@ -459,6 +463,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)OPT_STRING ('u' ,"local-user" , &keyid,"key-id" ,"use another key to sign the tag" ),OPT__FORCE (&force,"replace the tag if exists" ), +OPT_COLUMN (0 ,"column" , &colopts,"show tag list in columns" ), OPT_GROUP("Tag listing options"), {
@@ -495,9 +500,25 @@ int cmd_tag(int argc, const char **argv, const char *prefix)if (list + delete + verify >1 )usage_with_options (git_tag_usage, options); -if (list) -return list_tags (argv, lines ==-1 ?0 : lines, - with_commit); +finalize_colopts (&colopts,-1 ); +if (list && lines !=-1 ) { +if (explicitly_enable_column (colopts)) +die (_ ("--column and -n are incompatible" )); + colopts =0 ; + } +if (list) { +int ret; +if (column_active (colopts)) { +struct column_options copts; +memset (&copts,0 ,sizeof (copts)); + copts.padding =2 ; +run_column_filter (colopts, &copts); + } + ret =list_tags (argv, lines ==-1 ?0 : lines, with_commit); +if (column_active (colopts)) +stop_column_filter (); +return ret; + }if (lines !=-1 )die (_ ("-n option is only allowed with -l." ));if (with_commit)
t/t7004-tag.sh +44 -0
50 lines not on this page · raw message
Signature · 1 line
1.7.3.1.256.g2539c.dirty