"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: regress: Replace sed -i with ed for portability
To:
Christian Weisgerber <naddy@mips.inka.de>
Cc:
gameoftrees@openbsd.org
Date:
Sun, 5 Mar 2023 08:53:27 +0100

Download raw body.

Thread
On Sat, Mar 04, 2023 at 09:34:05PM +0100, Christian Weisgerber wrote:
> Thomas and I would like to replace the ubiquitous use of "sed -i"
> in the regression tests with ed(1).
> 
> "sed -i" is fundamentally unportable.  The implementations that
> support the -i option for in-place editing differ in a crucial
> aspect: GNU and OpenBSD sed(1) treat the extension for the backup
> file as an optional argument and use "sed -i" for no backup file.
> FreeBSD sed(1) treats the extension as an obligatory argument and
> uses "sed -i ''" for no backup file.  There is no single syntax
> that works for both.  Handling this in -portable is painful.
> 
> Apart from calling "sed -i" directly, a few regression tests also
> create shell scripts that contain "sed -i" and are executed later.
> 
> I'm attaching a model diff that replaces all instances of "sed -i"
> with ed.  Take a look, see if you like it.  For the script use,
> check commit.sh or histedit.sh.  If the use of "EOF" to terminate
> nested here documents is too confusing, we can use a different
> delimiter for the inner one.  (Any suggestions?)
> 
> We can tweak this to taste, because I used a Perl script to generate
> the diff, which I'm also attaching.

Surely this move is in revenge of my switching the default editor
spawned by 'got commit' from ed to vi?
Regardless, more use of ed is fine by me.

> Testing this has turned up an oddity: test_commit_prepared_logmsg()
> in commit.sh produces a script that performs s/foo/bar/ on a file,
> but that file doesn't contain the string "foo", so no replacement
> happens.  Unlike sed(1), ed(1) treats this as an error.  What is
> that part of the test supposed to accomplish?

This looks like a copy-paste error to me. I am sure this particular
sed -i line could just be deleted.