don't transform sha1 to string and back for icommits
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
diff --git a/lib/got_lib_privsep.h b/lib/got_lib_privsep.h
index ed426cc..037cf65 100644
--- a/lib/got_lib_privsep.h
+++ b/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__));
diff --git a/lib/privsep.c b/lib/privsep.c
index 31052e7..85b125e 100644
--- a/lib/privsep.c
+++ b/lib/privsep.c
@@ -244,9 +244,7 @@ got_privsep_send_commit_obj(struct imsgbuf *ibuf, struct got_commit_object *comm
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, struct got_commit_object *comm
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, struct got_commit_object *comm
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 **commit,
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 **commit,
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 **commit,
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: