Merge branch 'hj/pretty-naked-decoration'
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Sep 2014 19:36:08 +0000 (12:36 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Sep 2014 19:36:09 +0000 (12:36 -0700)
The pretty-format specifier "%d", which expanded to " (tagname)"
for a tagged commit, gained a cousin "%D" that just gives the
"tagname" without frills.

* hj/pretty-naked-decoration:
pretty: add %D format specifier

Documentation/pretty-formats.txt
log-tree.c
log-tree.h
pretty.c
t/t4205-log-pretty-formats.sh
index 6c30723740cff5d88d3696f45e2325bc565e5f4a..eecc39dec99b3cab3da3e36440653ea46ac762b9 100644 (file)
@@ -130,6 +130,7 @@ The placeholders are:
 - '%ci': committer date, ISO 8601-like format
 - '%cI': committer date, strict ISO 8601 format
 - '%d': ref names, like the --decorate option of linkgit:git-log[1]
+- '%D': ref names without the " (", ")" wrapping.
 - '%e': encoding
 - '%s': subject
 - '%f': sanitized subject line, suitable for a filename
@@ -184,8 +185,9 @@ The placeholders are:
 NOTE: Some placeholders may depend on other options given to the
 revision traversal engine. For example, the `%g*` reflog options will
 insert an empty string unless we are traversing reflog entries (e.g., by
-`git log -g`). The `%d` placeholder will use the "short" decoration
-format if `--decorate` was not already provided on the command line.
+`git log -g`). The `%d` and `%D` placeholders will use the "short"
+decoration format if `--decorate` was not already provided on the command
+line.
 
 If you add a `+` (plus sign) after '%' of a placeholder, a line-feed
 is inserted immediately before the expansion if and only if the
index bcee7c596696eb1da109b3ff375e09453045a60f..cff7ac1dbd8942f3013e6fa91d30d2ea33495854 100644 (file)
@@ -174,14 +174,16 @@ static void show_children(struct rev_info *opt, struct commit *commit, int abbre
 }
 
 /*
- * The caller makes sure there is no funny color before
- * calling. format_decorations makes sure the same after return.
+ * The caller makes sure there is no funny color before calling.
+ * format_decorations_extended makes sure the same after return.
  */
-void format_decorations(struct strbuf *sb,
+void format_decorations_extended(struct strbuf *sb,
                        const struct commit *commit,
-                       int use_color)
+                       int use_color,
+                       const char *prefix,
+                       const char *separator,
+                       const char *suffix)
 {
-       const char *prefix;
        const struct name_decoration *decoration;
        const char *color_commit =
                diff_get_color(use_color, DIFF_COMMIT);
@@ -191,7 +193,6 @@ void format_decorations(struct strbuf *sb,
        decoration = get_name_decoration(&commit->object);
        if (!decoration)
                return;
-       prefix = " (";
        while (decoration) {
                strbuf_addstr(sb, color_commit);
                strbuf_addstr(sb, prefix);
@@ -200,11 +201,11 @@ void format_decorations(struct strbuf *sb,
                        strbuf_addstr(sb, "tag: ");
                strbuf_addstr(sb, decoration->name);
                strbuf_addstr(sb, color_reset);
-               prefix = ", ";
+               prefix = separator;
                decoration = decoration->next;
        }
        strbuf_addstr(sb, color_commit);
-       strbuf_addch(sb, ')');
+       strbuf_addstr(sb, suffix);
        strbuf_addstr(sb, color_reset);
 }
 
index d6ecd4dc46b82147c5c7e00dcfa2e9088ab00d7c..b26160c4d64b041ed31826a61d4b898c8608c0a2 100644 (file)
@@ -13,7 +13,13 @@ int log_tree_diff_flush(struct rev_info *);
 int log_tree_commit(struct rev_info *, struct commit *);
 int log_tree_opt_parse(struct rev_info *, const char **, int);
 void show_log(struct rev_info *opt);
-void format_decorations(struct strbuf *sb, const struct commit *commit, int use_color);
+void format_decorations_extended(struct strbuf *sb, const struct commit *commit,
+                            int use_color,
+                            const char *prefix,
+                            const char *separator,
+                            const char *suffix);
+#define format_decorations(strbuf, commit, color) \
+                            format_decorations_extended((strbuf), (commit), (color), " (", ", ", ")")
 void show_decorations(struct rev_info *opt, struct commit *commit);
 void log_write_email_headers(struct rev_info *opt, struct commit *commit,
                             const char **subject_p,
index 31f2edef1106200761aff49758545972000d9c28..5fd9de6ce11da25b8ddf8ece9f718023394624e6 100644 (file)
--- a/pretty.c
+++ b/pretty.c
@@ -1179,6 +1179,10 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
                load_ref_decorations(DECORATE_SHORT_REFS);
                format_decorations(sb, commit, c->auto_color);
                return 1;
+       case 'D':
+               load_ref_decorations(DECORATE_SHORT_REFS);
+               format_decorations_extended(sb, commit, c->auto_color, "", ", ", "");
+               return 1;
        case 'g':               /* reflog info */
                switch(placeholder[1]) {
                case 'd':       /* reflog selector */
index 9b75399572b1cbe1bfcb00995e1660a93fe6a4c6..7398605e7b894259548f257aaf3e92d9481534eb 100755 (executable)
@@ -465,4 +465,15 @@ EOF
        test_cmp expected actual1
 '
 
+test_expect_success 'clean log decoration' '
+       git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
+       cat >expected <<EOF &&
+$head1 tag: refs/tags/tag2
+$head2 tag: refs/tags/message-one
+$old_head1 tag: refs/tags/message-two
+EOF
+       sort actual >actual1 &&
+       test_cmp expected actual1
+'
+
 test_done