t / t3302-notes-index-expensive.shon commit t3302: do not chdir around in the primary test process (f23b1d0)
   1#!/bin/sh
   2#
   3# Copyright (c) 2007 Johannes E. Schindelin
   4#
   5
   6test_description='Test commit notes index (expensive!)'
   7
   8. ./test-lib.sh
   9
  10test_set_prereq NOT_EXPENSIVE
  11test -n "$GIT_NOTES_TIMING_TESTS" && test_set_prereq EXPENSIVE
  12
  13create_repo () {
  14        number_of_commits=$1
  15        nr=0
  16        test -d .git || {
  17        git init &&
  18        (
  19                while test $nr -lt $number_of_commits
  20                do
  21                        nr=$(($nr+1))
  22                        mark=$(($nr+$nr))
  23                        notemark=$(($mark+1))
  24                        test_tick &&
  25                        cat <<-INPUT_END &&
  26                        commit refs/heads/master
  27                        mark :$mark
  28                        committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  29                        data <<COMMIT
  30                        commit #$nr
  31                        COMMIT
  32
  33                        M 644 inline file
  34                        data <<EOF
  35                        file in commit #$nr
  36                        EOF
  37
  38                        blob
  39                        mark :$notemark
  40                        data <<EOF
  41                        note for commit #$nr
  42                        EOF
  43
  44                        INPUT_END
  45                        echo "N :$notemark :$mark" >>note_commit
  46                done &&
  47                test_tick &&
  48                cat <<-INPUT_END &&
  49                commit refs/notes/commits
  50                committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
  51                data <<COMMIT
  52                notes
  53                COMMIT
  54
  55                INPUT_END
  56
  57                cat note_commit
  58        ) |
  59        git fast-import --quiet &&
  60        git config core.notesRef refs/notes/commits
  61        }
  62}
  63
  64test_notes () {
  65        count=$1 &&
  66        git config core.notesRef refs/notes/commits &&
  67        git log | grep "^    " >output &&
  68        i=$count &&
  69        while test $i -gt 0
  70        do
  71                echo "    commit #$i" &&
  72                echo "    note for commit #$i" &&
  73                i=$(($i-1))
  74        done >expect &&
  75        test_cmp expect output
  76}
  77
  78write_script time_notes <<\EOF
  79        mode=$1
  80        i=1
  81        while test $i -lt $2
  82        do
  83                case $1 in
  84                no-notes)
  85                        GIT_NOTES_REF=non-existing
  86                        export GIT_NOTES_REF
  87                        ;;
  88                notes)
  89                        unset GIT_NOTES_REF
  90                        ;;
  91                esac
  92                git log
  93                i=$(($i+1))
  94        done >/dev/null
  95EOF
  96
  97time_notes () {
  98        for mode in no-notes notes
  99        do
 100                echo $mode
 101                /usr/bin/time ../time_notes $mode $1
 102        done
 103}
 104
 105do_tests () {
 106        pr=$1
 107        count=$2
 108
 109        test_expect_success $pr "setup $count" '
 110                mkdir "$count" &&
 111                (
 112                        cd "$count" &&
 113                        create_repo "$count"
 114                )
 115        '
 116
 117        test_expect_success $pr 'notes work' '
 118                (
 119                        cd "$count" &&
 120                        test_notes "$count"
 121                )
 122        '
 123
 124        test_expect_success USR_BIN_TIME,$pr 'notes timing with /usr/bin/time' '
 125                (
 126                        cd "$count" &&
 127                        time_notes 100
 128                )
 129        '
 130}
 131
 132do_tests NOT_EXPENSIVE 10
 133for count in 100 1000 10000
 134do
 135        do_tests EXPENSIVE $count
 136done
 137
 138test_done