Skip to content

Commit 3ed24b6

Browse files
jherlandgitster
authored andcommitted
t3302-notes-index-expensive: Speed up create_repo()
Creating repos with 10/100/1000/10000 commits and notes takes a lot of time. However, using git-fast-import to do the job is a lot more efficient than using plumbing commands to do the same. This patch decreases the overall run-time of this test on my machine from ~3 to ~1 minutes. Signed-off-by: Johan Herland <[email protected]> Acked-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent a8dd2e7 commit 3ed24b6

File tree

1 file changed

+47
-27
lines changed

1 file changed

+47
-27
lines changed

t/t3302-notes-index-expensive.sh

Lines changed: 47 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,50 @@ test -z "$GIT_NOTES_TIMING_TESTS" && {
1616
create_repo () {
1717
number_of_commits=$1
1818
nr=0
19-
parent=
2019
test -d .git || {
2120
git init &&
22-
tree=$(git write-tree) &&
23-
while [ $nr -lt $number_of_commits ]; do
24-
test_tick &&
25-
commit=$(echo $nr | git commit-tree $tree $parent) ||
26-
return
27-
parent="-p $commit"
28-
nr=$(($nr+1))
29-
done &&
30-
git update-ref refs/heads/master $commit &&
31-
{
32-
GIT_INDEX_FILE=.git/temp; export GIT_INDEX_FILE;
33-
git rev-list HEAD | cat -n | sed "s/^[ ][ ]*/ /g" |
34-
while read nr sha1; do
35-
blob=$(echo note $nr | git hash-object -w --stdin) &&
36-
echo $sha1 | sed "s/^/0644 $blob 0 /"
37-
done | git update-index --index-info &&
38-
tree=$(git write-tree) &&
21+
(
22+
while [ $nr -lt $number_of_commits ]; do
23+
nr=$(($nr+1))
24+
mark=$(($nr+$nr))
25+
notemark=$(($mark+1))
26+
test_tick &&
27+
cat <<INPUT_END &&
28+
commit refs/heads/master
29+
mark :$mark
30+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
31+
data <<COMMIT
32+
commit #$nr
33+
COMMIT
34+
35+
M 644 inline file
36+
data <<EOF
37+
file in commit #$nr
38+
EOF
39+
40+
blob
41+
mark :$notemark
42+
data <<EOF
43+
note for commit #$nr
44+
EOF
45+
46+
INPUT_END
47+
48+
echo "N :$notemark :$mark" >> note_commit
49+
done &&
3950
test_tick &&
40-
commit=$(echo notes | git commit-tree $tree) &&
41-
git update-ref refs/notes/commits $commit
42-
} &&
51+
cat <<INPUT_END &&
52+
commit refs/notes/commits
53+
committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> $GIT_COMMITTER_DATE
54+
data <<COMMIT
55+
notes
56+
COMMIT
57+
58+
INPUT_END
59+
60+
cat note_commit
61+
) |
62+
git fast-import --quiet &&
4363
git config core.notesRef refs/notes/commits
4464
}
4565
}
@@ -48,13 +68,13 @@ test_notes () {
4868
count=$1 &&
4969
git config core.notesRef refs/notes/commits &&
5070
git log | grep "^ " > output &&
51-
i=1 &&
52-
while [ $i -le $count ]; do
53-
echo " $(($count-$i))" &&
54-
echo " note $i" &&
55-
i=$(($i+1));
71+
i=$count &&
72+
while [ $i -gt 0 ]; do
73+
echo " commit #$i" &&
74+
echo " note for commit #$i" &&
75+
i=$(($i-1));
5676
done > expect &&
57-
git diff expect output
77+
test_cmp expect output
5878
}
5979

6080
cat > time_notes << \EOF

0 commit comments

Comments
 (0)