commit 2ce68b2f7dacf0570238e20785be3ec2b3f4ad71 from: Stefan Sperling date: Sun Sep 09 14:07:11 2018 UTC don't redundantly open pack file in dump_delta_chain_to_file() commit - 48095039dd1ff130ee371378632341bf6db50b89 commit + 2ce68b2f7dacf0570238e20785be3ec2b3f4ad71 blob - 31e19806e5649f9f3d75c5fea60910c49817aa5c blob + 5674cbed0eca909e8d21a5d4e8148a7796762e9f --- lib/pack.c +++ lib/pack.c @@ -1254,7 +1254,7 @@ get_delta_chain_max_size(uint64_t *max_size, struct go static const struct got_error * dump_delta_chain_to_file(size_t *result_size, struct got_delta_chain *deltas, - const char *path_packfile, FILE *outfile, struct got_repository *repo) + struct got_pack *pack, FILE *outfile) { const struct got_error *err = NULL; struct got_delta *delta; @@ -1293,7 +1293,6 @@ dump_delta_chain_to_file(size_t *result_size, struct g /* Deltas are ordered in ascending order. */ SIMPLEQ_FOREACH(delta, &deltas->entries, entry) { if (n == 0) { - struct got_pack *pack; size_t base_len, mapoff; off_t delta_data_offset; @@ -1306,12 +1305,6 @@ dump_delta_chain_to_file(size_t *result_size, struct g goto done; } - pack = get_cached_pack(path_packfile, repo); - if (pack == NULL) { - err = got_error(GOT_ERR_BAD_DELTA_CHAIN); - goto done; - } - delta_data_offset = delta->offset + delta->tslen; if (delta_data_offset >= pack->filesize) { err = got_error(GOT_ERR_PACK_OFFSET); @@ -1513,11 +1506,19 @@ got_packfile_extract_object(FILE **f, struct got_objec struct got_repository *repo) { const struct got_error *err = NULL; + struct got_pack *pack; *f = NULL; if ((obj->flags & GOT_OBJ_FLAG_PACKED) == 0) return got_error(GOT_ERR_OBJ_NOT_PACKED); + + pack = get_cached_pack(obj->path_packfile, repo); + if (pack == NULL) { + err = cache_pack(&pack, obj->path_packfile, NULL, repo); + if (err) + return err; + } *f = got_opentemp(); if (*f == NULL) { @@ -1526,15 +1527,6 @@ got_packfile_extract_object(FILE **f, struct got_objec } if ((obj->flags & GOT_OBJ_FLAG_DELTIFIED) == 0) { - struct got_pack *pack; - - pack = get_cached_pack(obj->path_packfile, repo); - if (pack == NULL) { - err = cache_pack(&pack, obj->path_packfile, NULL, repo); - if (err) - goto done; - } - if (obj->pack_offset >= pack->filesize) { err = got_error(GOT_ERR_PACK_OFFSET); goto done; @@ -1552,8 +1544,8 @@ got_packfile_extract_object(FILE **f, struct got_objec err = got_inflate_to_file_fd(&obj->size, pack->fd, *f); } } else - err = dump_delta_chain_to_file(&obj->size, - &obj->deltas, obj->path_packfile, *f, repo); + err = dump_delta_chain_to_file(&obj->size, &obj->deltas, pack, + *f); done: if (err && *f) { fclose(*f);