diff mbox series

[v4,3/6] t/lib-cruft.sh: extract some cruft-related helpers

Message ID aa7588f8176b7e699005680697746ba5dcf75005.1741648467.git.me@ttaylorr.com (mailing list archive)
State New
Headers show
Series pack-objects: freshen objects with multi-cruft packs | expand

Commit Message

Taylor Blau March 11, 2025, 12:21 a.m. UTC
The test script in t7704-repack-cruft.sh uses a handful of helpers to
generate and pack random blobs, but a forthcoming test in t5329 will
want to make use of generate_random_blob().

Instead of rewriting that function, move it (and the related helpers) to
its own reusable library to avoid duplicating the function.

Signed-off-by: Taylor Blau <me@ttaylorr.com>
---
 t/lib-cruft.sh          | 23 +++++++++++++++++++++++
 t/t7704-repack-cruft.sh | 22 +---------------------
 2 files changed, 24 insertions(+), 21 deletions(-)
 create mode 100644 t/lib-cruft.sh
diff mbox series

Patch

diff --git a/t/lib-cruft.sh b/t/lib-cruft.sh
new file mode 100644
index 0000000000..9fdc0b01b0
--- /dev/null
+++ b/t/lib-cruft.sh
@@ -0,0 +1,23 @@ 
+# generate_random_blob <seed-string> [<size>]
+generate_random_blob () {
+	test-tool genrandom "$@" >blob &&
+	git hash-object -w -t blob blob &&
+	rm blob
+}
+
+# pack_random_blob <seed-string> [<size>]
+pack_random_blob () {
+	generate_random_blob "$@" &&
+	git repack -d -q >/dev/null
+}
+
+# generate_cruft_pack <seed-string> [<size>]
+generate_cruft_pack () {
+	pack_random_blob "$@" >/dev/null &&
+
+	ls $packdir/pack-*.pack | xargs -n 1 basename >in &&
+	pack="$(git pack-objects --cruft $packdir/pack <in)" &&
+	git prune-packed &&
+
+	echo "$packdir/pack-$pack.mtimes"
+}
diff --git a/t/t7704-repack-cruft.sh b/t/t7704-repack-cruft.sh
index 5ce2648a29..88c6ce2913 100755
--- a/t/t7704-repack-cruft.sh
+++ b/t/t7704-repack-cruft.sh
@@ -3,6 +3,7 @@ 
 test_description='git repack works correctly'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-cruft.sh
 
 objdir=.git/objects
 packdir=$objdir/pack
@@ -128,27 +129,6 @@  test_expect_success '--expire-to stores pruned objects (5.minutes.ago)' '
 	)
 '
 
-generate_random_blob() {
-	test-tool genrandom "$@" >blob &&
-	git hash-object -w -t blob blob &&
-	rm blob
-}
-
-pack_random_blob () {
-	generate_random_blob "$@" &&
-	git repack -d -q >/dev/null
-}
-
-generate_cruft_pack () {
-	pack_random_blob "$@" >/dev/null &&
-
-	ls $packdir/pack-*.pack | xargs -n 1 basename >in &&
-	pack="$(git pack-objects --cruft $packdir/pack <in)" &&
-	git prune-packed &&
-
-	echo "$packdir/pack-$pack.mtimes"
-}
-
 test_expect_success '--max-cruft-size creates new packs when above threshold' '
 	git init max-cruft-size-large &&
 	(