{"thread":{"id":"33513","subject":"[PATCH v3] branch: colour upstream branches","startedAt":"2013-04-15T02:37:49Z","lastAt":"2013-04-15T12:16:44Z","messageCount":3,"participants":["Felipe Contreras","Junio C Hamano","Duy Nguyen"],"isPatch":true,"patchVersion":3,"patchTotal":null},"messages":[{"id":"214257","messageId":"1365993469-6874-1-git-send-email-felipe.contreras@gmail.com","threadId":"33513","inReplyTo":null,"subject":"[PATCH v3] branch: colour upstream branches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-15T02:37:49Z","receivedAt":"2013-04-15T02:37:49Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Otherwise when using 'git branch -vv' it's hard to see them among so\nmuch output.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n\nThis time with strbuf.\n\n Documentation/config.txt |  3 ++-\n builtin/branch.c         | 38 ++++++++++++++++++++++++++++++--------\n 2 files changed, 32 insertions(+), 9 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex bc750d5..302533f 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -794,7 +794,8 @@ color.branch::\n color.branch.<slot>::\n \tUse customized color for branch coloration. `<slot>` is one of\n \t`current` (the current branch), `local` (a local branch),\n-\t`remote` (a remote-tracking branch in refs/remotes/), `plain` (other\n+\t`remote` (a remote-tracking branch in refs/remotes/),\n+\t`upstream` (upstream tracking branch), `plain` (other\n \trefs).\n +\n The value for these configuration variables is a list of colors (at most\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 00d17d2..26e9322 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -40,13 +40,15 @@ static char branch_colors[][COLOR_MAXLEN] = {\n \tGIT_COLOR_RED,\t\t/* REMOTE */\n \tGIT_COLOR_NORMAL,\t/* LOCAL */\n \tGIT_COLOR_GREEN,\t/* CURRENT */\n+\tGIT_COLOR_BLUE,\t\t/* UPSTREAM */\n };\n enum color_branch {\n \tBRANCH_COLOR_RESET = 0,\n \tBRANCH_COLOR_PLAIN = 1,\n \tBRANCH_COLOR_REMOTE = 2,\n \tBRANCH_COLOR_LOCAL = 3,\n-\tBRANCH_COLOR_CURRENT = 4\n+\tBRANCH_COLOR_CURRENT = 4,\n+\tBRANCH_COLOR_UPSTREAM = 5,\n };\n \n static enum merge_filter {\n@@ -71,6 +73,8 @@ static int parse_branch_color_slot(const char *var, int ofs)\n \t\treturn BRANCH_COLOR_LOCAL;\n \tif (!strcasecmp(var+ofs, \"current\"))\n \t\treturn BRANCH_COLOR_CURRENT;\n+\tif (!strcasecmp(var+ofs, \"upstream\"))\n+\t\treturn BRANCH_COLOR_UPSTREAM;\n \treturn -1;\n }\n \n@@ -417,36 +421,54 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,\n \tint ours, theirs;\n \tchar *ref = NULL;\n \tstruct branch *branch = branch_get(branch_name);\n+\tstruct strbuf fancy;\n+\n+\tstrbuf_init(&fancy, 0);\n \n \tif (!stat_tracking_info(branch, &ours, &theirs)) {\n \t\tif (branch && branch->merge && branch->merge[0]->dst &&\n-\t\t    show_upstream_ref)\n-\t\t\tstrbuf_addf(stat, \"[%s] \",\n-\t\t\t    shorten_unambiguous_ref(branch->merge[0]->dst, 0));\n+\t\t    show_upstream_ref) {\n+\t\t\tref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n+\t\t\tif (want_color(branch_use_color))\n+\t\t\t\tstrbuf_addf(stat, \"[%s%s%s] \",\n+\t\t\t\t\t\tbranch_get_color(BRANCH_COLOR_UPSTREAM),\n+\t\t\t\t\t\tref, branch_get_color(BRANCH_COLOR_RESET));\n+\t\t\telse\n+\t\t\t\tstrbuf_addf(stat, \"[%s] \", ref);\n+\t\t}\n \t\treturn;\n \t}\n \n-\tif (show_upstream_ref)\n+\tif (show_upstream_ref) {\n \t\tref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n+\t\tif (want_color(branch_use_color))\n+\t\t\tstrbuf_addf(&fancy, \"%s%s%s\",\n+\t\t\t\t\tbranch_get_color(BRANCH_COLOR_UPSTREAM),\n+\t\t\t\t\tref, branch_get_color(BRANCH_COLOR_RESET));\n+\t\telse\n+\t\t\tstrbuf_addstr(&fancy, ref);\n+\t}\n+\n \tif (!ours) {\n \t\tif (ref)\n-\t\t\tstrbuf_addf(stat, _(\"[%s: behind %d]\"), ref, theirs);\n+\t\t\tstrbuf_addf(stat, _(\"[%s: behind %d]\"), fancy.buf, theirs);\n \t\telse\n \t\t\tstrbuf_addf(stat, _(\"[behind %d]\"), theirs);\n \n \t} else if (!theirs) {\n \t\tif (ref)\n-\t\t\tstrbuf_addf(stat, _(\"[%s: ahead %d]\"), ref, ours);\n+\t\t\tstrbuf_addf(stat, _(\"[%s: ahead %d]\"), fancy.buf, ours);\n \t\telse\n \t\t\tstrbuf_addf(stat, _(\"[ahead %d]\"), ours);\n \t} else {\n \t\tif (ref)\n \t\t\tstrbuf_addf(stat, _(\"[%s: ahead %d, behind %d]\"),\n-\t\t\t\t    ref, ours, theirs);\n+\t\t\t\t    fancy.buf, ours, theirs);\n \t\telse\n \t\t\tstrbuf_addf(stat, _(\"[ahead %d, behind %d]\"),\n \t\t\t\t    ours, theirs);\n \t}\n+\tstrbuf_release(&fancy);\n \tstrbuf_addch(stat, ' ');\n \tfree(ref);\n }\n-- \n1.8.2.1.643.ge3cc75d\n"},{"id":"214260","messageId":"7vwqs433l5.fsf@alter.siamese.dyndns.org","threadId":"33513","inReplyTo":"1365993469-6874-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH v3] branch: colour upstream branches","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-15T02:55:18Z","receivedAt":"2013-04-15T02:55:18Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> Otherwise when using 'git branch -vv' it's hard to see them among so\n> much output.\n>\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>\n> This time with strbuf.\n>\n>  Documentation/config.txt |  3 ++-\n>  builtin/branch.c         | 38 ++++++++++++++++++++++++++++++--------\n>  2 files changed, 32 insertions(+), 9 deletions(-)\n>\n> diff --git a/Documentation/config.txt b/Documentation/config.txt\n> index bc750d5..302533f 100644\n> --- a/Documentation/config.txt\n> +++ b/Documentation/config.txt\n> @@ -794,7 +794,8 @@ color.branch::\n>  color.branch.<slot>::\n>  \tUse customized color for branch coloration. `<slot>` is one of\n>  \t`current` (the current branch), `local` (a local branch),\n> -\t`remote` (a remote-tracking branch in refs/remotes/), `plain` (other\n> +\t`remote` (a remote-tracking branch in refs/remotes/),\n> +\t`upstream` (upstream tracking branch), `plain` (other\n>  \trefs).\n>  +\n>  The value for these configuration variables is a list of colors (at most\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index 00d17d2..26e9322 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -40,13 +40,15 @@ static char branch_colors[][COLOR_MAXLEN] = {\n>  \tGIT_COLOR_RED,\t\t/* REMOTE */\n>  \tGIT_COLOR_NORMAL,\t/* LOCAL */\n>  \tGIT_COLOR_GREEN,\t/* CURRENT */\n> +\tGIT_COLOR_BLUE,\t\t/* UPSTREAM */\n>  };\n>  enum color_branch {\n>  \tBRANCH_COLOR_RESET = 0,\n>  \tBRANCH_COLOR_PLAIN = 1,\n>  \tBRANCH_COLOR_REMOTE = 2,\n>  \tBRANCH_COLOR_LOCAL = 3,\n> -\tBRANCH_COLOR_CURRENT = 4\n> +\tBRANCH_COLOR_CURRENT = 4,\n> +\tBRANCH_COLOR_UPSTREAM = 5,\n>  };\n\nWe had to fix these \"trailing comma in enums\" to help other peoples'\ncompilers a few times.  Yes, they happily take the trailing comma at\nthe end of array values above.  Don't complain to me ;-)\n\n> @@ -417,36 +421,54 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,\n>  \tint ours, theirs;\n>  \tchar *ref = NULL;\n>  \tstruct branch *branch = branch_get(branch_name);\n> +\tstruct strbuf fancy;\n> +\n> +\tstrbuf_init(&fancy, 0);\n>  \n>  \tif (!stat_tracking_info(branch, &ours, &theirs)) {\n>  \t\tif (branch && branch->merge && branch->merge[0]->dst &&\n> -\t\t    show_upstream_ref)\n> -\t\t\tstrbuf_addf(stat, \"[%s] \",\n> -\t\t\t    shorten_unambiguous_ref(branch->merge[0]->dst, 0));\n> +\t\t    show_upstream_ref) {\n> +\t\t\tref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n> +\t\t\tif (want_color(branch_use_color))\n> +\t\t\t\tstrbuf_addf(stat, \"[%s%s%s] \",\n> +\t\t\t\t\t\tbranch_get_color(BRANCH_COLOR_UPSTREAM),\n> +\t\t\t\t\t\tref, branch_get_color(BRANCH_COLOR_RESET));\n> +\t\t\telse\n> +\t\t\t\tstrbuf_addf(stat, \"[%s] \", ref);\n> +\t\t}\n>  \t\treturn;\n>  \t}\n>  \n> -\tif (show_upstream_ref)\n> +\tif (show_upstream_ref) {\n>  \t\tref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n> +\t\tif (want_color(branch_use_color))\n> +\t\t\tstrbuf_addf(&fancy, \"%s%s%s\",\n> +\t\t\t\t\tbranch_get_color(BRANCH_COLOR_UPSTREAM),\n> +\t\t\t\t\tref, branch_get_color(BRANCH_COLOR_RESET));\n> +\t\telse\n> +\t\t\tstrbuf_addstr(&fancy, ref);\n> +\t}\n> +\n>  \tif (!ours) {\n>  \t\tif (ref)\n> -\t\t\tstrbuf_addf(stat, _(\"[%s: behind %d]\"), ref, theirs);\n> +\t\t\tstrbuf_addf(stat, _(\"[%s: behind %d]\"), fancy.buf, theirs);\n>  \t\telse\n>  \t\t\tstrbuf_addf(stat, _(\"[behind %d]\"), theirs);\n>  \n>  \t} else if (!theirs) {\n>  \t\tif (ref)\n> -\t\t\tstrbuf_addf(stat, _(\"[%s: ahead %d]\"), ref, ours);\n> +\t\t\tstrbuf_addf(stat, _(\"[%s: ahead %d]\"), fancy.buf, ours);\n>  \t\telse\n>  \t\t\tstrbuf_addf(stat, _(\"[ahead %d]\"), ours);\n>  \t} else {\n>  \t\tif (ref)\n>  \t\t\tstrbuf_addf(stat, _(\"[%s: ahead %d, behind %d]\"),\n> -\t\t\t\t    ref, ours, theirs);\n> +\t\t\t\t    fancy.buf, ours, theirs);\n>  \t\telse\n>  \t\t\tstrbuf_addf(stat, _(\"[ahead %d, behind %d]\"),\n>  \t\t\t\t    ours, theirs);\n>  \t}\n> +\tstrbuf_release(&fancy);\n>  \tstrbuf_addch(stat, ' ');\n>  \tfree(ref);\n>  }\n\nFairly straight-forward and looks good.\n"},{"id":"214297","messageId":"CACsJy8A9ii475i98n39HFMjRqBRHnoywn03k03qcbesJYbGUGA@mail.gmail.com","threadId":"33513","inReplyTo":"1365993469-6874-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH v3] branch: colour upstream branches","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-04-15T12:16:44Z","receivedAt":"2013-04-15T12:16:44Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Apr 15, 2013 at 12:37 PM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> @@ -417,36 +421,54 @@ static void fill_tracking_info(struct strbuf *stat, const char *branch_name,\n>         int ours, theirs;\n>         char *ref = NULL;\n>         struct branch *branch = branch_get(branch_name);\n> +       struct strbuf fancy;\n> +\n> +       strbuf_init(&fancy, 0);\n\nNitpick. You could have done \"struct strbuf fancy = STRBUF_INIT;\". No\nneed to resend, I think, unless there are other changes.\n--\nDuy\n"}]}