Browse Source

Merge branch 'mg/pretty-magic-space'

* mg/pretty-magic-space:
  pretty: Introduce ' ' modifier to add space if non-empty

Conflicts:
	pretty.c
maint
Junio C Hamano 15 years ago
parent
commit
223a923c37
  1. 4
      Documentation/pretty-formats.txt
  2. 15
      pretty.c
  3. 10
      t/t6006-rev-list-format.sh

4
Documentation/pretty-formats.txt

@ -159,6 +159,10 @@ If you add a `-` (minus sign) after '%' of a placeholder, line-feeds that @@ -159,6 +159,10 @@ If you add a `-` (minus sign) after '%' of a placeholder, line-feeds that
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

15
pretty.c

@ -941,7 +941,8 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder, @@ -941,7 +941,8 @@ static size_t format_commit_item(struct strbuf *sb, const char *placeholder,
enum {
NO_MAGIC,
ADD_LF_BEFORE_NON_EMPTY,
DEL_LF_BEFORE_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, @@ -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, @@ -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, @@ -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) {

10
t/t6006-rev-list-format.sh

@ -200,6 +200,16 @@ test_expect_success 'add LF before non-empty (2)' ' @@ -200,6 +200,16 @@ test_expect_success 'add LF before non-empty (2)' '
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 &&

Loading…
Cancel
Save