From a8b59ef578df2b06a89fecd46f3d379895e77e8f Mon Sep 17 00:00:00 2001 From: Johan Herland Date: Mon, 7 Dec 2009 12:27:26 +0100 Subject: [PATCH] Add more testcases to test fast-import of notes This patch adds testcases verifying correct behaviour in several scenarios regarding fast-import of notes: - using a mixture of 'N' and 'M' commands - updating existing notes - concatenation of notes - 'deleteall' also removes notes - fanout schemes is added/removed when needed - git-fast-import's branch unload/reload preserves notes - non-notes are not clobbered in the presence of notes Signed-off-by: Johan Herland Signed-off-by: Junio C Hamano --- t/t9301-fast-import-notes.sh | 623 +++++++++++++++++++++++++++++++++++ 1 file changed, 623 insertions(+) create mode 100755 t/t9301-fast-import-notes.sh diff --git a/t/t9301-fast-import-notes.sh b/t/t9301-fast-import-notes.sh new file mode 100755 index 0000000000..a5c99d8507 --- /dev/null +++ b/t/t9301-fast-import-notes.sh @@ -0,0 +1,623 @@ +#!/bin/sh +# +# Copyright (c) 2009 Johan Herland +# + +test_description='test git fast-import of notes objects' +. ./test-lib.sh + + +test_tick +cat >input < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data < $GIT_COMMITTER_DATE +data <input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +test_tick +cat >input < $GIT_COMMITTER_DATE +data <expect < actual && + test_cmp expect actual + +' + +# Write fast-import commands to create the given number of commits +fast_import_commits () { + my_ref=$1 + my_num_commits=$2 + my_append_to_file=$3 + my_i=0 + while test $my_i -lt $my_num_commits + do + my_i=$(($my_i + 1)) + test_tick + cat >>"$my_append_to_file" < $GIT_COMMITTER_DATE +data <>"$my_append_to_file" < $GIT_COMMITTER_DATE +data <>"$my_append_to_file" <>input < $GIT_COMMITTER_DATE +data <>expect < actual && + test_cmp expect actual + +' + +test_expect_success 'verify that lots of notes trigger a fanout scheme' ' + + # None of the entries in the top-level notes tree should be a full SHA1 + git ls-tree --name-only refs/notes/many_notes | + while read path + do + if test $(expr length "$path") -ge 40 + then + return 1 + fi + done + +' + +cat >>expect_non-note1 << EOF +This is not a note, but rather a regular file residing in a notes tree +EOF + +cat >>expect_non-note2 << EOF +Non-note file +EOF + +cat >>expect_non-note3 << EOF +Another non-note file +EOF + +test_expect_success 'verify that non-notes are untouched by a fanout change' ' + + git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual && + test_cmp expect_non-note1 actual && + git cat-file -p refs/notes/many_notes:deadbeef > actual && + test_cmp expect_non-note2 actual && + git cat-file -p refs/notes/many_notes:de/adbeef > actual && + test_cmp expect_non-note3 actual + +' +remaining_notes=10 +test_tick +cat >>input < $GIT_COMMITTER_DATE +data <>input <>expect <>expect < actual && + test_cmp expect actual + +' + +test_expect_success 'verify that removing notes trigger fanout consolidation' ' + + # All entries in the top-level notes tree should be a full SHA1 + git ls-tree --name-only -r refs/notes/many_notes | + while read path + do + # Explicitly ignore the non-note paths + test "$path" = "foobar/non-note.txt" && continue + test "$path" = "deadbeef" && continue + test "$path" = "de/adbeef" && continue + + if test $(expr length "$path") -ne 40 + then + return 1 + fi + done + +' + +test_expect_success 'verify that non-notes are untouched by a fanout change' ' + + git cat-file -p refs/notes/many_notes:foobar/non-note.txt > actual && + test_cmp expect_non-note1 actual && + git cat-file -p refs/notes/many_notes:deadbeef > actual && + test_cmp expect_non-note2 actual && + git cat-file -p refs/notes/many_notes:de/adbeef > actual && + test_cmp expect_non-note3 actual + +' + + +rm input expect +num_notes_refs=10 +num_commits=16 +some_commits=8 +# Create commits +fast_import_commits "refs/heads/more_commits" $num_commits input +# Create one note per above commit per notes ref +i=0 +while test $i -lt $num_notes_refs +do + i=$(($i + 1)) + fast_import_notes "refs/notes/more_notes_$i" $num_commits input +done +# Trigger branch reloading in git-fast-import by repeating the note creation +i=0 +while test $i -lt $num_notes_refs +do + i=$(($i + 1)) + fast_import_notes "refs/notes/more_notes_$i" $some_commits input " (2)" +done +# Finally create the expected output from the notes in refs/notes/more_notes_1 +i=$num_commits +while test $i -gt 0 +do + note_data="note for commit #$i" + if test $i -le $some_commits + then + note_data="$note_data (2)" + fi + cat >>expect < actual && + test_cmp expect actual + +' + +test_done