{"thread":{"id":"22638","subject":"[PATCH] git-for-each-ref: add new field name \"symbolic\"","startedAt":"2010-02-13T05:55:18Z","lastAt":"2010-02-13T08:51:32Z","messageCount":3,"participants":["Larry D'Anna","Junio C Hamano","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"134407","messageId":"1266040518-11748-1-git-send-email-larry@elder-gods.org","threadId":"22638","inReplyTo":null,"subject":"[PATCH] git-for-each-ref: add new field name \"symbolic\"","fromName":"Larry D'Anna","fromEmail":"larry@elder-gods.org","sentAt":"2010-02-13T05:55:18Z","receivedAt":"2010-02-13T05:55:18Z","isPatch":true,"sender":{"key":"larry@elder-gods.org","avatar":"https://avatars.githubusercontent.com/u/3013304?v=4"},"body":"%(symbolic) will expand to \"true\" for symbolic refs, and \"false\" otherwise.\nThis is a lot faster than calling git-symbolic-ref on every single ref from your\nshell script.\n\nSigned-off-by: Larry D'Anna <larry@elder-gods.org>\n---\n Documentation/git-for-each-ref.txt |    3 +++\n builtin-for-each-ref.c             |    5 +++++\n 2 files changed, 8 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt\nindex 7e83288..c2a694f 100644\n--- a/Documentation/git-for-each-ref.txt\n+++ b/Documentation/git-for-each-ref.txt\n@@ -92,6 +92,9 @@ upstream::\n \tfrom the displayed ref. Respects `:short` in the same way as\n \t`refname` above.\n \n+symbolic::\n+\t\"true\" for symbolic refs, \"false\" 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 a5a83f1..fd6973e 100644\n--- a/builtin-for-each-ref.c\n+++ b/builtin-for-each-ref.c\n@@ -33,6 +33,7 @@ struct ref_sort {\n struct refinfo {\n \tchar *refname;\n \tunsigned char objectname[20];\n+\tint flag;\n \tstruct atom_value *value;\n };\n \n@@ -66,6 +67,7 @@ static struct {\n \t{ \"creatordate\", FIELD_TIME },\n \t{ \"subject\" },\n \t{ \"body\" },\n+\t{ \"symbolic\" },\n \t{ \"contents\" },\n \t{ \"upstream\" },\n };\n@@ -576,6 +578,8 @@ static void populate_value(struct refinfo *ref)\n \n \t\tif (!prefixcmp(name, \"refname\"))\n \t\t\trefname = ref->refname;\n+\t\telse if (!prefixcmp(name, \"symbolic\"))\n+\t\t\trefname = (ref->flag & REF_ISSYMREF) ? \"true\" : \"false\";\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@@ -716,6 +720,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f\n \t * by maxcount logic.\n \t */\n \tref = xcalloc(1, sizeof(*ref));\n+\tref->flag = flag;\n \tref->refname = xstrdup(refname);\n \thashcpy(ref->objectname, sha1);\n \n-- \n1.7.0.rc2.40.g7d8aa\n"},{"id":"134413","messageId":"7v4ollshn5.fsf@alter.siamese.dyndns.org","threadId":"22638","inReplyTo":"1266040518-11748-1-git-send-email-larry@elder-gods.org","subject":"Re: [PATCH] git-for-each-ref: add new field name \"symbolic\"","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-02-13T07:45:50Z","receivedAt":"2010-02-13T07:45:50Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Larry D'Anna <larry@elder-gods.org> writes:\n\n> %(symbolic) will expand to \"true\" for symbolic refs, and \"false\" otherwise.\n> This is a lot faster than calling git-symbolic-ref on every single ref from your\n> shell script.\n\nI think this is a good idea, but I suspect that much more than half of\npeople who iterate over for-each-ref output and run symbolic-ref would\nactually want to learn what actual ref a symbolic one points at.  So you\nmay not be helping as much people as you could by going in this direction.\n\nInstead of expanding to \"true\", why not make it show the expansion if it\nis symbolic, and to empty if it is not?\n"},{"id":"134414","messageId":"20100213085132.GA13181@coredump.intra.peff.net","threadId":"22638","inReplyTo":"7v4ollshn5.fsf@alter.siamese.dyndns.org","subject":"Re: [PATCH] git-for-each-ref: add new field name \"symbolic\"","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2010-02-13T08:51:32Z","receivedAt":"2010-02-13T08:51:32Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Fri, Feb 12, 2010 at 11:45:50PM -0800, Junio C Hamano wrote:\n\n> Larry D'Anna <larry@elder-gods.org> writes:\n> \n> > %(symbolic) will expand to \"true\" for symbolic refs, and \"false\" otherwise.\n> > This is a lot faster than calling git-symbolic-ref on every single ref from your\n> > shell script.\n> \n> I think this is a good idea, but I suspect that much more than half of\n> people who iterate over for-each-ref output and run symbolic-ref would\n> actually want to learn what actual ref a symbolic one points at.  So you\n> may not be helping as much people as you could by going in this direction.\n> \n> Instead of expanding to \"true\", why not make it show the expansion if it\n> is symbolic, and to empty if it is not?\n\nThat was my first thought, too. Unfortunately it needs some pretty heavy\nrefactoring of the for_each_ref call chain, as we throw away the\ndereferenced ref name at the very bottom.\n\nSo while I would be in favor of a real \"%(symbolic)\" as you describe, it\nis significantly more work. If we are just going to do a flag check,\nthough, I would much rather see it called \"%(issymbolic)\" or something\nso that \"%(symbolic)\" can be used later for the actual value.\n\nOne other alternative would be to simply expose \"%(flags)\" which would\nexpand to nothing, \"symbolic\", \"packed\", or \"symbolic,packed\".\n\n-Peff\n"}]}