{"thread":{"id":"36287","subject":"[PATCH] Allow --pretty to be passed to git-describe.","startedAt":"2014-03-25T01:04:04Z","lastAt":"2014-03-25T05:50:35Z","messageCount":3,"participants":["Cyril Roelandt","Junio C Hamano","Eric Sunshine"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"237522","messageId":"1395709444-11220-1-git-send-email-tipecaml@gmail.com","threadId":"36287","inReplyTo":null,"subject":"[PATCH] Allow --pretty to be passed to git-describe.","fromName":"Cyril Roelandt","fromEmail":"tipecaml@gmail.com","sentAt":"2014-03-25T01:04:04Z","receivedAt":"2014-03-25T01:04:04Z","isPatch":true,"sender":{"key":"tipecaml@gmail.com","avatar":null},"body":"In some cases, ony may want to find the the most recent tag that is reachable\nfrom a commit and have it pretty printed, using the formatting options available\nin git-log and git-show.\n\nSigned-off-by: Cyril Roelandt <tipecaml@gmail.com>\n---\n Documentation/git-describe.txt |  4 ++++\n builtin/describe.c             | 39 ++++++++++++++++++++++++++++++++++-----\n 2 files changed, 38 insertions(+), 5 deletions(-)\n\ndiff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt\nindex d20ca40..fae4713 100644\n--- a/Documentation/git-describe.txt\n+++ b/Documentation/git-describe.txt\n@@ -93,6 +93,10 @@ OPTIONS\n \tThis is useful when you wish to not match tags on branches merged\n \tin the history of the target commit.\n \n+include::pretty-options.txt[]\n+\n+include::pretty-formats.txt[]\n+\n EXAMPLES\n --------\n \ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 24d740c..4c0ebae 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -8,8 +8,8 @@\n #include \"diff.h\"\n #include \"hashmap.h\"\n #include \"argv-array.h\"\n+#include \"revision.h\"\n \n-#define SEEN\t\t(1u << 0)\n #define MAX_TAGS\t(FLAG_BITS - 1)\n \n static const char * const describe_usage[] = {\n@@ -30,6 +30,8 @@ static int have_util;\n static const char *pattern;\n static int always;\n static const char *dirty;\n+static const char *fmt_pretty;\n+static enum cmit_fmt commit_format;\n \n /* diff-index command arguments to check if working tree is dirty. */\n static const char *diff_index_args[] = {\n@@ -266,8 +268,14 @@ static void describe(const char *arg, int last_one)\n \t\t * Exact match to an existing ref.\n \t\t */\n \t\tdisplay_name(n);\n-\t\tif (longformat)\n+\t\tif (longformat) {\n \t\t\tshow_suffix(0, n->tag ? n->tag->tagged->sha1 : sha1);\n+\t\t} else if (fmt_pretty) {\n+\t\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\t\tpp_commit_easy(commit_format, cmit, &buf);\n+\t\t\tprintf(\"%s\", buf.buf);\n+\t\t\tstrbuf_release(&buf);\n+\t\t}\n \t\tif (dirty)\n \t\t\tprintf(\"%s\", dirty);\n \t\tprintf(\"\\n\");\n@@ -386,9 +394,16 @@ static void describe(const char *arg, int last_one)\n \t\t}\n \t}\n \n-\tdisplay_name(all_matches[0].name);\n-\tif (abbrev)\n-\t\tshow_suffix(all_matches[0].depth, cmit->object.sha1);\n+\tif (fmt_pretty) {\n+\t\tstruct strbuf buf = STRBUF_INIT;\n+\t\tpp_commit_easy(commit_format, cmit, &buf);\n+\t\tprintf(\"%s\", buf.buf);\n+\t\tstrbuf_release(&buf);\n+\t} else {\n+\t\tdisplay_name(all_matches[0].name);\n+\t\tif (abbrev)\n+\t\t\tshow_suffix(all_matches[0].depth, cmit->object.sha1);\n+\t}\n \tif (dirty)\n \t\tprintf(\"%s\", dirty);\n \tprintf(\"\\n\");\n@@ -419,6 +434,10 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\t{OPTION_STRING, 0, \"dirty\",  &dirty, N_(\"mark\"),\n \t\t\tN_(\"append <mark> on dirty working tree (default: \\\"-dirty\\\")\"),\n \t\t\tPARSE_OPT_OPTARG, NULL, (intptr_t) \"-dirty\"},\n+\t\tOPT_STRING(0, \"pretty\",      &fmt_pretty, N_(\"pattern\"),\n+\t\t\t   N_(\"pretty print\")),\n+\t\tOPT_STRING(0, \"format\",      &fmt_pretty, N_(\"pattern\"),\n+\t\t\t   N_(\"pretty print\")),\n \t\tOPT_END(),\n \t};\n \n@@ -437,6 +456,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \tif (longformat && abbrev == 0)\n \t\tdie(_(\"--long is incompatible with --abbrev=0\"));\n \n+\tif (longformat && fmt_pretty)\n+\t\tdie(_(\"--long is incompatible with --pretty\"));\n+\n \tif (contains) {\n \t\tstruct argv_array args;\n \n@@ -458,6 +480,13 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n \t\treturn cmd_name_rev(args.argc, args.argv, prefix);\n \t}\n \n+\tif (fmt_pretty) {\n+\t\tstruct rev_info rev;\n+\t\tinit_revisions(&rev, prefix);\n+\t\tget_commit_format(fmt_pretty, &rev);\n+\t\tcommit_format = rev.commit_format;\n+\t}\n+\n \thashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0);\n \tfor_each_rawref(get_name, NULL);\n \tif (!names.size && !always)\n-- \n1.9.1\n"},{"id":"237526","messageId":"7vy4zyoom2.fsf@alter.siamese.dyndns.org","threadId":"36287","inReplyTo":"1395709444-11220-1-git-send-email-tipecaml@gmail.com","subject":"Re: [PATCH] Allow --pretty to be passed to git-describe.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-03-25T05:04:37Z","receivedAt":"2014-03-25T05:04:37Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Cyril Roelandt <tipecaml@gmail.com> writes:\n\n> In some cases, ony may want to find the the most recent tag that is reachable\n> from a commit and have it pretty printed, using the formatting options available\n> in git-log and git-show.\n\nSorry, but I do not understand the motivation I can read from these\nthree lines well enough to say that such a change makes any sense.\n\nIt somewhat sounds similar to adding a \"--long\" option to \"git show\"\nso that \"git show --long v1.9.0\" will act as if it were running a\n\"git log v1.9.0\".  Yes, you can add any option to tell a command to\ndo something that is usually considered to be a task for some other\ncommand, but does it even make sense to do so in the first place?\n"},{"id":"237527","messageId":"CAPig+cTXSt7V2MkoXBxrs+L+=xzzqRqM4VTvZAju9ES4t901qg@mail.gmail.com","threadId":"36287","inReplyTo":"1395709444-11220-1-git-send-email-tipecaml@gmail.com","subject":"Re: [PATCH] Allow --pretty to be passed to git-describe.","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2014-03-25T05:50:35Z","receivedAt":"2014-03-25T05:50:35Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Mar 24, 2014 at 9:04 PM, Cyril Roelandt <tipecaml@gmail.com> wrote:\n> In some cases, ony may want to find the the most recent tag that is reachable\n\ns/ony/one/\n\n> from a commit and have it pretty printed, using the formatting options available\n> in git-log and git-show.\n>\n> Signed-off-by: Cyril Roelandt <tipecaml@gmail.com>\n> ---\n>  Documentation/git-describe.txt |  4 ++++\n>  builtin/describe.c             | 39 ++++++++++++++++++++++++++++++++++-----\n>  2 files changed, 38 insertions(+), 5 deletions(-)\n>\n> diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt\n> index d20ca40..fae4713 100644\n> --- a/Documentation/git-describe.txt\n> +++ b/Documentation/git-describe.txt\n> @@ -93,6 +93,10 @@ OPTIONS\n>         This is useful when you wish to not match tags on branches merged\n>         in the history of the target commit.\n>\n> +include::pretty-options.txt[]\n> +\n> +include::pretty-formats.txt[]\n> +\n>  EXAMPLES\n>  --------\n>\n> diff --git a/builtin/describe.c b/builtin/describe.c\n> index 24d740c..4c0ebae 100644\n> --- a/builtin/describe.c\n> +++ b/builtin/describe.c\n> @@ -8,8 +8,8 @@\n>  #include \"diff.h\"\n>  #include \"hashmap.h\"\n>  #include \"argv-array.h\"\n> +#include \"revision.h\"\n>\n> -#define SEEN           (1u << 0)\n>  #define MAX_TAGS       (FLAG_BITS - 1)\n>\n>  static const char * const describe_usage[] = {\n> @@ -30,6 +30,8 @@ static int have_util;\n>  static const char *pattern;\n>  static int always;\n>  static const char *dirty;\n> +static const char *fmt_pretty;\n> +static enum cmit_fmt commit_format;\n>\n>  /* diff-index command arguments to check if working tree is dirty. */\n>  static const char *diff_index_args[] = {\n> @@ -266,8 +268,14 @@ static void describe(const char *arg, int last_one)\n>                  * Exact match to an existing ref.\n>                  */\n>                 display_name(n);\n> -               if (longformat)\n> +               if (longformat) {\n>                         show_suffix(0, n->tag ? n->tag->tagged->sha1 : sha1);\n> +               } else if (fmt_pretty) {\n> +                       struct strbuf buf = STRBUF_INIT;\n> +                       pp_commit_easy(commit_format, cmit, &buf);\n> +                       printf(\"%s\", buf.buf);\n> +                       strbuf_release(&buf);\n> +               }\n>                 if (dirty)\n>                         printf(\"%s\", dirty);\n>                 printf(\"\\n\");\n> @@ -386,9 +394,16 @@ static void describe(const char *arg, int last_one)\n>                 }\n>         }\n>\n> -       display_name(all_matches[0].name);\n> -       if (abbrev)\n> -               show_suffix(all_matches[0].depth, cmit->object.sha1);\n> +       if (fmt_pretty) {\n> +               struct strbuf buf = STRBUF_INIT;\n> +               pp_commit_easy(commit_format, cmit, &buf);\n> +               printf(\"%s\", buf.buf);\n> +               strbuf_release(&buf);\n> +       } else {\n> +               display_name(all_matches[0].name);\n> +               if (abbrev)\n> +                       show_suffix(all_matches[0].depth, cmit->object.sha1);\n> +       }\n>         if (dirty)\n>                 printf(\"%s\", dirty);\n>         printf(\"\\n\");\n> @@ -419,6 +434,10 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n>                 {OPTION_STRING, 0, \"dirty\",  &dirty, N_(\"mark\"),\n>                         N_(\"append <mark> on dirty working tree (default: \\\"-dirty\\\")\"),\n>                         PARSE_OPT_OPTARG, NULL, (intptr_t) \"-dirty\"},\n> +               OPT_STRING(0, \"pretty\",      &fmt_pretty, N_(\"pattern\"),\n> +                          N_(\"pretty print\")),\n> +               OPT_STRING(0, \"format\",      &fmt_pretty, N_(\"pattern\"),\n> +                          N_(\"pretty print\")),\n>                 OPT_END(),\n>         };\n>\n> @@ -437,6 +456,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n>         if (longformat && abbrev == 0)\n>                 die(_(\"--long is incompatible with --abbrev=0\"));\n>\n> +       if (longformat && fmt_pretty)\n> +               die(_(\"--long is incompatible with --pretty\"));\n> +\n>         if (contains) {\n>                 struct argv_array args;\n>\n> @@ -458,6 +480,13 @@ int cmd_describe(int argc, const char **argv, const char *prefix)\n>                 return cmd_name_rev(args.argc, args.argv, prefix);\n>         }\n>\n> +       if (fmt_pretty) {\n> +               struct rev_info rev;\n> +               init_revisions(&rev, prefix);\n> +               get_commit_format(fmt_pretty, &rev);\n> +               commit_format = rev.commit_format;\n> +       }\n> +\n>         hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0);\n>         for_each_rawref(get_name, NULL);\n>         if (!names.size && !always)\n> --\n> 1.9.1\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"}]}