@matheusbsbs / matheus-bagliano / commits / cfe5eda02a
Fork 0

t7700: consolidate code into test_has_duplicate_object()

The code to test that objects were not duplicated from the packfile was duplicated many times. Extract the duplicated code into test_has_duplicate_object() and use that instead. Refactor the resulting extraction so that if the git command fails, the return code is not silently lost. Signed-off-by: Denton Liu <liu.denton@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Denton Liu committed Dec 4, 2019 at 14:03 UTC cfe5eda02abddaaeb78c4e8bb31357112f0d5413
1 file changed +23 -48
t/t7700-repack.sh
+23 -48
@@ -21,6 +21,25 @@ test_no_missing_in_packs () {
21 test_must_be_empty missing
22 }
23
24 +# we expect $packsha1 and $objsha1 to be defined
25 +test_has_duplicate_object () {
26 + want_duplicate_object="$1"
27 + found_duplicate_object=false
28 + for p in .git/objects/pack/*.idx
29 + do
30 + idx=$(basename $p)
31 + test "pack-$packsha1.idx" = "$idx" && continue
32 + git verify-pack -v $p >packlist || return $?
33 + if egrep "^$objsha1" packlist
34 + then
35 + found_duplicate_object=true
36 + echo "DUPLICATE OBJECT FOUND"
37 + break
38 + fi
39 + done &&
40 + test "$want_duplicate_object" = "$found_duplicate_object"
41 +}
42 +
43 test_expect_success 'objects in packs marked .keep are not repacked' '
44 echo content1 >file1 &&
45 echo content2 >file2 &&
@@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' '
59 mv pack-* .git/objects/pack/ &&
60 git repack -A -d -l &&
61 git prune-packed &&
43 - for p in .git/objects/pack/*.idx
44 - do
45 - idx=$(basename $p)
46 - test "pack-$packsha1.idx" = "$idx" && continue
47 - if git verify-pack -v $p | egrep "^$objsha1"
48 - then
49 - found_duplicate_object=1
50 - echo "DUPLICATE OBJECT FOUND"
51 - break
52 - fi
53 - done &&
54 - test -z "$found_duplicate_object"
62 + test_has_duplicate_object false
63 '
64
65 test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' '
66 # build on $objsha1, $packsha1, and .keep state from previous
67 git repack -Adbl &&
60 - test_when_finished "found_duplicate_object=" &&
61 - for p in .git/objects/pack/*.idx
62 - do
63 - idx=$(basename $p)
64 - test "pack-$packsha1.idx" = "$idx" && continue
65 - if git verify-pack -v $p | egrep "^$objsha1"
66 - then
67 - found_duplicate_object=1
68 - echo "DUPLICATE OBJECT FOUND"
69 - break
70 - fi
71 - done &&
72 - test "$found_duplicate_object" = 1
68 + test_has_duplicate_object true
69 '
70
71 test_expect_success 'writing bitmaps via config can duplicate .keep objects' '
72 # build on $objsha1, $packsha1, and .keep state from previous
73 git -c repack.writebitmaps=true repack -Adl &&
78 - test_when_finished "found_duplicate_object=" &&
79 - for p in .git/objects/pack/*.idx
80 - do
81 - idx=$(basename $p)
82 - test "pack-$packsha1.idx" = "$idx" && continue
83 - if git verify-pack -v $p | egrep "^$objsha1"
84 - then
85 - found_duplicate_object=1
86 - echo "DUPLICATE OBJECT FOUND"
87 - break
88 - fi
89 - done &&
90 - test "$found_duplicate_object" = 1
74 + test_has_duplicate_object true
75 '
76
77 test_expect_success 'loose objects in alternate ODB are not repacked' '
@@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' '
84 git commit -m commit_file3 &&
85 git repack -a -d -l &&
86 git prune-packed &&
103 - for p in .git/objects/pack/*.idx
104 - do
105 - if git verify-pack -v $p | egrep "^$objsha1"
106 - then
107 - found_duplicate_object=1
108 - echo "DUPLICATE OBJECT FOUND"
109 - break
110 - fi
111 - done &&
112 - test -z "$found_duplicate_object"
87 + test_has_duplicate_object false
88 '
89
90 test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '