Merge branch 'mh/show-branch-color' into sb/show-branch-parse-options
* branch 'mh/show-branch-color': bash completion: show-branch color support show-branch: color the commit status signs
This commit is contained in:
commit
1ca20358e7
@ -604,6 +604,12 @@ color.pager::
|
|||||||
A boolean to enable/disable colored output when the pager is in
|
A boolean to enable/disable colored output when the pager is in
|
||||||
use (default is true).
|
use (default is true).
|
||||||
|
|
||||||
|
color.showbranch::
|
||||||
|
A boolean to enable/disable color in the output of
|
||||||
|
linkgit:git-show-branch[1]. May be set to `always`,
|
||||||
|
`false` (or `never`) or `auto` (or `true`), in which case colors are used
|
||||||
|
only when the output is to a terminal. Defaults to false.
|
||||||
|
|
||||||
color.status::
|
color.status::
|
||||||
A boolean to enable/disable color in the output of
|
A boolean to enable/disable color in the output of
|
||||||
linkgit:git-status[1]. May be set to `always`,
|
linkgit:git-status[1]. May be set to `always`,
|
||||||
|
@ -10,6 +10,7 @@ SYNOPSIS
|
|||||||
[verse]
|
[verse]
|
||||||
'git show-branch' [--all] [--remotes] [--topo-order] [--current]
|
'git show-branch' [--all] [--remotes] [--topo-order] [--current]
|
||||||
[--more=<n> | --list | --independent | --merge-base]
|
[--more=<n> | --list | --independent | --merge-base]
|
||||||
|
[--color | --no-color]
|
||||||
[--no-name | --sha1-name] [--topics] [<rev> | <glob>]...
|
[--no-name | --sha1-name] [--topics] [<rev> | <glob>]...
|
||||||
'git show-branch' (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]
|
'git show-branch' (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]
|
||||||
|
|
||||||
@ -107,6 +108,14 @@ OPTIONS
|
|||||||
When no explicit <ref> parameter is given, it defaults to the
|
When no explicit <ref> parameter is given, it defaults to the
|
||||||
current branch (or `HEAD` if it is detached).
|
current branch (or `HEAD` if it is detached).
|
||||||
|
|
||||||
|
--color::
|
||||||
|
Color the status sign (one of these: `*` `!` `+` `-`) of each commit
|
||||||
|
corresponding to the branch it's in.
|
||||||
|
|
||||||
|
--no-color::
|
||||||
|
Turn off colored output, even when the configuration file gives the
|
||||||
|
default to color output.
|
||||||
|
|
||||||
Note that --more, --list, --independent and --merge-base options
|
Note that --more, --list, --independent and --merge-base options
|
||||||
are mutually exclusive.
|
are mutually exclusive.
|
||||||
|
|
||||||
|
@ -2,12 +2,25 @@
|
|||||||
#include "commit.h"
|
#include "commit.h"
|
||||||
#include "refs.h"
|
#include "refs.h"
|
||||||
#include "builtin.h"
|
#include "builtin.h"
|
||||||
|
#include "color.h"
|
||||||
|
|
||||||
static const char show_branch_usage[] =
|
static const char show_branch_usage[] =
|
||||||
"git show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n[,b]] <branch>";
|
"git show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n[,b]] <branch>";
|
||||||
static const char show_branch_usage_reflog[] =
|
static const char show_branch_usage_reflog[] =
|
||||||
"--reflog is incompatible with --all, --remotes, --independent or --merge-base";
|
"--reflog is incompatible with --all, --remotes, --independent or --merge-base";
|
||||||
|
|
||||||
|
static int showbranch_use_color = -1;
|
||||||
|
static char column_colors[][COLOR_MAXLEN] = {
|
||||||
|
GIT_COLOR_RED,
|
||||||
|
GIT_COLOR_GREEN,
|
||||||
|
GIT_COLOR_YELLOW,
|
||||||
|
GIT_COLOR_BLUE,
|
||||||
|
GIT_COLOR_MAGENTA,
|
||||||
|
GIT_COLOR_CYAN,
|
||||||
|
};
|
||||||
|
|
||||||
|
#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))
|
||||||
|
|
||||||
static int default_num;
|
static int default_num;
|
||||||
static int default_alloc;
|
static int default_alloc;
|
||||||
static const char **default_arg;
|
static const char **default_arg;
|
||||||
@ -19,6 +32,20 @@ static const char **default_arg;
|
|||||||
|
|
||||||
#define DEFAULT_REFLOG 4
|
#define DEFAULT_REFLOG 4
|
||||||
|
|
||||||
|
static const char *get_color_code(int idx)
|
||||||
|
{
|
||||||
|
if (showbranch_use_color)
|
||||||
|
return column_colors[idx];
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
static const char *get_color_reset_code(void)
|
||||||
|
{
|
||||||
|
if (showbranch_use_color)
|
||||||
|
return GIT_COLOR_RESET;
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
static struct commit *interesting(struct commit_list *list)
|
static struct commit *interesting(struct commit_list *list)
|
||||||
{
|
{
|
||||||
while (list) {
|
while (list) {
|
||||||
@ -545,7 +572,12 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return git_default_config(var, value, cb);
|
if (!strcmp(var, "color.showbranch")) {
|
||||||
|
showbranch_use_color = git_config_colorbool(var, value, -1);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return git_color_default_config(var, value, cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
|
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
|
||||||
@ -611,6 +643,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
|||||||
|
|
||||||
git_config(git_show_branch_config, NULL);
|
git_config(git_show_branch_config, NULL);
|
||||||
|
|
||||||
|
if (showbranch_use_color == -1)
|
||||||
|
showbranch_use_color = git_use_color_default;
|
||||||
|
|
||||||
/* If nothing is specified, try the default first */
|
/* If nothing is specified, try the default first */
|
||||||
if (ac == 1 && default_num) {
|
if (ac == 1 && default_num) {
|
||||||
ac = default_num + 1;
|
ac = default_num + 1;
|
||||||
@ -658,6 +693,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
|||||||
parse_reflog_param(arg + 9, &reflog, &reflog_base);
|
parse_reflog_param(arg + 9, &reflog, &reflog_base);
|
||||||
else if (!prefixcmp(arg, "-g="))
|
else if (!prefixcmp(arg, "-g="))
|
||||||
parse_reflog_param(arg + 3, &reflog, &reflog_base);
|
parse_reflog_param(arg + 3, &reflog, &reflog_base);
|
||||||
|
else if (!strcmp(arg, "--color"))
|
||||||
|
showbranch_use_color = 1;
|
||||||
|
else if (!strcmp(arg, "--no-color"))
|
||||||
|
showbranch_use_color = 0;
|
||||||
else
|
else
|
||||||
usage(show_branch_usage);
|
usage(show_branch_usage);
|
||||||
ac--; av++;
|
ac--; av++;
|
||||||
@ -843,8 +882,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
|||||||
else {
|
else {
|
||||||
for (j = 0; j < i; j++)
|
for (j = 0; j < i; j++)
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
printf("%c [%s] ",
|
printf("%s%c%s [%s] ",
|
||||||
is_head ? '*' : '!', ref_name[i]);
|
get_color_code(i % COLUMN_COLORS_MAX),
|
||||||
|
is_head ? '*' : '!',
|
||||||
|
get_color_reset_code(), ref_name[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!reflog) {
|
if (!reflog) {
|
||||||
@ -903,7 +944,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
|
|||||||
mark = '*';
|
mark = '*';
|
||||||
else
|
else
|
||||||
mark = '+';
|
mark = '+';
|
||||||
putchar(mark);
|
printf("%s%c%s",
|
||||||
|
get_color_code(i % COLUMN_COLORS_MAX),
|
||||||
|
mark, get_color_reset_code());
|
||||||
}
|
}
|
||||||
putchar(' ');
|
putchar(' ');
|
||||||
}
|
}
|
||||||
|
@ -1365,7 +1365,8 @@ _git_config ()
|
|||||||
__gitcomp "$(__git_merge_strategies)"
|
__gitcomp "$(__git_merge_strategies)"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
color.branch|color.diff|color.interactive|color.status|color.ui)
|
color.branch|color.diff|color.interactive|\
|
||||||
|
color.showbranch|color.status|color.ui)
|
||||||
__gitcomp "always never auto"
|
__gitcomp "always never auto"
|
||||||
return
|
return
|
||||||
;;
|
;;
|
||||||
@ -1510,6 +1511,7 @@ _git_config ()
|
|||||||
color.interactive.help
|
color.interactive.help
|
||||||
color.interactive.prompt
|
color.interactive.prompt
|
||||||
color.pager
|
color.pager
|
||||||
|
color.showbranch
|
||||||
color.status
|
color.status
|
||||||
color.status.added
|
color.status.added
|
||||||
color.status.changed
|
color.status.changed
|
||||||
@ -1821,6 +1823,7 @@ _git_show_branch ()
|
|||||||
__gitcomp "
|
__gitcomp "
|
||||||
--all --remotes --topo-order --current --more=
|
--all --remotes --topo-order --current --more=
|
||||||
--list --independent --merge-base --no-name
|
--list --independent --merge-base --no-name
|
||||||
|
--color --no-color
|
||||||
--sha1-name --sparse --topics --reflog
|
--sha1-name --sparse --topics --reflog
|
||||||
"
|
"
|
||||||
return
|
return
|
||||||
|
Loading…
Reference in New Issue
Block a user