commit ac3cdf31e06d51b4966449da12216d3614e10576 from: Christian Weisgerber via: Thomas Adam date: Mon Mar 06 15:51:12 2023 UTC regress: replace "sed -i" with ed(1) for portable in-place editing "sed -i" is fundamentally unportable. 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. ok stsp op commit - 40f2f72b99bb70a7be40eada71e5acd8a77ab58d commit + ac3cdf31e06d51b4966449da12216d3614e10576 blob - 719bac3298df1e16197cba688737ead5ea2508cd blob + 2c121a047d8340ad0c16b6b008bc82fe3d7277eb --- regress/cmdline/blame.sh +++ regress/cmdline/blame.sh @@ -248,7 +248,10 @@ test_blame_lines_shifted_up() { local short_commit1=`trim_obj_id 32 $commit1` local author_time=`git_show_author_time $testroot/repo` - sed -i -e '/^[345]$/d' $testroot/wt/alpha + ed -s $testroot/wt/alpha <<-\EOF + g/^[345]$/d + w + EOF (cd $testroot/wt && got commit -m "change 2" > /dev/null) local commit2=`git_show_head $testroot/repo` local short_commit2=`trim_obj_id 32 $commit2` @@ -304,7 +307,10 @@ test_blame_lines_shifted_down() { local short_commit1=`trim_obj_id 32 $commit1` local author_time=`git_show_author_time $testroot/repo` - sed -i -e '/^8$/d' $testroot/wt/alpha + ed -s $testroot/wt/alpha <<-\EOF + g/^8$/d + w + EOF (cd $testroot/wt && got commit -m "change 2" > /dev/null) local commit2=`git_show_head $testroot/repo` local short_commit2=`trim_obj_id 32 $commit2` blob - b57e9531206c81f063628b12b4a2b476cc3e6135 blob + 26a31c050dfc034e8c024f4e945dafbc2d72cf28 --- regress/cmdline/commit.sh +++ regress/cmdline/commit.sh @@ -1852,7 +1852,10 @@ test_commit_logmsg_ref() { cat > $testroot/editor.sh < $testroot/stdout.expected echo -n "Updated to refs/heads/master: $head_rev" \ blob - 737b0cb81e316d7acd423ca57c68f090d5f33d9f blob + 79f558cff6a61109fdd1089a30e941fcf382b49d --- regress/cmdline/fetch.sh +++ regress/cmdline/fetch.sh @@ -360,7 +360,10 @@ test_fetch_branch() { fi # remove default branch information from got.conf - sed -i -e "/branch {/d" $testroot/repo-clone/got.conf + ed -s $testroot/repo-clone/got.conf <<-EOF + g/branch {/d + w + EOF # make another change on 'foo' and fetch it without got.conf (cd $testroot/repo && git checkout -q foo) @@ -1610,7 +1613,10 @@ test_fetch_honor_wt_conf_bflag() { # from repo: fetch got.conf branch which doesn't exist, so fallback # to repo HEAD "boo" # change default branch in got.conf from "master" to "foo" - sed -i "s/master/foo/" $testroot/repo-clone/got.conf + ed -s $testroot/repo-clone/got.conf <<-EOF + ,s/master/foo/ + w + EOF got fetch -q -r $testroot/repo-clone > $testroot/stdout ret=$? @@ -1708,7 +1714,10 @@ test_fetch_honor_wt_conf_bflag() { # from wt: fetch got.conf "master", wt "boo", and the repo's new HEAD # "hoo" as it no longer matches our remote HEAD symref target "master" - sed -i "s/foo/master/" $testroot/repo-clone/got.conf + ed -s $testroot/repo-clone/got.conf <<-EOF + ,s/foo/master/ + w + EOF echo "modified delta on master" > $testroot/repo/gamma/delta git_commit $testroot/repo -m "modified delta on master" local commit_id5=`git_show_head $testroot/repo` blob - 2544b3c1d2ee0467ce9294033382d12ae4ced52a blob + 7f41dbf2a6228ff4edc4bb8fd6d844625b1b6dc5 --- regress/cmdline/histedit.sh +++ regress/cmdline/histedit.sh @@ -131,7 +131,10 @@ test_histedit_no_op() { got diff -r $testroot/repo $orig_commit $new_commit2 \ > $testroot/diff - sed -i '' -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected + ed -s $testroot/diff.expected <<-EOF + ,s/$old_commit2/$new_commit2/ + w + EOF cmp -s $testroot/diff.expected $testroot/diff ret=$? if [ $ret -ne 0 ]; then @@ -340,7 +343,10 @@ test_histedit_swap() { got diff -r $testroot/repo $orig_commit $new_commit1 \ > $testroot/diff - sed -i '' -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected + ed -s $testroot/diff.expected <<-EOF + ,s/$old_commit2/$new_commit1/ + w + EOF cmp -s $testroot/diff.expected $testroot/diff ret=$? if [ $ret -ne 0 ]; then @@ -445,8 +451,11 @@ test_histedit_drop() { got diff -r $testroot/repo $orig_commit $new_commit2 \ > $testroot/diff - sed -i '' -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected - sed -i '' -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected + ed -s $testroot/diff.expected <<-EOF + ,s/$old_commit1/$orig_commit/ + ,s/$old_commit2/$new_commit2/ + w + EOF cmp -s $testroot/diff.expected $testroot/diff ret=$? if [ $ret -ne 0 ]; then @@ -1149,7 +1158,10 @@ test_histedit_path_prefix_edit() { got diff -r $testroot/repo $orig_commit $new_commit1 \ > $testroot/diff - sed -i '' -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected + ed -s $testroot/diff.expected <<-EOF + ,s/$old_commit1/$new_commit1/ + w + EOF cmp -s $testroot/diff.expected $testroot/diff ret=$? if [ $ret -ne 0 ]; then @@ -1564,9 +1576,10 @@ test_histedit_fold_only() { cat > $testroot/editor.sh < $testroot/editor.sh < $testroot/editor.sh < $testroot/editor.sh < $testroot/editor.sh < $testroot/log) - sed -i -e "s/$orig_commit1/$new_commit1/" $testroot/log.expected - sed -i -e "s/$orig_commit2/$new_commit2/" $testroot/log.expected + ed -s $testroot/log.expected <<-EOF + ,s/$orig_commit1/$new_commit1/ + ,s/$orig_commit2/$new_commit2/ + w + EOF cmp -s $testroot/log.expected $testroot/log ret=$? if [ $ret -ne 0 ]; then blob - e70257974f118426479de4291f7224d953e09e82 blob + 3ae6b968f8817e9efb7b1abb879557fe19622e08 --- regress/cmdline/revert.sh +++ regress/cmdline/revert.sh @@ -384,9 +384,12 @@ test_revert_patch() { return 1 fi - sed -i '' -e 's/^2$/a/' $testroot/wt/numbers - sed -i '' -e 's/^7$/b/' $testroot/wt/numbers - sed -i '' -e 's/^16$/c/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/a/ + ,s/^7$/b/ + ,s/^16$/c/ + w + EOF (cd $testroot/wt && got diff > $testroot/numbers.diff) @@ -564,7 +567,10 @@ EOF fi # put first hunk back - sed -i '' -e 's/^2$/a/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/a/ + w + EOF # revert middle hunk printf "n\ny\nn\n" > $testroot/patchscript @@ -866,7 +872,10 @@ test_revert_patch_one_change() { # Ensure file size is changed. Avoids race condition causing test # failures where 'got revert' does not see changes to revert if # timestamps and size in stat info remain unchanged. - sed -i '' -e 's/^2$/aa/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/aa/ + w + EOF # revert change with -p printf "y\n" > $testroot/patchscript blob - 2da7971145c62f07fd34f488c546f17a4380fd12 blob + bb9bf5f2cfb2999593b2a87a563f1f0272822950 --- regress/cmdline/stage.sh +++ regress/cmdline/stage.sh @@ -1449,9 +1449,12 @@ test_stage_patch() { return 1 fi - sed -i '' -e 's/^2$/a/' $testroot/wt/numbers - sed -i '' -e 's/^7$/b/' $testroot/wt/numbers - sed -i '' -e 's/^16$/c/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/a/ + ,s/^7$/b/ + ,s/^16$/c/ + w + EOF # don't stage any hunks printf "n\nn\nn\n" > $testroot/patchscript @@ -1736,9 +1739,12 @@ test_stage_patch_twice() { return 1 fi - sed -i '' -e 's/^2$/a/' $testroot/wt/numbers - sed -i '' -e 's/^7$/b/' $testroot/wt/numbers - sed -i '' -e 's/^16$/c/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/a/ + ,s/^7$/b/ + ,s/^16$/c/ + w + EOF # stage middle hunk printf "n\ny\nn\n" > $testroot/patchscript @@ -2232,9 +2238,12 @@ test_stage_patch_quit() { return 1 fi - sed -i '' -e 's/^2$/a/' $testroot/wt/numbers - sed -i '' -e 's/^7$/b/' $testroot/wt/numbers - sed -i '' -e 's/^16$/c/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/a/ + ,s/^7$/b/ + ,s/^16$/c/ + w + EOF (cd $testroot/wt && got rm zzz > /dev/null) # stage first hunk and quit; and don't pass a path argument to @@ -2341,9 +2350,12 @@ test_stage_patch_incomplete_script() { return 1 fi - sed -i '' -e 's/^2$/a/' $testroot/wt/numbers - sed -i '' -e 's/^7$/b/' $testroot/wt/numbers - sed -i '' -e 's/^16$/c/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/a/ + ,s/^7$/b/ + ,s/^16$/c/ + w + EOF # stage first hunk and then stop responding; got should error out printf "y\n" > $testroot/patchscript blob - c3dfaf5a6c26ee597b31705a4a382d777de7d6a2 blob + 282f6198ef06d3c01364dc6a50d274ad0a31821e --- regress/cmdline/status.sh +++ regress/cmdline/status.sh @@ -187,11 +187,17 @@ test_status_shows_local_mods_after_update() { return 1 fi - sed -i '' -e 's/2/22/' $testroot/repo/numbers + ed -s $testroot/repo/numbers <<-\EOF + ,s/2/22/ + w + EOF git_commit $testroot/repo -m "modified line 2" # modify line 7; both changes should merge cleanly - sed -i '' -e 's/7/77/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/7/77/ + w + EOF echo "G numbers" > $testroot/stdout.expected echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected @@ -342,11 +348,17 @@ test_status_shows_no_mods_after_complete_merge() { return 1 fi - sed -i '' -e 's/2/22/' $testroot/repo/numbers + ed -s $testroot/repo/numbers <<-\EOF + ,s/2/22/ + w + EOF git_commit $testroot/repo -m "modified line 2" # modify line 2 again; no local changes are left after merge - sed -i '' -e 's/2/22/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/2/22/ + w + EOF echo "G numbers" > $testroot/stdout.expected echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected @@ -396,11 +408,17 @@ test_status_shows_conflict() { return 1 fi - sed -i '' -e 's/2/22/' $testroot/repo/numbers + ed -s $testroot/repo/numbers <<-\EOF + ,s/2/22/ + w + EOF git_commit $testroot/repo -m "modified line 2" # modify line 2 in a conflicting way - sed -i '' -e 's/2/77/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/2/77/ + w + EOF echo "C numbers" > $testroot/stdout.expected echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected blob - ebf6d3cd41806a0cb17cdc6f75d6528777cf8631 blob + f5ebd5bc9adac2a53e2651879adde02156aa7f10 --- regress/cmdline/unstage.sh +++ regress/cmdline/unstage.sh @@ -198,9 +198,12 @@ test_unstage_patch() { return 1 fi - sed -i '' -e 's/^2$/a/' $testroot/wt/numbers - sed -i '' -e 's/^7$/b/' $testroot/wt/numbers - sed -i '' -e 's/^16$/c/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/a/ + ,s/^7$/b/ + ,s/^16$/c/ + w + EOF (cd $testroot/wt && got stage > /dev/null) ret=$? @@ -829,9 +832,12 @@ test_unstage_patch_quit() { return 1 fi - sed -i '' -e 's/^2$/a/' $testroot/wt/numbers - sed -i '' -e 's/^7$/b/' $testroot/wt/numbers - sed -i '' -e 's/^16$/c/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/^2$/a/ + ,s/^7$/b/ + ,s/^16$/c/ + w + EOF (cd $testroot/wt && got rm zzz > /dev/null) (cd $testroot/wt && got stage > /dev/null) blob - 0d8ff6767ff1c9ee4ac80bced71b0fd2ad8d1a39 blob + 4aa5a095404e1e99181588149852bfe3df333a9c --- regress/cmdline/update.sh +++ regress/cmdline/update.sh @@ -684,12 +684,18 @@ test_update_merges_file_edits() { echo "modified alpha" > $testroot/repo/alpha echo "modified beta" > $testroot/repo/beta - sed -i '' -e 's/2/22/' $testroot/repo/numbers + ed -s $testroot/repo/numbers <<-\EOF + ,s/2/22/ + w + EOF git_commit $testroot/repo -m "modified 3 files" echo "modified alpha, too" > $testroot/wt/alpha touch $testroot/wt/beta - sed -i '' -e 's/7/77/' $testroot/wt/numbers + ed -s $testroot/wt/numbers <<-\EOF + ,s/7/77/ + w + EOF echo "C alpha" > $testroot/stdout.expected echo "U beta" >> $testroot/stdout.expected