From: Junio C Hamano <gitster@pobox•com>
To: "Torsten Bögershausen" <tboegi@web•de>
Cc: git@vger•kernel.org, ps@pks•im
Subject: [PATCH] t6011: fix misconversion from perl to sed
Date: Tue, 06 May 2025 15:48:55 -0700 [thread overview]
Message-ID: <xmqq8qn9fj8o.fsf@gitster.g> (raw)
In-Reply-To: <71fcb24d-55e3-40bb-9368-5b47aa180993@web.de> ("Torsten Bögershausen"'s message of "Tue, 6 May 2025 14:32:04 +0200")
No, this is not about a quiz on regexp compatibility between Perl
and sed.
Back when cdbdc6bf (t: refactor tests depending on Perl substitution
operator, 2025-04-03) rewrite many use of perl with sed, the general
pattern of the original scripts were
chmod +w some_read_only_file &&
perl -p -e "regexp to munge" some_read_only_file >some_tmp &&
mv some_tmp some_read_only_file
persumably because the author new replacing some_read_only_file with
"mv" at the last step would not work without "mv -f" in some
environments (GNU does not seem to give any prompt when not running
interactively, which is what happens when running t/ scripts).
Replacing perl with sed would be fine as long as sed with updated
regexp does the equivalent munging.
But one place used to use a different construct in the original:
perl -i.bak -p -e "regexp to munge" some_read_only_file
With _no_ temporary file or "mv", "perl -i" allows you to replace a
read-only file in place.
When we replaced the use of "perl" with "sed" in the said commit,
however, because "sed -i" is not portable, we rewrote that in-place
replacement to
sed "regexp to munge" some_read_only_file >some_tmp &&
mv some_tmp some_read_only_file
Again, unfortunately that does not work in some environment, without
"mv -f".
We could run "mv -f" here, but we would then need to remove "chmod
+w" and have them use "mv -f" instead at all places that were
touched cdbdc6bf (t: refactor tests depending on Perl substitution
operator, 2025-04-03) to be consistent (and more concise).
For now, let's make it consistent in the other direction by mimick
the other places that made the target read-write before moving.
Speaking of portability, the outcome of using "sed" on non-text
files is unspecified, so the entire exercise of cdbdc6bf may have
needed to be reverted if people still used ancient version of
"standard compliant" sed that barfs on non-text files, but these
days we may be able to get away with "BSDs and GNU seem OK with it"
;-) But one fix at a time.
Reported-by: Torsten Bögershausen <tboegi@web•de>
Signed-off-by: Junio C Hamano <gitster@pobox•com>
---
t/t6011-rev-list-with-bad-commit.sh | 1 +
1 file changed, 1 insertion(+)
diff --git a/t/t6011-rev-list-with-bad-commit.sh b/t/t6011-rev-list-with-bad-commit.sh
index b6f3344dbf..1dd1e50d21 100755
--- a/t/t6011-rev-list-with-bad-commit.sh
+++ b/t/t6011-rev-list-with-bad-commit.sh
@@ -38,6 +38,7 @@ test_expect_success 'verify number of revisions' \
test_expect_success 'corrupt second commit object' '
for p in .git/objects/pack/*.pack
do
+ chmod +w "$p" &&
sed "s/second commit/socond commit/" "$p" >"$p.munged" &&
mv "$p.munged" "$p" ||
return 1
--
2.49.0-615-gd1e3f1cce9
next prev parent reply other threads:[~2025-05-06 22:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-06 12:32 Problems with t6011 Torsten Bögershausen
2025-05-06 21:18 ` Junio C Hamano
2025-05-06 22:48 ` Junio C Hamano [this message]
2025-05-07 4:57 ` [PATCH] t6011: fix misconversion from perl to sed Patrick Steinhardt
2025-05-07 15:29 ` Junio C Hamano
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=xmqq8qn9fj8o.fsf@gitster.g \
--to=gitster@pobox$(echo .)com \
--cc=git@vger$(echo .)kernel.org \
--cc=ps@pks$(echo .)im \
--cc=tboegi@web$(echo .)de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox