summaryrefslogtreecommitdiff
path: root/sha1_file.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2015-06-22 10:40:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2015-06-22 21:53:58 (GMT)
commitf813e9ea5f776ff82a4462c5e9405f2e904254f4 (patch)
tree1ad4f8148f508dde44d1e20e76beada6322f4270 /sha1_file.c
parentebb464f0cba9efcb5552fad02f452f09f68fc9b2 (diff)
downloadgit-f813e9ea5f776ff82a4462c5e9405f2e904254f4.zip
git-f813e9ea5f776ff82a4462c5e9405f2e904254f4.tar.gz
git-f813e9ea5f776ff82a4462c5e9405f2e904254f4.tar.bz2
for_each_packed_object: automatically open pack index
When for_each_packed_object is called, we call prepare_packed_git() to make sure we have the actual list of packs. But the latter does not actually open the pack indices, meaning that pack->nr_objects may simply be 0 if the pack has not otherwise been used since the program started. In practice, this didn't come up for the current callers, because they iterate the packed objects only after iterating all reachable objects (so for it to matter you would have to have a pack consisting only of unreachable objects). But it is a dangerous and confusing interface that should be fixed for future callers. Note that we do not end the iteration when a pack cannot be opened, but we do return an error. That lets you complete the iteration even in actively-repacked repository where an .idx file may racily go away, but it also lets callers know that they may not have gotten the complete list (which the current reachability-check caller does care about). We have to tweak one of the prune tests due to the changed return value; an earlier test creates bogus .idx files and does not clean them up. Having to make this tweak is a good thing; it means we will not prune in a broken repository, and the test confirms that we do not negatively impact a more lenient caller, count-objects. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'sha1_file.c')
-rw-r--r--sha1_file.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/sha1_file.c b/sha1_file.c
index f860d67..1dd6d7c 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -3466,14 +3466,19 @@ int for_each_packed_object(each_packed_object_fn cb, void *data, unsigned flags)
{
struct packed_git *p;
int r = 0;
+ int pack_errors = 0;
prepare_packed_git();
for (p = packed_git; p; p = p->next) {
if ((flags & FOR_EACH_OBJECT_LOCAL_ONLY) && !p->pack_local)
continue;
+ if (open_pack_index(p)) {
+ pack_errors = 1;
+ continue;
+ }
r = for_each_object_in_pack(p, cb, data);
if (r)
break;
}
- return r;
+ return r ? r : pack_errors;
}