commit 6d89869a98049341af4b0a79db823d11ac59d444 from: Stefan Sperling date: Sat Mar 17 02:35:04 2018 UTC use cached packfile in open_packed_object() commit - f78ec441a9df316cfb21a37c00e8147ad74d6827 commit + 6d89869a98049341af4b0a79db823d11ac59d444 blob - 2ba33f7285825caf1462e5f754c6d8889a4e5aec blob + 2690ec66c0c1716c8dfee8d7340003dbb2f39c98 --- lib/pack.c +++ lib/pack.c @@ -1009,7 +1009,7 @@ open_packed_object(struct got_object **obj, struct got 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 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 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 } done: free(path_packfile); - if (packfile && fclose(packfile) == -1 && err == 0) - err = got_error_from_errno(); return err; }