Re: [PATCH v3 1/3] t: add lib-crlf-messages.sh for messages containing CRLF
- From
Eric Sunshine <sunshine@sunshineco.com>
- Date
- Oct 14, 2020, 23:01 UTC
- Message-ID
- <20201014230115.GA14306@flurp.local>
- In-Reply-To
- <FA717D92-3798-44C0-8671-83596429C388@gmail.com>
On Wed, Oct 14, 2020 at 9:52 AM Philippe Blain <levraiphilippeblain@gmail.com> wrote:
Show 15 quoted lines
> > Le 14 oct. 2020 à 09:45, Eric Sunshine <sunshine@sunshineco.com> a écrit :
> >>> Le 12 oct. 2020 à 18:47, Eric Sunshine <sunshine@sunshineco.com> a écrit :
> >>> create_crlf_ref () {
> >>> branch=$1
> >>> cat >.crlf-message-$branch.txt &&
> >>> sed -n "1,/^$/p" <.crlf-message-$branch.txt | sed "/^$/d" | append_cr >.crlf-subject-$branch.txt &&
> >>> sed -n "/^$/,\$p" <.crlf-message-$branch.txt | sed "1d" | append_cr >.crlf-body-$branch.txt &&
> >
> > The code I proposed is very explicit about using CRLF terminators. The
> > here-doc fed to create_crlf_ref() contains only the normal LF, but
> > then create_crlf_ref() explicitly converts those to CRLF by calling
> > append_cr().
>
> Sorry, I missed that. I'll try to see if I can make it simpler using
> this approach then.By the way, if you also need .crlf-message-$branch.txt to have CRLF line endings, then you'll probably want to use a temporary file (for instance, .crlf-orig-$branch.txt), perhaps like this:
create_crlf_ref () {
branch=$1 &&
cat >.crlf-orig-$branch.txt &&
append_cr <.crlf-orig-$branch.txt >.crlf-message-$branch.txt &&
sed -n "1,/^$/p" <.crlf-orig-$branch.txt | sed "/^$/d" | append_cr >.crlf-subject-$branch.txt &&
sed -n "/^$/,\$p" <.crlf-orig-$branch.txt | sed "1d" | append_cr >.crlf-body-$branch.txt &&
...
}