Merge branch 'nd/columns'
A couple of commands learn --column option to produce columnar output. By Nguyễn Thái Ngọc Duy (9) and Zbigniew Jędrzejewski-Szmek (1) * nd/columns: tag: add --column column: support piping stdout to external git-column process status: add --column branch: add --column help: reuse print_columns() for help -a column: add dense layout support t9002: work around shells that are unable to set COLUMNS to 1 column: add columnar layout Stop starting pager recursively Add column layout skeleton and git-column
This commit is contained in:
@ -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;
|
||||
@ -482,7 +489,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);
|
||||
}
|
||||
@ -741,6 +753,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(),
|
||||
};
|
||||
|
||||
@ -763,6 +776,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);
|
||||
|
||||
@ -774,12 +788,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, quiet);
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user