{"thread":{"id":"46333","subject":"git-2.13.2: color.branch.local problem","startedAt":"2017-07-08T19:13:10Z","lastAt":"2017-07-09T10:00:52Z","messageCount":6,"participants":["Leo Razoumov","Jeff King"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"324000","messageId":"CADsUFkTuRK7wgtvZ16Dw-5y2CFXZByTBzNky6cQb0RzT58C5WQ@mail.gmail.com","threadId":"46333","inReplyTo":null,"subject":"git-2.13.2: color.branch.local problem","fromName":"Leo Razoumov","fromEmail":"slonik.az@gmail.com","sentAt":"2017-07-08T19:13:04Z","receivedAt":"2017-07-08T19:13:10Z","isPatch":false,"sender":{"key":"slonik.az@gmail.com","avatar":null},"body":"Hi Everyone,\n\nWhen I updated from git-2.10.2 to git-2.13.2 my 'color.branch.local'\nconfig setting gets ignored. Corresponding 'remote' or 'current'\nsettings are honored and work as expected\n\nRelevant parts of my config file is:\n  [color \"branch\"]\n    current=  reverse\n    local  = red bold\n    remote = green bold\n\nI am on macosx-10.11.6 El Capitan. Git installation courtesy of homebrew.\n\nUsing command\n$ git branch -a --color=always\nI see current branch in reverse, remote branches in green, but local\nbranches in default color (black)\n\nAny help is greatly appreciated.\n\nThanks,\n--Leo\n"},{"id":"324013","messageId":"20170709092834.nxfmqsxieg6boujh@sigill.intra.peff.net","threadId":"46333","inReplyTo":"CADsUFkTuRK7wgtvZ16Dw-5y2CFXZByTBzNky6cQb0RzT58C5WQ@mail.gmail.com","subject":"Re: git-2.13.2: color.branch.local problem","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-07-09T09:28:34Z","receivedAt":"2017-07-09T09:28:49Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sat, Jul 08, 2017 at 03:13:04PM -0400, Leo Razoumov wrote:\n\n> When I updated from git-2.10.2 to git-2.13.2 my 'color.branch.local'\n> config setting gets ignored. Corresponding 'remote' or 'current'\n> settings are honored and work as expected\n\nLooks like this is a regression from the switch to ref-filter in\nv2.13.0; it bisects to 949af0684 (branch: use ref-filter printing APIs,\n2017-01-10). It looks like we don't ever use BRANCH_COLOR_LOCAL. The fix\nis a little tricky because of another nearby issue. I'll send out a\npatch in a moment.\n\n-Peff\n"},{"id":"324014","messageId":"20170709095708.moymrozmqdv2oixx@sigill.intra.peff.net","threadId":"46333","inReplyTo":"20170709092834.nxfmqsxieg6boujh@sigill.intra.peff.net","subject":"Re: git-2.13.2: color.branch.local problem","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-07-09T09:57:08Z","receivedAt":"2017-07-09T09:57:15Z","isPatch":false,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Sun, Jul 09, 2017 at 05:28:34AM -0400, Jeff King wrote:\n\n> On Sat, Jul 08, 2017 at 03:13:04PM -0400, Leo Razoumov wrote:\n> \n> > When I updated from git-2.10.2 to git-2.13.2 my 'color.branch.local'\n> > config setting gets ignored. Corresponding 'remote' or 'current'\n> > settings are honored and work as expected\n> \n> Looks like this is a regression from the switch to ref-filter in\n> v2.13.0; it bisects to 949af0684 (branch: use ref-filter printing APIs,\n> 2017-01-10). It looks like we don't ever use BRANCH_COLOR_LOCAL. The fix\n> is a little tricky because of another nearby issue. I'll send out a\n> patch in a moment.\n\nHere it is. This is intended for the maint branch.\n\n  [1/3]: branch: only perform HEAD check for local branches\n  [2/3]: branch: use BRANCH_COLOR_LOCAL in ref-filter format\n  [3/3]: branch: set remote color in ref-filter branch immediately\n\n builtin/branch.c        | 15 +++++++++------\n t/t3205-branch-color.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 53 insertions(+), 6 deletions(-)\n create mode 100755 t/t3205-branch-color.sh\n\n-Peff\n"},{"id":"324015","messageId":"20170709095810.vtwclyvqbayit2u6@sigill.intra.peff.net","threadId":"46333","inReplyTo":"20170709095708.moymrozmqdv2oixx@sigill.intra.peff.net","subject":"[PATCH 1/3] branch: only perform HEAD check for local branches","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-07-09T09:58:10Z","receivedAt":"2017-07-09T09:58:16Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"When assembling the ref-filter format to show \"git branch\"\noutput, we put the \"%(if)%(HEAD)\" conditional at the start\nof the overall format. But there's no point in checking\nwhether a remote branch matches HEAD, as it never will.\nThe check should go inside the local conditional; we\nassemble that format inside the \"local\" strbuf.\n\nBy itself, this is just a minor optimization. But in a\nfuture patch, we'll need this refactoring to fix\nlocal-branch coloring.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/branch.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex c958e9325..a849373b7 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -335,8 +335,9 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r\n \tstruct strbuf local = STRBUF_INIT;\n \tstruct strbuf remote = STRBUF_INIT;\n \n-\tstrbuf_addf(&fmt, \"%%(if)%%(HEAD)%%(then)* %s%%(else)  %%(end)\",\n+\tstrbuf_addf(&local, \"%%(if)%%(HEAD)%%(then)* %s%%(else)  %%(end)\",\n \t\t    branch_get_color(BRANCH_COLOR_CURRENT));\n+\tstrbuf_addf(&remote, \"  \");\n \n \tif (filter->verbose) {\n \t\tstruct strbuf obname = STRBUF_INIT;\n-- \n2.13.2.1066.gabaed60bd\n\n"},{"id":"324016","messageId":"20170709095932.rkmvtmojn3jrw3o5@sigill.intra.peff.net","threadId":"46333","inReplyTo":"20170709095708.moymrozmqdv2oixx@sigill.intra.peff.net","subject":"[PATCH 2/3] branch: use BRANCH_COLOR_LOCAL in ref-filter format","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-07-09T09:59:33Z","receivedAt":"2017-07-09T09:59:40Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"Since 949af0684 (branch: use ref-filter printing APIs,\n2017-01-10), git-branch's output is generated by passing a\ncustom format to the ref-filter code. This format forgot to\npass BRANCH_COLOR_LOCAL, meaning that local branches\n(besides the current one) were never colored at all.\n\nWe can add it in the %(if) block where we decide whether the\nbranch is \"current\" or merely \"local\".  Note that this means\nthe current/local coloring is either/or. You can't set:\n\n  [color \"branch\"]\n  local = blue\n  current = bold\n\nand expect the current branch to be \"bold blue\". This\nmatches the pre-949af0684 behavior.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/branch.c        |  5 +++--\n t/t3205-branch-color.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++\n 2 files changed, 47 insertions(+), 2 deletions(-)\n create mode 100755 t/t3205-branch-color.sh\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex a849373b7..ee4e93c3a 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -335,8 +335,9 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r\n \tstruct strbuf local = STRBUF_INIT;\n \tstruct strbuf remote = STRBUF_INIT;\n \n-\tstrbuf_addf(&local, \"%%(if)%%(HEAD)%%(then)* %s%%(else)  %%(end)\",\n-\t\t    branch_get_color(BRANCH_COLOR_CURRENT));\n+\tstrbuf_addf(&local, \"%%(if)%%(HEAD)%%(then)* %s%%(else)  %s%%(end)\",\n+\t\t    branch_get_color(BRANCH_COLOR_CURRENT),\n+\t\t    branch_get_color(BRANCH_COLOR_LOCAL));\n \tstrbuf_addf(&remote, \"  \");\n \n \tif (filter->verbose) {\ndiff --git a/t/t3205-branch-color.sh b/t/t3205-branch-color.sh\nnew file mode 100755\nindex 000000000..9343550f5\n--- /dev/null\n+++ b/t/t3205-branch-color.sh\n@@ -0,0 +1,44 @@\n+#!/bin/sh\n+\n+test_description='basic branch output coloring'\n+. ./test-lib.sh\n+\n+test_expect_success 'set up some sample branches' '\n+\ttest_commit foo &&\n+\tgit update-ref refs/remotes/origin/master HEAD &&\n+\tgit update-ref refs/heads/other HEAD\n+'\n+\n+# choose non-default colors to make sure config\n+# is taking effect\n+test_expect_success 'set up some color config' '\n+\tgit config color.branch always &&\n+\tgit config color.branch.local blue &&\n+\tgit config color.branch.remote yellow &&\n+\tgit config color.branch.current cyan\n+'\n+\n+test_expect_success 'regular output shows colors' '\n+\tcat >expect <<-\\EOF &&\n+\t* <CYAN>master<RESET>\n+\t  <BLUE>other<RESET>\n+\t  <YELLOW>remotes/origin/master<RESET>\n+\tEOF\n+\tgit branch -a >actual.raw &&\n+\ttest_decode_color <actual.raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_expect_success 'verbose output shows colors' '\n+\toid=$(git rev-parse --short HEAD) &&\n+\tcat >expect <<-EOF &&\n+\t* <CYAN>master               <RESET> $oid foo\n+\t  <BLUE>other                <RESET> $oid foo\n+\t  <YELLOW>remotes/origin/master<RESET> $oid foo\n+\tEOF\n+\tgit branch -v -a >actual.raw &&\n+\ttest_decode_color <actual.raw >actual &&\n+\ttest_cmp expect actual\n+'\n+\n+test_done\n-- \n2.13.2.1066.gabaed60bd\n\n"},{"id":"324017","messageId":"20170709100045.neb5ovc776wnfphs@sigill.intra.peff.net","threadId":"46333","inReplyTo":"20170709095708.moymrozmqdv2oixx@sigill.intra.peff.net","subject":"[PATCH 3/3] branch: set remote color in ref-filter branch immediately","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-07-09T10:00:45Z","receivedAt":"2017-07-09T10:00:52Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"We set the current and local branch colors at the top of the\nbuild_format() function. Let's do the same for the remote\ncolor. This saves a little bit of repetition, but more\nimportantly it puts all of the color-setting in the same\nplace. That makes it easier to see that we are coloring all\npossibilities.\n\nSigned-off-by: Jeff King <peff@peff.net>\n---\n builtin/branch.c | 11 ++++++-----\n 1 file changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex ee4e93c3a..8a0595e11 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -338,7 +338,8 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r\n \tstrbuf_addf(&local, \"%%(if)%%(HEAD)%%(then)* %s%%(else)  %s%%(end)\",\n \t\t    branch_get_color(BRANCH_COLOR_CURRENT),\n \t\t    branch_get_color(BRANCH_COLOR_LOCAL));\n-\tstrbuf_addf(&remote, \"  \");\n+\tstrbuf_addf(&remote, \"  %s\",\n+\t\t    branch_get_color(BRANCH_COLOR_REMOTE));\n \n \tif (filter->verbose) {\n \t\tstruct strbuf obname = STRBUF_INIT;\n@@ -361,17 +362,17 @@ static char *build_format(struct ref_filter *filter, int maxwidth, const char *r\n \t\telse\n \t\t\tstrbuf_addf(&local, \"%%(if)%%(upstream:track)%%(then)%%(upstream:track) %%(end)%%(contents:subject)\");\n \n-\t\tstrbuf_addf(&remote, \"%s%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s\"\n+\t\tstrbuf_addf(&remote, \"%%(align:%d,left)%s%%(refname:lstrip=2)%%(end)%s\"\n \t\t\t    \"%%(if)%%(symref)%%(then) -> %%(symref:short)\"\n \t\t\t    \"%%(else) %s %%(contents:subject)%%(end)\",\n-\t\t\t    branch_get_color(BRANCH_COLOR_REMOTE), maxwidth, quote_literal_for_format(remote_prefix),\n+\t\t\t    maxwidth, quote_literal_for_format(remote_prefix),\n \t\t\t    branch_get_color(BRANCH_COLOR_RESET), obname.buf);\n \t\tstrbuf_release(&obname);\n \t} else {\n \t\tstrbuf_addf(&local, \"%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)\",\n \t\t\t    branch_get_color(BRANCH_COLOR_RESET));\n-\t\tstrbuf_addf(&remote, \"%s%s%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)\",\n-\t\t\t    branch_get_color(BRANCH_COLOR_REMOTE), quote_literal_for_format(remote_prefix),\n+\t\tstrbuf_addf(&remote, \"%s%%(refname:lstrip=2)%s%%(if)%%(symref)%%(then) -> %%(symref:short)%%(end)\",\n+\t\t\t    quote_literal_for_format(remote_prefix),\n \t\t\t    branch_get_color(BRANCH_COLOR_RESET));\n \t}\n \n-- \n2.13.2.1066.gabaed60bd\n"}]}