aboutsummaryrefslogtreecommitdiffstats
path: root/packfile.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2019-04-05 14:04:24 -0400
committerJunio C Hamano <gitster@pobox.com>2019-04-16 16:58:21 +0900
commit4828ce9871fee0ea0309220c461fdedf255df931 (patch)
tree9538b55727ac0701e39d3f5763e3a2970d805802 /packfile.c
parentpackfile.h: drop extern from function declarations (diff)
downloadgit-4828ce9871fee0ea0309220c461fdedf255df931.tar.xz
git-4828ce9871fee0ea0309220c461fdedf255df931.zip
pack-revindex: open index if necessary
We can't create a pack revindex if we haven't actually looked at the index. Normally we would never get as far as creating a revindex without having already been looking in the pack, so this code never bothered to double-check that pack->index_data had been loaded. But with the new multi-pack-index feature, many code paths might not load the individual pack .idx at all (they'd find objects via the midx and then open the .pack, but not its index). This can't yet be triggered in practice, because a bug in the midx code means we accidentally open up the individual .idx files anyway. But in preparation for fixing that, let's have the revindex code check that everything it needs has been loaded. In most cases this will just be a quick noop. But note that this does introduce a possibility of error (if we have to open the index and it's corrupt), so load_pack_revindex() now returns a result code, and callers need to handle the error. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'packfile.c')
-rw-r--r--packfile.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/packfile.c b/packfile.c
index 16bcb75262d..6e40bd89c76 100644
--- a/packfile.c
+++ b/packfile.c
@@ -2023,8 +2023,10 @@ int for_each_object_in_pack(struct packed_git *p,
uint32_t i;
int r = 0;
- if (flags & FOR_EACH_OBJECT_PACK_ORDER)
- load_pack_revindex(p);
+ if (flags & FOR_EACH_OBJECT_PACK_ORDER) {
+ if (load_pack_revindex(p))
+ return -1;
+ }
for (i = 0; i < p->num_objects; i++) {
uint32_t pos;