{"thread":{"id":"18993","subject":"[PATCH] show-branch: color the commit status signs","startedAt":"2009-04-21T21:52:59Z","lastAt":"2009-04-22T21:41:25Z","messageCount":5,"participants":["Markus Heidelberg","Stephen Boyd","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"111909","messageId":"1240350779-9686-1-git-send-email-markus.heidelberg@web.de","threadId":"18993","inReplyTo":null,"subject":"[PATCH] show-branch: color the commit status signs","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2009-04-21T21:52:59Z","receivedAt":"2009-04-21T21:52:59Z","isPatch":true,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"Make it possible to color the status character ('*' '!' '+' '-') of\ncommits. Each branch uses a single color. This makes it easier to follow\na particular branch, especially when there are gaps in the output.\n\nAdd the config option color.showbranch and the command line options\n --color and --no-color to control the colored output.\n\nSigned-off-by: Markus Heidelberg <markus.heidelberg@web.de>\n---\n\n    I will send a patch for bash completion of --[no-]color and\n    color.showbranch, when this patch is accepted.\n\n Documentation/config.txt          |    6 ++++\n Documentation/git-show-branch.txt |    8 ++++++\n builtin-show-branch.c             |   51 ++++++++++++++++++++++++++++++++++---\n 3 files changed, 61 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 35056e1..1383a29 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -595,6 +595,12 @@ color.pager::\n \tA boolean to enable/disable colored output when the pager is in\n \tuse (default is true).\n \n+color.showbranch::\n+\tA boolean to enable/disable color in the output of\n+\tlinkgit:git-show-branch[1]. May be set to `always`,\n+\t`false` (or `never`) or `auto` (or `true`), in which case colors are used\n+\tonly when the output is to a terminal. Defaults to false.\n+\n color.status::\n \tA boolean to enable/disable color in the output of\n \tlinkgit:git-status[1]. May be set to `always`,\ndiff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt\nindex 7e9ff37..1ec3601 100644\n--- a/Documentation/git-show-branch.txt\n+++ b/Documentation/git-show-branch.txt\n@@ -10,6 +10,7 @@ SYNOPSIS\n [verse]\n 'git show-branch' [--all] [--remotes] [--topo-order] [--current]\n \t\t[--more=<n> | --list | --independent | --merge-base]\n+\t\t[--color | --no-color]\n \t\t[--no-name | --sha1-name] [--topics] [<rev> | <glob>]...\n 'git show-branch' (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]\n \n@@ -107,6 +108,13 @@ OPTIONS\n \tWhen no explicit <ref> parameter is given, it defaults to the\n \tcurrent branch (or `HEAD` if it is detached).\n \n+--color::\n+\tColor the status sign of the commits. Each branch uses a single color.\n+\n+--no-color::\n+\tTurn off colored output, even when the configuration file gives the\n+\tdefault to color output.\n+\n Note that --more, --list, --independent and --merge-base options\n are mutually exclusive.\n \ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 828e6f8..fc38f5e 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -2,12 +2,25 @@\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"builtin.h\"\n+#include \"color.h\"\n \n static const char show_branch_usage[] =\n \"git show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n[,b]] <branch>\";\n static const char show_branch_usage_reflog[] =\n \"--reflog is incompatible with --all, --remotes, --independent or --merge-base\";\n \n+static int showbranch_use_color = -1;\n+static char column_colors[][COLOR_MAXLEN] = {\n+\tGIT_COLOR_RED,\n+\tGIT_COLOR_GREEN,\n+\tGIT_COLOR_YELLOW,\n+\tGIT_COLOR_BLUE,\n+\tGIT_COLOR_MAGENTA,\n+\tGIT_COLOR_CYAN,\n+};\n+\n+#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))\n+\n static int default_num;\n static int default_alloc;\n static const char **default_arg;\n@@ -19,6 +32,20 @@ static const char **default_arg;\n \n #define DEFAULT_REFLOG\t4\n \n+static const char *get_color_code(int idx)\n+{\n+\tif (showbranch_use_color)\n+\t\treturn column_colors[idx];\n+\treturn \"\";\n+}\n+\n+static const char *get_color_reset_code(void)\n+{\n+\tif (showbranch_use_color)\n+\t\treturn GIT_COLOR_RESET;\n+\treturn \"\";\n+}\n+\n static struct commit *interesting(struct commit_list *list)\n {\n \twhile (list) {\n@@ -545,7 +572,12 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)\n \t\treturn 0;\n \t}\n \n-\treturn git_default_config(var, value, cb);\n+\tif (!strcmp(var, \"color.showbranch\")) {\n+\t\tshowbranch_use_color = git_config_colorbool(var, value, -1);\n+\t\treturn 0;\n+\t}\n+\n+\treturn git_color_default_config(var, value, cb);\n }\n \n static int omit_in_dense(struct commit *commit, struct commit **rev, int n)\n@@ -611,6 +643,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \n \tgit_config(git_show_branch_config, NULL);\n \n+\tif (showbranch_use_color == -1)\n+\t\tshowbranch_use_color = git_use_color_default;\n+\n \t/* If nothing is specified, try the default first */\n \tif (ac == 1 && default_num) {\n \t\tac = default_num + 1;\n@@ -658,6 +693,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\tparse_reflog_param(arg + 9, &reflog, &reflog_base);\n \t\telse if (!prefixcmp(arg, \"-g=\"))\n \t\t\tparse_reflog_param(arg + 3, &reflog, &reflog_base);\n+\t\telse if (!strcmp(arg, \"--color\"))\n+\t\t\tshowbranch_use_color = 1;\n+\t\telse if (!strcmp(arg, \"--no-color\"))\n+\t\t\tshowbranch_use_color = 0;\n \t\telse\n \t\t\tusage(show_branch_usage);\n \t\tac--; av++;\n@@ -843,8 +882,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\telse {\n \t\t\t\tfor (j = 0; j < i; j++)\n \t\t\t\t\tputchar(' ');\n-\t\t\t\tprintf(\"%c [%s] \",\n-\t\t\t\t       is_head ? '*' : '!', ref_name[i]);\n+\t\t\t\tprintf(\"%s%c%s [%s] \",\n+\t\t\t\t       get_color_code(i % COLUMN_COLORS_MAX),\n+\t\t\t\t       is_head ? '*' : '!',\n+\t\t\t\t       get_color_reset_code(), ref_name[i]);\n \t\t\t}\n \n \t\t\tif (!reflog) {\n@@ -903,7 +944,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\t\tmark = '*';\n \t\t\t\telse\n \t\t\t\t\tmark = '+';\n-\t\t\t\tputchar(mark);\n+\t\t\t\tprintf(\"%s%c%s\",\n+\t\t\t\t       get_color_code(i % COLUMN_COLORS_MAX),\n+\t\t\t\t       mark, get_color_reset_code());\n \t\t\t}\n \t\t\tputchar(' ');\n \t\t}\n-- \n1.6.3.rc1.61.ge6ab3\n"},{"id":"111985","messageId":"780e0a6b0904221226s43a40a12k8bf83de12fa7815d@mail.gmail.com","threadId":"18993","inReplyTo":"1240350779-9686-1-git-send-email-markus.heidelberg@web.de","subject":"Re: [PATCH] show-branch: color the commit status signs","fromName":"Stephen Boyd","fromEmail":"bebarino@gmail.com","sentAt":"2009-04-22T19:26:55Z","receivedAt":"2009-04-22T19:26:55Z","isPatch":true,"sender":{"key":"bebarino@gmail.com","avatar":"https://avatars.githubusercontent.com/u/38832?v=4"},"body":"On Tue, Apr 21, 2009, Markus Heidelberg <markus.heidelberg@web.de> wrote:\n> +--color::\n> +       Color the status sign of the commits. Each branch uses a single color.\n\nI don't know what the status sign of a commit is without reading your commit\nmessage. Maybe reword this to be:\n\nColor the status sign ('*' '!' '+' '-') of each commit corresponding\nto the branch\nit's in.\n\n> +static char column_colors[][COLOR_MAXLEN] = {\n> +       GIT_COLOR_RED,\n> +       GIT_COLOR_GREEN,\n> +       GIT_COLOR_YELLOW,\n> +       GIT_COLOR_BLUE,\n> +       GIT_COLOR_MAGENTA,\n> +       GIT_COLOR_CYAN,\n> +};\n> +\n> +#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))\n\nThis looks like a copy/paste (with a small edit) from graph.c so maybe you\nwant to refactor the original code from graph.c to color.h?\n"},{"id":"112004","messageId":"200904222245.24034.markus.heidelberg@web.de","threadId":"18993","inReplyTo":"780e0a6b0904221226s43a40a12k8bf83de12fa7815d@mail.gmail.com","subject":"Re: [PATCH] show-branch: color the commit status signs","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2009-04-22T20:45:23Z","receivedAt":"2009-04-22T20:45:23Z","isPatch":true,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"Stephen Boyd, 22.04.2009:\n> On Tue, Apr 21, 2009, Markus Heidelberg <markus.heidelberg@web.de> wrote:\n> > +--color::\n> > +       Color the status sign of the commits. Each branch uses a single color.\n> \n> I don't know what the status sign of a commit is without reading your commit\n> message. Maybe reword this to be:\n> \n> Color the status sign ('*' '!' '+' '-') of each commit corresponding\n> to the branch\n> it's in.\n\nI had some problems with finding the right words for the description and\nstill wasn't satisfied with it. I think your suggestion makes it easier\nand will include it.\n\n> > +static char column_colors[][COLOR_MAXLEN] = {\n> > +       GIT_COLOR_RED,\n> > +       GIT_COLOR_GREEN,\n> > +       GIT_COLOR_YELLOW,\n> > +       GIT_COLOR_BLUE,\n> > +       GIT_COLOR_MAGENTA,\n> > +       GIT_COLOR_CYAN,\n> > +};\n> > +\n> > +#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))\n> \n> This looks like a copy/paste (with a small edit) from graph.c so maybe you\n> want to refactor the original code from graph.c to color.h?\n\nHow exactly do you think it can be refactored and then combined?\n\nMarkus\n"},{"id":"112012","messageId":"7vskk01j9y.fsf@gitster.siamese.dyndns.org","threadId":"18993","inReplyTo":"200904222245.24034.markus.heidelberg@web.de","subject":"Re: [PATCH] show-branch: color the commit status signs","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2009-04-22T21:16:25Z","receivedAt":"2009-04-22T21:16:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Markus Heidelberg <markus.heidelberg@web.de> writes:\n\n> Stephen Boyd, 22.04.2009:\n>> On Tue, Apr 21, 2009, Markus Heidelberg <markus.heidelberg@web.de> wrote:\n>> > +--color::\n>> > +       Color the status sign of the commits. Each branch uses a single color.\n>> \n>> I don't know what the status sign of a commit is without reading your commit\n>> message. Maybe reword this to be:\n>> \n>> Color the status sign ('*' '!' '+' '-') of each commit corresponding\n>> to the branch\n>> it's in.\n>\n> I had some problems with finding the right words for the description and\n> still wasn't satisfied with it. I think your suggestion makes it easier\n> and will include it.\n>\n>> > +static char column_colors[][COLOR_MAXLEN] = {\n>> > +       GIT_COLOR_RED,\n>> > +       GIT_COLOR_GREEN,\n>> > +       GIT_COLOR_YELLOW,\n>> > +       GIT_COLOR_BLUE,\n>> > +       GIT_COLOR_MAGENTA,\n>> > +       GIT_COLOR_CYAN,\n>> > +};\n>> > +\n>> > +#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))\n>> \n>> This looks like a copy/paste (with a small edit) from graph.c so maybe you\n>> want to refactor the original code from graph.c to color.h?\n>\n> How exactly do you think it can be refactored and then combined?\n\nThese tables belong to each command.  Your show-branches do not\nnecessarily want to get different set or number of colors when graph\noutput updates its color palette to have richer set of colors.  I do not\nsee any need for \"refactoring\" here.\n"},{"id":"112020","messageId":"1240436485-30518-1-git-send-email-markus.heidelberg@web.de","threadId":"18993","inReplyTo":"7vskk01j9y.fsf@gitster.siamese.dyndns.org","subject":"[PATCH v2] show-branch: color the commit status signs","fromName":"Markus Heidelberg","fromEmail":"markus.heidelberg@web.de","sentAt":"2009-04-22T21:41:25Z","receivedAt":"2009-04-22T21:41:25Z","isPatch":true,"sender":{"key":"markus.heidelberg@web.de","avatar":"https://avatars.githubusercontent.com/u/6334512?v=4"},"body":"Make it possible to color the status character ('*' '!' '+' '-') of each\ncommit corresponding to the branch it's in. This makes it easier to\nfollow a particular branch, especially if there are larger gaps in the\noutput.\n\nAdd the config option color.showbranch and the command line options\n --color and --no-color to control the colored output.\n\nSigned-off-by: Markus Heidelberg <markus.heidelberg@web.de>\n---\n\n    Clarify the --color description based on the suggestion from\n    Stephen Boyd.\n\n Documentation/config.txt          |    6 ++++\n Documentation/git-show-branch.txt |    9 ++++++\n builtin-show-branch.c             |   51 ++++++++++++++++++++++++++++++++++---\n 3 files changed, 62 insertions(+), 4 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 35056e1..1383a29 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -595,6 +595,12 @@ color.pager::\n \tA boolean to enable/disable colored output when the pager is in\n \tuse (default is true).\n \n+color.showbranch::\n+\tA boolean to enable/disable color in the output of\n+\tlinkgit:git-show-branch[1]. May be set to `always`,\n+\t`false` (or `never`) or `auto` (or `true`), in which case colors are used\n+\tonly when the output is to a terminal. Defaults to false.\n+\n color.status::\n \tA boolean to enable/disable color in the output of\n \tlinkgit:git-status[1]. May be set to `always`,\ndiff --git a/Documentation/git-show-branch.txt b/Documentation/git-show-branch.txt\nindex 7e9ff37..05868b6 100644\n--- a/Documentation/git-show-branch.txt\n+++ b/Documentation/git-show-branch.txt\n@@ -10,6 +10,7 @@ SYNOPSIS\n [verse]\n 'git show-branch' [--all] [--remotes] [--topo-order] [--current]\n \t\t[--more=<n> | --list | --independent | --merge-base]\n+\t\t[--color | --no-color]\n \t\t[--no-name | --sha1-name] [--topics] [<rev> | <glob>]...\n 'git show-branch' (-g|--reflog)[=<n>[,<base>]] [--list] [<ref>]\n \n@@ -107,6 +108,14 @@ OPTIONS\n \tWhen no explicit <ref> parameter is given, it defaults to the\n \tcurrent branch (or `HEAD` if it is detached).\n \n+--color::\n+\tColor the status sign (one of these: `*` `!` `+` `-`) of each commit\n+\tcorresponding to the branch it's in.\n+\n+--no-color::\n+\tTurn off colored output, even when the configuration file gives the\n+\tdefault to color output.\n+\n Note that --more, --list, --independent and --merge-base options\n are mutually exclusive.\n \ndiff --git a/builtin-show-branch.c b/builtin-show-branch.c\nindex 828e6f8..fc38f5e 100644\n--- a/builtin-show-branch.c\n+++ b/builtin-show-branch.c\n@@ -2,12 +2,25 @@\n #include \"commit.h\"\n #include \"refs.h\"\n #include \"builtin.h\"\n+#include \"color.h\"\n \n static const char show_branch_usage[] =\n \"git show-branch [--sparse] [--current] [--all] [--remotes] [--topo-order] [--more=count | --list | --independent | --merge-base ] [--topics] [<refs>...] | --reflog[=n[,b]] <branch>\";\n static const char show_branch_usage_reflog[] =\n \"--reflog is incompatible with --all, --remotes, --independent or --merge-base\";\n \n+static int showbranch_use_color = -1;\n+static char column_colors[][COLOR_MAXLEN] = {\n+\tGIT_COLOR_RED,\n+\tGIT_COLOR_GREEN,\n+\tGIT_COLOR_YELLOW,\n+\tGIT_COLOR_BLUE,\n+\tGIT_COLOR_MAGENTA,\n+\tGIT_COLOR_CYAN,\n+};\n+\n+#define COLUMN_COLORS_MAX (ARRAY_SIZE(column_colors))\n+\n static int default_num;\n static int default_alloc;\n static const char **default_arg;\n@@ -19,6 +32,20 @@ static const char **default_arg;\n \n #define DEFAULT_REFLOG\t4\n \n+static const char *get_color_code(int idx)\n+{\n+\tif (showbranch_use_color)\n+\t\treturn column_colors[idx];\n+\treturn \"\";\n+}\n+\n+static const char *get_color_reset_code(void)\n+{\n+\tif (showbranch_use_color)\n+\t\treturn GIT_COLOR_RESET;\n+\treturn \"\";\n+}\n+\n static struct commit *interesting(struct commit_list *list)\n {\n \twhile (list) {\n@@ -545,7 +572,12 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)\n \t\treturn 0;\n \t}\n \n-\treturn git_default_config(var, value, cb);\n+\tif (!strcmp(var, \"color.showbranch\")) {\n+\t\tshowbranch_use_color = git_config_colorbool(var, value, -1);\n+\t\treturn 0;\n+\t}\n+\n+\treturn git_color_default_config(var, value, cb);\n }\n \n static int omit_in_dense(struct commit *commit, struct commit **rev, int n)\n@@ -611,6 +643,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \n \tgit_config(git_show_branch_config, NULL);\n \n+\tif (showbranch_use_color == -1)\n+\t\tshowbranch_use_color = git_use_color_default;\n+\n \t/* If nothing is specified, try the default first */\n \tif (ac == 1 && default_num) {\n \t\tac = default_num + 1;\n@@ -658,6 +693,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\tparse_reflog_param(arg + 9, &reflog, &reflog_base);\n \t\telse if (!prefixcmp(arg, \"-g=\"))\n \t\t\tparse_reflog_param(arg + 3, &reflog, &reflog_base);\n+\t\telse if (!strcmp(arg, \"--color\"))\n+\t\t\tshowbranch_use_color = 1;\n+\t\telse if (!strcmp(arg, \"--no-color\"))\n+\t\t\tshowbranch_use_color = 0;\n \t\telse\n \t\t\tusage(show_branch_usage);\n \t\tac--; av++;\n@@ -843,8 +882,10 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\telse {\n \t\t\t\tfor (j = 0; j < i; j++)\n \t\t\t\t\tputchar(' ');\n-\t\t\t\tprintf(\"%c [%s] \",\n-\t\t\t\t       is_head ? '*' : '!', ref_name[i]);\n+\t\t\t\tprintf(\"%s%c%s [%s] \",\n+\t\t\t\t       get_color_code(i % COLUMN_COLORS_MAX),\n+\t\t\t\t       is_head ? '*' : '!',\n+\t\t\t\t       get_color_reset_code(), ref_name[i]);\n \t\t\t}\n \n \t\t\tif (!reflog) {\n@@ -903,7 +944,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)\n \t\t\t\t\tmark = '*';\n \t\t\t\telse\n \t\t\t\t\tmark = '+';\n-\t\t\t\tputchar(mark);\n+\t\t\t\tprintf(\"%s%c%s\",\n+\t\t\t\t       get_color_code(i % COLUMN_COLORS_MAX),\n+\t\t\t\t       mark, get_color_reset_code());\n \t\t\t}\n \t\t\tputchar(' ');\n \t\t}\n-- \n1.6.3.rc1.61.ge6ab3\n"}]}