make got_packfile_extract_object_to_mem() accept pack instead of repo
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 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112
diff --git a/lib/got_lib_pack.h b/lib/got_lib_pack.h
index 549406d..4de7dfb 100644
--- a/lib/got_lib_pack.h
+++ b/lib/got_lib_pack.h
@@ -165,6 +165,6 @@ const struct got_error *got_packfile_open_object(struct got_object **,
const struct got_error *got_packfile_extract_object(struct got_pack *,
struct got_object *, FILE *);
const struct got_error *got_packfile_extract_object_to_mem(uint8_t **, size_t *,
- struct got_object *, struct got_repository *);
+ struct got_object *, struct got_pack *);
const struct got_error *got_pack_get_packfile_size(size_t *, const char *);
struct got_pack *got_repo_get_cached_pack(struct got_repository *, const char *);
diff --git a/lib/object.c b/lib/object.c
index a19cdc7..876b0f7 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -327,6 +327,27 @@ got_object_qid_alloc(struct got_object_qid **qid, struct got_object_id *id)
return NULL;
}
+static const struct got_error *
+extract_packed_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);
+
+ pack = got_repo_get_cached_pack(repo, obj->path_packfile);
+ if (pack == NULL) {
+ err = got_repo_cache_pack(&pack, repo,
+ obj->path_packfile, NULL);
+ if (err)
+ return err;
+ }
+
+ return got_packfile_extract_object_to_mem(buf, len, obj, pack);
+}
+
const struct got_error *
got_object_commit_open(struct got_commit_object **commit,
struct got_repository *repo, struct got_object *obj)
@@ -345,7 +366,7 @@ got_object_commit_open(struct got_commit_object **commit,
if (obj->flags & GOT_OBJ_FLAG_PACKED) {
uint8_t *buf;
size_t len;
- err = got_packfile_extract_object_to_mem(&buf, &len, obj, repo);
+ err = extract_packed_object_to_mem(&buf, &len, obj, repo);
if (err)
return err;
obj->size = len;
@@ -386,7 +407,7 @@ got_object_tree_open(struct got_tree_object **tree,
if (obj->flags & GOT_OBJ_FLAG_PACKED) {
uint8_t *buf;
size_t len;
- err = got_packfile_extract_object_to_mem(&buf, &len, obj, repo);
+ err = extract_packed_object_to_mem(&buf, &len, obj, repo);
if (err)
return err;
obj->size = len;
diff --git a/lib/pack.c b/lib/pack.c
index 329d024..d1d6698 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -1231,39 +1231,27 @@ got_packfile_extract_object(struct got_pack *pack, struct got_object *obj,
const struct got_error *
got_packfile_extract_object_to_mem(uint8_t **buf, size_t *len,
- struct got_object *obj, struct got_repository *repo)
+ struct got_object *obj, struct got_pack *pack)
{
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);
- pack = got_repo_get_cached_pack(repo, obj->path_packfile);
- if (pack == NULL) {
- err = got_repo_cache_pack(&pack, repo, obj->path_packfile, NULL);
- 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;
- }
+ if (obj->pack_offset >= pack->filesize)
+ return got_error(GOT_ERR_PACK_OFFSET);
if (pack->map) {
size_t mapoff = (size_t)obj->pack_offset;
err = got_inflate_to_mem_mmap(buf, len, pack->map,
mapoff, pack->filesize - mapoff);
} else {
- if (lseek(pack->fd, obj->pack_offset, SEEK_SET) == -1) {
- err = got_error_from_errno();
- goto done;
- }
+ if (lseek(pack->fd, obj->pack_offset, SEEK_SET) == -1)
+ return got_error_from_errno();
err = got_inflate_to_mem_fd(buf, len, pack->fd);
}
} else
err = dump_delta_chain_to_mem(buf, len, &obj->deltas, pack);
-done:
+
return err;
}