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(+) 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 --- git-repack.sh | 6 +----- t/t7700-repack.sh | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/git-repack.sh b/git-repack.sh index a736009c6..e02bf27aa 100755 --- a/git-repack.sh +++ b/git-repack.sh @@ -71,11 +71,7 @@ case ",$all_into_one," in existing="$existing $e" fi done - if test -n "$existing" - then - args="--kept-pack-only" - fi - if test -n "$args" -a -n "$unpack_unreachable" -a \ + if test -n "$existing" -a -n "$unpack_unreachable" -a \ -n "$remove_redundant" then args="$args $unpack_unreachable" 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 --- builtin-pack-objects.c | 4 ++-- t/t7700-repack.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b2e46264e..aae4d243b 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1915,7 +1915,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs) const unsigned char *sha1; struct object *o; - if (p->pack_keep) + if (!p->pack_local || p->pack_keep) continue; if (open_pack_index(p)) die("cannot open pack index"); @@ -1951,7 +1951,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs) const unsigned char *sha1; for (p = packed_git; p; p = p->next) { - if (p->pack_keep) + if (!p->pack_local || p->pack_keep) continue; if (open_pack_index(p)) 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 4d6acb70411cd4fe69610cf1b22f186fa01614f7 Mon Sep 17 00:00:00 2001 From: Brandon Casey Date: Thu, 19 Mar 2009 22:47:54 -0500 Subject: Remove --kept-pack-only option and associated infrastructure This option to pack-objects/rev-list was created to improve the -A and -a options of repack. It was found to be lacking in that it did not provide the ability to differentiate between local and non-local kept packs, and found to be unnecessary since objects residing in local kept packs can be filtered out by the --honor-pack-keep option. Signed-off-by: Brandon Casey Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 1 - cache.h | 1 - revision.c | 9 +-------- revision.h | 1 - sha1_file.c | 21 +-------------------- 5 files changed, 2 insertions(+), 31 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index aae4d243b..6222f19c7 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -2149,7 +2149,6 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) continue; } if (!strcmp("--unpacked", arg) || - !strcmp("--kept-pack-only", arg) || !strcmp("--reflog", arg) || !strcmp("--all", arg)) { use_internal_rev_list = 1; diff --git a/cache.h b/cache.h index 0a3d523d2..23c16d0d9 100644 --- a/cache.h +++ b/cache.h @@ -566,7 +566,6 @@ extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned l extern int move_temp_to_file(const char *tmpfile, const char *filename); extern int has_sha1_pack(const unsigned char *sha1); -extern int has_sha1_kept_pack(const unsigned char *sha1); extern int has_sha1_file(const unsigned char *sha1); extern int has_loose_object_nonlocal(const unsigned char *sha1); diff --git a/revision.c b/revision.c index 6d8ac4608..50a5b5f39 100644 --- a/revision.c +++ b/revision.c @@ -1062,10 +1062,6 @@ static int handle_revision_opt(struct rev_info *revs, int argc, const char **arg revs->edge_hint = 1; } else if (!strcmp(arg, "--unpacked")) { revs->unpacked = 1; - revs->kept_pack_only = 0; - } else if (!strcmp(arg, "--kept-pack-only")) { - revs->unpacked = 1; - revs->kept_pack_only = 1; } else if (!prefixcmp(arg, "--unpacked=")) { die("--unpacked= no longer supported."); } else if (!strcmp(arg, "-r")) { @@ -1475,10 +1471,7 @@ enum commit_action simplify_commit(struct rev_info *revs, struct commit *commit) { if (commit->object.flags & SHOWN) return commit_ignore; - if (revs->unpacked && - (revs->kept_pack_only - ? has_sha1_kept_pack(commit->object.sha1) - : has_sha1_pack(commit->object.sha1))) + if (revs->unpacked && has_sha1_pack(commit->object.sha1)) return commit_ignore; if (revs->show_all) return commit_show; diff --git a/revision.h b/revision.h index b9fa9c2a6..1d322759a 100644 --- a/revision.h +++ b/revision.h @@ -48,7 +48,6 @@ struct rev_info { edge_hint:1, limited:1, unpacked:1, - kept_pack_only:1, boundary:2, left_right:1, rewrite_parents:1, diff --git a/sha1_file.c b/sha1_file.c index 7ead56cc3..500fd9312 100644 --- a/sha1_file.c +++ b/sha1_file.c @@ -1856,8 +1856,7 @@ off_t find_pack_entry_one(const unsigned char *sha1, return 0; } -static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e, - int kept_pack_only) +static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e) { static struct packed_git *last_found = (void *)1; struct packed_git *p; @@ -1869,8 +1868,6 @@ static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e, p = (last_found == (void *)1) ? packed_git : last_found; do { - if (kept_pack_only && !p->pack_keep) - goto next; if (p->num_bad_objects) { unsigned i; for (i = 0; i < p->num_bad_objects; i++) @@ -1910,16 +1907,6 @@ static int find_pack_ent(const unsigned char *sha1, struct pack_entry *e, return 0; } -static int find_pack_entry(const unsigned char *sha1, struct pack_entry *e) -{ - return find_pack_ent(sha1, e, 0); -} - -static int find_kept_pack_entry(const unsigned char *sha1, struct pack_entry *e) -{ - return find_pack_ent(sha1, e, 1); -} - struct packed_git *find_sha1_pack(const unsigned char *sha1, struct packed_git *packs) { @@ -2387,12 +2374,6 @@ int has_sha1_pack(const unsigned char *sha1) return find_pack_entry(sha1, &e); } -int has_sha1_kept_pack(const unsigned char *sha1) -{ - struct pack_entry e; - return find_kept_pack_entry(sha1, &e); -} - int has_sha1_file(const unsigned char *sha1) { struct pack_entry e; -- 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(+) 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 --- builtin-pack-objects.c | 26 +++++++++++++++++++++++++- t/t7700-repack.sh | 2 +- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 6222f19c7..ad3f8e775 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1944,6 +1944,29 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs) free(in_pack.array); } +static int has_sha1_pack_kept_or_nonlocal(const unsigned char *sha1) +{ + static struct packed_git *last_found = (void *)1; + struct packed_git *p; + + p = (last_found != (void *)1) ? last_found : packed_git; + + while (p) { + if ((!p->pack_local || p->pack_keep) && + find_pack_entry_one(sha1, p)) { + last_found = p; + return 1; + } + if (p == last_found) + p = packed_git; + else + p = p->next; + if (p == last_found) + p = p->next; + } + return 0; +} + static void loosen_unused_packed_objects(struct rev_info *revs) { struct packed_git *p; @@ -1959,7 +1982,8 @@ static void loosen_unused_packed_objects(struct rev_info *revs) for (i = 0; i < p->num_objects; i++) { sha1 = nth_packed_object_sha1(p, i); - if (!locate_object_entry(sha1)) + if (!locate_object_entry(sha1) && + !has_sha1_pack_kept_or_nonlocal(sha1)) if (force_object_loose(sha1, p->mtime)) die("unable to force loose object"); } 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