"log --author-date-order" follow-up
cover "log --author-date-order" follow-up
Complete the series to teach "--author-date-order" to the commands in the log family by adding some tests.
We did not have explicit tests for --date-order, so the third patch in this series adds one while at it.
Junio C Hamano (5):
t/lib-t6000: style fixes
topology tests: teach a helper to take abbreviated timestamps
t6003: add --date-order test
topology tests: teach a helper to set author dates as well
t6003: add --author-date-order test
t/lib-t6000.sh | 104 ++++++++++++++++++++++------------------- t/t6002-rev-list-bisect.sh | 84 ++++++++++++++++----------------- t/t6003-rev-list-topo-order.sh | 101 +++++++++++++++++++++++++++------------ 3 files changed, 169 insertions(+), 120 deletions(-)
Signature · 1 line
1.8.3.1-682-g924db96
PATCH 1/5 t/lib-t6000: style fixes
Mostly fixes to initial indentation with 8-SP (they should be HT) and wrapping long lines.
--- t/lib-t6000.sh | 87 +++++++++++++++++++++++++++------------------------------- 1 file changed, 40 insertions(+), 47 deletions(-)
t/lib-t6000.sh +40 -47
@@ -1,55 +1,50 @@ : included from 6002 and others -[ -d .git/refs/tags ] || mkdir -p .git/refs/tags +mkdir -p .git/refs/tags -:> sed.script +>sed.script -# Answer the sha1 has associated with the tag. The tag must exist in .git or .git/refs/tags -tag() -{ +# Answer the sha1 has associated with the tag. The tag must exist in .git/refs/tags +tag () { _tag=$1 - [ -f .git/refs/tags/$_tag ] || error "tag: \"$_tag\" does not exist" - cat .git/refs/tags/$_tag + test -f ".git/refs/tags/$_tag" || error "tag: \"$_tag\" does not exist" + cat ".git/refs/tags/$_tag" } # Generate a commit using the text specified to make it unique and the tree # named by the tag specified. -unique_commit() -{ +unique_commit () { _text=$1 - _tree=$2 + _tree=$2 shift 2 - echo $_text | git commit-tree $(tag $_tree) "$@" + echo "$_text" | git commit-tree $(tag "$_tree") "$@" } # Save the output of a command into the tag specified. Prepend # a substitution script for the tag onto the front of sed.script -save_tag() -{ +save_tag () { _tag=$1 - [ -n "$_tag" ] || error "usage: save_tag tag commit-args ..." + test -n "$_tag" || error "usage: save_tag tag commit-args ..." shift 1 - "$@" >.git/refs/tags/$_tag + "$@" >".git/refs/tags/$_tag" - echo "s/$(tag $_tag)/$_tag/g" > sed.script.tmp - cat sed.script >> sed.script.tmp + echo "s/$(tag $_tag)/$_tag/g" >sed.script.tmp + cat sed.script >>sed.script.tmp rm sed.script mv sed.script.tmp sed.script } # Replace unhelpful sha1 hashses with their symbolic equivalents -entag() -{ +entag () { sed -f sed.script } # Execute a command after first saving, then setting the GIT_AUTHOR_EMAIL # tag to a specified value. Restore the original value on return. -as_author() -{ +as_author () { _author=$1 shift 1 - _save=$GIT_AUTHOR_EMAIL + _save=$GIT_AUTHOR_EMAIL GIT_AUTHOR_EMAIL="$_author" export GIT_AUTHOR_EMAIL
@@ -63,45 +58,41 @@ as_author() fi } -commit_date() -{ - _commit=$1 - git cat-file commit $_commit | sed -n "s/^committer .*> \([0-9]*\) .*/\1/p" +commit_date () { + _commit=$1 + git cat-file commit $_commit | + sed -n "s/^committer .*> \([0-9]*\) .*/\1/p" } -on_committer_date() -{ - _date=$1 - shift 1 - GIT_COMMITTER_DATE="$_date" - export GIT_COMMITTER_DATE - "$@" - unset GIT_COMMITTER_DATE +on_committer_date () { + _date=$1 + shift 1 + GIT_COMMITTER_DATE="$_date" + export GIT_COMMITTER_DATE + "$@" + unset GIT_COMMITTER_DATE } # Execute a command and suppress any error output. -hide_error() -{ +hide_error () { "$@" 2>/dev/null } -check_output() -{ +check_output () { _name=$1 shift 1 - if eval "$*" | entag > $_name.actual + if eval "$*" | entag >"$_name.actual" then - test_cmp $_name.expected $_name.actual + test_cmp "$_name.expected" "$_name.actual" else - return 1; + return 1 fi } # Turn a reasonable test description into a reasonable test name. # All alphanums translated into -'s which are then compressed and stripped # from front and back. -name_from_description() -{ +name_from_description () { perl -pe ' s/[^A-Za-z0-9.]/-/g; s/-+/-/g;
@@ -119,9 +110,11 @@ name_from_description() test_output_expect_success() { _description=$1 - _test=$2 - [ $# -eq 2 ] || error "usage: test_output_expect_success description test <<EOF ... EOF" - _name=$(echo $_description | name_from_description) - cat > $_name.expected + _test=$2 + test $# -eq 2 || + error "usage: test_output_expect_success description test <<EOF ... EOF" + + _name=$(echo $_description | name_from_description) + cat >"$_name.expected" test_expect_success "$_description" "check_output $_name \"$_test\"" }
Signature · 1 line
1.8.3.1-682-g924db96
PATCH 2/5 topology tests: teach a helper to take abbreviated timestamps
In reply to Junio C HamanoThe on_committer_date helper in t/lib-t6000 is used in t6002 and t6003 with timestamps on a single day within a single minute (i.e. 1971-08-16 00:00) and the tests repeat this over and over.
The actual value of the timestamp, however, does not matter very much; only their relative ordering does.
Introduce another helper to expand only the suffix of the timestamp to a full timestamp to make the lines shorter, and use it in this helper. Also, because all the commits in the test are made with specific GIT_COMMITTER_DATE, stop unsetting it at the end of the helper.
We'll be specifying the author timestamp to these test commits in a later patch, which will be helped with this change.
Also remove a test that was commented-out from t6003; it used to test a commit with the same parent listed twice, which was allowed by mistake but was fixed long time ago.
--- t/lib-t6000.sh | 17 +++++++-- t/t6002-rev-list-bisect.sh | 84 +++++++++++++++++++++--------------------- t/t6003-rev-list-topo-order.sh | 57 +++++++++++++--------------- 3 files changed, 81 insertions(+), 77 deletions(-)
t/lib-t6000.sh +13 -4
@@ -64,13 +64,22 @@ commit_date () { sed -n "s/^committer .*> \([0-9]*\) .*/\1/p" } +# Assign the value of fake date to a variable, but +# allow fairly common "1971-08-16 00:00" to be omittd +assign_fake_date () { + case "$2" in + ??:??:??) eval "$1='1971-08-16 $2'" ;; + ??:??) eval "$1='1971-08-16 00:$2'" ;; + ??) eval "$1='1971-08-16 00:00:$2'" ;; + *) eval "$1='$2'" ;; + esac +} + on_committer_date () { - _date=$1 - shift 1 - GIT_COMMITTER_DATE="$_date" + assign_fake_date GIT_COMMITTER_DATE "$1" export GIT_COMMITTER_DATE + shift 1 "$@" - unset GIT_COMMITTER_DATE } # Execute a command and suppress any error output.
t/t6002-rev-list-bisect.sh +42 -42
96 lines not on this page · raw message
t/t6003-rev-list-topo-order.sh +26 -31
65 lines not on this page · raw message
Signature · 1 line
1.8.3.1-682-g924db96
PATCH 3/5 t6003: add --date-order test
In reply to Junio C HamanoThe "--date-order" output is a slight twist of "--topo-order" in that commits from parallel histories are shown in their committer date order without an attempt to clump commits from a single line of history together like --topo-order does.
--- t/t6003-rev-list-topo-order.sh | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+)
t/t6003-rev-list-topo-order.sh +22 -0
@@ -100,6 +100,28 @@ l0 root EOF +test_output_expect_success 'simple date order' 'git rev-list --date-order HEAD' <<EOF +l5 +l4 +l3 +a4 +b4 +a3 +a2 +c3 +c2 +b3 +b2 +c1 +b1 +a1 +a0 +l2 +l1 +l0 +root +EOF + test_output_expect_success 'two diamonds topo order (g6)' 'git rev-list --topo-order g4' <<EOF g4 h2
Signature · 1 line
1.8.3.1-682-g924db96
PATCH 4/5 topology tests: teach a helper to set author dates as well
In reply to Junio C HamanoIntroduce on_dates helper that is similar to on_committer_date but also sets the author date, not just the committer date.
At this step, just set the same timestamp to the author date as the committer date, as no test looks at author date yet.
--- t/lib-t6000.sh | 8 +++++++ t/t6003-rev-list-topo-order.sh | 52 +++++++++++++++++++++--------------------- 2 files changed, 34 insertions(+), 26 deletions(-)
t/lib-t6000.sh +8 -0
@@ -82,6 +82,14 @@ on_committer_date () { "$@" } +on_dates () { + assign_fake_date GIT_COMMITTER_DATE "$1" + assign_fake_date GIT_AUTHOR_DATE "$2" + export GIT_COMMITTER_DATE GIT_AUTHOR_DATE + shift 2 + "$@" +} + # Execute a command and suppress any error output. hide_error () { "$@" 2>/dev/null
t/t6003-rev-list-topo-order.sh +26 -26
58 lines not on this page · raw message
Signature · 1 line
1.8.3.1-682-g924db96
PATCH 5/5 t6003: add --author-date-order test
In reply to Junio C HamanoTweak the --topo/date-order test vector a bit and mark the author dates of two commits (a2 and a3) earlier than their own committer dates, making them much older than other commits that are made on parallel branches to simulate the case where a long running topic was rebased recently.
They will show up as recent in the --date-order output due to their timestamps, but they appear a lot later in the --author-date-order output, even though their committer timestamp says otherwise.
--- t/t6003-rev-list-topo-order.sh | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-)
t/t6003-rev-list-topo-order.sh +24 -2
@@ -28,8 +28,8 @@ on_dates "00:08" "00:08" as_author [email protected] save_tag b2 unique_commit on_dates "00:09" "00:09" save_tag b3 unique_commit b3 tree -p b2 on_dates "00:10" "00:10" save_tag c2 unique_commit c2 tree -p c1 -p b2 on_dates "00:11" "00:11" save_tag c3 unique_commit c3 tree -p c2 -on_dates "00:12" "00:12" save_tag a2 unique_commit a2 tree -p a1 -on_dates "00:13" "00:13" save_tag a3 unique_commit a3 tree -p a2 +on_dates "00:12" "00:00" save_tag a2 unique_commit a2 tree -p a1 +on_dates "00:13" "00:01" save_tag a3 unique_commit a3 tree -p a2 on_dates "00:14" "00:14" save_tag b4 unique_commit b4 tree -p b3 -p a3 on_dates "00:15" "00:15" save_tag a4 unique_commit a4 tree -p a3 -p b4 -p c3 on_dates "00:16" "00:16" save_tag l3 unique_commit l3 tree -p a4
@@ -122,6 +122,28 @@ l0 root EOF +test_output_expect_success 'simple author-date order' 'git rev-list --author-date-order HEAD' <<EOF +l5 +l4 +l3 +a4 +b4 +c3 +c2 +b3 +b2 +c1 +b1 +a3 +a2 +a1 +a0 +l2 +l1 +l0 +root +EOF + test_output_expect_success 'two diamonds topo order (g6)' 'git rev-list --topo-order g4' <<EOF g4 h2
Signature · 1 line
1.8.3.1-682-g924db96