read packed commits with privsep
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 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
diff --git a/lib/got_lib_object_parse.h b/lib/got_lib_object_parse.h
index f37d598..901a18c 100644
--- a/lib/got_lib_object_parse.h
+++ b/lib/got_lib_object_parse.h
@@ -40,3 +40,5 @@ struct got_packidx;
const struct got_error *got_object_packed_read_privsep(struct got_object **,
struct got_repository *, struct got_pack *, struct got_packidx *, int,
struct got_object_id *);
+const struct got_error *got_object_read_packed_commit_privsep(
+ struct got_commit_object **, struct got_object *, struct got_pack *);
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index bd788e1..7a9837d 100644
--- a/lib/got_lib_privsep.h
+++ b/lib/got_lib_privsep.h
@@ -213,6 +213,8 @@ const struct got_error *got_privsep_send_obj_req(struct imsgbuf *, int,
const struct got_error *got_privsep_send_blob_req(struct imsgbuf *, int, int);
const struct got_error *got_privsep_send_obj(struct imsgbuf *,
struct got_object *);
+const struct got_error *got_privsep_get_imsg_obj(struct got_object **,
+ struct imsg *, struct imsgbuf *);
const struct got_error *got_privsep_recv_obj(struct got_object **,
struct imsgbuf *);
const struct got_error *got_privsep_send_commit(struct imsgbuf *,
diff --git a/lib/object.c b/lib/object.c
index a7327c3..f98a68d 100644
--- a/lib/object.c
+++ b/lib/object.c
@@ -365,14 +365,15 @@ got_object_commit_open(struct got_commit_object **commit,
return got_error(GOT_ERR_OBJ_TYPE);
if (obj->flags & GOT_OBJ_FLAG_PACKED) {
- uint8_t *buf;
- size_t len;
- err = extract_packed_object_to_mem(&buf, &len, obj, repo);
- if (err)
- return err;
- obj->size = len;
- err = got_object_parse_commit(commit, buf, len);
- free(buf);
+ struct got_pack *pack;
+ 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;
+ }
+ err = got_object_read_packed_commit_privsep(commit, obj, pack);
} else {
int fd;
err = open_loose_object(&fd, obj, repo);
diff --git a/lib/object_parse.c b/lib/object_parse.c
index e65fda0..823f934 100644
--- a/lib/object_parse.c
+++ b/lib/object_parse.c
@@ -712,7 +712,7 @@ request_commit(struct got_commit_object **commit, struct got_repository *repo,
ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_COMMIT].ibuf;
- err = got_privsep_send_obj_req(ibuf, fd,obj);
+ err = got_privsep_send_obj_req(ibuf, fd, obj);
if (err)
return err;
@@ -720,6 +720,19 @@ request_commit(struct got_commit_object **commit, struct got_repository *repo,
}
const struct got_error *
+got_object_read_packed_commit_privsep(struct got_commit_object **commit,
+ struct got_object *obj, struct got_pack *pack)
+{
+ const struct got_error *err = NULL;
+
+ err = got_privsep_send_obj_req(pack->privsep_child->ibuf, -1, obj);
+ if (err)
+ return err;
+
+ return got_privsep_recv_commit(commit, pack->privsep_child->ibuf);
+}
+
+const struct got_error *
got_object_read_commit_privsep(struct got_commit_object **commit,
struct got_object *obj, int obj_fd, struct got_repository *repo)
{
@@ -765,7 +778,7 @@ request_tree(struct got_tree_object **tree, struct got_repository *repo,
ibuf = repo->privsep_children[GOT_REPO_PRIVSEP_CHILD_TREE].ibuf;
- err = got_privsep_send_obj_req(ibuf, fd,obj);
+ err = got_privsep_send_obj_req(ibuf, fd, obj);
if (err)
return err;
diff --git a/lib/privsep.c b/lib/privsep.c
index 74df15b..068c8e8 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -449,13 +449,56 @@ receive_delta(struct got_delta **delta, struct imsgbuf *ibuf)
}
const struct got_error *
+got_privsep_get_imsg_obj(struct got_object **obj, struct imsg *imsg,
+ struct imsgbuf *ibuf)
+{
+ const struct got_error *err = NULL;
+ struct got_imsg_object iobj;
+ size_t datalen = imsg->hdr.len - IMSG_HEADER_SIZE;
+ int i;
+
+ if (datalen != sizeof(iobj))
+ return got_error(GOT_ERR_PRIVSEP_LEN);
+
+ memcpy(&iobj, imsg->data, sizeof(iobj));
+ if (iobj.ndeltas < 0 ||
+ iobj.ndeltas > GOT_DELTA_CHAIN_RECURSION_MAX)
+ return got_error(GOT_ERR_PRIVSEP_LEN);
+
+ if (iobj.ndeltas > 0 &&
+ (iobj.flags & GOT_OBJ_FLAG_DELTIFIED) == 0)
+ return got_error(GOT_ERR_BAD_OBJ_DATA);
+
+ *obj = calloc(1, sizeof(**obj));
+ if (*obj == NULL)
+ return got_error_from_errno();
+
+ (*obj)->type = iobj.type;
+ (*obj)->flags = iobj.flags;
+ (*obj)->hdrlen = iobj.hdrlen;
+ (*obj)->size = iobj.size;
+ /* id and path_packfile might be copied in by caller */
+ (*obj)->pack_offset = iobj.pack_offset;
+ SIMPLEQ_INIT(&(*obj)->deltas.entries);
+ for (i = 0; i < iobj.ndeltas; i++) {
+ struct got_delta *delta;
+ err = receive_delta(&delta, ibuf);
+ if (err)
+ break;
+ (*obj)->deltas.nentries++;
+ SIMPLEQ_INSERT_TAIL(&(*obj)->deltas.entries, delta,
+ entry);
+ }
+
+ return err;
+}
+
+const struct got_error *
got_privsep_recv_obj(struct got_object **obj, struct imsgbuf *ibuf)
{
const struct got_error *err = NULL;
struct imsg imsg;
- struct got_imsg_object iobj;
size_t datalen;
- int i;
const size_t min_datalen =
MIN(sizeof(struct got_imsg_error), sizeof(struct got_imsg_object));
@@ -472,45 +515,7 @@ got_privsep_recv_obj(struct got_object **obj, struct imsgbuf *ibuf)
err = recv_imsg_error(&imsg, datalen);
break;
case GOT_IMSG_OBJECT:
- if (datalen != sizeof(iobj)) {
- err = got_error(GOT_ERR_PRIVSEP_LEN);
- break;
- }
-
- memcpy(&iobj, imsg.data, sizeof(iobj));
- if (iobj.ndeltas < 0 ||
- iobj.ndeltas > GOT_DELTA_CHAIN_RECURSION_MAX) {
- err = got_error(GOT_ERR_PRIVSEP_LEN);
- break;
- }
- if (iobj.ndeltas > 0 &&
- (iobj.flags & GOT_OBJ_FLAG_DELTIFIED) == 0) {
- err = got_error(GOT_ERR_BAD_OBJ_DATA);
- break;
- }
-
- *obj = calloc(1, sizeof(**obj));
- if (*obj == NULL) {
- err = got_error_from_errno();
- break;
- }
-
- (*obj)->type = iobj.type;
- (*obj)->flags = iobj.flags;
- (*obj)->hdrlen = iobj.hdrlen;
- (*obj)->size = iobj.size;
- /* id and path_packfile might be copied in by caller */
- (*obj)->pack_offset = iobj.pack_offset;
- SIMPLEQ_INIT(&(*obj)->deltas.entries);
- for (i = 0; i < iobj.ndeltas; i++) {
- struct got_delta *delta;
- err = receive_delta(&delta, ibuf);
- if (err)
- break;
- (*obj)->deltas.nentries++;
- SIMPLEQ_INSERT_TAIL(&(*obj)->deltas.entries, delta,
- entry);
- }
+ err = got_privsep_get_imsg_obj(obj, &imsg, ibuf);
break;
default:
err = got_error(GOT_ERR_PRIVSEP_MSG);
@@ -576,6 +581,7 @@ done:
free(buf);
return err;
}
+
const struct got_error *
got_privsep_recv_commit(struct got_commit_object **commit, struct imsgbuf *ibuf)
{
diff --git a/libexec/got-read-pack/got-read-pack.c b/libexec/got-read-pack/got-read-pack.c
index f243749..19b70b7 100644
--- a/libexec/got-read-pack/got-read-pack.c
+++ b/libexec/got-read-pack/got-read-pack.c
@@ -68,7 +68,39 @@ static const struct got_error *
commit_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack,
struct got_packidx *packidx)
{
- return got_error(GOT_ERR_NOT_IMPL);
+ const struct got_error *err = NULL;
+ struct got_object *obj = NULL;
+ struct got_commit_object *commit = NULL;
+ uint8_t *buf;
+ size_t len;
+
+ err = got_privsep_get_imsg_obj(&obj, imsg, ibuf);
+ if (err)
+ return err;
+
+ if (obj->type != GOT_OBJ_TYPE_COMMIT)
+ return got_error(GOT_ERR_OBJ_TYPE);
+
+ err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack);
+ if (err)
+ return err;
+
+ obj->size = len;
+ err = got_object_parse_commit(&commit, buf, len);
+ free(buf);
+
+ err = got_privsep_send_commit(ibuf, commit);
+ if (obj)
+ got_object_close(obj);
+ got_object_commit_close(commit);
+ if (err) {
+ if (err->code == GOT_ERR_PRIVSEP_PIPE)
+ err = NULL;
+ else
+ got_privsep_send_error(ibuf, err);
+ }
+
+ return err;
}
static const struct got_error *