#!/bin/sh # # Copyright (c) 2009 Johan Herland # setglobal test_description = ''test git fast-import of notes objects'' source ./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 proc fast_import_commits { setglobal my_ref = $1 setglobal my_num_commits = $2 setglobal my_append_to_file = $3 setglobal my_i = '0' while test $my_i -lt $my_num_commits { setglobal my_i = $shExpr('$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 ' # Change the notes for the three top commits test_tick cat >input < $GIT_COMMITTER_DATE data <>input <>expect < actual && test_cmp expect actual ' test_expect_success 'verify that changing notes respect existing fanout' ' # 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 ' setglobal 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 setglobal num_notes_refs = '10' setglobal num_commits = '16' setglobal some_commits = '8' # Create commits fast_import_commits "refs/heads/more_commits" $num_commits input # Create one note per above commit per notes ref setglobal i = '0' while test $i -lt $num_notes_refs { setglobal i = $shExpr('$i + 1') fast_import_notes "refs/notes/more_notes_$i" $num_commits input } # Trigger branch reloading in git-fast-import by repeating the note creation setglobal i = '0' while test $i -lt $num_notes_refs { setglobal i = $shExpr('$i + 1') fast_import_notes "refs/notes/more_notes_$i" $some_commits input " (2)" } # Finally create the expected output from the notes in refs/notes/more_notes_1 setglobal i = $num_commits while test $i -gt 0 { setglobal note_data = ""note for commit #$i"" if test $i -le $some_commits { setglobal note_data = ""$note_data (2)"" } cat >>expect < actual && test_cmp expect actual ' test_done