# [PATCH] t6023-merge-file: Work around non-portable sed usage

4 messages from 2008-09-08 to 2008-09-08. Participants: Arjen Laarhoven, Brandon Casey, Junio C Hamano.
Thread: https://gitlist.dev/t/15433

## Arjen Laarhoven, 2008-09-08 18:29

Subject: [PATCH] t6023-merge-file: Work around non-portable sed usage
Message-ID: <1220898558-73783-1-git-send-email-arjen@yaph.org>
URL: https://gitlist.dev/e/1220898558-73783-1-git-send-email-arjen%40yaph.org

```
OS X sed doesn't understand '\n' on the right side of a substitution.
Use a valid substitution character instead and use 'tr' to convert
those to a newline.

Signed-off-by: Arjen Laarhoven <arjen@yaph.org>
---
This patch prevents the "diff3 -m" feature in next (commit
e0af48e49682ea) from breaking the tests which are added in that
commit.

 t/t6023-merge-file.sh |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh
index 42620e0..5e18d68 100755
--- a/t/t6023-merge-file.sh
+++ b/t/t6023-merge-file.sh
@@ -150,8 +150,8 @@ test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
 
 '
 
-sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit;/" < new6.txt > new8.txt
-sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit --/" < new7.txt > new9.txt
+sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
+sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
 
 test_expect_success 'ZEALOUS_ALNUM' '
 
-- 
1.6.0.1.402.ga75a

```

## Brandon Casey, 2008-09-08 19:06

Subject: Re: [PATCH] t6023-merge-file: Work around non-portable sed usage
Message-ID: <cNVNi0DglMtk8yH2LYJQdUZ7rfXlu4pff2TkbJj4KU6hnx-n_IQ3nw@cipher.nrlssc.navy.mil>
URL: https://gitlist.dev/e/cNVNi0DglMtk8yH2LYJQdUZ7rfXlu4pff2TkbJj4KU6hnx-n_IQ3nw%40cipher.nrlssc.navy.mil
In-Reply-To: <1220898558-73783-1-git-send-email-arjen@yaph.org>

```
Arjen Laarhoven wrote:
> OS X sed doesn't understand '\n' on the right side of a substitution.
> Use a valid substitution character instead and use 'tr' to convert
> those to a newline.
> 
> Signed-off-by: Arjen Laarhoven <arjen@yaph.org>
> ---
> This patch prevents the "diff3 -m" feature in next (commit
> e0af48e49682ea) from breaking the tests which are added in that
> commit.
> 
>  t/t6023-merge-file.sh |    4 ++--
>  1 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/t/t6023-merge-file.sh b/t/t6023-merge-file.sh
> index 42620e0..5e18d68 100755
> --- a/t/t6023-merge-file.sh
> +++ b/t/t6023-merge-file.sh
> @@ -150,8 +150,8 @@ test_expect_success 'MERGE_ZEALOUS simplifies non-conflicts' '
>  
>  '
>  
> -sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit;/" < new6.txt > new8.txt
> -sed -e 's/deerit./&\n\n\n\n/' -e "s/locavit,/locavit --/" < new7.txt > new9.txt
> +sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit;/"< new6.txt | tr '%' '\012' > new8.txt
> +sed -e 's/deerit./&%%%%/' -e "s/locavit,/locavit --/" < new7.txt | tr '%' '\012' > new9.txt
>  
>  test_expect_success 'ZEALOUS_ALNUM' '
>  

I was just encountering this myself.

sed can be fixed without the use of tr by replacing '\n' with an explicit newline like:

sed -e 's/deerit./&\
\
\
\
/' -e "s/locavit,/locavit;/" < new6.txt > new8.txt

Of course it doesn't fit on one line though.

-brandon

```

## Arjen Laarhoven, 2008-09-08 19:23

Subject: Re: [PATCH] t6023-merge-file: Work around non-portable sed usage
Message-ID: <20080908192313.GB4148@regex.yaph.org>
URL: https://gitlist.dev/e/20080908192313.GB4148%40regex.yaph.org
In-Reply-To: <cNVNi0DglMtk8yH2LYJQdUZ7rfXlu4pff2TkbJj4KU6hnx-n_IQ3nw@cipher.nrlssc.navy.mil>

```
On Mon, Sep 08, 2008 at 02:06:02PM -0500, Brandon Casey wrote:
[...]
> I was just encountering this myself.
> 
> sed can be fixed without the use of tr by replacing '\n' with an explicit newline like:
> 
> sed -e 's/deerit./&\
> \
> \
> \
> /' -e "s/locavit,/locavit;/" < new6.txt > new8.txt
> 
> Of course it doesn't fit on one line though.

I don't think replacing 2 lines with 10 is a big win (not counting a
possible comment explaining why it's necessary).  I'd rather replaced
the thing with a Perl one-liner though, but that seems a bit frowned
upon, correct?

Arjen

-- 
Arjen Laarhoven

The presence of those seeking the truth is infinitely to be preferred to 
those who think they've found it.
                                -- Terry Pratchett, "Monstrous Regiment"

```

## Junio C Hamano, 2008-09-08 19:26

Subject: Re: [PATCH] t6023-merge-file: Work around non-portable sed usage
Message-ID: <7vej3ufnh3.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vej3ufnh3.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080908192313.GB4148@regex.yaph.org>

```
arjen@yaph.org (Arjen Laarhoven) writes:

> On Mon, Sep 08, 2008 at 02:06:02PM -0500, Brandon Casey wrote:
> [...]
>> I was just encountering this myself.
>> 
>> sed can be fixed without the use of tr by replacing '\n' with an explicit newline like:
>> 
>> sed -e 's/deerit./&\
>> \
>> \
>> \
>> /' -e "s/locavit,/locavit;/" < new6.txt > new8.txt
>> 
>> Of course it doesn't fit on one line though.
>
> I don't think replacing 2 lines with 10 is a big win (not counting a
> possible comment explaining why it's necessary).  I'd rather replaced
> the thing with a Perl one-liner though, but that seems a bit frowned
> upon, correct?

Perl one-liner is Ok, so are pregenerated test vectors in separate
directory (i.e. ship with t/t6023/new6.txt file and refer to it from the
test as "$TEST_DIRECTORY/t6023/new6.txt"), but I think your original patch
to use % is perfectly fine for this one.

```
