diff options
author | Harry Jeffery <harry@exec64.co.uk> | 2014-09-18 21:53:53 +0100 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2014-09-18 15:15:21 -0700 |
commit | 9271095cc5571e306d709ebf8eb7f0a388254d9d (patch) | |
tree | 82f6c8af5766632711b0daa9012f4af903c1b3bb | |
parent | 96db324a73fdada6fbe7b63221986f8f18cc63b0 (diff) | |
download | git-hj/pretty-naked-decoration.tar.gz |
pretty: add %D format specifierhj/pretty-naked-decoration
Add a new format specifier, '%D' that is identical in behaviour to '%d',
except that it does not include the ' (' prefix or ')' suffix provided
by '%d'.
Signed-off-by: Harry Jeffery <harry@exec64.co.uk>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r-- | Documentation/pretty-formats.txt | 6 | ||||
-rw-r--r-- | log-tree.c | 17 | ||||
-rw-r--r-- | log-tree.h | 8 | ||||
-rw-r--r-- | pretty.c | 4 | ||||
-rwxr-xr-x | t/t4205-log-pretty-formats.sh | 11 |
5 files changed, 35 insertions, 11 deletions
diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt index 85d63532a3..26904d716f 100644 --- a/Documentation/pretty-formats.txt +++ b/Documentation/pretty-formats.txt @@ -128,6 +128,7 @@ The placeholders are: - '%ct': committer date, UNIX timestamp - '%ci': committer date, 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 @@ -182,8 +183,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 diff --git a/log-tree.c b/log-tree.c index 0c53dc11ab..f120fd34d1 100644 --- a/log-tree.c +++ b/log-tree.c @@ -179,14 +179,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; struct name_decoration *decoration; const char *color_commit = diff_get_color(use_color, DIFF_COMMIT); @@ -196,7 +198,6 @@ void format_decorations(struct strbuf *sb, decoration = lookup_decoration(&name_decoration, &commit->object); if (!decoration) return; - prefix = " ("; while (decoration) { strbuf_addstr(sb, color_commit); strbuf_addstr(sb, prefix); @@ -205,11 +206,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); } diff --git a/log-tree.h b/log-tree.h index d6ecd4dc46..b26160c4d6 100644 --- a/log-tree.h +++ b/log-tree.h @@ -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, @@ -1190,6 +1190,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 */ diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 349c531989..e6015e2684 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -450,4 +450,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 |