git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC PATCHv3 1/4] am: avoid re-directing stdin twice

From
Chris Packham <judge.packham@gmail.com>
Date
Sep 5, 2014, 21:31 UTC
Message-ID
<CAFOYHZBct1CRA+NumVMvbbuELWTRoGL5FkhBfHD2Wk7QZVe1fA@mail.gmail.com>
In-Reply-To
<540A1C7B.80109@kdbg.org>
On Sat, Sep 6, 2014 at 8:26 AM, Johannes Sixt <j6t@kdbg.org> wrote:
Show 50 quoted lines
> Am 05.09.2014 12:06, schrieb Chris Packham:
>> In check_patch_format we feed $1 to a block that attempts to determine
>> the patch format. Since we've already redirected $1 to stdin there is no
>> need to redirect it again when we invoke tr. This prevents the following
>> errors when invoking git am
>>
>>   $ git am patch.patch
>>   tr: write error: Broken pipe
>>   tr: write error
>>   Patch format detection failed.
>>
>> Cc: Stephen Boyd <bebarino@gmail.com>
>> Signed-off-by: Chris Packham <judge.packham@gmail.com>
>> ---
>> Nothing new since http://article.gmane.org/gmane.comp.version-control.git/256425
>>
>>  git-am.sh | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/git-am.sh b/git-am.sh
>> index ee61a77..fade7f8 100755
>> --- a/git-am.sh
>> +++ b/git-am.sh
>> @@ -250,7 +250,7 @@ check_patch_format () {
>>                       # discarding the indented remainder of folded lines,
>>                       # and see if it looks like that they all begin with the
>>                       # header field names...
>> -                     tr -d '\015' <"$1" |
>> +                     tr -d '\015' |
>>                       sed -n -e '/^$/q' -e '/^[       ]/d' -e p |
>>                       sane_egrep -v '^[!-9;-~]+:' >/dev/null ||
>>                       patch_format=mbox
>>
>
> I think this change is wrong. This pipeline checks whether one of the
> lines at the top of the file contains something that looks like an email
> header. With your change, the first three lines would not be looked at
> because they were already consumed earlier.
>
> I wonder why tr (assuming it is *this* instance of tr) dies with a write
> error instead of from a SIGPIPE. Is SIGPIPE ignored somewhere and then
> the tr invocation inherits this "ignore SIGPIPE" setting?
>
> The only thing your version changes is that tr writes a bit less text
> into the pipe. Perhaps its just sufficient that the output fits into the
> pipe buffer, and no error occurs anymore? Then the new version is not a
> real fix: make the patch text a bit longer, and the error is back.
>
> -- Hannes
>

I did notice some oddities when attempting to reproduce this issue. They would be explained by the output fitting into the buffer. So yes perhaps this solution has just changed enough so that it no longer triggers on the particular patch I was testing with. It still seems a bit funny that we start re-reading the input part way through processing it.

Perhaps putting the tr outside the whole block would be a better solution?
Previous: Johannes SixtNext: Junio C Hamano
Message 4 of 13 in “[RFC PATCHv3 0/4] am: patch-format”
  1. Chris PackhamSep 5, 2014
  2. 1/4 am: avoid re-directing stdin twiceChris Packham, Sep 5, 2014
  3. Johannes SixtSep 5, 2014
  4. Chris PackhamSep 5, 2014
  5. Junio C HamanoSep 5, 2014
  6. Junio C HamanoSep 5, 2014
  7. Junio C HamanoSep 5, 2014
  8. Stephen BoydSep 5, 2014
  9. Junio C HamanoSep 6, 2014
  10. Torsten BögershausenSep 6, 2014
  11. 2/4 t/am: add test for stgit patch formatChris Packham, Sep 5, 2014
  12. 3/4 t/am: add tests for hg patch formatChris Packham, Sep 5, 2014
  13. 4/4 am: add gitk patch formatChris Packham, Sep 5, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.