@@ -40,18 +40,22 @@ init_repo() {
4040 git config maintenance.auto false
4141
4242 # start with an initial commit
43- git \
43+ local commit_date=$( _test_seq_date $( _test_next_seq .) )
44+ GIT_COMMITTER_DATE=" $commit_date " git \
4445 -c user.name=' test' \
4546 -c user.email=' test@example.com' \
46- commit -q --allow-empty -m " init"
47+ commit -q --allow-empty -m " init" \
48+ --date " $commit_date "
4749
4850 # create some bogus branch
4951 git checkout -q -b bogus
5052
51- git \
53+ commit_date=$( _test_seq_date $( _test_next_seq .) )
54+ GIT_COMMITTER_DATE=" $commit_date " git \
5255 -c user.name=' test' \
5356 -c user.email=' test@example.com' \
54- commit -q --allow-empty -m " commit on other branch"
57+ commit -q --allow-empty -m " commit on other branch" \
58+ --date " $commit_date "
5559
5660 # back to master
5761 git checkout -q master
@@ -127,6 +131,23 @@ fetch_head_ref() {
127131 git -C $repo rev-parse HEAD
128132}
129133
134+ # Per-repo monotonic counter used to give commits and waited tags distinct,
135+ # deterministic timestamps. git's committer-date and tag creator-date have
136+ # 1-second resolution; tests previously got distinct timestamps with `sleep 1`,
137+ # which made the suite slow. The counter is persisted to a file so it survives
138+ # the command-substitution subshells callers use.
139+ _test_next_seq () {
140+ local repo=$1
141+ local seq_file=" $repo /.git/.test_seq"
142+ local seq=$(( $(cat "$seq_file " 2 >/ dev/ null || echo 0 ) + 1 ))
143+ echo " $seq " > " $seq_file "
144+ echo " $seq "
145+ }
146+
147+ _test_seq_date () {
148+ date -u -d " @$(( 946684800 + $1 )) " " +%Y-%m-%d %H:%M:%S +0000"
149+ }
150+
130151make_commit_to_file_on_branch () {
131152 local repo=$1
132153 local file=$2
@@ -154,10 +175,12 @@ make_commit_to_file_on_branch() {
154175 commit -q -m " commit $( wc -l $repo /$file ) $msg " \
155176 --date " $( date -R -d ' 1 year' ) "
156177 else
157- git -C $repo \
178+ local commit_date=$( _test_seq_date $( _test_next_seq $repo ) )
179+ GIT_COMMITTER_DATE=" $commit_date " git -C $repo \
158180 -c user.name=' test' \
159181 -c user.email=' test@example.com' \
160- commit -q -m " commit $( wc -l $repo /$file ) $msg "
182+ commit -q -m " commit $( wc -l $repo /$file ) $msg " \
183+ --date " $commit_date "
161184 fi
162185
163186 # output resulting sha
@@ -183,10 +206,12 @@ make_commit_to_file_on_branch_with_path() {
183206 mkdir -p $repo /$path
184207 echo x >> $repo /$path /$file
185208 git -C $repo add $path /$file
186- git -C $repo \
209+ local commit_date=$( _test_seq_date $( _test_next_seq $repo ) )
210+ GIT_COMMITTER_DATE=" $commit_date " git -C $repo \
187211 -c user.name=' test' \
188212 -c user.email=' test@example.com' \
189- commit -q -m " commit $( wc -l $repo /$path /$file ) $msg "
213+ commit -q -m " commit $( wc -l $repo /$path /$file ) $msg " \
214+ --date " $commit_date "
190215
191216 # output resulting sha
192217 git -C $repo rev-parse HEAD
@@ -254,10 +279,12 @@ make_empty_commit() {
254279 local repo=$1
255280 local msg=${2-}
256281
257- git -C $repo \
282+ local commit_date=$( _test_seq_date $( _test_next_seq $repo ) )
283+ GIT_COMMITTER_DATE=" $commit_date " git -C $repo \
258284 -c user.name=' test' \
259285 -c user.email=' test@example.com' \
260- commit -q --allow-empty -m " commit $msg "
286+ commit -q --allow-empty -m " commit $msg " \
287+ --date " $commit_date "
261288
262289 # output resulting sha
263290 git -C $repo rev-parse HEAD
@@ -271,11 +298,9 @@ make_annotated_tag() {
271298
272299 if [ " $wait " == true ]; then
273300 # Give each successive waited tag a distinct, increasing creation date so tags
274- # sort deterministically. git's creatordate has only 1-second resolution, so
275- # rather than sleeping 1s per tag we inject a monotonically increasing committer
276- # date (the annotated tag's tagger/creator date).
277- _annotated_tag_seq=$(( ${_annotated_tag_seq:- 0} + 1 ))
278- GIT_COMMITTER_DATE=" $( date -u -d " @$(( 946684800 + _annotated_tag_seq )) " " +%Y-%m-%d %H:%M:%S +0000" ) " \
301+ # sort deterministically. The shared per-repo counter (see _test_next_seq) is
302+ # also bumped by commits, so commit and tag ordering interleaves correctly.
303+ GIT_COMMITTER_DATE=" $( _test_seq_date $( _test_next_seq $repo ) ) " \
279304 git -C $repo tag -f -a " $tag " -m " $msg "
280305 else
281306 git -C $repo tag -f -a " $tag " -m " $msg "
0 commit comments