summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 6068cdc)
raw | patch | inline | side by side (parent: 6068cdc)
author | Michael J Gruber <git@drmicha.warpmail.net> | |
Mon, 14 Jun 2010 16:12:29 +0000 (18:12 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Wed, 16 Jun 2010 21:45:09 +0000 (14:45 -0700) |
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>
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>
Documentation/pretty-formats.txt | patch | blob | history | |
pretty.c | patch | blob | history | |
t/t6006-rev-list-format.sh | patch | blob | history |
index 8c68ce94f990b0c7f3bc909cc3dc0c4e2a37cf3b..561cc9f7d7ef1a2502d608e59e2eae345bffd685 100644 (file)
immediately precede the expansion are deleted if and only if the
placeholder expands to an empty string.
+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.
+
* 'tformat:'
+
The 'tformat:' format works exactly like 'format:', except that it
diff --git a/pretty.c b/pretty.c
index 8b18efda9cd6eb615900687c0205daa832794c92..9e845dcb0b7ffca8794b555508b27fe291a0b529 100644 (file)
--- a/pretty.c
+++ b/pretty.c
NO_MAGIC,
ADD_LF_BEFORE_NON_EMPTY,
DEL_LF_BEFORE_EMPTY,
+ ADD_SP_BEFORE_NON_EMPTY,
} magic = NO_MAGIC;
switch (placeholder[0]) {
case '+':
magic = ADD_LF_BEFORE_NON_EMPTY;
break;
+ case ' ':
+ magic = ADD_SP_BEFORE_NON_EMPTY;
+ break;
default:
break;
}
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;
}
{
struct userformat_want *w = context;
- if (*placeholder == '+' || *placeholder == '-')
+ if (*placeholder == '+' || *placeholder == '-' || *placeholder == ' ')
placeholder++;
switch (*placeholder) {
index 9b77073df880d4597742e20d738273244d2e4a10..cccacd4add48524abd4a3021f8048a6c45c245ea 100755 (executable)
grep "^$" actual
'
+test_expect_success 'add SP before non-empty (1)' '
+ git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual &&
+ test $(wc -w <actual) = 2
+'
+
+test_expect_success 'add SP before non-empty (2)' '
+ git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual &&
+ test $(wc -w <actual) = 4
+'
+
test_expect_success '--abbrev' '
echo SHORT SHORT SHORT >expect2 &&
echo LONG LONG LONG >expect3 &&