From: Harry Jeffery <harry@exec64.co.uk>
To: git@vger.kernel.org
Subject: [PATCH] pretty-format: add append line-feed format specifier
Date: Tue, 09 Sep 2014 19:09:50 +0100 [thread overview]
Message-ID: <540F426E.6080908@exec64.co.uk> (raw)
Add a new format prefix `_` that causes a line-feed to be inserted
immediately after an expansion if the expansion expands to a non-empty
string. This is useful for when you would like a line for an expansion
to be prepended, but only when the expansion expands to a non empty
string, such as inserting a '%_d' expansion before a commit to show any
refs pointing towards it.
Signed-off-by: Harry Jeffery <harry@exec64.co.uk>
---
Documentation/pretty-formats.txt | 4 ++++
pretty.c | 10 ++++++++--
2 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/Documentation/pretty-formats.txt
b/Documentation/pretty-formats.txt
index 85d6353..842cd17 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -197,6 +197,10 @@ If you add a ` ` (space) after '%' of a
placeholder, a space
is inserted immediately before the expansion if and only if the
placeholder expands to a non-empty string.
+If you add a `_` (underscore) after '%' of a placeholder, a line-feed
+is inserted immediately after the expansion if and only if the
+placeholder expands to a non-empty string.
+
* 'tformat:'
+
The 'tformat:' format works exactly like 'format:', except that it
diff --git a/pretty.c b/pretty.c
index 44b9f64..ddb930d 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1416,7 +1416,8 @@ static size_t format_commit_item(struct strbuf
*sb, /* in UTF-8 */
NO_MAGIC,
ADD_LF_BEFORE_NON_EMPTY,
DEL_LF_BEFORE_EMPTY,
- ADD_SP_BEFORE_NON_EMPTY
+ ADD_SP_BEFORE_NON_EMPTY,
+ ADD_LF_AFTER_NON_EMPTY
} magic = NO_MAGIC;
switch (placeholder[0]) {
@@ -1429,6 +1430,9 @@ static size_t format_commit_item(struct strbuf
*sb, /* in UTF-8 */
case ' ':
magic = ADD_SP_BEFORE_NON_EMPTY;
break;
+ case '_':
+ magic = ADD_LF_AFTER_NON_EMPTY;
+ break;
default:
break;
}
@@ -1449,6 +1453,8 @@ static size_t format_commit_item(struct strbuf
*sb, /* in UTF-8 */
} else if (orig_len != sb->len) {
if (magic == ADD_LF_BEFORE_NON_EMPTY)
strbuf_insert(sb, orig_len, "\n", 1);
+ else if (magic == ADD_LF_AFTER_NON_EMPTY)
+ strbuf_addch(sb, '\n');
else if (magic == ADD_SP_BEFORE_NON_EMPTY)
strbuf_insert(sb, orig_len, " ", 1);
}
@@ -1460,7 +1466,7 @@ static size_t userformat_want_item(struct strbuf
*sb, const char *placeholder,
{
struct userformat_want *w = context;
- if (*placeholder == '+' || *placeholder == '-' || *placeholder == ' ')
+ if (*placeholder == '+' || *placeholder == '-' || *placeholder == ' '
|| *placeholder == '_')
placeholder++;
switch (*placeholder) {
--
2.1.0
next reply other threads:[~2014-09-09 18:09 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-09 18:09 Harry Jeffery [this message]
2014-09-09 19:15 ` [PATCH] pretty-format: add append line-feed format specifier Junio C Hamano
2014-09-09 19:30 ` Harry Jeffery
2014-09-09 19:37 ` Junio C Hamano
2014-09-09 21:45 ` Jeff King
2014-09-09 22:17 ` Harry Jeffery
2014-09-09 22:31 ` Jeff King
2014-09-10 17:19 ` Junio C Hamano
2014-09-12 4:49 ` Jeff King
2014-09-12 16:36 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=540F426E.6080908@exec64.co.uk \
--to=harry@exec64.co.uk \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).