threads / patch / 23170

patchAdd `%B' in format strings for raw commit body in `git log' and friends

Subject: [PATCH] Add `%B' in format strings for raw commit body in `git log' and friends

## tl;dr

6 messages between Mar 25, 2010 and Apr 5, 2010. Diffs are folded; open one to read it.

replies: 5people: 2as markdown or json

Eli Barzilay· Mar 25, 2010, 02:51 UTC · lore
Also update the documentation text and add a test.
Signed-off-by: Eli Barzilay <eli@barzilay.org>
---

This is re a feature request I made a few days ago. The test is trivial, since there are only two commits with a single line.

 Documentation/pretty-formats.txt |    1 +
 pretty.c                         |    4 ++++
 t/t6006-rev-list-format.sh       |    9 +++++++++
 3 files changed, 14 insertions(+), 0 deletions(-)
Show changes to 3 files +14 −0

Documentation/pretty-formats.txt, pretty.c, t/t6006-rev-list-format.sh

diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
index 1686a54..bd760d3 100644
--- a/Documentation/pretty-formats.txt
+++ b/Documentation/pretty-formats.txt
@@ -123,6 +123,7 @@ The placeholders are:
 - '%s': subject
 - '%f': sanitized subject line, suitable for a filename
 - '%b': body
+- '%B': raw body (unwrapped subject and body)
 - '%N': commit notes
 - '%gD': reflog selector, e.g., `refs/stash@\{1\}`
 - '%gd': shortened reflog selector, e.g., `stash@\{1\}`
diff --git a/pretty.c b/pretty.c
index 6ba3da8..14c9568 100644
--- a/pretty.c
+++ b/pretty.c
@@ -797,6 +797,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
 	case 'e':	/* encoding */
 		strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
 		return 1;
+	case 'B':	/* raw body */
+		/* message_off is always left at the initial newline */
+		strbuf_addstr(sb, msg + c->message_off + 1);
+		return 1;
 	}
 
 	/* Now we need to parse the commit message. */
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index b0047d3..5d15f18 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -101,6 +101,15 @@ commit 131a310eb913d107dd3c09a65d1651175898735d
 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
 EOF
 
+test_format raw-body %B <<'EOF'
+commit 131a310eb913d107dd3c09a65d1651175898735d
+changed foo
+
+commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
+added foo
+
+EOF
+
 test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
 commit 131a310eb913d107dd3c09a65d1651175898735d
 foobarbazxyzzy
-- 
1.7.0.3
Eli Barzilay· Apr 4, 2010, 21:37 UTC · re: Eli Barzilay · lore

Re: [PATCH] Add `%B' in format strings for raw commit body in `git log' and friends

A while ago I sent the patch below. There were no replies. Is there anything else that I should do, or is there any problem in doing this?

Eli Barzilay <eli@barzilay.org> writes:
Show 60 quoted lines
> Also update the documentation text and add a test.
>
> Signed-off-by: Eli Barzilay <eli@barzilay.org>
> ---
>
> This is re a feature request I made a few days ago.  The test is
> trivial, since there are only two commits with a single line.
>
>  Documentation/pretty-formats.txt |    1 +
>  pretty.c                         |    4 ++++
>  t/t6006-rev-list-format.sh       |    9 +++++++++
>  3 files changed, 14 insertions(+), 0 deletions(-)
>
> diff --git a/Documentation/pretty-formats.txt b/Documentation/pretty-formats.txt
> index 1686a54..bd760d3 100644
> --- a/Documentation/pretty-formats.txt
> +++ b/Documentation/pretty-formats.txt
> @@ -123,6 +123,7 @@ The placeholders are:
>  - '%s': subject
>  - '%f': sanitized subject line, suitable for a filename
>  - '%b': body
> +- '%B': raw body (unwrapped subject and body)
>  - '%N': commit notes
>  - '%gD': reflog selector, e.g., `refs/stash@\{1\}`
>  - '%gd': shortened reflog selector, e.g., `stash@\{1\}`
> diff --git a/pretty.c b/pretty.c
> index 6ba3da8..14c9568 100644
> --- a/pretty.c
> +++ b/pretty.c
> @@ -797,6 +797,10 @@ static size_t format_commit_one(struct strbuf *sb, const char *placeholder,
>  	case 'e':	/* encoding */
>  		strbuf_add(sb, msg + c->encoding.off, c->encoding.len);
>  		return 1;
> +	case 'B':	/* raw body */
> +		/* message_off is always left at the initial newline */
> +		strbuf_addstr(sb, msg + c->message_off + 1);
> +		return 1;
>  	}
>  
>  	/* Now we need to parse the commit message. */
> diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
> index b0047d3..5d15f18 100755
> --- a/t/t6006-rev-list-format.sh
> +++ b/t/t6006-rev-list-format.sh
> @@ -101,6 +101,15 @@ commit 131a310eb913d107dd3c09a65d1651175898735d
>  commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
>  EOF
>  
> +test_format raw-body %B <<'EOF'
> +commit 131a310eb913d107dd3c09a65d1651175898735d
> +changed foo
> +
> +commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
> +added foo
> +
> +EOF
> +
>  test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF'
>  commit 131a310eb913d107dd3c09a65d1651175898735d
>  foobarbazxyzzy
-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
Eli Barzilay· Apr 4, 2010, 22:33 UTC · re: Junio C Hamano · lore

Re: [PATCH] Add `%B' in format strings for raw commit body in `git log' and friends

On Apr  4, Junio C Hamano wrote:
> Isn't this the same as "%s%n%+b"?

The problem with that is that it wraps the first paragraph. So it's fine as long as it's always used as a subject line.

(I'm migrating a project to git, and some people will never remember to do that.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!
Junio C Hamano· Apr 5, 2010, 01:30 UTC · re: Eli Barzilay · lore

Re: Re: [PATCH] Add `%B' in format strings for raw commit body in `git log' and friends

Eli Barzilay <eli@barzilay.org> writes:
Show 8 quoted lines
> On Apr  4, Junio C Hamano wrote:
>> Isn't this the same as "%s%n%+b"?
>
> The problem with that is that it wraps the first paragraph.  So it's
> fine as long as it's always used as a subject line.
>
> (I'm migrating a project to git, and some people will never remember
> to do that.)

Ok, but then "rev-list --pretty=format:%B" would not be as a good tool for migration to begin with (imagine a log message that begins with "commit"), compared to say "rev-list --pretty=raw".

It also feels a bit funny to list %B that doesn't do the paragraph pretty-printing in pretty-formats.txt documentation ;-) but that is not an objection.

Eli Barzilay· Apr 5, 2010, 06:06 UTC · re: Junio C Hamano · lore

Re: Re: [PATCH] Add `%B' in format strings for raw commit body in `git log' and friends

On Apr  4, Junio C Hamano wrote:
Show 14 quoted lines
> Eli Barzilay <eli@barzilay.org> writes:
> 
> > On Apr  4, Junio C Hamano wrote:
> >> Isn't this the same as "%s%n%+b"?
> >
> > The problem with that is that it wraps the first paragraph.  So it's
> > fine as long as it's always used as a subject line.
> >
> > (I'm migrating a project to git, and some people will never remember
> > to do that.)
> 
> Ok, but then "rev-list --pretty=format:%B" would not be as a good
> tool for migration to begin with (imagine a log message that begins
> with "commit"), compared to say "rev-list --pretty=raw".

Ah, sorry -- I phrased that poorely. We're doing the actual migration with git-svn, so that's not the problem. The relation to migrating is that people are not used to using the first paragraph as a subject line, which means that there will be commit messages that look like:

  Fix foo, which means:
  1. Do this,
  2. Do that,
  3. Remove bar.

and such messages come out really ugly. If a project is well behaved in regards to commit messages always having a subject line, then there's no big problem, of course. (It can be a little worse if I have scripts that look for lines with a specific format like commands for a bug tracking system.)

> It also feels a bit funny to list %B that doesn't do the paragraph
> pretty-printing in pretty-formats.txt documentation ;-) but that is
> not an objection.

(Well, my understanding was that the pretty formats is about the format strings in general.)

-- 
          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                    http://barzilay.org/                   Maze is Life!

← back to recent threads