#!/bin/sh global test_description := ''Test that adding/removing many notes triggers automatic fanout restructuring'' source ./test-lib.sh test_expect_success 'creating many notes with git-notes' ' num_notes=300 && i=0 && while test $i -lt $num_notes do i=$(($i + 1)) && test_tick && echo "file for commit #$i" > file && git add file && git commit -q -m "commit #$i" && git notes add -m "note #$i" || return 1 done ' test_expect_success 'many notes created correctly with git-notes' ' git log | grep "^ " > output && i=300 && while test $i -gt 0 do echo " commit #$i" && echo " note #$i" && i=$(($i - 1)); done > expect && test_cmp expect output ' test_expect_success 'many notes created with git-notes triggers fanout' ' # Expect entire notes tree to have a fanout == 1 git ls-tree -r --name-only refs/notes/commits | while read path do case "$path" in ??/??????????????????????????????????????) : true ;; *) echo "Invalid path \"$path\"" && return 1 ;; esac done ' test_expect_success 'deleting most notes with git-notes' ' num_notes=250 && i=0 && git rev-list HEAD | while test $i -lt $num_notes && read sha1 do i=$(($i + 1)) && test_tick && git notes remove "$sha1" || exit 1 done ' test_expect_success 'most notes deleted correctly with git-notes' ' git log HEAD~250 | grep "^ " > output && i=50 && while test $i -gt 0 do echo " commit #$i" && echo " note #$i" && i=$(($i - 1)); done > expect && test_cmp expect output ' test_expect_success 'deleting most notes triggers fanout consolidation' ' # Expect entire notes tree to have a fanout == 0 git ls-tree -r --name-only refs/notes/commits | while read path do case "$path" in ????????????????????????????????????????) : true ;; *) echo "Invalid path \"$path\"" && return 1 ;; esac done ' test_done (CommandList children: [ (Assignment keyword: Assign_None pairs: [ (assign_pair lhs: (LhsName name:test_description) op: Equal rhs: {(SQ <"Test that adding/removing many notes triggers automatic fanout restructuring">)} spids: [4] ) ] spids: [4] ) (C {(.)} {(./test-lib.sh)}) (C {(test_expect_success)} {(SQ <"creating many notes with git-notes">)} { (SQ <"\n"> <"\tnum_notes=300 &&\n"> <"\ti=0 &&\n"> <"\twhile test $i -lt $num_notes\n"> <"\tdo\n"> <"\t\ti=$(($i + 1)) &&\n"> <"\t\ttest_tick &&\n"> <"\t\techo \"file for commit #$i\" > file &&\n"> <"\t\tgit add file &&\n"> <"\t\tgit commit -q -m \"commit #$i\" &&\n"> <"\t\tgit notes add -m \"note #$i\" || return 1\n"> <"\tdone\n"> ) } ) (C {(test_expect_success)} {(SQ <"many notes created correctly with git-notes">)} { (SQ <"\n"> <"\tgit log | grep \"^ \" > output &&\n"> <"\ti=300 &&\n"> <"\twhile test $i -gt 0\n"> <"\tdo\n"> <"\t\techo \" commit #$i\" &&\n"> <"\t\techo \" note #$i\" &&\n"> <"\t\ti=$(($i - 1));\n"> <"\tdone > expect &&\n"> <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"many notes created with git-notes triggers fanout">)} { (SQ <"\n"> <"\t# Expect entire notes tree to have a fanout == 1\n"> <"\tgit ls-tree -r --name-only refs/notes/commits |\n"> <"\twhile read path\n"> <"\tdo\n"> <"\t\tcase \"$path\" in\n"> <"\t\t??/??????????????????????????????????????)\n"> <"\t\t\t: true\n"> <"\t\t\t;;\n"> <"\t\t*)\n"> <"\t\t\techo \"Invalid path \\\"$path\\\"\" &&\n"> <"\t\t\treturn 1\n"> <"\t\t\t;;\n"> <"\t\tesac\n"> <"\tdone\n"> ) } ) (C {(test_expect_success)} {(SQ <"deleting most notes with git-notes">)} { (SQ <"\n"> <"\tnum_notes=250 &&\n"> <"\ti=0 &&\n"> <"\tgit rev-list HEAD |\n"> <"\twhile test $i -lt $num_notes && read sha1\n"> <"\tdo\n"> <"\t\ti=$(($i + 1)) &&\n"> <"\t\ttest_tick &&\n"> <"\t\tgit notes remove \"$sha1\" ||\n"> <"\t\texit 1\n"> <"\tdone\n"> ) } ) (C {(test_expect_success)} {(SQ <"most notes deleted correctly with git-notes">)} { (SQ <"\n"> <"\tgit log HEAD~250 | grep \"^ \" > output &&\n"> <"\ti=50 &&\n"> <"\twhile test $i -gt 0\n"> <"\tdo\n"> <"\t\techo \" commit #$i\" &&\n"> <"\t\techo \" note #$i\" &&\n"> <"\t\ti=$(($i - 1));\n"> <"\tdone > expect &&\n"> <"\ttest_cmp expect output\n"> ) } ) (C {(test_expect_success)} {(SQ <"deleting most notes triggers fanout consolidation">)} { (SQ <"\n"> <"\t# Expect entire notes tree to have a fanout == 0\n"> <"\tgit ls-tree -r --name-only refs/notes/commits |\n"> <"\twhile read path\n"> <"\tdo\n"> <"\t\tcase \"$path\" in\n"> <"\t\t????????????????????????????????????????)\n"> <"\t\t\t: true\n"> <"\t\t\t;;\n"> <"\t\t*)\n"> <"\t\t\techo \"Invalid path \\\"$path\\\"\" &&\n"> <"\t\t\treturn 1\n"> <"\t\t\t;;\n"> <"\t\tesac\n"> <"\tdone\n"> ) } ) (C {(test_done)}) ] )