"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
s/uint8_t[SHA1_DIGEST_LENGHT]/got_object_id for packed objects
To:
gameoftrees@openbsd.org
Date:
Tue, 31 Jan 2023 16:56:58 +0100

Download raw body.

Thread
similarly to the refs, packed objects embed a SHA1_DIGEST_LENGTH
buffer.  change it to be a struct got_object_id, should be a no-op for
the moment.

other imsgs are doing similar stuff, let's go through them one-by-one
though to less the chance of introducing breakage and ease a potential
bisect.

I first renamed the got_imsg_packed_object to id_new, fixed all the
places where it was written/read, then changed back, so hopefully i've
catched all the places it were used.

regress is passing with and without GOT_TEST_PACK=1.

ok?

diff /tmp/got
commit - faf5b56f3ad3ab701a16b6684c5f936210ff86f8
path + /tmp/got
blob - 5010cb878bd556b6b5255748ec43c5bda5a060da
file + lib/got_lib_privsep.h
--- lib/got_lib_privsep.h
+++ lib/got_lib_privsep.h
@@ -526,7 +526,7 @@ struct got_imsg_packed_object {
  * GOT_IMSG_PACKED_RAW_OBJECT_REQUEST data.
  */
 struct got_imsg_packed_object {
-	uint8_t id[SHA1_DIGEST_LENGTH];
+	struct got_object_id id;
 	int idx;
 } __attribute__((__packed__));
 
blob - d7a1dda565c2f2ee404c15276ebdd47e29965ed9
file + lib/privsep.c
--- lib/privsep.c
+++ lib/privsep.c
@@ -364,7 +364,7 @@ got_privsep_send_commit_req(struct imsgbuf *ibuf, int 
 	memset(&iobj, 0, sizeof(iobj));
 	if (pack_idx != -1) { /* commit is packed */
 		iobj.idx = pack_idx;
-		memcpy(iobj.id, id->sha1, sizeof(iobj.id));
+		memcpy(&iobj.id, id, sizeof(iobj.id));
 		data = &iobj;
 		len = sizeof(iobj);
 	} else {
@@ -423,7 +423,7 @@ got_privsep_send_tag_req(struct imsgbuf *ibuf, int fd,
 	memset(&iobj, 0, sizeof(iobj));
 	if (pack_idx != -1) { /* tag is packed */
 		iobj.idx = pack_idx;
-		memcpy(iobj.id, id->sha1, sizeof(iobj.id));
+		memcpy(&iobj.id, id, sizeof(iobj.id));
 		data = &iobj;
 		len = sizeof(iobj);
 	} else {
@@ -450,7 +450,7 @@ got_privsep_send_blob_req(struct imsgbuf *ibuf, int in
 	memset(&iobj, 0, sizeof(iobj));
 	if (pack_idx != -1) { /* blob is packed */
 		iobj.idx = pack_idx;
-		memcpy(iobj.id, id->sha1, sizeof(iobj.id));
+		memcpy(&iobj.id, id, sizeof(iobj.id));
 		data = &iobj;
 		len = sizeof(iobj);
 	} else {
@@ -1957,7 +1957,7 @@ got_privsep_send_packed_obj_req(struct imsgbuf *ibuf, 
 
 	memset(&iobj, 0, sizeof(iobj));
 	iobj.idx = idx;
-	memcpy(iobj.id, id->sha1, sizeof(iobj.id));
+	memcpy(&iobj.id, id, sizeof(iobj.id));
 
 	if (imsg_compose(ibuf, GOT_IMSG_PACKED_OBJECT_REQUEST, 0, 0, -1,
 	    &iobj, sizeof(iobj)) == -1)
@@ -1975,7 +1975,7 @@ got_privsep_send_packed_raw_obj_req(struct imsgbuf *ib
 
 	memset(&iobj, 0, sizeof(iobj));
 	iobj.idx = idx;
-	memcpy(iobj.id, id->sha1, sizeof(iobj.id));
+	memcpy(&iobj.id, id, sizeof(iobj.id));
 
 	if (imsg_compose(ibuf, GOT_IMSG_PACKED_RAW_OBJECT_REQUEST, 0, 0, -1,
 	    &iobj, sizeof(iobj)) == -1)
blob - cd5bce6f2ef11d44d4fdf5b929d094051d59464c
file + libexec/got-read-pack/got-read-pack.c
--- libexec/got-read-pack/got-read-pack.c
+++ libexec/got-read-pack/got-read-pack.c
@@ -95,7 +95,7 @@ object_request(struct imsg *imsg, struct imsgbuf *ibuf
 	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);
+	memcpy(&id, &iobj.id, sizeof(id));
 
 	obj = got_object_cache_get(objcache, &id);
 	if (obj) {
@@ -162,7 +162,7 @@ commit_request(struct imsg *imsg, struct imsgbuf *ibuf
 	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);
+	memcpy(&id, &iobj.id, sizeof(id));
 
 	err = open_commit(&commit, pack, packidx, iobj.idx, &id, objcache);
 	if (err)
@@ -237,7 +237,7 @@ tree_request(struct imsg *imsg, struct imsgbuf *ibuf, 
 	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);
+	memcpy(&id, &iobj.id, sizeof(id));
 
 	err = open_tree(&buf, entries, nentries, nentries_alloc,
 	    pack, packidx, iobj.idx, &id, objcache);
@@ -332,7 +332,7 @@ blob_request(struct imsg *imsg, struct imsgbuf *ibuf, 
 	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);
+	memcpy(&id, &iobj.id, sizeof(id));
 
 	obj = got_object_cache_get(objcache, &id);
 	if (obj) {
@@ -393,7 +393,7 @@ tag_request(struct imsg *imsg, struct imsgbuf *ibuf, s
 	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);
+	memcpy(&id, &iobj.id, sizeof(id));
 
 	obj = got_object_cache_get(objcache, &id);
 	if (obj) {
@@ -617,7 +617,7 @@ commit_traversal_request(struct imsg *imsg, struct ims
 	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);
+	memcpy(&id, &iobj.id, sizeof(id));
 
 	path_len = datalen - sizeof(iobj) - 1;
 	if (path_len < 0)
@@ -801,7 +801,7 @@ raw_object_request(struct imsg *imsg, struct imsgbuf *
 	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);
+	memcpy(&id, &iobj.id, sizeof(id));
 
 	obj = got_object_cache_get(objcache, &id);
 	if (obj) {