From: Omar Polo Subject: use struct got_object_id instead of just the digest To: gameoftrees@openbsd.org Date: Sun, 19 Feb 2023 14:30:20 +0100 This makes got_imsg_commit_painting_request, got_imsg_tag_object and GOT_IMSG_TRAVERSED_COMMITS bundle the struct got_object_id. They all copy the hash digest to the imsg struct and then from it to an object id, so this change for the moment is a no-op. It'll avoid breakages when the struct got_object_id will grow (i.e. soon™) ok? diff /home/op/w/gotd commit - b685c8da4da0617ce1f98749fbd7014bda6d3fc3 path + /home/op/w/gotd blob - 55cb4225a7ff5f243189735fc4e49c4be4d22e7a file + lib/got_lib_privsep.h --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -344,7 +344,7 @@ struct got_imsg_commit_painting_request { /* Structure for GOT_IMSG_COMMIT_PAINTING_REQUEST. */ struct got_imsg_commit_painting_request { - uint8_t id[SHA1_DIGEST_LENGTH]; + struct got_object_id id; int idx; int color; } __attribute__((__packed__)); @@ -365,7 +365,7 @@ struct got_imsg_tag_object { /* Structure for GOT_IMSG_TAG data. */ struct got_imsg_tag_object { - uint8_t id[SHA1_DIGEST_LENGTH]; + struct got_object_id id; int obj_type; size_t tag_len; size_t tagger_len; @@ -585,7 +585,7 @@ struct got_imsg_traversed_commits { /* Structure for GOT_IMSG_TRAVERSED_COMMITS */ struct got_imsg_traversed_commits { size_t ncommits; - /* Followed by ncommit IDs of SHA1_DIGEST_LENGTH each */ + /* Followed by ncommit struct got_object_id */ } __attribute__((__packed__)); /* Structure for GOT_IMSG_ENUMERATED_COMMIT */ blob - a60e0339f8024823ed0d7e275d26f839dbbdb717 file + lib/privsep.c --- lib/privsep.c +++ lib/privsep.c @@ -1793,7 +1793,7 @@ got_privsep_send_tag(struct imsgbuf *ibuf, struct got_ return got_error_from_errno("malloc"); itag = (struct got_imsg_tag_object *)buf; - memcpy(itag->id, tag->id.sha1, sizeof(itag->id)); + memcpy(&itag->id, &tag->id, sizeof(itag->id)); itag->obj_type = tag->obj_type; itag->tag_len = tag_len; itag->tagger_len = tagger_len; @@ -1864,7 +1864,7 @@ got_privsep_recv_tag(struct got_tag_object **tag, stru break; } - memcpy((*tag)->id.sha1, itag->id, SHA1_DIGEST_LENGTH); + memcpy(&(*tag)->id, &itag->id, sizeof(itag->id)); (*tag)->tag = strndup(imsg.data + len, itag->tag_len); if ((*tag)->tag == NULL) { @@ -2680,6 +2680,7 @@ got_privsep_recv_traversed_commits(struct got_commit_o const struct got_error *err = NULL; struct imsg imsg; struct got_imsg_traversed_commits *icommits; + struct got_object_id *ids; size_t datalen; int i, done = 0; @@ -2696,18 +2697,18 @@ got_privsep_recv_traversed_commits(struct got_commit_o case GOT_IMSG_TRAVERSED_COMMITS: icommits = imsg.data; if (datalen != sizeof(*icommits) + - icommits->ncommits * SHA1_DIGEST_LENGTH) { + icommits->ncommits * sizeof(*ids)) { err = got_error(GOT_ERR_PRIVSEP_LEN); break; } + ids = imsg.data + sizeof(*icommits); for (i = 0; i < icommits->ncommits; i++) { struct got_object_qid *qid; - uint8_t *sha1 = (uint8_t *)imsg.data + - sizeof(*icommits) + i * SHA1_DIGEST_LENGTH; + err = got_object_qid_alloc_partial(&qid); if (err) break; - memcpy(qid->id.sha1, sha1, SHA1_DIGEST_LENGTH); + memcpy(&qid->id, &ids[i], sizeof(ids[i])); STAILQ_INSERT_TAIL(commit_ids, qid, entry); /* The last commit may contain a change. */ @@ -3381,7 +3382,7 @@ got_privsep_send_painting_request(struct imsgbuf *ibuf struct got_imsg_commit_painting_request ireq; memset(&ireq, 0, sizeof(ireq)); - memcpy(ireq.id, id->sha1, sizeof(ireq.id)); + memcpy(&ireq.id, id, sizeof(ireq.id)); ireq.idx = idx; ireq.color = color; blob - 1cb98bf68ab578890b9806b248b38305052b2068 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 @@ -564,7 +564,7 @@ send_traversed_commits(struct got_object_id *commit_id wbuf = imsg_create(ibuf, GOT_IMSG_TRAVERSED_COMMITS, 0, 0, sizeof(struct got_imsg_traversed_commits) + - ncommits * SHA1_DIGEST_LENGTH); + ncommits * sizeof(commit_ids[0])); if (wbuf == NULL) return got_error_from_errno("imsg_create TRAVERSED_COMMITS"); @@ -573,7 +573,7 @@ send_traversed_commits(struct got_object_id *commit_id for (i = 0; i < ncommits; i++) { struct got_object_id *id = &commit_ids[i]; - if (imsg_add(wbuf, id->sha1, SHA1_DIGEST_LENGTH) == -1) { + if (imsg_add(wbuf, id, sizeof(*id)) == -1) { return got_error_from_errno( "imsg_add TRAVERSED_COMMITS"); } @@ -658,7 +658,7 @@ commit_traversal_request(struct imsg *imsg, struct ims } if (sizeof(struct got_imsg_traversed_commits) + - ncommits * SHA1_DIGEST_LENGTH >= max_datalen) { + ncommits * sizeof(commit_ids[0]) >= max_datalen) { err = send_traversed_commits(commit_ids, ncommits, ibuf); if (err) @@ -1193,7 +1193,7 @@ enumerate_tree(int *have_all_entries, struct imsgbuf * err = got_object_qid_alloc_partial(&qid); if (err) return err; - memcpy(&qid->id.sha1, tree_id, SHA1_DIGEST_LENGTH); + memcpy(&qid->id, tree_id, sizeof(*tree_id)); qid->data = strdup(path); if (qid->data == NULL) { err = got_error_from_errno("strdup"); @@ -1797,7 +1797,7 @@ commit_painting_request(struct imsg *imsg, struct imsg if (datalen != sizeof(ireq)) return got_error(GOT_ERR_PRIVSEP_LEN); memcpy(&ireq, imsg->data, sizeof(ireq)); - memcpy(id.sha1, ireq.id, SHA1_DIGEST_LENGTH); + memcpy(&id, &ireq.id, sizeof(id)); err = queue_commit_id(&ids, &id, ireq.color); if (err)