make object caching actually work in got-read-pack
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
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index 91f70c7..b39f11f 100644
--- a/lib/got_lib_privsep.h
+++ b/lib/got_lib_privsep.h
@@ -177,6 +177,7 @@ struct got_imsg_pack {
* Structure for GOT_IMSG_PACKED_OBJECT_REQUEST data.
*/
struct got_imsg_packed_object {
+ uint8_t id[SHA1_DIGEST_LENGTH];
int idx;
};
@@ -211,5 +212,6 @@ const struct got_error *got_privsep_send_blob(struct imsgbuf *, size_t);
const struct got_error *got_privsep_recv_blob(size_t *, struct imsgbuf *);
const struct got_error *got_privsep_init_pack_child(struct imsgbuf *,
struct got_pack *, struct got_packidx *);
-const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int);
+const struct got_error *got_privsep_send_packed_obj_req(struct imsgbuf *, int,
+ struct got_object_id *);
const struct got_error *got_privsep_send_pack_child_ready(struct imsgbuf *);
diff --git a/lib/object_parse.c b/lib/object_parse.c
index 2ff896a..7ae2b4c 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -191,7 +191,7 @@ request_packed_object(struct got_object **obj, struct got_pack *pack, int idx,
const struct got_error *err = NULL;
struct imsgbuf *ibuf = pack->privsep_child->ibuf;
- err = got_privsep_send_packed_obj_req(ibuf, idx);
+ err = got_privsep_send_packed_obj_req(ibuf, idx, id);
if (err)
return err;
diff --git a/lib/pack.c b/lib/pack.c
index 4d61efe..fd18041 100644
--- a/lib/pack.c
+++ b/lib/pack.c
@@ -589,8 +589,7 @@ open_plain_object(struct got_object **obj, const char *path_packfile,
(*obj)->pack_idx = idx;
(*obj)->hdrlen = 0;
(*obj)->size = size;
- if (id)
- memcpy(&(*obj)->id, id, sizeof((*obj)->id));
+ memcpy(&(*obj)->id, id, sizeof((*obj)->id));
(*obj)->pack_offset = offset;
return NULL;
@@ -887,8 +886,7 @@ open_delta_object(struct got_object **obj, struct got_packidx *packidx,
(*obj)->flags = 0;
(*obj)->hdrlen = 0;
(*obj)->size = 0; /* Not known because deltas aren't applied yet. */
- if (id)
- memcpy(&(*obj)->id, id, sizeof((*obj)->id));
+ memcpy(&(*obj)->id, id, sizeof((*obj)->id));
(*obj)->pack_offset = offset + tslen;
(*obj)->path_packfile = strdup(pack->path_packfile);
diff --git a/lib/privsep.c b/lib/privsep.c
index 9079955..be1744b 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -860,11 +860,13 @@ got_privsep_init_pack_child(struct imsgbuf *ibuf, struct got_pack *pack,
}
const struct got_error *
-got_privsep_send_packed_obj_req(struct imsgbuf *ibuf, int idx)
+got_privsep_send_packed_obj_req(struct imsgbuf *ibuf, int idx,
+ struct got_object_id *id)
{
struct got_imsg_packed_object iobj;
iobj.idx = idx;
+ memcpy(iobj.id, id->sha1, sizeof(iobj.id));
if (imsg_compose(ibuf, GOT_IMSG_PACKED_OBJECT_REQUEST, 0, 0, -1,
&iobj, sizeof(iobj)) == -1)
diff --git a/libexec/got-read-pack/got-read-pack.c b/libexec/got-read-pack/got-read-pack.c
index 87e9fc0..010b14b 100644
--- a/libexec/got-read-pack/got-read-pack.c
+++ b/libexec/got-read-pack/got-read-pack.c
@@ -49,14 +49,16 @@ object_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
const struct got_error *err = NULL;
struct got_imsg_packed_object iobj;
struct got_object *obj;
+ struct got_object_id id;
size_t datalen;
datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
if (datalen != sizeof(iobj))
return got_error(GOT_ERR_PRIVSEP_LEN);
memcpy(&iobj, imsg->data, sizeof(iobj));
+ memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH);
- err = got_packfile_open_object(&obj, pack, packidx, iobj.idx, NULL);
+ err = got_packfile_open_object(&obj, pack, packidx, iobj.idx, &id);
if (err)
return err;
obj->refcnt++;