git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Michael J Gruber <git@drmicha.warpmail.net>
To: James McCoy <vega.james@gmail.com>, git@vger.kernel.org
Cc: Jeff King <peff@peff.net>
Subject: Re: [PATCH] filter-branch: strip pgp signature in commit messages
Date: Thu, 8 Oct 2015 10:15:48 +0200	[thread overview]
Message-ID: <56162634.2010800@drmicha.warpmail.net> (raw)
In-Reply-To: <20151008050122.GA21369@freya.jamessan.com>

James McCoy venit, vidit, dixit 08.10.2015 07:01:
> df062010 (filter-branch: avoid passing commit message through sed)
> introduced a regression when filtering gpg signed commits.  The gpgsig
> header is multi-line and contains an empty line.  Although the signature
> is indented, making the line a whitespace only line, this still results
> in $header_line being empty, causing the “skip header lines” loop to
> exit.
> 
> The rest of the commit object is then re-used as the rewritten commit
> message, causing the new message to include the signature of the
> original commit.

I had to wrap my head around that commit message quite a bit and ended
up testing the issue myself. So the catch is:

df062010 (filter-branch: avoid passing commit message through sed)
introduced a regression when filtering gpg signed commits. As a
consequence, "filter-branch --msg-filter cat" (which should leave the
commit message unchanged) spills the signature (without the BEGIN line,
but with the END line) into (in front of) the original commit message.

The reason is that although...

... original commit.

Fix this by keeping track of the in/out-of signature state when parsing
the header lines.


[No, this does not alleviate my dislike for the commit signature
implementation, and I have not checked the patch - the test looks good
to me, though.]

> Signed-off-by: James McCoy <vega.james@gmail.com>
> ---
>  git-filter-branch.sh     | 14 +++++++++++---
>  t/t7003-filter-branch.sh | 14 ++++++++++++++
>  2 files changed, 25 insertions(+), 3 deletions(-)
> 
> diff --git a/git-filter-branch.sh b/git-filter-branch.sh
> index 5b3f63d..dd49b13 100755
> --- a/git-filter-branch.sh
> +++ b/git-filter-branch.sh
> @@ -347,10 +347,18 @@ while read commit parents; do
>  	fi
>  
>  	{
> -		while read -r header_line && test -n "$header_line"
> +		while read -r header_line &&
> +			( test -n "$header_line" || test -n "$gpg_signature" )
>  		do
> -			# skip header lines...
> -			:;
> +			# skip header lines... but track whether we are in a
> +			# PGP signature, since it will have a whitespace only
> +			# line which causes $header_line to be empty
> +			if [ "${header_line#gpgsig}" != "$header_line" ]; then
> +				gpg_signature=1
> +			elif test -n "$gpg_signature" &&
> +				expr "$header_line" : ".*END PGP" >/dev/null; then
> +				gpg_signature=
> +			fi
>  		done
>  		# and output the actual commit message
>  		cat
> diff --git a/t/t7003-filter-branch.sh b/t/t7003-filter-branch.sh
> index 855afda..377c648 100755
> --- a/t/t7003-filter-branch.sh
> +++ b/t/t7003-filter-branch.sh
> @@ -2,6 +2,7 @@
>  
>  test_description='git filter-branch'
>  . ./test-lib.sh
> +. "$TEST_DIRECTORY/lib-gpg.sh"
>  
>  test_expect_success 'setup' '
>  	test_commit A &&
> @@ -292,6 +293,19 @@ test_expect_success 'Tag name filtering strips gpg signature' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success GPG 'Filtering retains message of gpg signed commit' '
> +	mkdir gpg &&
> +	touch gpg/foo &&
> +	git add gpg &&
> +	test_tick &&
> +	git commit -S -m "Adding gpg" &&
> +
> +	git log -1 --format="%s" > expect &&
> +	git filter-branch -f --msg-filter "cat" &&
> +	git log -1 --format="%s" > actual &&
> +	test_cmp expect actual
> +'
> +
>  test_expect_success 'Tag name filtering allows slashes in tag names' '
>  	git tag -m tag-with-slash X/1 &&
>  	git cat-file tag X/1 | sed -e s,X/1,X/2, > expect &&
> 

  reply	other threads:[~2015-10-08  8:16 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-10-08  5:01 [PATCH] filter-branch: strip pgp signature in commit messages James McCoy
2015-10-08  8:15 ` Michael J Gruber [this message]
2015-10-08  8:43   ` Michael J Gruber
2015-10-08 10:00     ` Michael J Gruber
2015-10-08 11:36       ` James McCoy

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=56162634.2010800@drmicha.warpmail.net \
    --to=git@drmicha.warpmail.net \
    --cc=git@vger.kernel.org \
    --cc=peff@peff.net \
    --cc=vega.james@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).