Skip to content

Commit 1367b12

Browse files
elibarzilaygitster
authored andcommitted
Add %B' in format strings for raw commit body in git log' and friends
Also update the documentation text and add a test. Signed-off-by: Eli Barzilay <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 11766ca commit 1367b12

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

Documentation/pretty-formats.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ The placeholders are:
123123
- '%s': subject
124124
- '%f': sanitized subject line, suitable for a filename
125125
- '%b': body
126+
- '%B': raw body (unwrapped subject and body)
126127
- '%N': commit notes
127128
- '%gD': reflog selector, e.g., `refs/stash@\{1\}`
128129
- '%gd': shortened reflog selector, e.g., `stash@\{1\}`

pretty.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,6 +797,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
797797
case 'e': /* encoding */
798798
strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
799799
return 1;
800+
case 'B': /* raw body */
801+
/* message_off is always left at the initial newline */
802+
strbuf_addstr(sb, msg + c->message_off + 1);
803+
return 1;
800804
}
801805

802806
/* Now we need to parse the commit message. */

t/t6006-rev-list-format.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ commit 131a310eb913d107dd3c09a65d1651175898735d
101101
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
102102
EOF
103103

104+
test_format raw-body %B <<'EOF'
105+
commit 131a310eb913d107dd3c09a65d1651175898735d
106+
changed foo
107+
108+
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
109+
added foo
110+
111+
EOF
112+
104113
test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
105114
commit 131a310eb913d107dd3c09a65d1651175898735d
106115
foobarbazxyzzy

0 commit comments

Comments
 (0)