{"thread":{"id":"35255","subject":"[PATCH 1/3] for-each-ref: introduce %C(...) for color","startedAt":"2013-10-31T09:46:11Z","lastAt":"2013-11-12T03:38:31Z","messageCount":15,"participants":["Ramkumar Ramachandra","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":3},"messages":[{"id":"229908","messageId":"1383212774-5232-1-git-send-email-artagnon@gmail.com","threadId":"35255","inReplyTo":null,"subject":"[PATCH (resend) 0/3] Minor f-e-r enhacements","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-10-31T09:46:11Z","receivedAt":"2013-10-31T09:46:11Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Hi,\n\nI've been running git with these patches applied locally for a long\ntime. Although I've sent them to the list before, they've been\noverlooked.\n\nThanks.\n\nRamkumar Ramachandra (3):\n  for-each-ref: introduce %C(...) for color\n  for-each-ref: introduce %(HEAD) asterisk marker\n  for-each-ref: introduce %(upstream:track[short])\n\n Documentation/git-for-each-ref.txt | 14 ++++++-\n builtin/for-each-ref.c             | 75 ++++++++++++++++++++++++++++++++++----\n 2 files changed, 79 insertions(+), 10 deletions(-)\n\n-- \n1.8.5.rc0.3.gb488857\n"},{"id":"229907","messageId":"1383212774-5232-2-git-send-email-artagnon@gmail.com","threadId":"35255","inReplyTo":"1383212774-5232-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-10-31T09:46:12Z","receivedAt":"2013-10-31T09:46:12Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Enhance 'git for-each-ref' with color formatting options.  You can now\nuse the following format in for-each-ref:\n\n  %C(green)%(refname:short)%C(reset)\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Documentation/git-for-each-ref.txt |  4 +++-\n builtin/for-each-ref.c             | 23 +++++++++++++++++++----\n 2 files changed, 22 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt\nindex f2e08d1..6fa4464 100644\n--- a/Documentation/git-for-each-ref.txt\n+++ b/Documentation/git-for-each-ref.txt\n@@ -45,7 +45,9 @@ OPTIONS\n \tIt also interpolates `%%` to `%`, and `%xx` where `xx`\n \tare hex digits interpolates to character with hex code\n \t`xx`; for example `%00` interpolates to `\\0` (NUL),\n-\t`%09` to `\\t` (TAB) and `%0a` to `\\n` (LF).\n+\t`%09` to `\\t` (TAB) and `%0a` to `\\n` (LF). Additionally,\n+\tcolors can be specified using `%C(...)`, with names\n+\tdescribed in color.branch.*.\n \n <pattern>...::\n \tIf one or more patterns are given, only refs are shown that\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 1d4083c..6da2903 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -9,6 +9,7 @@\n #include \"quote.h\"\n #include \"parse-options.h\"\n #include \"remote.h\"\n+#include \"color.h\"\n \n /* Quoting styles */\n #define QUOTE_NONE 0\n@@ -155,10 +156,13 @@ static const char *find_next(const char *cp)\n \twhile (*cp) {\n \t\tif (*cp == '%') {\n \t\t\t/*\n+\t\t\t * %C( is the start of a color;\n \t\t\t * %( is the start of an atom;\n \t\t\t * %% is a quoted per-cent.\n \t\t\t */\n-\t\t\tif (cp[1] == '(')\n+\t\t\tif (cp[1] == 'C' && cp[2] == '(')\n+\t\t\t\treturn cp;\n+\t\t\telse if (cp[1] == '(')\n \t\t\t\treturn cp;\n \t\t\telse if (cp[1] == '%')\n \t\t\t\tcp++; /* skip over two % */\n@@ -180,8 +184,11 @@ static int verify_format(const char *format)\n \t\tconst char *ep = strchr(sp, ')');\n \t\tif (!ep)\n \t\t\treturn error(\"malformed format string %s\", sp);\n-\t\t/* sp points at \"%(\" and ep points at the closing \")\" */\n-\t\tparse_atom(sp + 2, ep);\n+\t\t/* Ignore color specifications: %C(\n+\t\t * sp points at \"%(\" and ep points at the closing \")\"\n+\t\t */\n+\t\tif (prefixcmp(sp, \"%C(\"))\n+\t\t\tparse_atom(sp + 2, ep);\n \t\tcp = ep + 1;\n \t}\n \treturn 0;\n@@ -933,12 +940,20 @@ static void emit(const char *cp, const char *ep)\n static void show_ref(struct refinfo *info, const char *format, int quote_style)\n {\n \tconst char *cp, *sp, *ep;\n+\tchar color[COLOR_MAXLEN] = \"\";\n \n \tfor (cp = format; *cp && (sp = find_next(cp)); cp = ep + 1) {\n \t\tep = strchr(sp, ')');\n \t\tif (cp < sp)\n \t\t\temit(cp, sp);\n-\t\tprint_value(info, parse_atom(sp + 2, ep), quote_style);\n+\n+\t\t/* Do we have a color specification? */\n+\t\tif (!prefixcmp(sp, \"%C(\"))\n+\t\t\tcolor_parse_mem(sp + 3, ep - sp - 3, \"--format\", color);\n+\t\telse {\n+\t\t\tprintf(\"%s\", color);\n+\t\t\tprint_value(info, parse_atom(sp + 2, ep), quote_style);\n+\t\t}\n \t}\n \tif (*cp) {\n \t\tsp = cp + strlen(cp);\n-- \n1.8.5.rc0.3.gb488857\n"},{"id":"229910","messageId":"1383212774-5232-3-git-send-email-artagnon@gmail.com","threadId":"35255","inReplyTo":"1383212774-5232-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 2/3] for-each-ref: introduce %(HEAD) asterisk marker","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-10-31T09:46:13Z","receivedAt":"2013-10-31T09:46:13Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"'git branch' shows which branch you are currently on with an '*', but\n'git for-each-ref' misses this feature.  So, extend its format with\n%(HEAD) for the same effect.\n\nNow you can use the following format in for-each-ref:\n\n  %C(red)%(HEAD)%C(reset) %(refname:short)\n\nto display a red asterisk next to the current ref.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Documentation/git-for-each-ref.txt |  4 ++++\n builtin/for-each-ref.c             | 13 +++++++++++--\n 2 files changed, 15 insertions(+), 2 deletions(-)\n\ndiff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt\nindex 6fa4464..bb9c4c1 100644\n--- a/Documentation/git-for-each-ref.txt\n+++ b/Documentation/git-for-each-ref.txt\n@@ -95,6 +95,10 @@ upstream::\n \tfrom the displayed ref. Respects `:short` in the same way as\n \t`refname` above.\n \n+HEAD::\n+\tUsed to indicate the currently checked out branch.  Is '*' if\n+\tHEAD points to the current ref, and ' ' otherwise.\n+\n In addition to the above, for commit and tag objects, the header\n field names (`tree`, `parent`, `object`, `type`, and `tag`) can\n be used to specify the value in the header field.\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 6da2903..b841545 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -76,6 +76,7 @@ static struct {\n \t{ \"upstream\" },\n \t{ \"symref\" },\n \t{ \"flag\" },\n+\t{ \"HEAD\" },\n };\n \n /*\n@@ -682,8 +683,16 @@ static void populate_value(struct refinfo *ref)\n \t\t\t\tv->s = xstrdup(buf + 1);\n \t\t\t}\n \t\t\tcontinue;\n-\t\t}\n-\t\telse\n+\t\t} else if (!strcmp(name, \"HEAD\")) {\n+\t\t\tconst char *head;\n+\t\t\tunsigned char sha1[20];\n+\t\t\thead = resolve_ref_unsafe(\"HEAD\", sha1, 1, NULL);\n+\t\t\tif (!strcmp(ref->refname, head))\n+\t\t\t\tv->s = \"*\";\n+\t\t\telse\n+\t\t\t\tv->s = \" \";\n+\t\t\tcontinue;\n+\t\t} else\n \t\t\tcontinue;\n \n \t\tformatp = strchr(name, ':');\n-- \n1.8.5.rc0.3.gb488857\n"},{"id":"229909","messageId":"1383212774-5232-4-git-send-email-artagnon@gmail.com","threadId":"35255","inReplyTo":"1383212774-5232-1-git-send-email-artagnon@gmail.com","subject":"[PATCH 3/3] for-each-ref: introduce %(upstream:track[short])","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-10-31T09:46:14Z","receivedAt":"2013-10-31T09:46:14Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Introduce %(upstream:track) to display \"[ahead M, behind N]\" and\n%(upstream:trackshort) to display \"=\", \">\", \"<\", or \"<>\"\nappropriately (inspired by contrib/completion/git-prompt.sh).\n\nNow you can use the following format in for-each-ref:\n\n  %C(green)%(refname:short)%C(reset)%(upstream:trackshort)\n\nto display refs with terse tracking information.\n\nNote that :track and :trackshort only work with \"upstream\", and error\nout when used with anything else.\n\nSigned-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n---\n Documentation/git-for-each-ref.txt |  6 +++++-\n builtin/for-each-ref.c             | 39 ++++++++++++++++++++++++++++++++++++--\n 2 files changed, 42 insertions(+), 3 deletions(-)\n\ndiff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt\nindex bb9c4c1..3ef6aa8 100644\n--- a/Documentation/git-for-each-ref.txt\n+++ b/Documentation/git-for-each-ref.txt\n@@ -93,7 +93,11 @@ objectname::\n upstream::\n \tThe name of a local ref which can be considered ``upstream''\n \tfrom the displayed ref. Respects `:short` in the same way as\n-\t`refname` above.\n+\t`refname` above.  Additionally respects `:track` to show\n+\t\"[ahead N, behind M]\" and `:trackshort` to show the terse\n+\tversion (like the prompt) \">\", \"<\", \"<>\", or \"=\".  Has no\n+\teffect if the ref does not have tracking information\n+\tassociated with it.\n \n HEAD::\n \tUsed to indicate the currently checked out branch.  Is '*' if\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex b841545..7d5c174 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -648,6 +648,7 @@ static void populate_value(struct refinfo *ref)\n \t\tint deref = 0;\n \t\tconst char *refname;\n \t\tconst char *formatp;\n+\t\tstruct branch *branch;\n \n \t\tif (*name == '*') {\n \t\t\tderef = 1;\n@@ -659,7 +660,6 @@ static void populate_value(struct refinfo *ref)\n \t\telse if (!prefixcmp(name, \"symref\"))\n \t\t\trefname = ref->symref ? ref->symref : \"\";\n \t\telse if (!prefixcmp(name, \"upstream\")) {\n-\t\t\tstruct branch *branch;\n \t\t\t/* only local branches may have an upstream */\n \t\t\tif (prefixcmp(ref->refname, \"refs/heads/\"))\n \t\t\t\tcontinue;\n@@ -686,6 +686,7 @@ static void populate_value(struct refinfo *ref)\n \t\t} else if (!strcmp(name, \"HEAD\")) {\n \t\t\tconst char *head;\n \t\t\tunsigned char sha1[20];\n+\n \t\t\thead = resolve_ref_unsafe(\"HEAD\", sha1, 1, NULL);\n \t\t\tif (!strcmp(ref->refname, head))\n \t\t\t\tv->s = \"*\";\n@@ -698,11 +699,45 @@ static void populate_value(struct refinfo *ref)\n \t\tformatp = strchr(name, ':');\n \t\t/* look for \"short\" refname format */\n \t\tif (formatp) {\n+\t\t\tint num_ours, num_theirs;\n+\n \t\t\tformatp++;\n \t\t\tif (!strcmp(formatp, \"short\"))\n \t\t\t\trefname = shorten_unambiguous_ref(refname,\n \t\t\t\t\t\t      warn_ambiguous_refs);\n-\t\t\telse\n+\t\t\telse if (!strcmp(formatp, \"track\") &&\n+\t\t\t\t!prefixcmp(name, \"upstream\")) {\n+\t\t\t\tchar buf[40];\n+\n+\t\t\t\tstat_tracking_info(branch, &num_ours, &num_theirs);\n+\t\t\t\tif (!num_ours && !num_theirs)\n+\t\t\t\t\tv->s = \"\";\n+\t\t\t\telse if (!num_ours) {\n+\t\t\t\t\tsprintf(buf, \"[behind %d]\", num_theirs);\n+\t\t\t\t\tv->s = xstrdup(buf);\n+\t\t\t\t} else if (!num_theirs) {\n+\t\t\t\t\tsprintf(buf, \"[ahead %d]\", num_ours);\n+\t\t\t\t\tv->s = xstrdup(buf);\n+\t\t\t\t} else {\n+\t\t\t\t\tsprintf(buf, \"[ahead %d, behind %d]\",\n+\t\t\t\t\t\tnum_ours, num_theirs);\n+\t\t\t\t\tv->s = xstrdup(buf);\n+\t\t\t\t}\n+\t\t\t\tcontinue;\n+\t\t\t} else if (!strcmp(formatp, \"trackshort\") &&\n+\t\t\t\t!prefixcmp(name, \"upstream\")) {\n+\n+\t\t\t\tstat_tracking_info(branch, &num_ours, &num_theirs);\n+\t\t\t\tif (!num_ours && !num_theirs)\n+\t\t\t\t\tv->s = \"=\";\n+\t\t\t\telse if (!num_ours)\n+\t\t\t\t\tv->s = \"<\";\n+\t\t\t\telse if (!num_theirs)\n+\t\t\t\t\tv->s = \">\";\n+\t\t\t\telse\n+\t\t\t\t\tv->s = \"<>\";\n+\t\t\t\tcontinue;\n+\t\t\t} else\n \t\t\t\tdie(\"unknown %.*s format %s\",\n \t\t\t\t    (int)(formatp - name), name, formatp);\n \t\t}\n-- \n1.8.5.rc0.3.gb488857\n"},{"id":"229976","messageId":"xmqq38nh411p.fsf@gitster.dls.corp.google.com","threadId":"35255","inReplyTo":"1383212774-5232-2-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-10-31T20:50:58Z","receivedAt":"2013-10-31T20:50:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> Enhance 'git for-each-ref' with color formatting options.  You can now\n> use the following format in for-each-ref:\n>\n>   %C(green)%(refname:short)%C(reset)\n\nSo far, every magic for-each-ref takes were of form %(...); was\nthere a reason why this had to be %C(...), not %(color=blah), or\nsomething more in-line with the existing other magic?\n\n>\n> Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>\n> ---\n>  Documentation/git-for-each-ref.txt |  4 +++-\n>  builtin/for-each-ref.c             | 23 +++++++++++++++++++----\n>  2 files changed, 22 insertions(+), 5 deletions(-)\n>\n> diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt\n> index f2e08d1..6fa4464 100644\n> --- a/Documentation/git-for-each-ref.txt\n> +++ b/Documentation/git-for-each-ref.txt\n> @@ -45,7 +45,9 @@ OPTIONS\n>  \tIt also interpolates `%%` to `%`, and `%xx` where `xx`\n>  \tare hex digits interpolates to character with hex code\n>  \t`xx`; for example `%00` interpolates to `\\0` (NUL),\n> -\t`%09` to `\\t` (TAB) and `%0a` to `\\n` (LF).\n> +\t`%09` to `\\t` (TAB) and `%0a` to `\\n` (LF). Additionally,\n> +\tcolors can be specified using `%C(...)`, with names\n> +\tdescribed in color.branch.*.\n>  \n>  <pattern>...::\n>  \tIf one or more patterns are given, only refs are shown that\n> diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\n> index 1d4083c..6da2903 100644\n> --- a/builtin/for-each-ref.c\n> +++ b/builtin/for-each-ref.c\n> @@ -9,6 +9,7 @@\n>  #include \"quote.h\"\n>  #include \"parse-options.h\"\n>  #include \"remote.h\"\n> +#include \"color.h\"\n>  \n>  /* Quoting styles */\n>  #define QUOTE_NONE 0\n> @@ -155,10 +156,13 @@ static const char *find_next(const char *cp)\n>  \twhile (*cp) {\n>  \t\tif (*cp == '%') {\n>  \t\t\t/*\n> +\t\t\t * %C( is the start of a color;\n>  \t\t\t * %( is the start of an atom;\n>  \t\t\t * %% is a quoted per-cent.\n>  \t\t\t */\n> -\t\t\tif (cp[1] == '(')\n> +\t\t\tif (cp[1] == 'C' && cp[2] == '(')\n> +\t\t\t\treturn cp;\n> +\t\t\telse if (cp[1] == '(')\n>  \t\t\t\treturn cp;\n>  \t\t\telse if (cp[1] == '%')\n>  \t\t\t\tcp++; /* skip over two % */\n> @@ -180,8 +184,11 @@ static int verify_format(const char *format)\n>  \t\tconst char *ep = strchr(sp, ')');\n>  \t\tif (!ep)\n>  \t\t\treturn error(\"malformed format string %s\", sp);\n> -\t\t/* sp points at \"%(\" and ep points at the closing \")\" */\n> -\t\tparse_atom(sp + 2, ep);\n> +\t\t/* Ignore color specifications: %C(\n> +\t\t * sp points at \"%(\" and ep points at the closing \")\"\n> +\t\t */\n> +\t\tif (prefixcmp(sp, \"%C(\"))\n> +\t\t\tparse_atom(sp + 2, ep);\n>  \t\tcp = ep + 1;\n>  \t}\n>  \treturn 0;\n> @@ -933,12 +940,20 @@ static void emit(const char *cp, const char *ep)\n>  static void show_ref(struct refinfo *info, const char *format, int quote_style)\n>  {\n>  \tconst char *cp, *sp, *ep;\n> +\tchar color[COLOR_MAXLEN] = \"\";\n>  \n>  \tfor (cp = format; *cp && (sp = find_next(cp)); cp = ep + 1) {\n>  \t\tep = strchr(sp, ')');\n>  \t\tif (cp < sp)\n>  \t\t\temit(cp, sp);\n> -\t\tprint_value(info, parse_atom(sp + 2, ep), quote_style);\n> +\n> +\t\t/* Do we have a color specification? */\n> +\t\tif (!prefixcmp(sp, \"%C(\"))\n> +\t\t\tcolor_parse_mem(sp + 3, ep - sp - 3, \"--format\", color);\n> +\t\telse {\n> +\t\t\tprintf(\"%s\", color);\n> +\t\t\tprint_value(info, parse_atom(sp + 2, ep), quote_style);\n> +\t\t}\n>  \t}\n>  \tif (*cp) {\n>  \t\tsp = cp + strlen(cp);\n"},{"id":"229996","messageId":"CALkWK0nEMpVUkzafjDkVV-uaLTYzHYUTsZkmwRPkLFa=8NEkPA@mail.gmail.com","threadId":"35255","inReplyTo":"xmqq38nh411p.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-11-01T08:37:56Z","receivedAt":"2013-11-01T08:37:56Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> Ramkumar Ramachandra <artagnon@gmail.com> writes:\n>\n>> Enhance 'git for-each-ref' with color formatting options.  You can now\n>> use the following format in for-each-ref:\n>>\n>>   %C(green)%(refname:short)%C(reset)\n>\n> So far, every magic for-each-ref takes were of form %(...); was\n> there a reason why this had to be %C(...), not %(color=blah), or\n> something more in-line with the existing other magic?\n\nIt is in-line with the color specification in pretty-formats. Would\nyou strongly prefer something else?\n"},{"id":"230005","messageId":"xmqqli182mde.fsf@gitster.dls.corp.google.com","threadId":"35255","inReplyTo":"CALkWK0nEMpVUkzafjDkVV-uaLTYzHYUTsZkmwRPkLFa=8NEkPA@mail.gmail.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-11-01T15:05:33Z","receivedAt":"2013-11-01T15:05:33Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>> Ramkumar Ramachandra <artagnon@gmail.com> writes:\n>>\n>>> Enhance 'git for-each-ref' with color formatting options.  You can now\n>>> use the following format in for-each-ref:\n>>>\n>>>   %C(green)%(refname:short)%C(reset)\n>>\n>> So far, every magic for-each-ref takes were of form %(...); was\n>> there a reason why this had to be %C(...), not %(color=blah), or\n>> something more in-line with the existing other magic?\n>\n> It is in-line with the color specification in pretty-formats. Would\n> you strongly prefer something else?\n\nThis patch is about for-each-ref and your series does not seem to\naim to unify it in any way with pretty-formats, so I would have\nexpected an enhancement in line with the former, not the latter.\n"},{"id":"230009","messageId":"xmqq61sc2g9w.fsf@gitster.dls.corp.google.com","threadId":"35255","inReplyTo":"1383212774-5232-4-git-send-email-artagnon@gmail.com","subject":"Re: [PATCH 3/3] for-each-ref: introduce %(upstream:track[short])","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-11-01T17:17:15Z","receivedAt":"2013-11-01T17:17:15Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"This patch needed on top of 3/3 for me to pass gcc cleanly.\n\n-- >8 --\nSubject: [PATCH] fixup! for-each-ref: introduce %(upstream:track[short])\n\nThe condition !prefixcmp(name, \"upstream\") must be true for the\nvariable \"branch\" to be reused, so the variable should be always set\nwhen it gets used, but GCC does not seem to realize this fact.\n---\n builtin/for-each-ref.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)\n\ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 7d5c174..871d86c 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -648,7 +648,7 @@ static void populate_value(struct refinfo *ref)\n \t\tint deref = 0;\n \t\tconst char *refname;\n \t\tconst char *formatp;\n-\t\tstruct branch *branch;\n+\t\tstruct branch *branch = NULL;\n \n \t\tif (*name == '*') {\n \t\t\tderef = 1;\n@@ -727,6 +727,7 @@ static void populate_value(struct refinfo *ref)\n \t\t\t} else if (!strcmp(formatp, \"trackshort\") &&\n \t\t\t\t!prefixcmp(name, \"upstream\")) {\n \n+\t\t\t\tassert(branch != NULL);\n \t\t\t\tstat_tracking_info(branch, &num_ours, &num_theirs);\n \t\t\t\tif (!num_ours && !num_theirs)\n \t\t\t\t\tv->s = \"=\";\n-- \n1.8.5-rc0-205-g5b7460b\n"},{"id":"230029","messageId":"CALkWK0k-8noAJbgzPx3NEx-ucUdZoS4VmqNCKjm3R_5eqFnR7w@mail.gmail.com","threadId":"35255","inReplyTo":"xmqqli182mde.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-11-02T06:02:29Z","receivedAt":"2013-11-02T06:02:29Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> This patch is about for-each-ref and your series does not seem to\n> aim to unify it in any way with pretty-formats, so I would have\n> expected an enhancement in line with the former, not the latter.\n\nWhile I might never attempt a unification again, there's no harm in\ngetting the formats to resemble each other in part; it's likely that\nusers of f-e-r format will be familiar with pretty-formats.\n"},{"id":"230081","messageId":"xmqqzjpkyqtf.fsf@gitster.dls.corp.google.com","threadId":"35255","inReplyTo":"CALkWK0k-8noAJbgzPx3NEx-ucUdZoS4VmqNCKjm3R_5eqFnR7w@mail.gmail.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-11-04T18:17:32Z","receivedAt":"2013-11-04T18:17:32Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>> This patch is about for-each-ref and your series does not seem to\n>> aim to unify it in any way with pretty-formats, so I would have\n>> expected an enhancement in line with the former, not the latter.\n>\n> While I might never attempt a unification again, there's no harm in\n> getting the formats to resemble each other in part.\n\nYes, but...\n\n> it's likely that\n> users of f-e-r format will be familiar with pretty-formats.\n\n... users of for-each-ref format will be _more_ familiar with\nformats used by for-each-ref, and it would make a lot more sense to\nkeep the syntactic resemblance between existing features to show\nmagic things in for-each-ref and the new feature to show color\n(which is merely one new \"magic\" to the vocabulary in the context of\nfor-each-ref), no?\n"},{"id":"230177","messageId":"CALkWK0k0wxoK-MZk-KXiUiUgxVBKQGROFJBZbRs2LjNLA9iopA@mail.gmail.com","threadId":"35255","inReplyTo":"xmqqzjpkyqtf.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-11-07T06:36:13Z","receivedAt":"2013-11-07T06:36:13Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> ... users of for-each-ref format will be _more_ familiar with\n> formats used by for-each-ref, and it would make a lot more sense to\n> keep the syntactic resemblance between existing features to show\n> magic things in for-each-ref and the new feature to show color\n> (which is merely one new \"magic\" to the vocabulary in the context of\n> for-each-ref), no?\n\nOkay, so what do you suggest in place of %C(...)?\n"},{"id":"230202","messageId":"xmqqvc045bvq.fsf@gitster.dls.corp.google.com","threadId":"35255","inReplyTo":"CALkWK0k0wxoK-MZk-KXiUiUgxVBKQGROFJBZbRs2LjNLA9iopA@mail.gmail.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-11-07T18:02:01Z","receivedAt":"2013-11-07T18:02:01Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> Junio C Hamano wrote:\n>> ... users of for-each-ref format will be _more_ familiar with\n>> formats used by for-each-ref, and it would make a lot more sense to\n>> keep the syntactic resemblance between existing features to show\n>> magic things in for-each-ref and the new feature to show color\n>> (which is merely one new \"magic\" to the vocabulary in the context of\n>> for-each-ref), no?\n>\n> Okay, so what do you suggest in place of %C(...)?\n\nIf %(authordate) is \"I want to see the author date here\", and\n%(authordate:short) is \"I want to see the author date here in the\nshort form\", you would expect \"I want colored output in green\" to be\nspelled as %(color:green), or something, perhaps?\n"},{"id":"230235","messageId":"CALkWK0=w1G2O_W1LnfstqzaMjOQ0GWqJXeeRN4ymfsvohQBfyA@mail.gmail.com","threadId":"35255","inReplyTo":"xmqqvc045bvq.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-11-08T12:14:47Z","receivedAt":"2013-11-08T12:14:47Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano wrote:\n> If %(authordate) is \"I want to see the author date here\", and\n> %(authordate:short) is \"I want to see the author date here in the\n> short form\", you would expect \"I want colored output in green\" to be\n> spelled as %(color:green), or something, perhaps?\n\nLast time, we almost managed a unification: tokens like %authordate in\nf-e-r correspond to tokens like %ae in pretty-formats; %C(...) is\ndifferent in that it doesn't actually output anything, but changes the\ncolor of tokens following it. While I'm not opposed to %(color:...), I\nwould prefer a color syntax that is different from other-token syntax,\nlike in pretty-formats.\n"},{"id":"230240","messageId":"xmqqppqaol6w.fsf@gitster.dls.corp.google.com","threadId":"35255","inReplyTo":"CALkWK0=w1G2O_W1LnfstqzaMjOQ0GWqJXeeRN4ymfsvohQBfyA@mail.gmail.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2013-11-08T17:30:31Z","receivedAt":"2013-11-08T17:30:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Ramkumar Ramachandra <artagnon@gmail.com> writes:\n\n> ... %C(...) is\n> different in that it doesn't actually output anything, but changes the\n> color of tokens following it. While I'm not opposed to %(color:...), I\n> would prefer a color syntax that is different from other-token syntax,\n> like in pretty-formats.\n\nYou may prefer it, but I do not see why users prefer to memorize\nthat a magic that consumes no display output columns uses a syntax\ndifferent from all the other magic introducers that follows %(name\nof the magic with string after colon to give more specifics to the\nmagic) syntax.\n\nIn all honesty, the %XY mnemonic syntax in pretty-format is a\nsyntactic disaster.  It is perfectly OK to have a set of often used\nshorthand, but because we started without a consistent long-hand, we\nended up with %Cred and %C(yellow), leading us to a nonsense like\nthis (try it yourself and weep):\n\n    $ git show -s --format='%CredAnd%CyellowAreNotTheSameColor'\n\nIt would have been much saner if we started from %(color:yellow),\n%(subject), etc., i.e. have a single long-hand magic introducer\n%(...), and added a set of often-used short-hands like %s.\n\nI am not opposed to unify the internal implementations and the\nexternal interfaces of pretty, for-each-ref and friends, but\nmodelling the external UI after the \"mnemonic only with ad hoc\nadditions\" mess the pretty-format uses is a huge mistake.\n"},{"id":"230463","messageId":"CALkWK0mz9PFce4F6xiDBeT+Cf=7Mihbb0fp9fa9WJJaMr5uH-g@mail.gmail.com","threadId":"35255","inReplyTo":"xmqqppqaol6w.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH 1/3] for-each-ref: introduce %C(...) for color","fromName":"Ramkumar Ramachandra","fromEmail":"artagnon@gmail.com","sentAt":"2013-11-12T03:38:31Z","receivedAt":"2013-11-12T03:38:31Z","isPatch":true,"sender":{"key":"r@artagnon.com","avatar":"https://avatars.githubusercontent.com/u/37226?v=4"},"body":"Junio C Hamano <gitster@pobox.com> wrote:\n>     $ git show -s --format='%CredAnd%CyellowAreNotTheSameColor'\n\nOuch, this is quite a disaster.\n\n> It would have been much saner if we started from %(color:yellow),\n> %(subject), etc., i.e. have a single long-hand magic introducer\n> %(...), and added a set of often-used short-hands like %s.\n>\n> I am not opposed to unify the internal implementations and the\n> external interfaces of pretty, for-each-ref and friends, but\n> modelling the external UI after the \"mnemonic only with ad hoc\n> additions\" mess the pretty-format uses is a huge mistake.\n\nOkay, I'm convinced; I'll rework the series to do %(color:...) and\nresubmit shortly.\n\nThanks.\n"}]}