commit 704b89c4330d9641c93302516a59957a847736c1 from: Stefan Sperling date: Thu May 23 19:44:01 2019 UTC make got-read-pack actually use its object cache commit - ff563a3de3ff9931c2702516c74c8aea8d5cf142 commit + 704b89c4330d9641c93302516a59957a847736c1 blob - 3952d83a577c5510f0af5c58e08788892c81184c blob + 7147a9755c2e0788c9ee549a1d956e32fe1c80b9 --- libexec/got-read-pack/got-read-pack.c +++ libexec/got-read-pack/got-read-pack.c @@ -52,6 +52,26 @@ catch_sigint(int signo) } static const struct got_error * +open_object(struct got_object **obj, struct got_pack *pack, + struct got_packidx *packidx, int idx, struct got_object_id *id, + struct got_object_cache *objcache) +{ + const struct got_error *err; + + err = got_packfile_open_object(obj, pack, packidx, idx, id); + if (err) + return err; + (*obj)->refcnt++; + + err = got_object_cache_add(objcache, id, *obj); + if (err) + return err; + (*obj)->refcnt++; + + return NULL; +} + +static const struct got_error * object_request(struct imsg *imsg, struct imsgbuf *ibuf, struct got_pack *pack, struct got_packidx *packidx, struct got_object_cache *objcache) { @@ -67,16 +87,16 @@ object_request(struct imsg *imsg, struct imsgbuf *ibuf memcpy(&iobj, imsg->data, sizeof(iobj)); memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH); - err = got_packfile_open_object(&obj, pack, packidx, iobj.idx, &id); - if (err) - return err; - obj->refcnt++; + obj = got_object_cache_get(objcache, &id); + if (obj) { + obj->refcnt++; + } else { + err = open_object(&obj, pack, packidx, iobj.idx, &id, + objcache); + if (err) + goto done; + } - err = got_object_cache_add(objcache, &obj->id, obj); - if (err) - goto done; - obj->refcnt++; - err = got_privsep_send_obj(ibuf, obj); done: got_object_close(obj); @@ -102,9 +122,15 @@ commit_request(struct imsg *imsg, struct imsgbuf *ibuf memcpy(&iobj, imsg->data, sizeof(iobj)); memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH); - err = got_packfile_open_object(&obj, pack, packidx, iobj.idx, &id); - if (err) - return err; + obj = got_object_cache_get(objcache, &id); + if (obj) { + obj->refcnt++; + } else { + err = open_object(&obj, pack, packidx, iobj.idx, &id, + objcache); + if (err) + return err; + } err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack); if (err) @@ -149,9 +175,15 @@ tree_request(struct imsg *imsg, struct imsgbuf *ibuf, memcpy(&iobj, imsg->data, sizeof(iobj)); memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH); - err = got_packfile_open_object(&obj, pack, packidx, iobj.idx, &id); - if (err) - return err; + obj = got_object_cache_get(objcache, &id); + if (obj) { + obj->refcnt++; + } else { + err = open_object(&obj, pack, packidx, iobj.idx, &id, + objcache); + if (err) + return err; + } err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack); if (err) @@ -231,9 +263,15 @@ blob_request(struct imsg *imsg, struct imsgbuf *ibuf, memcpy(&iobj, imsg->data, sizeof(iobj)); memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH); - err = got_packfile_open_object(&obj, pack, packidx, iobj.idx, &id); - if (err) - return err; + obj = got_object_cache_get(objcache, &id); + if (obj) { + obj->refcnt++; + } else { + err = open_object(&obj, pack, packidx, iobj.idx, &id, + objcache); + if (err) + return err; + } err = receive_file(&outfile, ibuf, GOT_IMSG_BLOB_OUTFD); if (err) @@ -297,9 +335,15 @@ tag_request(struct imsg *imsg, struct imsgbuf *ibuf, s memcpy(&iobj, imsg->data, sizeof(iobj)); memcpy(id.sha1, iobj.id, SHA1_DIGEST_LENGTH); - err = got_packfile_open_object(&obj, pack, packidx, iobj.idx, &id); - if (err) - return err; + obj = got_object_cache_get(objcache, &id); + if (obj) { + obj->refcnt++; + } else { + err = open_object(&obj, pack, packidx, iobj.idx, &id, + objcache); + if (err) + return err; + } err = got_packfile_extract_object_to_mem(&buf, &len, obj, pack); if (err)