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

Re: [PATCH 4/4] t4200: avoid passing a non-newline terminated file to sed

From
Brandon Casey <casey@nrlssc.navy.mil>
Date
May 6, 2009, 21:12 UTC
Message-ID
<RsLiW_EIDQ01u5uSMUrIIMzSbMhkfwGJBEGppONH79Im4WyT76bS5A@cipher.nrlssc.navy.mil>
In-Reply-To
<7vhbzyukyi.fsf@alter.siamese.dyndns.org>
Junio C Hamano wrote:
Show 17 quoted lines
> Brandon Casey <casey@nrlssc.navy.mil> writes:
> 
>> Some versions of sed exit non-zero if the file they are supplied is not
>> newline terminated.  Solaris's /usr/xpg4/bin/sed is one such sed.  So
>> rework this test to avoid doing so.
> 
> I think up to your 3/4 is reasonable, but this is not enough for POSIX
> conformance (it is Ok if it is just aiming to fix "Solaris quirk").  POSIX
> sed is only required to work on text files, but .git/MERGE_RR is not a
> text file (it is a sequence of NUL terminated records).
> 
> I think something like this may work better.  Can somebody test?
> 
>> -	sha1=$(sed -e "s/	.*//" .git/MERGE_RR) &&
>> +	sha1=$({ cat .git/MERGE_RR; echo; } | sed -e "s/	.*//") &&
> 
> 	sha1=$(tr "\\000" "\\012" <./git/MERGE_RR | sed -e "s/	.*//") &&

I was about to reply that this fix works fine (actually, I was about to reply over an hour ago but was interrupted).

But, while testing it I noticed that you had a typo in your version that _did_not_ cause the test to fail. You have an extra slash in the path to '.git/MERGE_RR' which would have caused sha1 to be unset.

The 'sha1' variable that is set here on line 193 is used on the next line to set 'rr', but 'rr' is never used again. Unless I'm missing something, it appears these two lines can be deleted.

-brandon
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 31 in “shell compatibility issues with SunOS 5.10”
  1. Nguyen Thai Ngoc DuyMay 6, 2009
  2. Junio C HamanoMay 6, 2009
  3. Nguyen Thai Ngoc DuyMay 6, 2009
  4. Nguyen Thai Ngoc DuyMay 7, 2009
  5. Johannes SixtMay 6, 2009
  6. Nguyen Thai Ngoc DuyMay 6, 2009
  7. Ralf WildenhuesMay 6, 2009
  8. Johannes SchindelinMay 6, 2009
  9. Nguyen Thai Ngoc DuyMay 6, 2009
  10. Jeff KingMay 6, 2009
  11. Brandon CaseyMay 6, 2009
  12. 0/4 workaround some Solaris sed issuesBrandon Casey, May 6, 2009
  13. 1/4 t4118: add missing '&&'Brandon Casey, May 6, 2009
  14. 2/4 t4118: avoid sed invocation on file without terminating newlineBrandon Casey, May 6, 2009
  15. 3/4 t/annotate-tests.sh: avoid passing a non-newline terminated file to sedBrandon Casey, May 6, 2009
  16. 4/4 t4200: avoid passing a non-newline terminated file to sedBrandon Casey, May 6, 2009
  17. Junio C HamanoMay 6, 2009
  18. Brandon CaseyMay 6, 2009
  19. Junio C HamanoMay 6, 2009
  20. 1/2 t4200: remove two unnecessary linesBrandon Casey, May 6, 2009
  21. 2/2 t4200: convert sed expression which operates on non-text file to perlBrandon Casey, May 6, 2009
  22. Nguyen Thai Ngoc DuyMay 6, 2009
  23. Nguyen Thai Ngoc DuyMay 7, 2009
  24. Brandon CaseyMay 7, 2009
  25. Junio C HamanoMay 7, 2009
  26. Johannes SixtMay 7, 2009
  27. Brandon CaseyMay 7, 2009
  28. Nguyen Thai Ngoc DuyMay 6, 2009
  29. Brandon CaseyMay 7, 2009
  30. Junio C HamanoMay 7, 2009
  31. Brandon CaseyMay 7, 2009

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.