{"thread":{"id":"926","subject":"[PATCH 1/7] Additional --merge-order tests and general cleanup of t/t6001-rev-list-merge-order.sh","startedAt":"2005-06-14T02:04:34Z","lastAt":"2005-06-14T02:04:34Z","messageCount":1,"participants":["Jon Seymour"],"isPatch":true,"patchVersion":1,"patchTotal":7},"messages":[{"id":"4929","messageId":"20050614020434.23254.qmail@blackcubes.dyndns.org","threadId":"926","inReplyTo":null,"subject":"[PATCH 1/7] Additional --merge-order tests and general cleanup of t/t6001-rev-list-merge-order.sh","fromName":"Jon Seymour","fromEmail":"jon.seymour@gmail.com","sentAt":"2005-06-14T02:04:34Z","receivedAt":"2005-06-14T02:04:34Z","isPatch":true,"sender":{"key":"jon.seymour@gmail.com","avatar":"https://avatars.githubusercontent.com/u/207131?v=4"},"body":"\nSigned-off-by: Jon Seymour <jon.seymour@gmail.com>\n\n---\n\nThis series of patches is intended to apply on top of:\n\n[PATCH 1/2] Changes to non-epoch.c code required for author-oriented \n\t    git-rev-list changes\n[PATCH 2/2] Add support for author-oriented git-rev-list switches [rev 11]\n\nThis series of 7 patches ultimately splits epoch.c into two and \nre-renders the --merge-order sort support into a generalized \nfacility for performing incremental topological sorts on git\ncommit graphs. This facility can be used by any tool that needs\na topological sort simply by customizing the traversal methods \nin the epoch_methods structure [ which is later renamed to\ntraversal ].\n\nAs part of this refactorisation, this change also achieves\na better separation of concerns between the epoch.c and rev-list.c.\nIn particular, all knowledge of the --show-breaks and output limiting\nis now in rev-list.c, close to where the tool is configured, leaving\nthe traversal algorithms themselves relatively pure.\n\nAssuming these patches are accepted into the mainline, I intend to use\nthese new facilities to build algorithms that:\n   - list a unique path between two commits (useful for undo/redo logic)\n   - list the segments in the graph (useful for building visualisations)\n---\n\n t/t6001-rev-list-merge-order.sh |  240 +++++++++++++++++++++++++--------------\n 1 files changed, 156 insertions(+), 84 deletions(-)\n\ndiff --git a/t/t6001-rev-list-merge-order.sh b/t/t6001-rev-list-merge-order.sh\nold mode 100644\nnew mode 100755\n--- a/t/t6001-rev-list-merge-order.sh\n+++ b/t/t6001-rev-list-merge-order.sh\n@@ -3,77 +3,74 @@\n # Copyright (c) 2005 Jon Seymour\n #\n \n-test_description='Test rev-list --merge-order\n-'\n+test_description='Tests git-rev-list --merge-order functionality'\n+\n . ./test-lib.sh\n+\n+#\n+# TODO: move the following block (upto --- end ...) into testlib.sh\n+#\n [ -d .git/refs/tags ] || mkdir -p .git/refs/tags\n \n sed_script=\"\";\n \n+# Answer the sha1 has associated with the tag. The tag must exist in .git or .git/refs/tags\n function tag\n {\n-\tlocal _tag=$1\n+\t_tag=$1\n \t[ -f .git/refs/tags/$_tag ] || error \"tag: \\\"$_tag\\\" does not exist\"\n \tcat .git/refs/tags/$_tag\n }\n \n-function commit\n+# Generate a commit using the text specified to make it unique and the tree\n+# named by the tag specified.\n+function unique_commit\n {\n-\tlocal _tag=$1\n-        local _tree=$2\n+\t_text=$1\n+        _tree=$2\n \tshift 2\n-    \techo $_tag | git-commit-tree $(tag $_tree) \"$@\"\n+    \techo $_text | git-commit-tree $(tag $_tree) \"$@\"\n }\n \n+# Save the output of a command into the tag specified. Prepend\n+# a substitution script for the tag onto the front of $sed_script\n function save_tag\n {\n-\tlocal _tag=$1\t\n-\t[ -n \"$_tag\" ] || error \"usage: do_commit tag commit-args ...\"\n+\t_tag=$1\t\n+\t[ -n \"$_tag\" ] || error \"usage: save_tag tag commit-args ...\"\n \tshift 1\n     \t\"$@\" >.git/refs/tags/$_tag\n     \tsed_script=\"s/$(tag $_tag)/$_tag/g${sed_script+;}$sed_script\"\n }\n \n+# Replace unhelpful sha1 hashses with their symbolic equivalents \n function entag\n {\n \tsed \"$sed_script\"\n }\n \n+# Execute a command after first saving, then setting the GIT_AUTHOR_EMAIL\n+# tag to a specified value. Restore the original value on return.\n function as_author\n {\n-\tlocal _author=$1\n+\t_author=$1\n \tshift 1\n-        local _save=$GIT_AUTHOR_EMAIL\n+        _save=$GIT_AUTHOR_EMAIL\n \n \texport GIT_AUTHOR_EMAIL=\"$_author\"\n \t\"$@\"\n         export GIT_AUTHOR_EMAIL=\"$_save\"\n }\n \n+# Execute a command and suppress any error output.\n function hide_error\n {\n \t\"$@\" 2>/dev/null\n }\n \n-function check_adjacency\n-{\n-    read previous\n-    echo \"= $previous\"\n-    while read next\n-    do\n-        if ! (git-cat-file commit $previous | grep \"^parent $next\" >/dev/null)\n-        then\n-            echo \"^ $next\"\n-        else\n-            echo \"| $next\"\n-        fi\n-        previous=$next\n-    done\n-}\n-\n function check_output\n {\n-\tlocal _name=$1\n+\t_name=$1\n \tshift 1\n \tif \"$@\" | entag > $_name.actual\n \tthen\n@@ -84,64 +81,99 @@ function check_output\n \t\n }\n \n+# Turn a reasonable test description into a reasonable test name.\n+# All alphanums translated into -'s which are then compressed and stripped\n+# from front and back.\n function name_from_description\n {\n-        tr \"'\" '.' | tr '~`!@#$%^&*()_+={}[]|\\;:\"<>,/?-' '.' | tr -s '.' | tr ' ' '-' | tr '[A-Z]' '[a-z]' | sed \"s/^\\.*//\"\n+        tr \"'\" '-' | tr '~`!@#$%^&*()_+={}[]|\\;:\"<>,/? ' '-' | tr -s '-' | tr '[A-Z]' '[a-z]' | sed \"s/^-*//;s/-*\\$//\"\n }\n \n-#\n-# stdin contains expected result\n-#\n+\n+# Execute the test described by the first argument, by eval'ing\n+# command line specified in the 2nd argument. Check the status code\n+# is zero and that the output matches the stream read from \n+# stdin.\n function test_output_expect_success\n {\t\n-\tlocal _description=$1\n-\tshift 1\n-        local _name=$(echo $_description | name_from_description)\n+\t_description=$1\n+        _test=$2\n+        [ $# -eq 2 ] || error \"usage: test_output_expect_success description test <<EOF ... EOF\"\n+        _name=$(echo $_description | name_from_description)\n \tcat > $_name.expected\n-\ttest_expect_success \"$_description\" \"check_output $_name $*\" \n+\ttest_expect_success \"$_description\" \"check_output $_name $_test\" \n+}\n+\n+# --- end of stuff to move ---\n+\n+# test-case specific test function\n+function check_adjacency\n+{\n+    read previous\n+    echo \"= $previous\"\n+    while read next\n+    do\n+        if ! (git-cat-file commit $previous | grep \"^parent $next\" >/dev/null)\n+        then\n+            echo \"^ $next\"\n+        else\n+            echo \"| $next\"\n+        fi\n+        previous=$next\n+    done\n }\n \n+\n date >path0\n git-update-cache --add path0\n save_tag tree git-write-tree\n-hide_error save_tag root commit root tree\n-save_tag l0 commit l0 tree -p root\n-save_tag l1 commit l1 tree -p l0\n-save_tag l2 commit l2 tree -p l1\n-save_tag a0 commit a0 tree -p l2\n-save_tag a1 commit a1 tree -p a0\n-save_tag b1 commit b1 tree -p a0\n-save_tag c1 commit c1 tree -p b1\n-as_author foobar@example.com save_tag b2 commit b2 tree -p b1\n-save_tag b3 commit b2 tree -p b2\n-save_tag c2 commit c2 tree -p c1 -p b2\n-save_tag c3 commit c3 tree -p c2\n-save_tag a2 commit a2 tree -p a1\n-save_tag a3 commit a3 tree -p a2\n-save_tag b4 commit b4 tree -p b3 -p a3\n-save_tag a4 commit a4 tree -p a3 -p b4 -p c3\n-save_tag l3 commit l3 tree -p a4\n-save_tag l4 commit l4 tree -p l3\n-save_tag l5 commit l5 tree -p l4\n-hide_error save_tag e1 as_author e@example.com commit e1 tree\n-save_tag e2 as_author e@example.com commit e2 tree -p e1\n-save_tag f1 as_author f@example.com commit f1 tree -p e1\n-save_tag e3 as_author e@example.com commit e3 tree -p e2\n-save_tag f2 as_author f@example.com commit f2 tree -p f1\n-save_tag e4 as_author e@example.com commit e4 tree -p e3 -p f2\n-save_tag e5 as_author e@example.com commit e5 tree -p e4\n-save_tag f3 as_author f@example.com commit f3 tree -p f2\n-save_tag f4 as_author f@example.com commit f4 tree -p f3\n-save_tag e6 as_author e@example.com commit e6 tree -p e5 -p f4\n-save_tag f5 as_author f@example.com commit f5 tree -p f4\n-save_tag f6 as_author f@example.com commit f6 tree -p f5 -p e6\n-save_tag e7 as_author e@example.com commit e7 tree -p e6\n-save_tag e8 as_author e@example.com commit e8 tree -p e7\n-save_tag e9 as_author e@example.com commit e9 tree -p e8\n-save_tag f7 as_author f@example.com commit f7 tree -p f6\n-save_tag f8 as_author f@example.com commit f8 tree -p f7\n-save_tag f9 as_author f@example.com commit f9 tree -p f8\n-save_tag e10 as_author e@example.com commit e1 tree -p e9 -p f8\n+hide_error save_tag root unique_commit root tree\n+save_tag l0 unique_commit l0 tree -p root\n+save_tag l1 unique_commit l1 tree -p l0\n+save_tag l2 unique_commit l2 tree -p l1\n+save_tag a0 unique_commit a0 tree -p l2\n+save_tag a1 unique_commit a1 tree -p a0\n+save_tag b1 unique_commit b1 tree -p a0\n+save_tag c1 unique_commit c1 tree -p b1\n+as_author foobar@example.com save_tag b2 unique_commit b2 tree -p b1\n+save_tag b3 unique_commit b2 tree -p b2\n+save_tag c2 unique_commit c2 tree -p c1 -p b2\n+save_tag c3 unique_commit c3 tree -p c2\n+save_tag a2 unique_commit a2 tree -p a1\n+save_tag a3 unique_commit a3 tree -p a2\n+save_tag b4 unique_commit b4 tree -p b3 -p a3\n+save_tag a4 unique_commit a4 tree -p a3 -p b4 -p c3\n+save_tag l3 unique_commit l3 tree -p a4\n+save_tag l4 unique_commit l4 tree -p l3\n+save_tag l5 unique_commit l5 tree -p l4\n+hide_error save_tag e1 as_author e@example.com unique_commit e1 tree\n+save_tag e2 as_author e@example.com unique_commit e2 tree -p e1\n+save_tag f1 as_author f@example.com unique_commit f1 tree -p e1\n+save_tag e3 as_author e@example.com unique_commit e3 tree -p e2\n+save_tag f2 as_author f@example.com unique_commit f2 tree -p f1\n+save_tag e4 as_author e@example.com unique_commit e4 tree -p e3 -p f2\n+save_tag e5 as_author e@example.com unique_commit e5 tree -p e4\n+save_tag f3 as_author f@example.com unique_commit f3 tree -p f2\n+save_tag f4 as_author f@example.com unique_commit f4 tree -p f3\n+save_tag e6 as_author e@example.com unique_commit e6 tree -p e5 -p f4\n+save_tag f5 as_author f@example.com unique_commit f5 tree -p f4\n+save_tag f6 as_author f@example.com unique_commit f6 tree -p f5 -p e6\n+save_tag e7 as_author e@example.com unique_commit e7 tree -p e6\n+save_tag e8 as_author e@example.com unique_commit e8 tree -p e7\n+save_tag e9 as_author e@example.com unique_commit e9 tree -p e8\n+save_tag f7 as_author f@example.com unique_commit f7 tree -p f6\n+save_tag f8 as_author f@example.com unique_commit f8 tree -p f7\n+save_tag f9 as_author f@example.com unique_commit f9 tree -p f8\n+save_tag e10 as_author e@example.com unique_commit e1 tree -p e9 -p f8\n+\n+hide_error save_tag g0 unique_commit g0 tree\n+save_tag g1 unique_commit g1 tree -p g0\n+save_tag h1 unique_commit g2 tree -p g0\n+save_tag g2 unique_commit g3 tree -p g1 -p h1\n+save_tag h2 unique_commit g4 tree -p g2\n+save_tag g3 unique_commit g5 tree -p g2\n+save_tag g4 unique_commit g6 tree -p g3 -p h2\n+\n tag l5 > .git/HEAD\n \n #\n@@ -153,15 +185,15 @@ tag l5 > .git/HEAD\n #\n echo $sed_script > sed.script\n \n-test_expect_success 'Testing that the rev-list has correct number of entries' 'git-rev-list HEAD | wc -l | tr -s \" \"' <<EOF\n+test_expect_success 'rev-list has correct number of entries' 'git-rev-list HEAD | wc -l | tr -s \" \"' <<EOF\n 19\n EOF\n \n normal_adjacency_count=$(git-rev-list HEAD | check_adjacency | grep -c \"\\^\" | tr -d ' ')\n merge_order_adjacency_count=$(git-rev-list --merge-order HEAD | check_adjacency | grep -c \"\\^\" | tr -d ' ')\n-test_expect_success 'Testing that --merge-order produces as many or fewer discontinuities' '[ $merge_order_adjacency_count -le $normal_adjacency_count ]'\n+test_expect_success '--merge-order produces as many or fewer discontinuities' '[ $merge_order_adjacency_count -le $normal_adjacency_count ]'\n \n-test_output_expect_success 'Simple Merge Order Test' 'git-rev-list --merge-order --show-breaks HEAD' <<EOF\n+test_output_expect_success 'simple merge order' 'git-rev-list --merge-order --show-breaks HEAD' <<EOF\n = l5\n | l4\n | l3\n@@ -183,7 +215,17 @@ test_output_expect_success 'Simple Merge\n = root\n EOF\n \n-test_output_expect_success 'Multiple heads' 'git-rev-list --merge-order a3 b3 c3' <<EOF\n+test_output_expect_success 'two diamonds merge order (g6)' 'git-rev-list --merge-order --show-breaks g4' <<EOF\n+= g4\n+| h2\n+^ g3\n+= g2\n+| h1\n+^ g1\n+= g0\n+EOF\n+\n+test_output_expect_success 'multiple heads' 'git-rev-list --merge-order a3 b3 c3' <<EOF\n c3\n c2\n c1\n@@ -200,7 +242,7 @@ l0\n root\n EOF\n \n-test_output_expect_success 'Prune at a1' 'git-rev-list --merge-order a3 b3 c3 ^a1' <<EOF\n+test_output_expect_success 'multiple heads, prune at a1' 'git-rev-list --merge-order a3 b3 c3 ^a1' <<EOF\n c3\n c2\n c1\n@@ -211,7 +253,7 @@ a3\n a2\n EOF\n \n-test_output_expect_success 'Prune at l1' 'git-rev-list --merge-order a3 b3 c3 ^l1' <<EOF\n+test_output_expect_success 'multiple heads, prune at l1' 'git-rev-list --merge-order a3 b3 c3 ^l1' <<EOF\n c3\n c2\n c1\n@@ -225,7 +267,7 @@ a0\n l2\n EOF\n \n-test_output_expect_success 'Head at l5, Prune at l1' 'git-rev-list --merge-order l5 ^l1' <<EOF\n+test_output_expect_success 'cross-epoch, head at l5, prune at l1' 'git-rev-list --merge-order l5 ^l1' <<EOF\n l5\n l4\n l3\n@@ -244,7 +286,7 @@ a0\n l2\n EOF\n \n-test_output_expect_success 'Duplicated head arguments' 'git-rev-list --merge-order l5 l5 ^l1' <<EOF\n+test_output_expect_success 'duplicated head arguments' 'git-rev-list --merge-order l5 l5 ^l1' <<EOF\n l5\n l4\n l3\n@@ -263,7 +305,7 @@ a0\n l2\n EOF\n \n-test_output_expect_success 'Prune near merge' 'git-rev-list --merge-order a4 ^c3' <<EOF\n+test_output_expect_success 'prune near merge' 'git-rev-list --merge-order a4 ^c3' <<EOF\n a4\n b4\n b3\n@@ -294,7 +336,7 @@ test_output_expect_success '--wrt-author\n = root\n EOF\n \n-test_output_expect_success \"Prune at foobar@example.com\" 'git-rev-list --show-breaks --wrt-author --author=foobar@example.com --prune-at-author HEAD' <<EOF\n+test_output_expect_success \"prune at foobar@example.com\" 'git-rev-list --show-breaks --wrt-author --author=foobar@example.com --prune-at-author HEAD' <<EOF\n = l5\n | l4\n | l3\n@@ -392,6 +434,36 @@ test_output_expect_success \"three nodes \n = root\n EOF\n \n+test_output_expect_success \"linear prune l2 ^root\" 'git-rev-list --show-breaks l2 ^root' <<EOF\n+= l2\n+| l1\n+| l0\n+EOF\n+\n+test_output_expect_success \"linear prune l2 ^l0\" 'git-rev-list --show-breaks l2 ^l0' <<EOF\n+= l2\n+| l1\n+EOF\n+\n+test_output_expect_success \"linear prune l2 ^l1\" 'git-rev-list --show-breaks l2 ^l1' <<EOF\n+= l2\n+EOF\n+\n+test_output_expect_success \"linear prune l5 ^a4\" 'git-rev-list --show-breaks l5 ^a4' <<EOF\n+= l5\n+| l4\n+| l3\n+EOF\n+\n+test_output_expect_success \"linear prune l5 ^l3\" 'git-rev-list --show-breaks l5 ^l3' <<EOF\n+= l5\n+| l4\n+EOF\n+\n+test_output_expect_success \"linear prune l5 ^l4\" 'git-rev-list --show-breaks l5 ^l4' <<EOF\n+= l5\n+EOF\n+\n test_expect_failure \"all heads uninteresting\" 'git-rev-list --show-breaks a3 ^a3'\n #\n #\n------------\n"}]}