{"thread":{"id":"33502","subject":"[PATCH] branch: colour upstream branches","startedAt":"2013-04-14T01:46:25Z","lastAt":"2013-04-15T01:35:08Z","messageCount":10,"participants":["Felipe Contreras","Thomas Rast","Duy Nguyen"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"214148","messageId":"1365903985-24920-1-git-send-email-felipe.contreras@gmail.com","threadId":"33502","inReplyTo":null,"subject":"[PATCH] branch: colour upstream branches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-14T01:46:25Z","receivedAt":"2013-04-14T01:46:25Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"It's hard to see them among so much output otherwise.\n\nSigned-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n---\n builtin/branch.c | 27 ++++++++++++++++++++-------\n 1 file changed, 20 insertions(+), 7 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 00d17d2..a1cdc29 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -417,32 +417,45 @@ 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\tGIT_COLOR_BLUE, ref, GIT_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\tGIT_COLOR_BLUE, ref, GIT_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.641.gd16d37a\n"},{"id":"214226","messageId":"87li8lylql.fsf@hexa.v.cablecom.net","threadId":"33502","inReplyTo":"1365903985-24920-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Thomas Rast","fromEmail":"trast@inf.ethz.ch","sentAt":"2013-04-14T19:07:30Z","receivedAt":"2013-04-14T19:07:30Z","isPatch":true,"sender":{"key":"tr@thomasrast.ch","avatar":"https://avatars.githubusercontent.com/u/153510?v=4"},"body":"Felipe Contreras <felipe.contreras@gmail.com> writes:\n\n> It's hard to see them among so much output otherwise.\n>\n> Signed-off-by: Felipe Contreras <felipe.contreras@gmail.com>\n> ---\n>  builtin/branch.c | 27 ++++++++++++++++++++-------\n>  1 file changed, 20 insertions(+), 7 deletions(-)\n>\n> diff --git a/builtin/branch.c b/builtin/branch.c\n> index 00d17d2..a1cdc29 100644\n> --- a/builtin/branch.c\n> +++ b/builtin/branch.c\n> @@ -417,32 +417,45 @@ 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\tGIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n\nAFAICS you are hardcoding the color?  The other bits of branch colors\nare configurable through branch.color.*, so why not this?\n\n-- \nThomas Rast\ntrast@{inf,student}.ethz.ch\n"},{"id":"214235","messageId":"CACsJy8DdBkPDXORxv08cFi+i5Q4WiBjjbNf9GyB4hv+t-K=wRQ@mail.gmail.com","threadId":"33502","inReplyTo":"1365903985-24920-1-git-send-email-felipe.contreras@gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-04-14T22:31:23Z","receivedAt":"2013-04-14T22:31:23Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Sun, Apr 14, 2013 at 11:46 AM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> +       char fancy[80];\n>\n> -       if (show_upstream_ref)\n> +       if (show_upstream_ref) {\n>                 ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n> +               if (want_color(branch_use_color))\n> +                       snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n> +                                       GIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n> +               else\n> +                       strncpy(fancy, ref, sizeof(fancy));\n> +       }\n> +\n\nPlease use strbuf for \"fancy\". I also agree with Thomas that the color\nshould not be hard coded.\n--\nDuy\n"},{"id":"214236","messageId":"CAMP44s2j-Cqksu29fJRTqDNGBNi1tZkE0gfgj69K-ckFwVgnRg@mail.gmail.com","threadId":"33502","inReplyTo":"CACsJy8DdBkPDXORxv08cFi+i5Q4WiBjjbNf9GyB4hv+t-K=wRQ@mail.gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-14T23:22:16Z","receivedAt":"2013-04-14T23:22:16Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Apr 14, 2013 at 5:31 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Sun, Apr 14, 2013 at 11:46 AM, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n>> +       char fancy[80];\n>>\n>> -       if (show_upstream_ref)\n>> +       if (show_upstream_ref) {\n>>                 ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n>> +               if (want_color(branch_use_color))\n>> +                       snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n>> +                                       GIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n>> +               else\n>> +                       strncpy(fancy, ref, sizeof(fancy));\n>> +       }\n>> +\n>\n> Please use strbuf for \"fancy\".\n\nWhy? We would need to initialize and free it. What's the advantage?\n\n-- \nFelipe Contreras\n"},{"id":"214239","messageId":"CACsJy8AGFEEkS2qQygnbZOorGv=DKc2OgC-nZ47+k2oYGBBD2Q@mail.gmail.com","threadId":"33502","inReplyTo":"CAMP44s2j-Cqksu29fJRTqDNGBNi1tZkE0gfgj69K-ckFwVgnRg@mail.gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-04-14T23:46:40Z","receivedAt":"2013-04-14T23:46:40Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Apr 15, 2013 at 9:22 AM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Sun, Apr 14, 2013 at 5:31 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>> On Sun, Apr 14, 2013 at 11:46 AM, Felipe Contreras\n>> <felipe.contreras@gmail.com> wrote:\n>>> +       char fancy[80];\n>>>\n>>> -       if (show_upstream_ref)\n>>> +       if (show_upstream_ref) {\n>>>                 ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n>>> +               if (want_color(branch_use_color))\n>>> +                       snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n>>> +                                       GIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n>>> +               else\n>>> +                       strncpy(fancy, ref, sizeof(fancy));\n>>> +       }\n>>> +\n>>\n>> Please use strbuf for \"fancy\".\n>\n> Why? We would need to initialize and free it. What's the advantage?\n\n>From a quick glance, I don't see any gurantee that \"ref\" (plus ansi\ncodes) will always fit in 80 bytes.\n--\nDuy\n"},{"id":"214241","messageId":"CAMP44s38e4n_jKC-f973JJUXuxkD2dqP+ECwzxvUMWxit2P2PA@mail.gmail.com","threadId":"33502","inReplyTo":"CACsJy8AGFEEkS2qQygnbZOorGv=DKc2OgC-nZ47+k2oYGBBD2Q@mail.gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-14T23:54:21Z","receivedAt":"2013-04-14T23:54:21Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Apr 14, 2013 at 6:46 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Mon, Apr 15, 2013 at 9:22 AM, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n>> On Sun, Apr 14, 2013 at 5:31 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>> On Sun, Apr 14, 2013 at 11:46 AM, Felipe Contreras\n>>> <felipe.contreras@gmail.com> wrote:\n>>>> +       char fancy[80];\n>>>>\n>>>> -       if (show_upstream_ref)\n>>>> +       if (show_upstream_ref) {\n>>>>                 ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n>>>> +               if (want_color(branch_use_color))\n>>>> +                       snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n>>>> +                                       GIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n>>>> +               else\n>>>> +                       strncpy(fancy, ref, sizeof(fancy));\n>>>> +       }\n>>>> +\n>>>\n>>> Please use strbuf for \"fancy\".\n>>\n>> Why? We would need to initialize and free it. What's the advantage?\n>\n> From a quick glance, I don't see any gurantee that \"ref\" (plus ansi\n> codes) will always fit in 80 bytes.\n\nWould changing it to 1024 (MAXREFLEN) fix it?\n\n-- \nFelipe Contreras\n"},{"id":"214243","messageId":"CACsJy8CTmh2eMDqBpr0agiTGcHkP_AQBLLg2A4HM203u9G1v9g@mail.gmail.com","threadId":"33502","inReplyTo":"CAMP44s38e4n_jKC-f973JJUXuxkD2dqP+ECwzxvUMWxit2P2PA@mail.gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-04-15T00:55:02Z","receivedAt":"2013-04-15T00:55:02Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Apr 15, 2013 at 9:54 AM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Sun, Apr 14, 2013 at 6:46 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>> On Mon, Apr 15, 2013 at 9:22 AM, Felipe Contreras\n>> <felipe.contreras@gmail.com> wrote:\n>>> On Sun, Apr 14, 2013 at 5:31 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>>> On Sun, Apr 14, 2013 at 11:46 AM, Felipe Contreras\n>>>> <felipe.contreras@gmail.com> wrote:\n>>>>> +       char fancy[80];\n>>>>>\n>>>>> -       if (show_upstream_ref)\n>>>>> +       if (show_upstream_ref) {\n>>>>>                 ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n>>>>> +               if (want_color(branch_use_color))\n>>>>> +                       snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n>>>>> +                                       GIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n>>>>> +               else\n>>>>> +                       strncpy(fancy, ref, sizeof(fancy));\n>>>>> +       }\n>>>>> +\n>>>>\n>>>> Please use strbuf for \"fancy\".\n>>>\n>>> Why? We would need to initialize and free it. What's the advantage?\n>>\n>> From a quick glance, I don't see any gurantee that \"ref\" (plus ansi\n>> codes) will always fit in 80 bytes.\n>\n> Would changing it to 1024 (MAXREFLEN) fix it?\n\nYou still need to take ansi codes into account. I think it's easier to\njust use strbuf.\n--\nDuy\n"},{"id":"214245","messageId":"CAMP44s27Tj4x5U34ysdfQx8uzxAz=yJZ+rkWxLWtQHzAeoF8SA@mail.gmail.com","threadId":"33502","inReplyTo":"CACsJy8CTmh2eMDqBpr0agiTGcHkP_AQBLLg2A4HM203u9G1v9g@mail.gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-15T01:24:38Z","receivedAt":"2013-04-15T01:24:38Z","isPatch":true,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"On Sun, Apr 14, 2013 at 7:55 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Mon, Apr 15, 2013 at 9:54 AM, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n>> On Sun, Apr 14, 2013 at 6:46 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>> On Mon, Apr 15, 2013 at 9:22 AM, Felipe Contreras\n>>> <felipe.contreras@gmail.com> wrote:\n>>>> On Sun, Apr 14, 2013 at 5:31 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>>>> On Sun, Apr 14, 2013 at 11:46 AM, Felipe Contreras\n>>>>> <felipe.contreras@gmail.com> wrote:\n>>>>>> +       char fancy[80];\n>>>>>>\n>>>>>> -       if (show_upstream_ref)\n>>>>>> +       if (show_upstream_ref) {\n>>>>>>                 ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n>>>>>> +               if (want_color(branch_use_color))\n>>>>>> +                       snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n>>>>>> +                                       GIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n>>>>>> +               else\n>>>>>> +                       strncpy(fancy, ref, sizeof(fancy));\n>>>>>> +       }\n>>>>>> +\n>>>>>\n>>>>> Please use strbuf for \"fancy\".\n>>>>\n>>>> Why? We would need to initialize and free it. What's the advantage?\n>>>\n>>> From a quick glance, I don't see any gurantee that \"ref\" (plus ansi\n>>> codes) will always fit in 80 bytes.\n>>\n>> Would changing it to 1024 (MAXREFLEN) fix it?\n>\n> You still need to take ansi codes into account. I think it's easier to\n> just use strbuf.\n\nI'm not sure what you mean. If there was an issue with snprintf, then\nthere would be with this in refs.c:\n\n\tif (recursion > MAXDEPTH || strlen(refname) > MAXREFLEN)\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"214248","messageId":"CACsJy8Cecymz-vPQ_WwGzB8kR6B_j5vm8MPVykrO44C5Vk=1Zg@mail.gmail.com","threadId":"33502","inReplyTo":"CAMP44s27Tj4x5U34ysdfQx8uzxAz=yJZ+rkWxLWtQHzAeoF8SA@mail.gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Duy Nguyen","fromEmail":"pclouds@gmail.com","sentAt":"2013-04-15T01:31:01Z","receivedAt":"2013-04-15T01:31:01Z","isPatch":true,"sender":{"key":"pclouds@gmail.com","avatar":"https://avatars.githubusercontent.com/u/720?v=4"},"body":"On Mon, Apr 15, 2013 at 11:24 AM, Felipe Contreras\n<felipe.contreras@gmail.com> wrote:\n> On Sun, Apr 14, 2013 at 7:55 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>> On Mon, Apr 15, 2013 at 9:54 AM, Felipe Contreras\n>> <felipe.contreras@gmail.com> wrote:\n>>> On Sun, Apr 14, 2013 at 6:46 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>>> On Mon, Apr 15, 2013 at 9:22 AM, Felipe Contreras\n>>>> <felipe.contreras@gmail.com> wrote:\n>>>>> On Sun, Apr 14, 2013 at 5:31 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>>>>> On Sun, Apr 14, 2013 at 11:46 AM, Felipe Contreras\n>>>>>> <felipe.contreras@gmail.com> wrote:\n>>>>>>> +       char fancy[80];\n>>>>>>>\n>>>>>>> -       if (show_upstream_ref)\n>>>>>>> +       if (show_upstream_ref) {\n>>>>>>>                 ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n>>>>>>> +               if (want_color(branch_use_color))\n>>>>>>> +                       snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n>>>>>>> +                                       GIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n>>>>>>> +               else\n>>>>>>> +                       strncpy(fancy, ref, sizeof(fancy));\n>>>>>>> +       }\n>>>>>>> +\n>>>>>>\n>>>>>> Please use strbuf for \"fancy\".\n>>>>>\n>>>>> Why? We would need to initialize and free it. What's the advantage?\n>>>>\n>>>> From a quick glance, I don't see any gurantee that \"ref\" (plus ansi\n>>>> codes) will always fit in 80 bytes.\n>>>\n>>> Would changing it to 1024 (MAXREFLEN) fix it?\n>>\n>> You still need to take ansi codes into account. I think it's easier to\n>> just use strbuf.\n>\n> I'm not sure what you mean. If there was an issue with snprintf, then\n> there would be with this in refs.c:\n>\n>         if (recursion > MAXDEPTH || strlen(refname) > MAXREFLEN)\n\nI mean GIT_COLOR_BLUE and GIT_COLOR_RESET take some bytes from\n\"fancy\". In the stretched case where ref takes all MAXREFLEN, then\nfancy must be a little bit bigger. Why do we need to think hard about\nthe size of fancy when strbuf would solve it nicely?\n--\nDuy\n"},{"id":"214250","messageId":"CAMP44s1NpPVyRZGDdM2r3R7DrJOkZhFY8cyZX_CgJBomjmSVog@mail.gmail.com","threadId":"33502","inReplyTo":"CACsJy8Cecymz-vPQ_WwGzB8kR6B_j5vm8MPVykrO44C5Vk=1Zg@mail.gmail.com","subject":"Re: [PATCH] branch: colour upstream branches","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2013-04-15T01:35:08Z","receivedAt":"2013-04-15T01:35:08Z","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:31 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n> On Mon, Apr 15, 2013 at 11:24 AM, Felipe Contreras\n> <felipe.contreras@gmail.com> wrote:\n>> On Sun, Apr 14, 2013 at 7:55 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>> On Mon, Apr 15, 2013 at 9:54 AM, Felipe Contreras\n>>> <felipe.contreras@gmail.com> wrote:\n>>>> On Sun, Apr 14, 2013 at 6:46 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>>>> On Mon, Apr 15, 2013 at 9:22 AM, Felipe Contreras\n>>>>> <felipe.contreras@gmail.com> wrote:\n>>>>>> On Sun, Apr 14, 2013 at 5:31 PM, Duy Nguyen <pclouds@gmail.com> wrote:\n>>>>>>> On Sun, Apr 14, 2013 at 11:46 AM, Felipe Contreras\n>>>>>>> <felipe.contreras@gmail.com> wrote:\n>>>>>>>> +       char fancy[80];\n>>>>>>>>\n>>>>>>>> -       if (show_upstream_ref)\n>>>>>>>> +       if (show_upstream_ref) {\n>>>>>>>>                 ref = shorten_unambiguous_ref(branch->merge[0]->dst, 0);\n>>>>>>>> +               if (want_color(branch_use_color))\n>>>>>>>> +                       snprintf(fancy, sizeof(fancy), \"%s%s%s\",\n>>>>>>>> +                                       GIT_COLOR_BLUE, ref, GIT_COLOR_RESET);\n>>>>>>>> +               else\n>>>>>>>> +                       strncpy(fancy, ref, sizeof(fancy));\n>>>>>>>> +       }\n>>>>>>>> +\n>>>>>>>\n>>>>>>> Please use strbuf for \"fancy\".\n>>>>>>\n>>>>>> Why? We would need to initialize and free it. What's the advantage?\n>>>>>\n>>>>> From a quick glance, I don't see any gurantee that \"ref\" (plus ansi\n>>>>> codes) will always fit in 80 bytes.\n>>>>\n>>>> Would changing it to 1024 (MAXREFLEN) fix it?\n>>>\n>>> You still need to take ansi codes into account. I think it's easier to\n>>> just use strbuf.\n>>\n>> I'm not sure what you mean. If there was an issue with snprintf, then\n>> there would be with this in refs.c:\n>>\n>>         if (recursion > MAXDEPTH || strlen(refname) > MAXREFLEN)\n>\n> I mean GIT_COLOR_BLUE and GIT_COLOR_RESET take some bytes from\n> \"fancy\". In the stretched case where ref takes all MAXREFLEN, then\n> fancy must be a little bit bigger. Why do we need to think hard about\n\nI don't see that as a big issue, since it's a matter of finding the\nmaximum length of those, but the argument from Jeff convinces me; I\nwould not like to add extra code for the snprintf corner cases.\n\nCheers.\n\n-- \nFelipe Contreras\n"}]}