git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: git@vger.kernel.org
Cc: "Junio C Hamano" <gitster@pobox.com>,
	"Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Giuseppe Bilotta" <giuseppe.bilotta@gmail.com>
Subject: Re: [PATCH] git-am: Ignore whitespace before patches
Date: Wed, 9 Jun 2010 15:35:03 +0000	[thread overview]
Message-ID: <AANLkTikIlGeIEDdCo35us_Ovfmw3Cj4TQwCgDWAf1ecB@mail.gmail.com> (raw)
In-Reply-To: <1273944188-9472-1-git-send-email-avarab@gmail.com>

On Sat, May 15, 2010 at 17:23, Ævar Arnfjörð Bjarmason <avarab@gmail.com> wrote:
> Change git-am to ignore whitespace (as defined by sh's read) at the
> beginning of patches.
>
> Empty lines are wont to creep in at the beginning of patches, here's
> an example from a raw Gmail attachment:
>
>    20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 20  |                |
>    20 20 20 20 20 20 20 20  20 20 20 20 20 20 20 0a  |               .|
>    52 65 74 75 72 6e 2d 50  61 74 68 3a 20 3c 61 76  |Return-Path: <av|
>
> Whitespace is also likely to appear if the user copy/pastes the patch
> around, e.g. via a pastebin, or any any number of other cases. This
> harms nothing and makes git-am's detection more fault tolerant.
>
> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
> ---
>  git-am.sh     |   16 +++++++++++++++-
>  t/t4150-am.sh |   30 ++++++++++++++++++++++++++++++
>  2 files changed, 45 insertions(+), 1 deletions(-)
>
> diff --git a/git-am.sh b/git-am.sh
> index 1056075..1b4baa8 100755
> --- a/git-am.sh
> +++ b/git-am.sh
> @@ -172,7 +172,21 @@ check_patch_format () {
>        # otherwise, check the first few lines of the first patch to try
>        # to detect its format
>        {
> -               read l1
> +               while read -r line
> +               do
> +                       case "$line" in
> +                               "")
> +                                       # Just skip whitespace
> +                                       continue
> +                                       ;;
> +                               *)
> +                                       # First non-empty line
> +                                       l1=$line
> +                                       break
> +                                       ;;
> +                       esac
> +               done
> +
>                read l2
>                read l3
>                case "$l1" in
> diff --git a/t/t4150-am.sh b/t/t4150-am.sh
> index 810b04b..3d089de 100755
> --- a/t/t4150-am.sh
> +++ b/t/t4150-am.sh
> @@ -318,6 +318,36 @@ test_expect_success 'am without --committer-date-is-author-date' '
>        test "$at" != "$ct"
>  '
>
> +test_expect_success 'am applying a patch that begins with an empty line' '
> +       git checkout first &&
> +       test_tick &&
> +       echo > patch1-white &&
> +       cat patch1 >> patch1-white &&
> +       git am patch1-white &&
> +       git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
> +       at=$(sed -ne "/^author /s/.*> //p" head1) &&
> +       ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
> +       test "$at" != "$ct"
> +'
> +
> +test_expect_success 'am applying a patch that begins with many empty lines' '
> +       git checkout first &&
> +       test_tick &&
> +       echo "   " > patch1-white2 &&
> +       echo "  " >> patch1-white2 &&
> +       echo " " >> patch1-white2 &&
> +       echo "" >> patch1-white2 &&
> +       echo " " >> patch1-white2 &&
> +       echo "  " >> patch1-white2 &&
> +       echo "   " >> patch1-white2 &&
> +       cat patch1 >> patch1-white2 &&
> +       git am patch1-white2 &&
> +       git cat-file commit HEAD | sed -e "/^\$/q" >head1 &&
> +       at=$(sed -ne "/^author /s/.*> //p" head1) &&
> +       ct=$(sed -ne "/^committer /s/.*> //p" head1) &&
> +       test "$at" != "$ct"
> +'
> +
>  # This checks for +0000 because TZ is set to UTC and that should
>  # show up when the current time is used. The date in message is set
>  # by test_tick that uses -0700 timezone; if this feature does not
> --
> 1.7.1.84.gd92f8
>
>

Adding Giuseppe Bilotta who wrote the original code I'm modifying to
the CC list.

It would be nice to get an ack or tested-by for this trivial patch. It
makes git-am & GMail integration much easier. Thanks.

  reply	other threads:[~2010-06-09 15:35 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-15 17:23 [PATCH] git-am: Ignore whitespace before patches Ævar Arnfjörð Bjarmason
2010-06-09 15:35 ` Ævar Arnfjörð Bjarmason [this message]
2010-06-10 16:51 ` Junio C Hamano
2010-06-10 17:03   ` Ævar Arnfjörð Bjarmason
2010-08-11 19:57 ` [PATCH v2] " Ævar Arnfjörð Bjarmason
2010-08-11 22:50   ` Jon Seymour
2010-08-11 22:55     ` Ævar Arnfjörð Bjarmason
2010-08-12 19:13   ` Jay Soffian
2010-08-12 20:04     ` Ævar Arnfjörð Bjarmason
2010-08-12 20:24     ` Jonathan Nieder
2010-08-12 21:34       ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=AANLkTikIlGeIEDdCo35us_Ovfmw3Cj4TQwCgDWAf1ecB@mail.gmail.com \
    --to=avarab@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=giuseppe.bilotta@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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).