{"thread":{"id":"33512","subject":"[PATCH v2] branch: colour upstream branches","startedAt":"2013-04-14T23:38:27Z","lastAt":"2013-04-15T02:27:05Z","messageCount":4,"participants":["Felipe Contreras","Jeff King","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"214238","messageId":"1365982707-25455-1-git-send-email-felipe.contreras@gmail.com","threadId":"33512","inReplyTo":null,"subject":"[PATCH v2] branch: colour upstream branches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-14T23:38:27Z","receivedAt":"2013-04-14T23:38:27Z","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 Documentation/config.txt |  3 ++-\n builtin/branch.c         | 35 +++++++++++++++++++++++++++--------\n 2 files changed, 29 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..9696419 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,32 +421,47 @@ 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+\tchar fancy[80];\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\tsnprintf(fancy, sizeof(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\tstrncpy(fancy, ref, sizeof(fancy));\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, 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, 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, ours, theirs);\n \t\telse\n \t\t\tstrbuf_addf(stat, _(\"[ahead %d, behind %d]\"),\n \t\t\t\t    ours, theirs);\n-- \n1.8.2.1.643.ge3cc75d\n"},{"id":"214242","messageId":"20130415004746.GA6477@sigill.intra.peff.net","threadId":"33512","inReplyTo":"1365982707-25455-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH v2] branch: colour upstream branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2013-04-15T00:47:46Z","receivedAt":"2013-04-15T00:47:46Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Apr 14, 2013 at 06:38:27PM -0500, Felipe Contreras wrote:\n\n> +\t\tif (want_color(branch_use_color))\n> +\t\t\tsnprintf(fancy, sizeof(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\tstrncpy(fancy, ref, sizeof(fancy));\n\n  $ man strncpy | grep -C1 Warning\n  The strncpy() function is similar, except that at most n bytes of src are\n  copied.  Warning: If there is no null byte among the first n bytes of src,\n  the string placed in dest will not be null-terminated.\n\n-Peff\n"},{"id":"214253","messageId":"7vd2tw4l2e.fsf@alter.siamese.dyndns.org","threadId":"33512","inReplyTo":"20130415004746.GA6477@sigill.intra.peff.net","subject":"Re: [PATCH v2] branch: colour upstream branches","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-04-15T01:52:25Z","receivedAt":"2013-04-15T01:52:25Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Jeff King <peff@peff.net> writes:\n\n> On Sun, Apr 14, 2013 at 06:38:27PM -0500, Felipe Contreras wrote:\n>\n>> +\t\tif (want_color(branch_use_color))\n>> +\t\t\tsnprintf(fancy, sizeof(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\tstrncpy(fancy, ref, sizeof(fancy));\n>\n>   $ man strncpy | grep -C1 Warning\n>   The strncpy() function is similar, except that at most n bytes of src are\n>   copied.  Warning: If there is no null byte among the first n bytes of src,\n>   the string placed in dest will not be null-terminated.\n\nIs there a reason to avoid strbuf_addf() here?  We are talking about\noutput for human consumption and not performance critical code, no?\n"},{"id":"214255","messageId":"CAMP44s0wLH0hyrj9xSn+LDS=nLbWuHavNeXv_U4NSYWyK5WncA@mail.gmail.com","threadId":"33512","inReplyTo":"7vd2tw4l2e.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH v2] branch: colour upstream branches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-15T02:27:05Z","receivedAt":"2013-04-15T02:27:05Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Apr 14, 2013 at 8:52 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Jeff King <peff@peff.net> writes:\n>\n>> On Sun, Apr 14, 2013 at 06:38:27PM -0500, Felipe Contreras wrote:\n>>\n>>> +            if (want_color(branch_use_color))\n>>> +                    snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n>>> +                                    branch_get_color(BRANCH_COLOR_UPSTREAM),\n>>> +                                    ref, branch_get_color(BRANCH_COLOR_RESET));\n>>> +            else\n>>> +                    strncpy(fancy, ref, sizeof(fancy));\n>>\n>>   $ man strncpy | grep -C1 Warning\n>>   The strncpy() function is similar, except that at most n bytes of src are\n>>   copied.  Warning: If there is no null byte among the first n bytes of src,\n>>   the string placed in dest will not be null-terminated.\n>\n> Is there a reason to avoid strbuf_addf() here?  We are talking about\n> output for human consumption and not performance critical code, no?\n\nIt's not about the performance, it's about the amount of code. But I\nalready agreed to do this.\n\n-- \nFelipe Contreras\n"}]}