* [PATCH] show-branch: color the commit status signs
@ 2009-04-21 21:52 Markus Heidelberg
2009-04-22 19:26 ` Stephen Boyd
0 siblings, 1 reply; 5+ messages in thread
From: Markus Heidelberg @ 2009-04-21 21:52 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Markus Heidelberg
Make it possible to color the status character ('*' '!' '+' '-') of
commits. Each branch uses a single color. This makes it easier to follow
a particular branch, especially when there are gaps in the output.
Add the config option color.showbranch and the command line options
--color and --no-color to control the colored output.
Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
---
I will send a patch for bash completion of --[no-]color and
color.showbranch, when this patch is accepted.
Documentation/config.txt | 6 ++++
Documentation/git-show-branch.txt | 8 ++++++
builtin-show-branch.c | 51 ++++++++++++++++++++++++++++++++++---
3 files changed, 61 insertions(+), 4 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 35056e1..1383a29 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -595,6 +595,12 @@ color.pager::
A boolean to enable/disable colored output when the pager is in
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::
A boolean to enable/disable color in the output of
linkgit:git-status[1]. May be set to `always`,
diff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt
index 7e9ff37..1ec3601 100644
--- a/Documentation/git-show-branch.txt
+++ b/Documentation/git-show-branch.txt
@@ -10,6 +10,7 @@ SYNOPSIS
[verse]
'git show-branch' [--all] [--remotes] [--topo-order] [--current]
[--more=<n> | --list | --independent | --merge-base]
+ [--color | --no-color]
[--no-name | --sha1-name] [--topics] [<rev> | <glob>]...
'git show-branch' (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]
@@ -107,6 +108,13 @@ OPTIONS
When no explicit <ref> parameter is given, it defaults to the
current branch (or `HEAD` if it is detached).
+--color::
+ Color the status sign of the commits. Each branch uses a single color.
+
+--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
are mutually exclusive.
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 828e6f8..fc38f5e 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -2,12 +2,25 @@
#include "commit.h"
#include "refs.h"
#include "builtin.h"
+#include "color.h"
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>";
static const char show_branch_usage_reflog[] =
"--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_alloc;
static const char **default_arg;
@@ -19,6 +32,20 @@ static const char **default_arg;
#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)
{
while (list) {
@@ -545,7 +572,12 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
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)
@@ -611,6 +643,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
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 (ac == 1 && default_num) {
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);
else if (!prefixcmp(arg, "-g="))
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
usage(show_branch_usage);
ac--; av++;
@@ -843,8 +882,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
else {
for (j = 0; j < i; j++)
putchar(' ');
- printf("%c [%s] ",
- is_head ? '*' : '!', ref_name[i]);
+ printf("%s%c%s [%s] ",
+ get_color_code(i % COLUMN_COLORS_MAX),
+ is_head ? '*' : '!',
+ get_color_reset_code(), ref_name[i]);
}
if (!reflog) {
@@ -903,7 +944,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
mark = '*';
else
mark = '+';
- putchar(mark);
+ printf("%s%c%s",
+ get_color_code(i % COLUMN_COLORS_MAX),
+ mark, get_color_reset_code());
}
putchar(' ');
}
--
1.6.3.rc1.61.ge6ab3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] show-branch: color the commit status signs
2009-04-21 21:52 [PATCH] show-branch: color the commit status signs Markus Heidelberg
@ 2009-04-22 19:26 ` Stephen Boyd
2009-04-22 20:45 ` Markus Heidelberg
0 siblings, 1 reply; 5+ messages in thread
From: Stephen Boyd @ 2009-04-22 19:26 UTC (permalink / raw)
To: Markus Heidelberg; +Cc: Junio C Hamano, git
On Tue, Apr 21, 2009, Markus Heidelberg <markus.heidelberg@web.de> wrote:
> +--color::
> + Color the status sign of the commits. Each branch uses a single color.
I don't know what the status sign of a commit is without reading your commit
message. Maybe reword this to be:
Color the status sign ('*' '!' '+' '-') of each commit corresponding
to the branch
it's in.
> +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))
This looks like a copy/paste (with a small edit) from graph.c so maybe you
want to refactor the original code from graph.c to color.h?
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] show-branch: color the commit status signs
2009-04-22 19:26 ` Stephen Boyd
@ 2009-04-22 20:45 ` Markus Heidelberg
2009-04-22 21:16 ` Junio C Hamano
0 siblings, 1 reply; 5+ messages in thread
From: Markus Heidelberg @ 2009-04-22 20:45 UTC (permalink / raw)
To: Stephen Boyd; +Cc: Junio C Hamano, git
Stephen Boyd, 22.04.2009:
> On Tue, Apr 21, 2009, Markus Heidelberg <markus.heidelberg@web.de> wrote:
> > +--color::
> > + Color the status sign of the commits. Each branch uses a single color.
>
> I don't know what the status sign of a commit is without reading your commit
> message. Maybe reword this to be:
>
> Color the status sign ('*' '!' '+' '-') of each commit corresponding
> to the branch
> it's in.
I had some problems with finding the right words for the description and
still wasn't satisfied with it. I think your suggestion makes it easier
and will include it.
> > +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))
>
> This looks like a copy/paste (with a small edit) from graph.c so maybe you
> want to refactor the original code from graph.c to color.h?
How exactly do you think it can be refactored and then combined?
Markus
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] show-branch: color the commit status signs
2009-04-22 20:45 ` Markus Heidelberg
@ 2009-04-22 21:16 ` Junio C Hamano
2009-04-22 21:41 ` [PATCH v2] " Markus Heidelberg
0 siblings, 1 reply; 5+ messages in thread
From: Junio C Hamano @ 2009-04-22 21:16 UTC (permalink / raw)
To: markus.heidelberg; +Cc: Stephen Boyd, git
Markus Heidelberg <markus.heidelberg@web.de> writes:
> Stephen Boyd, 22.04.2009:
>> On Tue, Apr 21, 2009, Markus Heidelberg <markus.heidelberg@web.de> wrote:
>> > +--color::
>> > + Color the status sign of the commits. Each branch uses a single color.
>>
>> I don't know what the status sign of a commit is without reading your commit
>> message. Maybe reword this to be:
>>
>> Color the status sign ('*' '!' '+' '-') of each commit corresponding
>> to the branch
>> it's in.
>
> I had some problems with finding the right words for the description and
> still wasn't satisfied with it. I think your suggestion makes it easier
> and will include it.
>
>> > +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))
>>
>> This looks like a copy/paste (with a small edit) from graph.c so maybe you
>> want to refactor the original code from graph.c to color.h?
>
> How exactly do you think it can be refactored and then combined?
These tables belong to each command. Your show-branches do not
necessarily want to get different set or number of colors when graph
output updates its color palette to have richer set of colors. I do not
see any need for "refactoring" here.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] show-branch: color the commit status signs
2009-04-22 21:16 ` Junio C Hamano
@ 2009-04-22 21:41 ` Markus Heidelberg
0 siblings, 0 replies; 5+ messages in thread
From: Markus Heidelberg @ 2009-04-22 21:41 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git, Stephen Boyd, Markus Heidelberg
Make it possible to color the status character ('*' '!' '+' '-') of each
commit corresponding to the branch it's in. This makes it easier to
follow a particular branch, especially if there are larger gaps in the
output.
Add the config option color.showbranch and the command line options
--color and --no-color to control the colored output.
Signed-off-by: Markus Heidelberg <markus.heidelberg@web.de>
---
Clarify the --color description based on the suggestion from
Stephen Boyd.
Documentation/config.txt | 6 ++++
Documentation/git-show-branch.txt | 9 ++++++
builtin-show-branch.c | 51 ++++++++++++++++++++++++++++++++++---
3 files changed, 62 insertions(+), 4 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 35056e1..1383a29 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -595,6 +595,12 @@ color.pager::
A boolean to enable/disable colored output when the pager is in
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::
A boolean to enable/disable color in the output of
linkgit:git-status[1]. May be set to `always`,
diff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt
index 7e9ff37..05868b6 100644
--- a/Documentation/git-show-branch.txt
+++ b/Documentation/git-show-branch.txt
@@ -10,6 +10,7 @@ SYNOPSIS
[verse]
'git show-branch' [--all] [--remotes] [--topo-order] [--current]
[--more=<n> | --list | --independent | --merge-base]
+ [--color | --no-color]
[--no-name | --sha1-name] [--topics] [<rev> | <glob>]...
'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
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
are mutually exclusive.
diff --git a/builtin-show-branch.c b/builtin-show-branch.c
index 828e6f8..fc38f5e 100644
--- a/builtin-show-branch.c
+++ b/builtin-show-branch.c
@@ -2,12 +2,25 @@
#include "commit.h"
#include "refs.h"
#include "builtin.h"
+#include "color.h"
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>";
static const char show_branch_usage_reflog[] =
"--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_alloc;
static const char **default_arg;
@@ -19,6 +32,20 @@ static const char **default_arg;
#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)
{
while (list) {
@@ -545,7 +572,12 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
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)
@@ -611,6 +643,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
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 (ac == 1 && default_num) {
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);
else if (!prefixcmp(arg, "-g="))
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
usage(show_branch_usage);
ac--; av++;
@@ -843,8 +882,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
else {
for (j = 0; j < i; j++)
putchar(' ');
- printf("%c [%s] ",
- is_head ? '*' : '!', ref_name[i]);
+ printf("%s%c%s [%s] ",
+ get_color_code(i % COLUMN_COLORS_MAX),
+ is_head ? '*' : '!',
+ get_color_reset_code(), ref_name[i]);
}
if (!reflog) {
@@ -903,7 +944,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
mark = '*';
else
mark = '+';
- putchar(mark);
+ printf("%s%c%s",
+ get_color_code(i % COLUMN_COLORS_MAX),
+ mark, get_color_reset_code());
}
putchar(' ');
}
--
1.6.3.rc1.61.ge6ab3
^ permalink raw reply related [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-04-22 21:42 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-21 21:52 [PATCH] show-branch: color the commit status signs Markus Heidelberg
2009-04-22 19:26 ` Stephen Boyd
2009-04-22 20:45 ` Markus Heidelberg
2009-04-22 21:16 ` Junio C Hamano
2009-04-22 21:41 ` [PATCH v2] " Markus Heidelberg
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.