commit 86acc5664b2eab0c8e696d98336235c2b027229a from: Stefan Sperling date: Mon Apr 23 14:39:36 2018 UTC don't transform sha1 to string and back for icommits commit - 366d86ca5a2c2ffa1b8ce950d21de2a1a1077ec3 commit + 86acc5664b2eab0c8e696d98336235c2b027229a blob - ed426cc84e6e5cd27543be64250d3f07befee495 blob + 037cf653ad0247ae919e99902639f2ca2214069c --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -98,7 +98,7 @@ struct got_imsg_object { /* Structure for GOT_IMSG_COMMIT data. */ struct got_imsg_commit_object { - uint8_t tree_id[SHA1_DIGEST_STRING_LENGTH]; + uint8_t tree_id[SHA1_DIGEST_LENGTH]; size_t author_len; size_t committer_len; size_t logmsg_len; @@ -106,7 +106,7 @@ struct got_imsg_commit_object { /* Followed by author_len + committer_len + logmsg_len data bytes */ - /* Followed by 'nparents' SHA1_DIGEST_STRING_LENGTH length strings */ + /* Followed by 'nparents' SHA1_DIGEST_LENGTH length strings */ /* XXX should use more messages to support very large log messages */ } __attribute__((__packed__)); blob - 31052e7015a354e8d691abe2926d7363bc157d85 blob + 85b125e761c9349c488108b05a63bb914fbb644f --- lib/privsep.c +++ lib/privsep.c @@ -244,9 +244,7 @@ got_privsep_send_commit_obj(struct imsgbuf *ibuf, stru size_t len, total; struct got_parent_id *pid; - if (got_sha1_digest_to_str(commit->tree_id->sha1, icommit.tree_id, - sizeof(icommit.tree_id)) == NULL) - return got_error(GOT_ERR_BAD_OBJ_ID_STR); + memcpy(icommit.tree_id, commit->tree_id->sha1, sizeof(icommit.tree_id)); icommit.author_len = strlen(commit->author); icommit.committer_len = strlen(commit->committer); icommit.logmsg_len = strlen(commit->logmsg); @@ -254,7 +252,7 @@ got_privsep_send_commit_obj(struct imsgbuf *ibuf, stru total = sizeof(icommit) + icommit.author_len + icommit.committer_len + icommit.logmsg_len + - icommit.nparents * (SHA1_DIGEST_STRING_LENGTH); + icommit.nparents * SHA1_DIGEST_LENGTH; /* XXX TODO support very large log messages properly */ if (total > MAX_IMSGSIZE) return got_error(GOT_ERR_NO_SPACE); @@ -273,14 +271,8 @@ got_privsep_send_commit_obj(struct imsgbuf *ibuf, stru memcpy(buf + len, commit->logmsg, icommit.logmsg_len); len += icommit.logmsg_len; SIMPLEQ_FOREACH(pid, &commit->parent_ids, entry) { - char id_str[SHA1_DIGEST_STRING_LENGTH]; - if (got_sha1_digest_to_str(pid->id->sha1, id_str, - sizeof(id_str)) == NULL) { - err = got_error(GOT_ERR_BAD_OBJ_ID_STR); - goto done; - } - memcpy(buf + len, id_str, SHA1_DIGEST_STRING_LENGTH); - len += SHA1_DIGEST_STRING_LENGTH; + memcpy(buf + len, pid->id, SHA1_DIGEST_LENGTH); + len += SHA1_DIGEST_LENGTH; } if (imsg_compose(ibuf, GOT_IMSG_COMMIT, 0, 0, -1, buf, len) == -1) { @@ -338,7 +330,7 @@ got_privsep_recv_commit_obj(struct got_commit_object * memcpy(&icommit, data, sizeof(icommit)); if (datalen != sizeof(icommit) + icommit.author_len + icommit.committer_len + icommit.logmsg_len + - icommit.nparents * (SHA1_DIGEST_STRING_LENGTH)) { + icommit.nparents * SHA1_DIGEST_LENGTH) { err = got_error(GOT_ERR_PRIVSEP_LEN); break; } @@ -354,11 +346,8 @@ got_privsep_recv_commit_obj(struct got_commit_object * break; } - if (!got_parse_sha1_digest((*commit)->tree_id->sha1, - icommit.tree_id)) { - err = got_error(GOT_ERR_BAD_OBJ_DATA); - break; - } + memcpy((*commit)->tree_id->sha1, icommit.tree_id, + SHA1_DIGEST_LENGTH); if (icommit.author_len == 0) { (*commit)->author = strdup(""); @@ -416,13 +405,24 @@ got_privsep_recv_commit_obj(struct got_commit_object * len += icommit.logmsg_len; for (i = 0; i < icommit.nparents; i++) { - char id_str[SHA1_DIGEST_STRING_LENGTH]; - memcpy(id_str, data + len + - i * SHA1_DIGEST_STRING_LENGTH, sizeof(id_str)); - id_str[SHA1_DIGEST_STRING_LENGTH - 1] = '\0'; - err = got_object_commit_add_parent(*commit, id_str); - if (err) + struct got_parent_id *pid; + + pid = calloc(1, sizeof(*pid)); + if (pid == NULL) { + err = got_error_from_errno(); break; + } + pid->id = calloc(1, sizeof(*pid->id)); + if (pid->id == NULL) { + err = got_error_from_errno(); + free(pid); + break; + } + + memcpy(pid->id, data + len + i * SHA1_DIGEST_LENGTH, + sizeof(*pid->id)); + SIMPLEQ_INSERT_TAIL(&(*commit)->parent_ids, pid, entry); + (*commit)->nparents++; } break; default: