{"thread":{"id":"40104","subject":"[PATCH v11 12/13] tag.c: implement '--format' option","startedAt":"2015-08-15T18:00:42Z","lastAt":"2015-08-17T21:38:33Z","messageCount":4,"participants":["Karthik Nayak","Junio C Hamano","Jacob Keller"],"isPatch":true,"patchVersion":11,"patchTotal":13},"messages":[{"id":"268135","messageId":"1439661643-16094-13-git-send-email-Karthik.188@gmail.com","threadId":"40104","inReplyTo":null,"subject":"[PATCH v11 12/13] tag.c: implement '--format' option","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2015-08-15T18:00:42Z","receivedAt":"2015-08-15T18:00:42Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"From: Karthik Nayak <karthik.188@gmail.com>\n\nImplement the '--format' option provided by 'ref-filter'.\nThis lets the user list tags as per desired format similar\nto the implementation in 'git for-each-ref'.\n\nAdd tests and documentation for the same.\n\nMentored-by: Christian Couder <christian.couder@gmail.com>\nMentored-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr>\nSigned-off-by: Karthik Nayak <karthik.188@gmail.com>\n---\n Documentation/git-tag.txt | 15 ++++++++++++++-\n builtin/tag.c             | 11 +++++++----\n t/t7004-tag.sh            | 16 ++++++++++++++++\n 3 files changed, 37 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt\nindex 3ac4a96..75703c5 100644\n--- a/Documentation/git-tag.txt\n+++ b/Documentation/git-tag.txt\n@@ -13,7 +13,8 @@ SYNOPSIS\n \t<tagname> [<commit> | <object>]\n 'git tag' -d <tagname>...\n 'git tag' [-n[<num>]] -l [--contains <commit>] [--points-at <object>]\n-\t[--column[=<options>] | --no-column] [--create-reflog] [--sort=<key>] [<pattern>...]\n+\t[--column[=<options>] | --no-column] [--create-reflog] [--sort=<key>]\n+\t[--format=<format>] [<pattern>...]\n 'git tag' -v <tagname>...\n \n DESCRIPTION\n@@ -158,6 +159,18 @@ This option is only applicable when listing tags without annotation lines.\n \tThe object that the new tag will refer to, usually a commit.\n \tDefaults to HEAD.\n \n+<format>::\n+\tA string that interpolates `%(fieldname)` from the object\n+\tpointed at by a ref being shown.  If `fieldname` is prefixed\n+\twith an asterisk (`*`) and the ref points at a tag object, the\n+\tvalue for the field in the object tag refers is used.  When\n+\tunspecified, defaults to `%(refname:short)`.  It also\n+\tinterpolates `%%` to `%`, and `%xx` where `xx` are hex digits\n+\tinterpolates to character with hex code `xx`; for example\n+\t`%00` interpolates to `\\0` (NUL), `%09` to `\\t` (TAB) and\n+\t`%0a` to `\\n` (LF).  The fields are same as those in `git\n+\tfor-each-ref`.\n+\n \n CONFIGURATION\n -------------\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 501fc52..69997a4 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -30,10 +30,9 @@ static const char * const git_tag_usage[] = {\n \n static unsigned int colopts;\n \n-static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting)\n+static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting, const char *format)\n {\n \tstruct ref_array array;\n-\tchar *format;\n \tint i;\n \n \tmemset(&array, 0, sizeof(array));\n@@ -43,7 +42,7 @@ static int list_tags(struct ref_filter *filter, struct ref_sorting *sorting)\n \n \tif (filter->lines)\n \t\tformat = \"%(align:16,left)%(refname:short)%(end)\";\n-\telse\n+\telse if (!format)\n \t\tformat = \"%(refname:short)\";\n \n \tverify_ref_format(format);\n@@ -327,6 +326,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \tstruct strbuf err = STRBUF_INIT;\n \tstruct ref_filter filter;\n \tstatic struct ref_sorting *sorting = NULL, **sorting_tail = &sorting;\n+\tconst char *format = NULL;\n \tstruct option options[] = {\n \t\tOPT_CMDMODE('l', \"list\", &cmdmode, N_(\"list tag names\"), 'l'),\n \t\t{ OPTION_INTEGER, 'n', NULL, &filter.lines, N_(\"n\"),\n@@ -359,6 +359,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\t\tOPTION_CALLBACK, 0, \"points-at\", &filter.points_at, N_(\"object\"),\n \t\t\tN_(\"print only tags of the object\"), 0, parse_opt_object_name\n \t\t},\n+\t\tOPT_STRING(  0 , \"format\", &format, N_(\"format\"), N_(\"format to use for the output\")),\n \t\tOPT_END()\n \t};\n \n@@ -398,8 +399,10 @@ int cmd_tag(int argc, const char **argv, const char *prefix)\n \t\t\tcopts.padding = 2;\n \t\t\trun_column_filter(colopts, &copts);\n \t\t}\n+\t\tif (format && (filter.lines != -1))\n+\t\t\tdie(_(\"--format and -n are incompatible\"));\n \t\tfilter.name_patterns = argv;\n-\t\tret = list_tags(&filter, sorting);\n+\t\tret = list_tags(&filter, sorting, format);\n \t\tif (column_active(colopts))\n \t\t\tstop_column_filter();\n \t\treturn ret;\ndiff --git a/t/t7004-tag.sh b/t/t7004-tag.sh\nindex 1f066aa..1809011 100755\n--- a/t/t7004-tag.sh\n+++ b/t/t7004-tag.sh\n@@ -1519,4 +1519,20 @@ EOF\"\n \ttest_cmp expect actual\n '\n \n+test_expect_success '--format cannot be used with -n' '\n+\ttest_must_fail git tag -l -n4 --format=\"%(refname)\"\n+'\n+\n+test_expect_success '--format should list tags as per format given' '\n+\tcat >expect <<-\\EOF &&\n+\trefname : refs/tags/foo1.10\n+\trefname : refs/tags/foo1.3\n+\trefname : refs/tags/foo1.6\n+\trefname : refs/tags/foo1.6-rc1\n+\trefname : refs/tags/foo1.6-rc2\n+\tEOF\n+\tgit tag -l --format=\"refname : %(refname)\" \"foo*\" >actual &&\n+\ttest_cmp expect actual\n+'\n+\n test_done\n-- \n2.5.0\n"},{"id":"268207","messageId":"xmqqwpwtd9d0.fsf@gitster.dls.corp.google.com","threadId":"40104","inReplyTo":"1439661643-16094-13-git-send-email-Karthik.188@gmail.com","subject":"Re: [PATCH v11 12/13] tag.c: implement '--format' option","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2015-08-17T19:04:59Z","receivedAt":"2015-08-17T19:04:59Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Karthik Nayak <karthik.188@gmail.com> writes:\n\n> From: Karthik Nayak <karthik.188@gmail.com>\n>\n> Implement the '--format' option provided by 'ref-filter'.\n> This lets the user list tags as per desired format similar\n> to the implementation in 'git for-each-ref'.\n>\n> Add tests and documentation for the same.\n\nHmm, do we want \"--format\" added to \"tag -l\" and \"branch -l\" in the\nfirst place?  Scriptors should be using \"for-each-ref\" plumbing in\nthe first place, and the point of unifying these three is to share\nfiltering features among them, which would make \"for-each-ref\" able\nto express what the other two can do.  I'd hesitate to add too much\nflexibility to \"branch -l\" and \"tag -l\" Porcelains to entice people\nto script around them.\n"},{"id":"268210","messageId":"CAOLa=ZSvJ7WO9XADUtZkm=QK6S3n1KRcG4nLpPLKnZUxQ+BrJQ@mail.gmail.com","threadId":"40104","inReplyTo":"xmqqwpwtd9d0.fsf@gitster.dls.corp.google.com","subject":"Re: [PATCH v11 12/13] tag.c: implement '--format' option","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2015-08-17T19:14:08Z","receivedAt":"2015-08-17T19:14:08Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"On Tue, Aug 18, 2015 at 12:34 AM, Junio C Hamano <gitster@pobox.com> wrote:\n> Karthik Nayak <karthik.188@gmail.com> writes:\n>\n>> From: Karthik Nayak <karthik.188@gmail.com>\n>>\n>> Implement the '--format' option provided by 'ref-filter'.\n>> This lets the user list tags as per desired format similar\n>> to the implementation in 'git for-each-ref'.\n>>\n>> Add tests and documentation for the same.\n>\n> Hmm, do we want \"--format\" added to \"tag -l\" and \"branch -l\" in the\n> first place?  Scriptors should be using \"for-each-ref\" plumbing in\n> the first place, and the point of unifying these three is to share\n> filtering features among them, which would make \"for-each-ref\" able\n> to express what the other two can do.  I'd hesitate to add too much\n> flexibility to \"branch -l\" and \"tag -l\" Porcelains to entice people\n> to script around them.\n>\n\nI'll leave that decision to you, but I see it as a good feature, when perhaps\nI just want to list tags with authors. Agreed `for-each-ref` can handle this too\nbut I don't see why `tag -l` shouldn't.\n\n-- \nRegards,\nKarthik Nayak\n"},{"id":"268231","messageId":"CA+P7+xr5C2DfAKtb-BDKUGW=4LB4ZRfO6wg=N-8APVNaCEgR5Q@mail.gmail.com","threadId":"40104","inReplyTo":"CAOLa=ZSvJ7WO9XADUtZkm=QK6S3n1KRcG4nLpPLKnZUxQ+BrJQ@mail.gmail.com","subject":"Re: [PATCH v11 12/13] tag.c: implement '--format' option","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2015-08-17T21:38:33Z","receivedAt":"2015-08-17T21:38:33Z","isPatch":true,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"On Mon, Aug 17, 2015 at 12:14 PM, Karthik Nayak <karthik.188@gmail.com> wrote:\n> On Tue, Aug 18, 2015 at 12:34 AM, Junio C Hamano <gitster@pobox.com> wrote:\n>> Karthik Nayak <karthik.188@gmail.com> writes:\n>>\n>>> From: Karthik Nayak <karthik.188@gmail.com>\n>>>\n>>> Implement the '--format' option provided by 'ref-filter'.\n>>> This lets the user list tags as per desired format similar\n>>> to the implementation in 'git for-each-ref'.\n>>>\n>>> Add tests and documentation for the same.\n>>\n>> Hmm, do we want \"--format\" added to \"tag -l\" and \"branch -l\" in the\n>> first place?  Scriptors should be using \"for-each-ref\" plumbing in\n>> the first place, and the point of unifying these three is to share\n>> filtering features among them, which would make \"for-each-ref\" able\n>> to express what the other two can do.  I'd hesitate to add too much\n>> flexibility to \"branch -l\" and \"tag -l\" Porcelains to entice people\n>> to script around them.\n>>\n>\n> I'll leave that decision to you, but I see it as a good feature, when perhaps\n> I just want to list tags with authors. Agreed `for-each-ref` can handle this too\n> but I don't see why `tag -l` shouldn't.\n>\n> --\n> Regards,\n> Karthik Nayak\n\nI agree with Karthik,it doesn't really hurt to add it to tag, and will\nallow users who aren't familiar with for-each-ref to be able to get\nthe --format for some use cases. I think it would increase visibility\nand use of the format option if it's available on tag and branch.\n\nRegards,\nJake\n"}]}