# [PATCH] Work around sed portability issue in t8006-blame-textconv

7 messages from 2011-12-31 to 2012-01-10. Participants: Ben Walton, Junio C Hamano.
Thread: https://gitlist.dev/t/29275

## Ben Walton, 2011-12-31 13:44

Subject: [PATCH] Work around sed portability issue in t8006-blame-textconv
Message-ID: <1325339068-6063-1-git-send-email-bwalton@artsci.utoronto.ca>
URL: https://gitlist.dev/e/1325339068-6063-1-git-send-email-bwalton%40artsci.utoronto.ca

```
In test 'blame --textconv with local changes' of t8006-blame-textconv,
using /usr/xpg4/bin/sed on Solaris as set by SANE_TOOL_PATH, an
additional newline was added to the output from the 'helper' script
driven by git attributes.

This was noted by sed with a message such as:
sed: Missing newline at end of file zero.bin.

In turn, this was triggering a fatal error from git blame:
fatal: unable to read files to diff

The git blame --textconv stdout was empty as a result of the error
condition above.  This caused the test to fail because the output
value differed from the expected result.

Use perl -p -e instead of sed -e to work around this portability issue
as it will not insert the newline.  This allows the git blame call to
complete at which point the output comparison is successful.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
---
 t/t8006-blame-textconv.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/t/t8006-blame-textconv.sh b/t/t8006-blame-textconv.sh
index 4ee42f1..c3c22f7 100755
--- a/t/t8006-blame-textconv.sh
+++ b/t/t8006-blame-textconv.sh
@@ -10,7 +10,7 @@ find_blame() {
 cat >helper <<'EOF'
 #!/bin/sh
 grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
-sed 's/^bin: /converted: /' "$1"
+perl -p -e 's/^bin: /converted: /' "$1"
 EOF
 chmod +x helper
 
-- 
1.7.4.1

```

## Junio C Hamano, 2012-01-03 19:05

Subject: Re: [PATCH] Work around sed portability issue in t8006-blame-textconv
Message-ID: <7vd3b0vc6h.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vd3b0vc6h.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1325339068-6063-1-git-send-email-bwalton@artsci.utoronto.ca>

```
Ben Walton <bwalton@artsci.utoronto.ca> writes:

> In test 'blame --textconv with local changes' of t8006-blame-textconv,
> using /usr/xpg4/bin/sed on Solaris as set by SANE_TOOL_PATH, an
> additional newline was added to the output from the 'helper' script
> driven by git attributes.
>
> This was noted by sed with a message such as:
> sed: Missing newline at end of file zero.bin.
>
> In turn, this was triggering a fatal error from git blame:
> fatal: unable to read files to diff

Interesting. A file with incomplete line technically is not a text file
and sed is supposed to work on text files, so it is allowed to be picky.

> Use perl -p -e instead of sed -e to work around this portability issue
> as it will not insert the newline.

I am not sure if additional newline is the problem, or the exit status
from sed is, from your description. Your first paragraph says you will get
output from sed but with an extra newline, and then later you said blame
noticed an error in its attempt to read the contents. I am suspecting that
it checked the exit status from the textconv subprocess and noticed the
error and that is the cause of the issue, but could you clarify?  IOW, I
am suspecting that replacing "as it will not insert the newline" with "as
it does not error out on an incomplete line" is necessary in this
sentence.

Thanks.

```

## Junio C Hamano, 2012-01-06 22:53

Subject: Re: [PATCH] Work around sed portability issue in t8006-blame-textconv
Message-ID: <7vehvcigsy.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vehvcigsy.fsf%40alter.siamese.dyndns.org
In-Reply-To: <7vd3b0vc6h.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano <gitster@pobox.com> writes:

> Ben Walton <bwalton@artsci.utoronto.ca> writes:
>
>> In test 'blame --textconv with local changes' of t8006-blame-textconv,
>> using /usr/xpg4/bin/sed on Solaris as set by SANE_TOOL_PATH, an
>> additional newline was added to the output from the 'helper' script
>> driven by git attributes.
>>
>> This was noted by sed with a message such as:
>> sed: Missing newline at end of file zero.bin.
>>
>> In turn, this was triggering a fatal error from git blame:
>> fatal: unable to read files to diff
>
> Interesting. A file with incomplete line technically is not a text file
> and sed is supposed to work on text files, so it is allowed to be picky.
>
>> Use perl -p -e instead of sed -e to work around this portability issue
>> as it will not insert the newline.
>
> I am not sure if additional newline is the problem, or the exit status
> from sed is, from your description. Your first paragraph says you will get
> output from sed but with an extra newline, and then later you said blame
> noticed an error in its attempt to read the contents. I am suspecting that
> it checked the exit status from the textconv subprocess and noticed the
> error and that is the cause of the issue, but could you clarify?  IOW, I
> am suspecting that replacing "as it will not insert the newline" with "as
> it does not error out on an incomplete line" is necessary in this
> sentence.

Ping?

```

## Ben Walton, 2012-01-09 03:40

Subject: Re: [PATCH] Work around sed portability issue in t8006-blame-textconv
Message-ID: <1326080292-sup-3735@pinkfloyd.chass.utoronto.ca>
URL: https://gitlist.dev/e/1326080292-sup-3735%40pinkfloyd.chass.utoronto.ca
In-Reply-To: <7vehvcigsy.fsf@alter.siamese.dyndns.org>

```
Excerpts from Junio C Hamano's message of Fri Jan 06 17:53:33 -0500 2012:

> Ping?

Sorry, I was out of email contact since last Sunday.  I'll look at
this tomorrow.  I think I tested the exit status from
/usr/xpg4/bin/sed on this file by hand and found that it was exiting
cleanly, but I'll verify and let you know.  If you're correct, I'll
adjust the commit message accordingly.

Thanks
-Ben
--
Ben Walton
Systems Programmer - CHASS
University of Toronto
C:416.407.5610 | W:416.978.4302

```

## Ben Walton, 2012-01-10 02:47

Subject: [PATCH 0/1] Re-roll of the test fix for sed on solaris
Message-ID: <1326163653-26565-1-git-send-email-bwalton@artsci.utoronto.ca>
URL: https://gitlist.dev/e/1326163653-26565-1-git-send-email-bwalton%40artsci.utoronto.ca
In-Reply-To: <7vd3b0vc6h.fsf@alter.siamese.dyndns.org>

```
Hi Junio,

It seems that you were correct in that it's the exit status from sed
that ultimately causes the breakage.  I've updated the commit message
to reflect this.

Thanks
-Ben

```

## Ben Walton, 2012-01-10 02:47

Subject: [PATCH] Use perl instead of sed for t8006-blame-textconv test
Message-ID: <1326163653-26565-2-git-send-email-bwalton@artsci.utoronto.ca>
URL: https://gitlist.dev/e/1326163653-26565-2-git-send-email-bwalton%40artsci.utoronto.ca
In-Reply-To: <1326163653-26565-1-git-send-email-bwalton@artsci.utoronto.ca>

```
In test 'blame --textconv with local changes' of t8006-blame-textconv,
using /usr/xpg4/bin/sed (as set by SANE_TOOL_PATH), an additional
newline was added to the output from the 'helper' script.

This was noted by sed with a message such as:
sed: Missing newline at end of file zero.bin.

Sed then exits with status 2 causing the helper script to also exit
with status 2.

In turn, this was triggering a fatal error from git blame:
fatal: unable to read files to diff

To work around this difference in sed behaviour, use perl -p instead
of sed -e as it exits cleanly and does not insert the additional
newline.

Signed-off-by: Ben Walton <bwalton@artsci.utoronto.ca>
---
 t/t8006-blame-textconv.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/t/t8006-blame-textconv.sh b/t/t8006-blame-textconv.sh
index 4ee42f1..c3c22f7 100755
--- a/t/t8006-blame-textconv.sh
+++ b/t/t8006-blame-textconv.sh
@@ -10,7 +10,7 @@ find_blame() {
 cat >helper <<'EOF'
 #!/bin/sh
 grep -q '^bin: ' "$1" || { echo "E: $1 is not \"binary\" file" 1>&2; exit 1; }
-sed 's/^bin: /converted: /' "$1"
+perl -p -e 's/^bin: /converted: /' "$1"
 EOF
 chmod +x helper
 
-- 
1.7.8.2

```

## Junio C Hamano, 2012-01-10 04:46

Subject: Re: [PATCH 0/1] Re-roll of the test fix for sed on solaris
Message-ID: <7vpqesb1wd.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vpqesb1wd.fsf%40alter.siamese.dyndns.org
In-Reply-To: <1326163653-26565-1-git-send-email-bwalton@artsci.utoronto.ca>

```
Ben Walton <bwalton@artsci.utoronto.ca> writes:

> It seems that you were correct in that it's the exit status from sed
> that ultimately causes the breakage.  I've updated the commit message
> to reflect this.

Thanks for being thorough. Very much appreciated.

```
