Skip to contentSkip to conversation

Allow --pretty to be passed to git-describe.

PATCH In review Cyril Roelandt 3 participants 3 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Allow --pretty to be passed to git-describe.

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.

---
 Documentation/git-describe.txt |  4 ++++
 builtin/describe.c             | 39 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 38 insertions(+), 5 deletions(-)
Documentation/git-describe.txt +4 -0
index d20ca40..fae4713 100644
@@ -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
 --------
 
builtin/describe.c +34 -5
index 24d740c..4c0ebae 100644
@@ -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)
Signature · 1 line
1.9.1
#1 lore raw
Quoted 3 lines · 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.

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?

#2 lore raw
In reply to Cyril Roelandt
Quoted 1 line · Cyril Roelandt

In some cases, ony may want to find the the most recent tag that is reachable

s/ony/one/

Quoted 125 lines

from a commit and have it pretty printed, using the formatting options available in git-log and git-show.

---
 Documentation/git-describe.txt |  4 ++++
 builtin/describe.c             | 39 ++++++++++++++++++++++++++++++++++-----
 2 files changed, 38 insertions(+), 5 deletions(-)
Documentation/git-describe.txt +4 -0
index d20ca40..fae4713 100644
@@ -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
 --------
 
builtin/describe.c +34 -6
index 24d740c..4c0ebae 100644
@@ -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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html