* [PATCH] Allow --pretty to be passed to git-describe.
@ 2014-03-25 1:04 Cyril Roelandt
2014-03-25 5:04 ` Junio C Hamano
2014-03-25 5:50 ` Eric Sunshine
0 siblings, 2 replies; 3+ messages in thread
From: Cyril Roelandt @ 2014-03-25 1:04 UTC (permalink / raw)
To: git; +Cc: Cyril Roelandt
In some cases, ony may want to find the the most recent tag that is reachable
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@gmail.com>
---
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
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH] Allow --pretty to be passed to git-describe.
2014-03-25 1:04 [PATCH] Allow --pretty to be passed to git-describe Cyril Roelandt
@ 2014-03-25 5:04 ` Junio C Hamano
2014-03-25 5:50 ` Eric Sunshine
1 sibling, 0 replies; 3+ messages in thread
From: Junio C Hamano @ 2014-03-25 5:04 UTC (permalink / raw)
To: Cyril Roelandt; +Cc: git
Cyril Roelandt <tipecaml@gmail.com> writes:
> In some cases, ony may want to find the the most recent tag that is reachable
> from a commit and have it pretty printed, using the formatting options available
> in git-log and git-show.
Sorry, but I do not understand the motivation I can read from these
three lines well enough to say that such a change makes any sense.
It somewhat sounds similar to adding a "--long" option to "git show"
so that "git show --long v1.9.0" will act as if it were running a
"git log v1.9.0". Yes, you can add any option to tell a command to
do something that is usually considered to be a task for some other
command, but does it even make sense to do so in the first place?
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] Allow --pretty to be passed to git-describe.
2014-03-25 1:04 [PATCH] Allow --pretty to be passed to git-describe Cyril Roelandt
2014-03-25 5:04 ` Junio C Hamano
@ 2014-03-25 5:50 ` Eric Sunshine
1 sibling, 0 replies; 3+ messages in thread
From: Eric Sunshine @ 2014-03-25 5:50 UTC (permalink / raw)
To: Cyril Roelandt; +Cc: Git List
On Mon, Mar 24, 2014 at 9:04 PM, Cyril Roelandt <tipecaml@gmail.com> 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@gmail.com>
> ---
> 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@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-03-25 5:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-03-25 1:04 [PATCH] Allow --pretty to be passed to git-describe Cyril Roelandt
2014-03-25 5:04 ` Junio C Hamano
2014-03-25 5:50 ` Eric Sunshine
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox