Re: [PATCH] Allow --pretty to be passed to git-describe.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Mar 24, 2014 at 9:04 PM, Cyril Roelandt <tipecaml@xxxxxxxxx> wrote:
> In some cases, ony may want to find the the most recent tag that is reachable

s/ony/one/

> from a commit and have it pretty printed, using the formatting options available
> in git-log and git-show.
>
> Signed-off-by: Cyril Roelandt <tipecaml@xxxxxxxxx>
> ---
>  Documentation/git-describe.txt |  4 ++++
>  builtin/describe.c             | 39 ++++++++++++++++++++++++++++++++++-----
>  2 files changed, 38 insertions(+), 5 deletions(-)
>
> diff --git a/Documentation/git-describe.txt b/Documentation/git-describe.txt
> index d20ca40..fae4713 100644
> --- a/Documentation/git-describe.txt
> +++ b/Documentation/git-describe.txt
> @@ -93,6 +93,10 @@ OPTIONS
>         This is useful when you wish to not match tags on branches merged
>         in the history of the target commit.
>
> +include::pretty-options.txt[]
> +
> +include::pretty-formats.txt[]
> +
>  EXAMPLES
>  --------
>
> diff --git a/builtin/describe.c b/builtin/describe.c
> index 24d740c..4c0ebae 100644
> --- a/builtin/describe.c
> +++ b/builtin/describe.c
> @@ -8,8 +8,8 @@
>  #include "diff.h"
>  #include "hashmap.h"
>  #include "argv-array.h"
> +#include "revision.h"
>
> -#define SEEN           (1u << 0)
>  #define MAX_TAGS       (FLAG_BITS - 1)
>
>  static const char * const describe_usage[] = {
> @@ -30,6 +30,8 @@ static int have_util;
>  static const char *pattern;
>  static int always;
>  static const char *dirty;
> +static const char *fmt_pretty;
> +static enum cmit_fmt commit_format;
>
>  /* diff-index command arguments to check if working tree is dirty. */
>  static const char *diff_index_args[] = {
> @@ -266,8 +268,14 @@ static void describe(const char *arg, int last_one)
>                  * Exact match to an existing ref.
>                  */
>                 display_name(n);
> -               if (longformat)
> +               if (longformat) {
>                         show_suffix(0, n->tag ? n->tag->tagged->sha1 : sha1);
> +               } else if (fmt_pretty) {
> +                       struct strbuf buf = STRBUF_INIT;
> +                       pp_commit_easy(commit_format, cmit, &buf);
> +                       printf("%s", buf.buf);
> +                       strbuf_release(&buf);
> +               }
>                 if (dirty)
>                         printf("%s", dirty);
>                 printf("\n");
> @@ -386,9 +394,16 @@ static void describe(const char *arg, int last_one)
>                 }
>         }
>
> -       display_name(all_matches[0].name);
> -       if (abbrev)
> -               show_suffix(all_matches[0].depth, cmit->object.sha1);
> +       if (fmt_pretty) {
> +               struct strbuf buf = STRBUF_INIT;
> +               pp_commit_easy(commit_format, cmit, &buf);
> +               printf("%s", buf.buf);
> +               strbuf_release(&buf);
> +       } else {
> +               display_name(all_matches[0].name);
> +               if (abbrev)
> +                       show_suffix(all_matches[0].depth, cmit->object.sha1);
> +       }
>         if (dirty)
>                 printf("%s", dirty);
>         printf("\n");
> @@ -419,6 +434,10 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
>                 {OPTION_STRING, 0, "dirty",  &dirty, N_("mark"),
>                         N_("append <mark> on dirty working tree (default: \"-dirty\")"),
>                         PARSE_OPT_OPTARG, NULL, (intptr_t) "-dirty"},
> +               OPT_STRING(0, "pretty",      &fmt_pretty, N_("pattern"),
> +                          N_("pretty print")),
> +               OPT_STRING(0, "format",      &fmt_pretty, N_("pattern"),
> +                          N_("pretty print")),
>                 OPT_END(),
>         };
>
> @@ -437,6 +456,9 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
>         if (longformat && abbrev == 0)
>                 die(_("--long is incompatible with --abbrev=0"));
>
> +       if (longformat && fmt_pretty)
> +               die(_("--long is incompatible with --pretty"));
> +
>         if (contains) {
>                 struct argv_array args;
>
> @@ -458,6 +480,13 @@ int cmd_describe(int argc, const char **argv, const char *prefix)
>                 return cmd_name_rev(args.argc, args.argv, prefix);
>         }
>
> +       if (fmt_pretty) {
> +               struct rev_info rev;
> +               init_revisions(&rev, prefix);
> +               get_commit_format(fmt_pretty, &rev);
> +               commit_format = rev.commit_format;
> +       }
> +
>         hashmap_init(&names, (hashmap_cmp_fn) commit_name_cmp, 0);
>         for_each_rawref(get_name, NULL);
>         if (!names.size && !always)
> --
> 1.9.1
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@xxxxxxxxxxxxxxx
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]