Skip to content

Commit df63c2e

Browse files
committed
Merge branch 'jk/test-commit-bulk'
A test helper has been introduced to optimize preparation of test repositories with many simple commits, and a handful of test scripts have been updated to use it. * jk/test-commit-bulk: t6200: use test_commit_bulk t5703: use test_commit_bulk t5702: use test_commit_bulk t3311: use test_commit_bulk t5310: increase the number of bitmapped commits test-lib: introduce test_commit_bulk
2 parents 75ce486 + 70b39fb commit df63c2e

6 files changed

+136
-33
lines changed

t/t3311-notes-merge-fanout.sh

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,12 +114,12 @@ cp expect_log_x expect_log_y
114114
test_expect_success 'Add a few hundred commits w/notes to trigger fanout (x -> y)' '
115115
git update-ref refs/notes/y refs/notes/x &&
116116
git config core.notesRef refs/notes/y &&
117-
i=5 &&
118-
while test $i -lt $num
117+
test_commit_bulk --start=6 --id=commit $((num - 5)) &&
118+
i=0 &&
119+
while test $i -lt $((num - 5))
119120
do
120-
i=$(($i + 1)) &&
121-
test_commit "commit$i" >/dev/null &&
122-
git notes add -m "notes for commit$i" || return 1
121+
git notes add -m "notes for commit$i" HEAD~$i || return 1
122+
i=$((i + 1))
123123
done &&
124124
test "$(git rev-parse refs/notes/y)" != "$(git rev-parse refs/notes/x)" &&
125125
# Expected number of commits and notes

t/t5310-pack-bitmaps.sh

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,9 @@ has_any () {
2121
}
2222

2323
test_expect_success 'setup repo with moderate-sized history' '
24-
for i in $(test_seq 1 10)
25-
do
26-
test_commit $i
27-
done &&
24+
test_commit_bulk --id=file 100 &&
2825
git checkout -b other HEAD~5 &&
29-
for i in $(test_seq 1 10)
30-
do
31-
test_commit side-$i
32-
done &&
26+
test_commit_bulk --id=side 10 &&
3327
git checkout master &&
3428
bitmaptip=$(git rev-parse master) &&
3529
blob=$(echo tagged-blob | git hash-object -w --stdin) &&
@@ -106,10 +100,7 @@ test_expect_success 'clone from bitmapped repository' '
106100
'
107101

108102
test_expect_success 'setup further non-bitmapped commits' '
109-
for i in $(test_seq 1 10)
110-
do
111-
test_commit further-$i
112-
done
103+
test_commit_bulk --id=further 10
113104
'
114105

115106
rev_list_tests 'partial bitmap'

t/t5702-protocol-v2.sh

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -499,10 +499,7 @@ test_expect_success 'upload-pack respects client shallows' '
499499
500500
# Add extra commits to the client so that the whole fetch takes more
501501
# than 1 request (due to negotiation)
502-
for i in $(test_seq 1 32)
503-
do
504-
test_commit -C client c$i
505-
done &&
502+
test_commit_bulk -C client --id=c 32 &&
506503
507504
git -C server checkout -b newbranch base &&
508505
test_commit -C server client_wants &&
@@ -711,10 +708,7 @@ test_expect_success 'when server does not send "ready", expect FLUSH' '
711708
# Create many commits to extend the negotiation phase across multiple
712709
# requests, so that the server does not send "ready" in the first
713710
# request.
714-
for i in $(test_seq 1 32)
715-
do
716-
test_commit -C http_child c$i
717-
done &&
711+
test_commit_bulk -C http_child --id=c 32 &&
718712
719713
# After the acknowledgments section, pretend that a DELIM
720714
# (0001) was sent instead of a FLUSH (0000).

t/t5703-upload-pack-ref-in-want.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ test_expect_success 'setup repos for change-while-negotiating test' '
176176
git clone "http://127.0.0.1:$LIB_HTTPD_PORT/smart/repo" "$LOCAL_PRISTINE" &&
177177
cd "$LOCAL_PRISTINE" &&
178178
git checkout -b side &&
179-
for i in $(test_seq 1 33); do test_commit s$i; done &&
179+
test_commit_bulk --id=s 33 &&
180180
181181
# Add novel commits to upstream
182182
git checkout master &&
@@ -287,7 +287,7 @@ test_expect_success 'setup repos for fetching with ref-in-want tests' '
287287
git clone "file://$REPO" "$LOCAL_PRISTINE" &&
288288
cd "$LOCAL_PRISTINE" &&
289289
git checkout -b side &&
290-
for i in $(test_seq 1 33); do test_commit s$i; done &&
290+
test_commit_bulk --id=s 33 &&
291291
292292
# Add novel commits to upstream
293293
git checkout master &&

t/t6200-fmt-merge-msg.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,7 @@ test_expect_success setup '
6666
git commit -a -m "Right #5" &&
6767
6868
git checkout -b long &&
69-
i=0 &&
70-
while test $i -lt 30
71-
do
72-
test_commit $i one &&
73-
i=$(($i+1))
74-
done &&
69+
test_commit_bulk --start=0 --message=%s --filename=one 30 &&
7570
7671
git show-branch &&
7772

t/test-lib-functions.sh

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,129 @@ test_merge () {
233233
git tag "$1"
234234
}
235235

236+
# Efficiently create <nr> commits, each with a unique number (from 1 to <nr>
237+
# by default) in the commit message.
238+
#
239+
# Usage: test_commit_bulk [options] <nr>
240+
# -C <dir>:
241+
# Run all git commands in directory <dir>
242+
# --ref=<n>:
243+
# ref on which to create commits (default: HEAD)
244+
# --start=<n>:
245+
# number commit messages from <n> (default: 1)
246+
# --message=<msg>:
247+
# use <msg> as the commit mesasge (default: "commit %s")
248+
# --filename=<fn>:
249+
# modify <fn> in each commit (default: %s.t)
250+
# --contents=<string>:
251+
# place <string> in each file (default: "content %s")
252+
# --id=<string>:
253+
# shorthand to use <string> and %s in message, filename, and contents
254+
#
255+
# The message, filename, and contents strings are evaluated by printf, with the
256+
# first "%s" replaced by the current commit number. So you can do:
257+
#
258+
# test_commit_bulk --filename=file --contents="modification %s"
259+
#
260+
# to have every commit touch the same file, but with unique content.
261+
#
262+
test_commit_bulk () {
263+
tmpfile=.bulk-commit.input
264+
indir=.
265+
ref=HEAD
266+
n=1
267+
message='commit %s'
268+
filename='%s.t'
269+
contents='content %s'
270+
while test $# -gt 0
271+
do
272+
case "$1" in
273+
-C)
274+
indir=$2
275+
shift
276+
;;
277+
--ref=*)
278+
ref=${1#--*=}
279+
;;
280+
--start=*)
281+
n=${1#--*=}
282+
;;
283+
--message=*)
284+
message=${1#--*=}
285+
;;
286+
--filename=*)
287+
filename=${1#--*=}
288+
;;
289+
--contents=*)
290+
contents=${1#--*=}
291+
;;
292+
--id=*)
293+
message="${1#--*=} %s"
294+
filename="${1#--*=}-%s.t"
295+
contents="${1#--*=} %s"
296+
;;
297+
-*)
298+
BUG "invalid test_commit_bulk option: $1"
299+
;;
300+
*)
301+
break
302+
;;
303+
esac
304+
shift
305+
done
306+
total=$1
307+
308+
add_from=
309+
if git -C "$indir" rev-parse --verify "$ref"
310+
then
311+
add_from=t
312+
fi
313+
314+
while test "$total" -gt 0
315+
do
316+
test_tick &&
317+
echo "commit $ref"
318+
printf 'author %s <%s> %s\n' \
319+
"$GIT_AUTHOR_NAME" \
320+
"$GIT_AUTHOR_EMAIL" \
321+
"$GIT_AUTHOR_DATE"
322+
printf 'committer %s <%s> %s\n' \
323+
"$GIT_COMMITTER_NAME" \
324+
"$GIT_COMMITTER_EMAIL" \
325+
"$GIT_COMMITTER_DATE"
326+
echo "data <<EOF"
327+
printf "$message\n" $n
328+
echo "EOF"
329+
if test -n "$add_from"
330+
then
331+
echo "from $ref^0"
332+
add_from=
333+
fi
334+
printf "M 644 inline $filename\n" $n
335+
echo "data <<EOF"
336+
printf "$contents\n" $n
337+
echo "EOF"
338+
echo
339+
n=$((n + 1))
340+
total=$((total - 1))
341+
done >"$tmpfile"
342+
343+
git -C "$indir" \
344+
-c fastimport.unpacklimit=0 \
345+
fast-import <"$tmpfile" || return 1
346+
347+
# This will be left in place on failure, which may aid debugging.
348+
rm -f "$tmpfile"
349+
350+
# If we updated HEAD, then be nice and update the index and working
351+
# tree, too.
352+
if test "$ref" = "HEAD"
353+
then
354+
git -C "$indir" checkout -f HEAD || return 1
355+
fi
356+
357+
}
358+
236359
# This function helps systems where core.filemode=false is set.
237360
# Use it instead of plain 'chmod +x' to set or unset the executable bit
238361
# of a file in the working directory and add it to the index.

0 commit comments

Comments
 (0)