233
git tag "$1"
234
}
235
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
+
359
# This function helps systems where core.filemode=false is set.
360
# Use it instead of plain 'chmod +x' to set or unset the executable bit
361
# of a file in the working directory and add it to the index.