#!/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 << """ commit refs/heads/master committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data < $GIT_COMMITTER_DATE data <input << """ commit refs/notes/test committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect << """ fourth commit third commit second commit first note for second commit first commit first note for first commit """ test_expect_success 'add notes with simple M command' ' git fast-import actual && test_cmp expect actual ' test_tick cat >input << """ feature notes commit refs/notes/test committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect << """ fourth commit first note for fourth commit third commit first note for third commit second commit first note for second commit first commit first note for first commit """ test_expect_success 'add notes with simple N command' ' git fast-import actual && test_cmp expect actual ' test_tick cat >input << """ commit refs/notes/test committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect << """ fourth commit second note for fourth commit third commit second note for third commit second commit second note for second commit first commit second note for first commit """ test_expect_success 'update existing notes with N command' ' git fast-import actual && test_cmp expect actual ' test_tick cat >input << """ commit refs/notes/test committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect << """ fourth commit pre-prefix of note for fourth commit $whitespace prefix of note for fourth commit $whitespace third note for fourth commit third commit prefix of note for third commit $whitespace third note for third commit second commit third note for second commit first commit third note for first commit """ test_expect_success 'add concatentation notes with M command' ' git fast-import actual && test_cmp expect actual ' test_tick cat >input << """ commit refs/notes/test committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect << """ fourth commit third commit second commit first commit """ test_expect_success 'verify that deleteall also removes notes' ' git fast-import actual && test_cmp expect actual ' test_tick cat >input << """ commit refs/notes/test committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <expect << """ fourth commit third commit fourth note for third commit second commit first commit fourth note for first commit """ test_expect_success 'verify that later N commands override earlier M commands' ' git fast-import 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 << """ commit $my_ref mark :$my_i committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <>$my_append_to_file << """ commit $my_notes_ref committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <>$my_append_to_file << """ N inline :$my_i data <>input << """ commit refs/notes/many_notes committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <>expect << """ commit #$i note for commit #$i """ setglobal i = $shExpr('$i - 1') } test_expect_success 'add lots of commits and notes' ' git fast-import 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 << """ This is not a note, but rather a regular file residing in a notes tree """ cat >>expect_non-note2 << """ Non-note file """ cat >>expect_non-note3 << """ Another non-note file """ 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 << """ commit refs/notes/many_notes committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <>input << """ N inline refs/heads/many_commits~$j data <>expect << """ commit #$i changed note for commit #$i """ setglobal i = $shExpr('$i - 1') setglobal j = $shExpr('$j + 1') } test_expect_success 'change a few existing notes' ' git fast-import 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 << """ commit refs/notes/many_notes committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE data <>input << """ N 0000000000000000000000000000000000000000 $sha1 """ } setglobal i = $num_commits rm expect while test $i -gt 0 { cat >>expect << """ commit #$i """ if test $i -le $remaining_notes { cat >>expect << """ note for commit #$i """ } setglobal i = $shExpr('$i - 1') } test_expect_success 'remove lots of notes' ' git fast-import 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 << """ commit #$i $note_data """ setglobal i = $shExpr('$i - 1') } test_expect_success "add notes to $num_commits commits in each of $num_notes_refs refs" ' git fast-import --active-branches=5 actual && test_cmp expect actual ' test_done