From fa37079fce1f4b2e6b73ab317c1840a860b56eb4 Mon Sep 17 00:00:00 2001 From: Thomas Adam Date: Sun, 3 Oct 2021 22:03:56 +0100 Subject: [PATCH] regress: use gdate/gln if on *BSD To minimise the amount of churn between the difference in date(1) and ln(n) semantics, use gdate and gln from coreutils. --- regress/cmdline/commit.sh | 12 +++++++++--- regress/cmdline/common.sh | 25 +++++++++++++++++++++++++ regress/cmdline/diff.sh | 8 ++++---- regress/cmdline/histedit.sh | 20 ++++++++++++-------- regress/cmdline/rebase.sh | 5 ++++- regress/cmdline/revert.sh | 10 +++++----- regress/cmdline/status.sh | 12 ++++++------ regress/cmdline/tag.sh | 23 +++++++++++++++++++---- regress/cmdline/update.sh | 4 ++-- 9 files changed, 86 insertions(+), 33 deletions(-) diff --git a/regress/cmdline/commit.sh b/regress/cmdline/commit.sh index 22b98dd9..f4828b6c 100755 --- a/regress/cmdline/commit.sh +++ b/regress/cmdline/commit.sh @@ -1377,7 +1377,7 @@ test_commit_prepared_logmsg() { cat > $testroot/editor.sh < $testroot/stdout.expected echo "commit $head_rev (master)" >> $testroot/stdout.expected echo "from: $GOT_AUTHOR" >> $testroot/stdout.expected @@ -1438,7 +1441,10 @@ EOF fi local author_time=`git_show_author_time $testroot/repo` - d=`env LC_TIME=C date -u -d "@$author_time" +"%a %b %e %X %Y UTC"` + local prev_LC_TIME="$LC_TIME" + export LC_TIME=C + d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"` + LC_TIME="$prev_LC_TIME" echo "-----------------------------------------------" \ > $testroot/stdout.expected echo "commit $head_rev (master)" >> $testroot/stdout.expected diff --git a/regress/cmdline/common.sh b/regress/cmdline/common.sh index c0b2732f..daf8b3ad 100644 --- a/regress/cmdline/common.sh +++ b/regress/cmdline/common.sh @@ -26,6 +26,31 @@ export GOT_TEST_ROOT="/tmp" export MALLOC_OPTIONS=S +date() +{ + DATECMD="date" + [ "$OSTYPE" != "linux-gnu" ] && DATECMD="gdate" + + "$DATECMD" "$@" +} + +ln() +{ + LNCMD="ln" + [ "$OSTYPE" != "linux-gnu" ] && LNCMD="gln" + + "$LNCMD" "$@" +} + +#sed() +#{ +# SEDCMD="sed" +# [ "$OSTYPE" != "linux-gnu" ] && LNCMD="gsed" +# +# "$SEDCMD" "$@" +#} + + git_init() { git init -q "$1" diff --git a/regress/cmdline/diff.sh b/regress/cmdline/diff.sh index 7bc83f4d..1faa0199 100755 --- a/regress/cmdline/diff.sh +++ b/regress/cmdline/diff.sh @@ -427,14 +427,14 @@ test_diff_shows_conflict() { return 1 fi - sed -i 's/2/22/' $testroot/repo/numbers - sed -i 's/8/33/' $testroot/repo/numbers + sed -i '' 's/2/22/' $testroot/repo/numbers + sed -i '' 's/8/33/' $testroot/repo/numbers git_commit $testroot/repo -m "modified line 2" local head_rev=`git_show_head $testroot/repo` # modify lines 2 and 8 in conflicting ways - sed -i 's/2/77/' $testroot/wt/numbers - sed -i 's/8/88/' $testroot/wt/numbers + sed -i '' 's/2/77/' $testroot/wt/numbers + sed -i '' 's/8/88/' $testroot/wt/numbers echo "C numbers" > $testroot/stdout.expected echo -n "Updated to refs/heads/master: $head_rev" \ diff --git a/regress/cmdline/histedit.sh b/regress/cmdline/histedit.sh index b41b92c7..bab97d4a 100755 --- a/regress/cmdline/histedit.sh +++ b/regress/cmdline/histedit.sh @@ -131,7 +131,7 @@ 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 + sed -i '' -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected cmp -s $testroot/diff.expected $testroot/diff ret="$?" if [ "$ret" != "0" ]; then @@ -154,7 +154,11 @@ test_histedit_no_op() { # We should have a backup of old commits (cd $testroot/repo && got histedit -l > $testroot/stdout) d_orig1=`date -u -d "@$old_author_time1" +"%G-%m-%d"` - d_orig2=`env LC_TIME=C date -u -d "@$old_author_time2" +"%a %b %e %X %Y UTC"` + + local prev_LC_TIME="$LC_TIME" + export LC_TIME=C + d_orig2=`date -u -d "@$old_author_time2" +"%a %b %e %X %Y UTC"` + export LC_TIME="$prev_LC_TIME" d_new2=`date -u -d "@$new_author_time2" +"%G-%m-%d"` d_orig=`date -u -d "@$orig_author_time" +"%G-%m-%d"` cat > $testroot/stdout.expected < $testroot/diff - sed -i -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected + sed -i '' -e "s/$old_commit2/$new_commit1/" $testroot/diff.expected cmp -s $testroot/diff.expected $testroot/diff ret="$?" if [ "$ret" != "0" ]; then @@ -445,8 +449,8 @@ 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 + sed -i '' -e "s/$old_commit1/$orig_commit/" $testroot/diff.expected + sed -i '' -e "s/$old_commit2/$new_commit2/" $testroot/diff.expected cmp -s $testroot/diff.expected $testroot/diff ret="$?" if [ "$ret" != "0" ]; then @@ -1150,7 +1154,7 @@ 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 + sed -i '' -e "s/$old_commit1/$new_commit1/" $testroot/diff.expected cmp -s $testroot/diff.expected $testroot/diff ret="$?" if [ "$ret" != "0" ]; then @@ -1565,7 +1569,7 @@ test_histedit_fold_only() { cat > $testroot/editor.sh < $testroot/editor.sh < $testroot/stdout) - d_orig2=`env LC_TIME=C date -u -d "@$orig_author_time2" +"%a %b %e %X %Y UTC"` + local prev_LC_TIME="$LC_TIME" + export LC_TIME=C + d_orig2=`date -u -d "@$orig_author_time2" +"%a %b %e %X %Y UTC"` + export LC_TIME="$prev_LC_TIME" d_new2=`date -u -d "@$new_author_time2" +"%G-%m-%d"` d_0=`date -u -d "@$commit0_author_time" +"%G-%m-%d"` cat > $testroot/stdout.expected < $testroot/numbers.diff) @@ -562,7 +562,7 @@ EOF fi # put first hunk back - sed -i -e 's/^2$/a/' $testroot/wt/numbers + sed -i '' -e 's/^2$/a/' $testroot/wt/numbers # revert middle hunk printf "n\ny\nn\n" > $testroot/patchscript @@ -860,7 +860,7 @@ 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 + sed -i '' -e 's/^2$/aa/' $testroot/wt/numbers # revert change with -p printf "y\n" > $testroot/patchscript diff --git a/regress/cmdline/status.sh b/regress/cmdline/status.sh index 6be56860..5cba1783 100755 --- a/regress/cmdline/status.sh +++ b/regress/cmdline/status.sh @@ -177,11 +177,11 @@ test_status_shows_local_mods_after_update() { return 1 fi - sed -i 's/2/22/' $testroot/repo/numbers + sed -i '' 's/2/22/' $testroot/repo/numbers git_commit $testroot/repo -m "modified line 2" # modify line 7; both changes should merge cleanly - sed -i 's/7/77/' $testroot/wt/numbers + sed -i '' 's/7/77/' $testroot/wt/numbers echo "G numbers" > $testroot/stdout.expected echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected @@ -335,12 +335,12 @@ test_status_shows_no_mods_after_complete_merge() { return 1 fi - sed -i 's/2/22/' $testroot/repo/numbers + sed -i '' 's/2/22/' $testroot/repo/numbers git_commit $testroot/repo -m "modified line 2" sleep 1 # modify line 2 again; no local changes are left after merge - sed -i 's/2/22/' $testroot/wt/numbers + sed -i '' 's/2/22/' $testroot/wt/numbers echo "G numbers" > $testroot/stdout.expected echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected @@ -390,11 +390,11 @@ test_status_shows_conflict() { return 1 fi - sed -i 's/2/22/' $testroot/repo/numbers + sed -i '' 's/2/22/' $testroot/repo/numbers git_commit $testroot/repo -m "modified line 2" # modify line 2 in a conflicting way - sed -i 's/2/77/' $testroot/wt/numbers + sed -i '' 's/2/77/' $testroot/wt/numbers echo "C numbers" > $testroot/stdout.expected echo -n "Updated to refs/heads/master: " >> $testroot/stdout.expected diff --git a/regress/cmdline/tag.sh b/regress/cmdline/tag.sh index 6e6e9148..2e908515 100755 --- a/regress/cmdline/tag.sh +++ b/regress/cmdline/tag.sh @@ -137,11 +137,20 @@ test_tag_list() { tag_id=`got ref -r $testroot/repo -l \ | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2` local tagger_time=`git_show_tagger_time $testroot/repo $tag` - d1=`env LC_TIME=C date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"` + + local prev_LC_TIME=$LC_TIME + export LC_TIME=C + d1=`date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"` + LC_TIME="$prev_LC_TIME" + tag_id2=`got ref -r $testroot/repo -l \ | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2` local tagger_time2=`git_show_tagger_time $testroot/repo $tag2` - d2=`env LC_TIME=C date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"` + + prev_LC_TIME="$LC_TIME" + export LC_TIME=C + d2=`date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"` + LC_TIME="$prev_LC_TIME" got tag -r $testroot/repo -l > $testroot/stdout @@ -184,11 +193,17 @@ test_tag_list_lightweight() { tag_id=`got ref -r $testroot/repo -l \ | grep "^refs/tags/$tag" | tr -d ' ' | cut -d: -f2` local tagger_time=`git_show_author_time $testroot/repo $tag` - d1=`env LC_TIME=C date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"` + local prev_LC_TIME=$LC_TIME + export LC_TIME=C + d1=`date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"` + LC_TIME="$prev_LC_TIME" tag_id2=`got ref -r $testroot/repo -l \ | grep "^refs/tags/$tag2" | tr -d ' ' | cut -d: -f2` local tagger_time2=`git_show_author_time $testroot/repo $tag2` - d2=`env LC_TIME=C date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"` + + export LC_TIME=C + d2=`date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"` + LC_TIME="$prev_LC_TIME" got tag -r $testroot/repo -l > $testroot/stdout diff --git a/regress/cmdline/update.sh b/regress/cmdline/update.sh index 0437598f..d93ef8c5 100755 --- a/regress/cmdline/update.sh +++ b/regress/cmdline/update.sh @@ -660,12 +660,12 @@ test_update_merges_file_edits() { echo "modified alpha" > $testroot/repo/alpha echo "modified beta" > $testroot/repo/beta - sed -i 's/2/22/' $testroot/repo/numbers + sed -i '' 's/2/22/' $testroot/repo/numbers git_commit $testroot/repo -m "modified 3 files" echo "modified alpha, too" > $testroot/wt/alpha touch $testroot/wt/beta - sed -i 's/7/77/' $testroot/wt/numbers + sed -i '' 's/7/77/' $testroot/wt/numbers echo "C alpha" > $testroot/stdout.expected echo "U beta" >> $testroot/stdout.expected -- 2.11.4.GIT