don't open pack redundantly in dump_delta_chain_to_mem()
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
diff --git a/lib/pack.c b/lib/pack.c
index 2f72ca4..31e1980 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -1410,8 +1410,7 @@ done:
static const struct got_error *
dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outlen,
- struct got_delta_chain *deltas, const char *path_packfile,
- struct got_repository *repo)
+ struct got_delta_chain *deltas, struct got_pack *pack)
{
const struct got_error *err = NULL;
struct got_delta *delta;
@@ -1436,7 +1435,6 @@ dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outlen,
/* Deltas are ordered in ascending order. */
SIMPLEQ_FOREACH(delta, &deltas->entries, entry) {
if (n == 0) {
- struct got_pack *pack;
size_t base_len;
size_t delta_data_offset;
@@ -1449,12 +1447,6 @@ dump_delta_chain_to_mem(uint8_t **outbuf, size_t *outlen,
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);
@@ -1575,20 +1567,19 @@ got_packfile_extract_object_to_mem(uint8_t **buf, size_t *len,
struct got_object *obj, struct got_repository *repo)
{
const struct got_error *err = NULL;
+ struct got_pack *pack;
if ((obj->flags & GOT_OBJ_FLAG_PACKED) == 0)
return got_error(GOT_ERR_OBJ_NOT_PACKED);
- 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;
- }
+ 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->flags & GOT_OBJ_FLAG_DELTIFIED) == 0) {
if (obj->pack_offset >= pack->filesize) {
err = got_error(GOT_ERR_PACK_OFFSET);
goto done;
@@ -1605,8 +1596,7 @@ got_packfile_extract_object_to_mem(uint8_t **buf, size_t *len,
err = got_inflate_to_mem_fd(buf, len, pack->fd);
}
} else
- err = dump_delta_chain_to_mem(buf, len, &obj->deltas,
- obj->path_packfile, repo);
+ err = dump_delta_chain_to_mem(buf, len, &obj->deltas, pack);
done:
return err;
}