use cached packfile in open_packed_object()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
diff --git a/lib/pack.c b/lib/pack.c
index 2ba33f7..2690ec6 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -1009,7 +1009,7 @@ open_packed_object(struct got_object **obj, struct got_repository *repo,
const struct got_error *err = NULL;
off_t offset;
char *path_packfile;
- FILE *packfile;
+ struct got_pack *pack;
uint8_t type;
uint64_t size;
size_t tslen;
@@ -1024,16 +1024,19 @@ open_packed_object(struct got_object **obj, struct got_repository *repo,
if (err)
return err;
- err = open_packfile(&packfile, path_packfile, repo, packidx);
- if (err)
- return err;
+ pack = get_cached_pack(path_packfile, repo);
+ if (pack == NULL) {
+ err = cache_pack(&pack, path_packfile, packidx, repo);
+ if (err)
+ goto done;
+ }
- if (fseeko(packfile, offset, SEEK_SET) != 0) {
+ if (fseeko(pack->packfile, offset, SEEK_SET) != 0) {
err = got_error_from_errno();
goto done;
}
- err = parse_object_type_and_size(&type, &size, &tslen, packfile);
+ err = parse_object_type_and_size(&type, &size, &tslen, pack->packfile);
if (err)
goto done;
@@ -1049,7 +1052,7 @@ open_packed_object(struct got_object **obj, struct got_repository *repo,
case GOT_OBJ_TYPE_OFFSET_DELTA:
case GOT_OBJ_TYPE_REF_DELTA:
err = open_delta_object(obj, repo, packidx, path_packfile,
- packfile, id, offset, tslen, type, size);
+ pack->packfile, id, offset, tslen, type, size);
break;
default:
@@ -1058,8 +1061,6 @@ open_packed_object(struct got_object **obj, struct got_repository *repo,
}
done:
free(path_packfile);
- if (packfile && fclose(packfile) == -1 && err == 0)
- err = got_error_from_errno();
return err;
}