From: Christian Weisgerber Subject: -portable: regress: stop using GNU date on BSD To: gameoftrees@openbsd.org Date: Fri, 3 Mar 2023 23:49:32 +0100 The diff below removes the requirement for GNU date on BSD systems and reduces the number of changes in -portable. * We check whether date(1) supports the -r option. For robustness, I picked 86400 because it is sufficiently different from 0, precedes any leap seconds, and in the event that a file "86400" exists, its timestamp is unlikely to match Jan 2 1970. * Only if the check fails do we define a date() wrapper function that invokes GNU date. The wrapper transforms BSD -r into the corresponding GNU -d option. * This allows us to drop all -portable changes that replace the date calls. As a result of this and the previous ln() wrapper removal, GNU coreutils are no longer required for running the regression tests on BSD. diff b237f6f6bc0a3c53cbc091d850eeebf278a6bc89 901964ccb251b73cf35a82c6bb1ab4c8d4e3e047 commit - b237f6f6bc0a3c53cbc091d850eeebf278a6bc89 commit + 901964ccb251b73cf35a82c6bb1ab4c8d4e3e047 blob - 7897a7e13c5efe5e42d7cafe4794e1e3ab0ce5b2 blob + 473f0cbbff46cfc9956105e30e007792516993d8 --- regress/cmdline/common.sh +++ regress/cmdline/common.sh @@ -38,7 +38,7 @@ date() # commands are used. [ -z "$PLATFORM" -a "$(uname)" = "Linux" ] && PLATFORM="linux" -date() +[ "$(date -u -r 86400 +%F 2>/dev/null)" = 1970-01-02 ] || date() { DATECMD="date" [ "$PLATFORM" != "linux" ] && { @@ -48,7 +48,17 @@ date() echo "Couldn't find gdate is GNU coreutils installed?" } } - command "$DATECMD" "$@" + + local flag r u + while getopts r:u flag; do + case $flag in + r) r=$OPTARG ;; + u) u=-u ;; + ?) exit 1 ;; + esac + done + shift $((OPTIND - 1)) + command "$DATECMD" $u ${r+-d"@$r"} "$@" } sed() blob - 3d48fd3967ec94a3096d042e38e36f52a695c6a0 blob + 719bac3298df1e16197cba688737ead5ea2508cd --- regress/cmdline/blame.sh +++ regress/cmdline/blame.sh @@ -65,7 +65,7 @@ test_blame_basic() { local short_commit2=`trim_obj_id 32 $commit2` local short_commit3=`trim_obj_id 32 $commit3` - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected echo "3) $short_commit3 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected @@ -113,7 +113,7 @@ test_blame_tag() { local short_commit1=`trim_obj_id 32 $commit1` local short_commit2=`trim_obj_id 32 $commit2` - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected @@ -149,7 +149,7 @@ test_blame_file_single_line() { local short_commit1=`trim_obj_id 32 $commit1` - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout @@ -184,7 +184,7 @@ test_blame_file_single_line_no_newline() { local short_commit1=`trim_obj_id 32 $commit1` - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected cmp -s $testroot/stdout.expected $testroot/stdout @@ -213,7 +213,7 @@ test_blame_all_lines_replaced() { (cd $testroot/wt && got blame alpha > $testroot/stdout) - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit1 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected echo "3) $short_commit1 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected @@ -265,7 +265,7 @@ test_blame_lines_shifted_up() { (cd $testroot/wt && got blame alpha > $testroot/stdout) - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit1 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected echo "3) $short_commit3 $d $GOT_AUTHOR_8 foo" >> $testroot/stdout.expected @@ -321,7 +321,7 @@ test_blame_lines_shifted_down() { (cd $testroot/wt && got blame alpha > $testroot/stdout) - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "01) $short_commit1 $d $GOT_AUTHOR_8 1" \ > $testroot/stdout.expected echo "02) $short_commit1 $d $GOT_AUTHOR_8 2" \ @@ -394,7 +394,7 @@ EOF local commit1=`git_show_head $testroot/repo` local short_commit1=`trim_obj_id 32 $commit1` local author_time1=`git_show_author_time $testroot/repo` - local d1=`date -u -d "@$author_time1" +"%G-%m-%d"` + local d1=`date -u -r $author_time1 +"%G-%m-%d"` cat > $testroot/wt/alpha < $testroot/wt/alpha < $testroot/wt/alpha < $testroot/stdout) @@ -718,7 +718,7 @@ test_blame_added_on_branch() { local short_commit2=`trim_obj_id 32 $commit2` local short_commit3=`trim_obj_id 32 $commit3` - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit1 $d $GOT_AUTHOR_8 1" > $testroot/stdout.expected echo "2) $short_commit2 $d $GOT_AUTHOR_8 2" >> $testroot/stdout.expected echo "3) $short_commit3 $d $GOT_AUTHOR_8 3" >> $testroot/stdout.expected @@ -789,7 +789,7 @@ test_blame_symlink() { return 1 fi - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit0 $d $GOT_AUTHOR_8 alpha" \ > $testroot/stdout.expected @@ -810,7 +810,7 @@ test_blame_symlink() { return 1 fi - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit0 $d $GOT_AUTHOR_8 beta" \ > $testroot/stdout.expected @@ -959,7 +959,7 @@ EOF (cd $testroot/wt && got blame alpha > $testroot/stdout) - d=`date -u -d "@$author_time" +"%G-%m-%d"` + d=`date -u -r $author_time +"%G-%m-%d"` echo "1) $short_commit5 $d $GOT_AUTHOR_8 X" > $testroot/stdout.expected echo "2) $short_commit1 $d $GOT_AUTHOR_8 A" >> $testroot/stdout.expected echo "3) $short_commit1 $d $GOT_AUTHOR_8 B" >> $testroot/stdout.expected blob - 74cf5cf5b28feb35d4b3b9bde9ff356cc0f2586c blob + bfe573c5cf15af13e12329ddaea88102d0dc9220 --- regress/cmdline/commit.sh +++ regress/cmdline/commit.sh @@ -1617,7 +1617,7 @@ EOF local author_time=`git_show_author_time $testroot/repo` local prev_LC_TIME="$LC_TIME" export LC_TIME=C - d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"` + d=`date -u -r $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 @@ -1659,7 +1659,7 @@ EOF local author_time=`git_show_author_time $testroot/repo` local prev_LC_TIME="$LC_TIME" export LC_TIME=C - d=`date -u -d "@$author_time" +"%a %b %e %X %Y UTC"` + d=`date -u -r $author_time +"%a %b %e %X %Y UTC"` LC_TIME="$prev_LC_TIME" echo "-----------------------------------------------" \ > $testroot/stdout.expected blob - a2f15eebb25a5cb8f1f524fcda7e9545a66598bf blob + a28c22fe55ef65ffb5ea21159dd2527f7fdecb10 --- regress/cmdline/histedit.sh +++ regress/cmdline/histedit.sh @@ -153,14 +153,14 @@ 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_orig1=`date -u -r $old_author_time1 +"%G-%m-%d"` local prev_LC_TIME="$LC_TIME" export LC_TIME=C - d_orig2=`date -u -d "@$old_author_time2" +"%a %b %e %X %Y UTC"` + d_orig2=`date -u -r $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"` + d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"` + d_orig=`date -u -r $orig_author_time +"%G-%m-%d"` cat > $testroot/stdout.expected < /dev/null) local commit_id2=`git_show_head $testroot/repo` local author_time2=`git_show_author_time $testroot/repo` - d=`date -u -d "@${author_time1}" +"%G-%m-%d"` + d=`date -u -r $author_time1 +"%G-%m-%d"` printf "$d %-7s test oneline\n" master > $testroot/stdout.expected - d=`date -u -d "@${author_time2}" +"%G-%m-%d"` + d=`date -u -r $author_time2 +"%G-%m-%d"` printf "$d %.7s test oneline\n" $commit_id1 >> $testroot/stdout.expected (cd $testroot/repo && got log -s | head -n 2 > $testroot/stdout) blob - 076ea66b61f236b000343e68fc3d1b761ac0b442 blob + 3dae9846af1f48ed12ad622a7be5ae5d83ac020d --- regress/cmdline/rebase.sh +++ regress/cmdline/rebase.sh @@ -155,10 +155,10 @@ test_rebase_basic() { (cd $testroot/repo && got rebase -l > $testroot/stdout) local prev_LC_TIME="$LC_TIME" export LC_TIME=C - d_orig2=`date -u -d "@$orig_author_time2" +"%a %b %e %X %Y UTC"` + d_orig2=`date -u -r $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"` + d_new2=`date -u -r $new_author_time2 +"%G-%m-%d"` + d_0=`date -u -r $commit0_author_time +"%G-%m-%d"` cat > $testroot/stdout.expected < $testroot/stdout @@ -247,14 +247,14 @@ test_tag_list_lightweight() { local tagger_time=`git_show_author_time $testroot/repo $tag` local prev_LC_TIME=$LC_TIME export LC_TIME=C - d1=`date -u -d "@$tagger_time" +"%a %b %e %X %Y UTC"` + d1=`date -u -r $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` export LC_TIME=C - d2=`date -u -d "@$tagger_time2" +"%a %b %e %X %Y UTC"` + d2=`date -u -r $tagger_time2 +"%a %b %e %X %Y UTC"` LC_TIME="$prev_LC_TIME" got tag -r $testroot/repo -l > $testroot/stdout -- Christian "naddy" Weisgerber naddy@mips.inka.de