summaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorMichael J Gruber <git@drmicha.warpmail.net>2010-06-14 18:12:29 +0200
committerJunio C Hamano <gitster@pobox.com>2010-06-16 14:45:09 -0700
commit7b88176e9bce658fd44c2192c1b7aa6e612ee0c2 (patch)
treeb69a131050b6b093f75addb97094118ba7c96d19 /pretty.c
parent6068cdcc832040ac644c56953be0670bb09afd12 (diff)
downloadgit-7b88176e9bce658fd44c2192c1b7aa6e612ee0c2.tar.gz
pretty: Introduce ' ' modifier to add space if non-empty
We have the '+' modifiier which helps combine format specifiers which may possibly be empty, e.g. '%s%+b%n'. Introduce an analogous ' ' (space) modifier which adds a space before non-empty items. This helps assemble "one line type" format specifiers. Signed-off-by: Michael J Gruber <git@drmicha.warpmail.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c13
1 files changed, 10 insertions, 3 deletions
diff --git a/pretty.c b/pretty.c
index 8b18efda9c..9e845dcb0b 100644
--- a/pretty.c
+++ b/pretty.c
@@ -942,6 +942,7 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
NO_MAGIC,
ADD_LF_BEFORE_NON_EMPTY,
DEL_LF_BEFORE_EMPTY,
+ ADD_SP_BEFORE_NON_EMPTY,
} magic = NO_MAGIC;
switch (placeholder[0]) {
@@ -951,6 +952,9 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
case '+':
magic = ADD_LF_BEFORE_NON_EMPTY;
break;
+ case ' ':
+ magic = ADD_SP_BEFORE_NON_EMPTY;
+ break;
default:
break;
}
@@ -965,8 +969,11 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
if ((orig_len == sb->len) && magic == DEL_LF_BEFORE_EMPTY) {
while (sb->len && sb->buf[sb->len - 1] == '\n')
strbuf_setlen(sb, sb->len - 1);
- } else if ((orig_len != sb->len) && magic == ADD_LF_BEFORE_NON_EMPTY) {
- strbuf_insert(sb, orig_len, "\n", 1);
+ } else if (orig_len != sb->len) {
+ if (magic == ADD_LF_BEFORE_NON_EMPTY)
+ strbuf_insert(sb, orig_len, "\n", 1);
+ else if (magic == ADD_SP_BEFORE_NON_EMPTY)
+ strbuf_insert(sb, orig_len, " ", 1);
}
return consumed + 1;
}
@@ -976,7 +983,7 @@ static size_t userformat_want_item(struct strbuf *sb, const char *placeholder,
{
struct userformat_want *w = context;
- if (*placeholder == '+' || *placeholder == '-')
+ if (*placeholder == '+' || *placeholder == '-' || *placeholder == ' ')
placeholder++;
switch (*placeholder) {