Commit Diff


commit - cfd633c2f10c03df8d5970fe61e67cb365af4dff
commit + e78854052d44df6460677e042f83e2bae4cb06e0
blob - 901a18c9afa705668a612325a0956997aaf7ba9e
blob + b427544ee597fb40d4802b61166507af2c7f124e
--- lib/got_lib_object_parse.h
+++ lib/got_lib_object_parse.h
@@ -42,3 +42,5 @@ const struct got_error *got_object_packed_read_privsep
     struct got_object_id *);
 const struct got_error *got_object_read_packed_commit_privsep(
     struct got_commit_object **, struct got_object *, struct got_pack *);
+const struct got_error *got_object_read_packed_tree_privsep(
+    struct got_tree_object **, struct got_object *, struct got_pack *);
blob - f98a68d7aefb8d527e59df0042970aa88632262b
blob + dd2760739e7a9945475e8be34c37f8273d9865da
--- lib/object.c
+++ lib/object.c
@@ -326,27 +326,6 @@ got_object_qid_alloc(struct got_object_qid **qid, stru
 	}
 
 	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 *
@@ -407,14 +386,15 @@ got_object_tree_open(struct got_tree_object **tree,
 		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_tree(tree, 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_tree_privsep(tree, obj, pack);
 	} else {
 		int fd;
 		err = open_loose_object(&fd, obj, repo);
blob - 823f934f9ebd17a1d15e557e8fc0bfb4fe6e554d
blob + ae91d511f1877e2f80758d82825de45907f3aa09
--- lib/object_parse.c
+++ lib/object_parse.c
@@ -823,7 +823,20 @@ got_object_read_tree_privsep(struct got_tree_object **
 
 	return request_tree(tree, repo, obj, obj_fd);
 }
+
+const struct got_error *
+got_object_read_packed_tree_privsep(struct got_tree_object **tree,
+    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_tree(tree, pack->privsep_child->ibuf);
+}
+
 static const struct got_error *
 request_blob(size_t *size, int outfd, int infd, struct got_repository *repo)
 {
blob - 068c8e85f99c20da787c879fe813eef62ffb12ce
blob + faa53d4db1d1e837fd01b682d269781bc0303fca
--- lib/privsep.c
+++ lib/privsep.c
@@ -278,7 +278,7 @@ got_privsep_send_obj_req(struct imsgbuf *ibuf, int fd,
 		iobj.flags = obj->flags;
 		iobj.hdrlen = obj->hdrlen;
 		iobj.size = obj->size;
-		iobj.ndeltas = 0;
+		iobj.ndeltas = obj->deltas.nentries;
 		if (iobj.flags & GOT_OBJ_FLAG_PACKED)
 			iobj.pack_offset = obj->pack_offset;
 
blob - 19b70b7eca7c7b30d93de4b0a36aa5587df4816f
blob + 8110b5f191c21cb946f29466fcbef12db68721f5
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
@@ -107,7 +107,39 @@ static const struct got_error *
 tree_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_tree_object *tree = 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_TREE)
+		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_tree(&tree, buf, len);
+	free(buf);
+
+	err = got_privsep_send_tree(ibuf, tree);
+	if (obj)
+		got_object_close(obj);
+	got_object_tree_close(tree);
+	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 *