From 386cb77210cdb09cd808698d21d0e796cd77f26f Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Fri, 27 Feb 2009 23:43:37 -0800 Subject: Consolidate ignore_packed logic more This refactors three loops that check if a given packfile is on the ignore_packed list into a function is_kept_pack(). The function returns false for a pack on the list, and true for a pack not on the list, because this list is solely used by "git repack" to pass list of packfiles that do not have corresponding .keep files, i.e. a packfile not on the list is "kept". Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) (limited to 'builtin-pack-objects.c') diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index fb5e14d56e..7e7719b832 100644 --- a/builtin-pack-objects.c +++ b/builtin-pack-objects.c @@ -1915,11 +1915,7 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs) const unsigned char *sha1; struct object *o; - for (i = 0; i < revs->num_ignore_packed; i++) { - if (matches_pack_name(p, revs->ignore_packed[i])) - break; - } - if (revs->num_ignore_packed <= i) + if (is_kept_pack(p, revs)) continue; if (open_pack_index(p)) die("cannot open pack index"); @@ -1955,11 +1951,7 @@ static void loosen_unused_packed_objects(struct rev_info *revs) const unsigned char *sha1; for (p = packed_git; p; p = p->next) { - for (i = 0; i < revs->num_ignore_packed; i++) { - if (matches_pack_name(p, revs->ignore_packed[i])) - break; - } - if (revs->num_ignore_packed <= i) + if (is_kept_pack(p, revs)) continue; if (open_pack_index(p)) -- cgit v1.2.3 From 03a9683d22eca52bc2b2b9b09258a143e76416f6 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 28 Feb 2009 00:00:21 -0800 Subject: Simplify is_kept_pack() This removes --unpacked= parameter from the revision parser, and rewrites its use in git-repack to pass a single --kept-pack-only option instead. The new --kept-pack-only option means just that. When this option is given, is_kept_pack() that used to say "not on the --unpacked= list" now says "the packfile has corresponding .keep file". Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'builtin-pack-objects.c') diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 7e7719b832..150258b629 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 (is_kept_pack(p, revs)) + if (is_kept_pack(p)) 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 (is_kept_pack(p, revs)) + if (is_kept_pack(p)) continue; if (open_pack_index(p)) @@ -2149,7 +2149,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) continue; } if (!strcmp("--unpacked", arg) || - !prefixcmp(arg, "--unpacked=") || + !strcmp("--kept-pack-only", arg) || !strcmp("--reflog", arg) || !strcmp("--all", arg)) { use_internal_rev_list = 1; -- cgit v1.2.3 From 69e020ae00ebd3f7ae3c2f35acb139361417ef64 Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Sat, 28 Feb 2009 00:37:19 -0800 Subject: is_kept_pack(): final clean-up Now is_kept_pack() is just a member lookup into a structure, we can write it as such. Also rewrite the sole caller of has_sha1_kept_pack() to switch on the criteria the callee uses (namely, revs->kept_pack_only) between calling has_sha1_kept_pack() and has_sha1_pack(), so that these two callees do not have to take a pointer to struct rev_info as an argument. This removes the header file dependency issue temporarily introduced by the earlier commit, so we revert changes associated to that as well. Signed-off-by: Junio C Hamano --- builtin-pack-objects.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin-pack-objects.c') diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 150258b629..b2e46264ee 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 (is_kept_pack(p)) + if (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 (is_kept_pack(p)) + if (p->pack_keep) continue; if (open_pack_index(p)) -- cgit v1.2.3 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'builtin-pack-objects.c') diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index b2e46264ee..aae4d243b3 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)) -- cgit v1.2.3 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 - 1 file changed, 1 deletion(-) (limited to 'builtin-pack-objects.c') diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index aae4d243b3..6222f19c78 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; -- cgit v1.2.3 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 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) (limited to 'builtin-pack-objects.c') diff --git a/builtin-pack-objects.c b/builtin-pack-objects.c index 6222f19c78..ad3f8e7751 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"); } -- cgit v1.2.3