From 92cd872202241a0b80e88dadac5a4db071c8d1fa Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 19 Mar 2009 22:47:50 -0500 Subject: t7700-repack: add two new tests demonstrating repacking flaws 1) The new --kept-pack-only mechansim of rev-list/pack-objects has replaced --unpacked=. This new mechansim does not operate solely on "local" packs now. The result is that objects residing in an alternate pack which has a .keep file will not be repacked with repack -a. This flaw is only apparent when a commit object is the one residing in an alternate kept pack. 2) The 'repack unpacked objects' and 'loosen unpacked objects' mechanisms of pack-objects, i.e. --keep-unreachable and --unpack-unreachable, now do not operate solely on local packs. The --keep-unreachable option no longer has any callers, but --unpack-unreachable is used when repack is called with '-A -d' and the local repo has existing packs. In this case, objects residing in alternate, not-kept packs will be loosened, and then immediately deleted by repack's call to prune-packed. The test must manually call pack-objects to avoid the call to prune-packed that is made by repack when -d is used. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 't') diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 3f602ea7d..fa4772101 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -69,5 +69,49 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is done ' +test_expect_failure 'packed obs in alternate ODB kept pack are repacked' ' + # swap the .keep so the commit object is in the pack with .keep + for p in alt_objects/pack/*.pack + do + base_name=$(basename $p .pack) + if test -f alt_objects/pack/$base_name.keep + then + rm alt_objects/pack/$base_name.keep + else + touch alt_objects/pack/$base_name.keep + fi + done + git repack -a -d && + myidx=$(ls -1 .git/objects/pack/*.idx) && + test -f "$myidx" && + for p in alt_objects/pack/*.idx; do + git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" + done | while read sha1 rest; do + if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then + echo "Missing object in local pack: $sha1" + return 1 + fi + done +' + +test_expect_failure 'packed unreachable obs in alternate ODB are not loosened' ' + rm -f alt_objects/pack/*.keep && + mv .git/objects/pack/* alt_objects/pack/ && + csha1=$(git rev-parse HEAD^{commit}) && + git reset --hard HEAD^ && + sleep 1 && + git reflog expire --expire=now --expire-unreachable=now --all && + # The pack-objects call on the next line is equivalent to + # git repack -A -d without the call to prune-packed + git pack-objects --honor-pack-keep --non-empty --all --reflog \ + --unpack-unreachable .git/objects/info/alternates && + test_must_fail git show $csha1 +' + test_done -- cgit v1.2.1 From 171110a4a67f04c28d2ac89385ab88ba051fc780 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 19 Mar 2009 22:47:51 -0500 Subject: git-repack.sh: don't use --kept-pack-only option to pack-objects The --kept-pack-only option to pack-objects treats all kept packs as equal. This results in objects that reside in an alternate pack that has a .keep file, not being packed into a newly created pack when the user specifies the -a option to repack. Since the user may not have any control over the alternate database, git should not refrain from repacking those objects even though they are in a pack with a .keep file. This fixes the 'packed obs in alternate ODB kept pack are repacked' test in t7700. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index fa4772101..adba8a1c6 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -69,7 +69,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is done ' -test_expect_failure 'packed obs in alternate ODB kept pack are repacked' ' +test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' # swap the .keep so the commit object is in the pack with .keep for p in alt_objects/pack/*.pack do -- cgit v1.2.1 From 79bc4c715516fdb393d107359327c1e7fbb8bf04 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 19 Mar 2009 22:47:52 -0500 Subject: pack-objects: only repack or loosen objects residing in "local" packs These two features were invented for use by repack when repack will delete the local packs that have been made redundant. The packs accessible through alternates are not deleted by repack, so the objects contained in them are still accessible after the local packs are deleted. They do not need to be repacked into the new pack or loosened. For the case of loosening they would immediately be deleted by the subsequent prune-packed that is called by repack anyway. This fixes the test 'packed unreachable obs in alternate ODB are not loosened' in t7700. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index adba8a1c6..1ef3892f9 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -94,7 +94,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' done ' -test_expect_failure 'packed unreachable obs in alternate ODB are not loosened' ' +test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f alt_objects/pack/*.keep && mv .git/objects/pack/* alt_objects/pack/ && csha1=$(git rev-parse HEAD^{commit}) && -- cgit v1.2.1 From 869a3d34c1aea92a10bc8eaa994bd55f4b0b04f2 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sat, 21 Mar 2009 17:25:30 -0500 Subject: t7700: demonstrate repack flaw which may loosen objects unnecessarily If an unreferenced object exists in both a local pack and in either a pack residing in an alternate object database or a local kept pack, then the pack-objects call made by repack will loosen that object only to have it immediately pruned by repack's call to prune-packed. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 't') diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1ef3892f9..013e488bd 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -113,5 +113,22 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' test_must_fail git show $csha1 ' +test_expect_failure 'local packed unreachable obs that exist in alternate ODB are not loosened' ' + echo `pwd`/alt_objects > .git/objects/info/alternates && + echo "$csha1" | git pack-objects --non-empty --all --reflog pack && + rm -f .git/objects/pack/* && + mv pack-* .git/objects/pack/ && + # The pack-objects call on the next line is equivalent to + # git repack -A -d without the call to prune-packed + git pack-objects --honor-pack-keep --non-empty --all --reflog \ + --unpack-unreachable .git/objects/info/alternates && + test_must_fail git show $csha1 +' + test_done -- cgit v1.2.1 From 094085e3362c592c932b41525ed37152ec171192 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Sat, 21 Mar 2009 17:26:11 -0500 Subject: pack-objects: don't loosen objects available in alternate or kept packs If pack-objects is called with the --unpack-unreachable option then it will unpack (i.e. loosen) all unreferenced objects from local not-kept packs, including those that also exist in packs residing in an alternate object database or a locally kept pack. The only user of this option is git-repack. In this case, repack will follow the call to pack-objects with a call to prune-packed, which will delete these newly loosened objects, making the act of loosening a waste of time. The unnecessary loosening can be avoided by checking whether an object exists in a non-local pack or a locally kept pack before loosening it. This fixes the 'local packed unreachable obs that exist in alternate ODB are not loosened' test in t7700. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- t/t7700-repack.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 't') diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 013e488bd..9ce546e3b 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -113,7 +113,7 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' test_must_fail git show $csha1 ' -test_expect_failure 'local packed unreachable obs that exist in alternate ODB are not loosened' ' +test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' echo `pwd`/alt_objects > .git/objects/info/alternates && echo "$csha1" | git pack-objects --non-empty --all --reflog pack && rm -f .git/objects/pack/* && -- cgit v1.2.1