commit 310a8ea5d9d2eca34e7cdd0484fc2a1ce40dba1e from: Omar Polo date: Wed Jul 10 09:32:15 2024 UTC use got_object_id_hex instead of got_sha1_digest_to_str (where possible) The latter assumes that we only have sha1 digests to pretty-print, while the former could, in the future, automatically switch to sha256. At the moment though, this is a no-op. commit - 740e7917ac3f37feb39510c99a184089bd22f519 commit + 310a8ea5d9d2eca34e7cdd0484fc2a1ce40dba1e blob - 77af3223695f08a4c263ad27a9d0d0333b0307e6 blob + e7ffbe35c285fb2e83fb85251116d412bee6743d --- gotd/repo_imsg.c +++ gotd/repo_imsg.c @@ -46,7 +46,7 @@ gotd_imsg_send_ack(struct got_object_id *id, struct im char hex[SHA1_DIGEST_STRING_LENGTH]; if (log_getverbose() > 0 && - got_sha1_digest_to_str(id->sha1, hex, sizeof(hex))) + got_object_id_hex(id, hex, sizeof(hex))) log_debug("sending ACK for %s", hex); memset(&iack, 0, sizeof(iack)); @@ -73,7 +73,7 @@ gotd_imsg_send_nak(struct got_object_id *id, struct im char hex[SHA1_DIGEST_STRING_LENGTH]; if (log_getverbose() > 0 && - got_sha1_digest_to_str(id->sha1, hex, sizeof(hex))) + got_object_id_hex(id, hex, sizeof(hex))) log_debug("sending NAK for %s", hex); memset(&inak, 0, sizeof(inak)); blob - 7e04767d68c4c1e7eff6a3520785b24aac07efcf blob + 8e583c72710583238e82354eae3e6075176b7820 --- gotd/repo_read.c +++ gotd/repo_read.c @@ -418,7 +418,7 @@ recv_want(struct imsg *imsg) memcpy(id.sha1, iwant.object_id, SHA1_DIGEST_LENGTH); if (log_getverbose() > 0 && - got_sha1_digest_to_str(id.sha1, hex, sizeof(hex))) + got_object_id_hex(&id, hex, sizeof(hex))) log_debug("client wants %s", hex); imsg_init(&ibuf, client->fd); @@ -463,7 +463,7 @@ recv_have(struct imsg *imsg) memcpy(id.sha1, ihave.object_id, SHA1_DIGEST_LENGTH); if (log_getverbose() > 0 && - got_sha1_digest_to_str(id.sha1, hex, sizeof(hex))) + got_object_id_hex(&id, hex, sizeof(hex))) log_debug("client has %s", hex); imsg_init(&ibuf, client->fd); blob - 65e8d06c9243e84fd149a9a8f68dc5afe4032615 blob + f06337e95fa7c9e3eabd7ab414f3060e6755265a --- gotd/repo_write.c +++ gotd/repo_write.c @@ -367,7 +367,7 @@ verify_object_type(struct got_object_id *id, int expec idx = got_packidx_get_object_idx(packidx, id); if (idx == -1) { - got_sha1_digest_to_str(id->sha1, hex, sizeof(hex)); + got_object_id_hex(id, hex, sizeof(hex)); return got_error_fmt(GOT_ERR_BAD_PACKFILE, "object %s is missing from pack file", hex); } @@ -378,7 +378,7 @@ verify_object_type(struct got_object_id *id, int expec return err; if (obj->type != expected_obj_type) { - got_sha1_digest_to_str(id->sha1, hex, sizeof(hex)); + got_object_id_hex(id, hex, sizeof(hex)); got_object_type_label(&typestr, expected_obj_type); err = got_error_fmt(GOT_ERR_OBJ_TYPE, "%s is not pointing at a %s object", hex, typestr); @@ -437,7 +437,7 @@ protect_require_yca(struct got_object_id *tip_id, goto done; if (obj_type != GOT_OBJ_TYPE_COMMIT) { - got_sha1_digest_to_str(expected_yca_id->sha1, hex, sizeof(hex)); + got_object_id_hex(expected_yca_id, hex, sizeof(hex)); err = got_error_fmt(GOT_ERR_OBJ_TYPE, "%s is not pointing at a commit object", hex); goto done; @@ -492,8 +492,7 @@ protect_require_yca(struct got_object_id *tip_id, idx = got_packidx_get_object_idx(packidx, &qid->id); if (idx == -1) { - got_sha1_digest_to_str(qid->id.sha1, - hex, sizeof(hex)); + got_object_id_hex(&qid->id, hex, sizeof(hex)); err = got_error_fmt(GOT_ERR_BAD_PACKFILE, "object %s is missing from pack file", hex); goto done; @@ -505,8 +504,7 @@ protect_require_yca(struct got_object_id *tip_id, goto done; if (obj->type != GOT_OBJ_TYPE_COMMIT) { - got_sha1_digest_to_str(qid->id.sha1, - hex, sizeof(hex)); + got_object_id_hex(&qid->id, hex, sizeof(hex)); err = got_error_fmt(GOT_ERR_OBJ_TYPE, "%s is not pointing at a commit object", hex); @@ -1424,7 +1422,7 @@ verify_packfile(void) int idx = got_packidx_get_object_idx(packidx, &ref_update->new_id); if (idx == -1) { - got_sha1_digest_to_str(ref_update->new_id.sha1, + got_object_id_hex(&ref_update->new_id, hex, sizeof(hex)); err = got_error_fmt(GOT_ERR_BAD_PACKFILE, "object %s is missing from pack file", blob - 6bf274adf88e73b93de4344f929dd503dc20aa24 blob + f4f6c729dd161c635672dc12af8bdf34b2c7721e --- lib/patch.c +++ lib/patch.c @@ -797,8 +797,8 @@ prepare_merge(int *do_merge, char **apath, FILE **afil err = got_object_tree_find_path(&id, NULL, repo, tree, path); if (err) return err; - got_sha1_digest_to_str(id->sha1, p->blob, sizeof(p->blob)); - got_sha1_digest_to_str(commit_id->sha1, p->cid, sizeof(p->cid)); + got_object_id_hex(id, p->blob, sizeof(p->blob)); + got_object_id_hex(commit_id, p->cid, sizeof(p->cid)); free(id); err = open_blob(apath, afile, p->blob, repo); *do_merge = err == NULL; blob - 5dcffb2885a13005b4a036fbdd3148bafb5410d6 blob + 6ec79e85a76b5ba40ce146e249e75e24f79d7df9 --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -555,7 +555,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, for (i = 0; i < nref; i++) { if (got_object_id_cmp(&have[i], &want[i]) == 0) continue; - got_sha1_digest_to_str(want[i].sha1, hashstr, sizeof(hashstr)); + got_object_id_hex(&want[i], hashstr, sizeof(hashstr)); n = snprintf(buf, sizeof(buf), "want %s%s\n", hashstr, sent_my_capabilites || my_capabilities == NULL ? "" : my_capabilities); @@ -578,7 +578,7 @@ fetch_pack(int fd, int packfd, uint8_t *pack_sha1, TAILQ_FOREACH(pe, have_refs, entry) { struct got_object_id *id = pe->data; - got_sha1_digest_to_str(id->sha1, hashstr, sizeof(hashstr)); + got_object_id_hex(id, hashstr, sizeof(hashstr)); n = snprintf(buf, sizeof(buf), "have %s\n", hashstr); if (n < 0 || (size_t)n >= sizeof(buf)) { err = got_error(GOT_ERR_NO_SPACE); blob - 7c7c29553882ad9c792d99d2dc1c9cdda83597de blob + 2a2c22971801db07832f237f3969bc2e90a0c745 --- libexec/got-send-pack/got-send-pack.c +++ libexec/got-send-pack/got-send-pack.c @@ -463,7 +463,7 @@ send_pack(int fd, struct got_pathlist_head *refs, goto done; } - got_sha1_digest_to_str(their_id->sha1, old_hashstr, + got_object_id_hex(their_id, old_hashstr, sizeof(old_hashstr)); got_sha1_digest_to_str(zero_id, new_hashstr, sizeof(new_hashstr)); @@ -505,14 +505,13 @@ send_pack(int fd, struct got_pathlist_head *refs, } continue; } - got_sha1_digest_to_str(their_id->sha1, old_hashstr, + got_object_id_hex(their_id, old_hashstr, sizeof(old_hashstr)); } else { got_sha1_digest_to_str(zero_id, old_hashstr, sizeof(old_hashstr)); } - got_sha1_digest_to_str(id->sha1, new_hashstr, - sizeof(new_hashstr)); + got_object_id_hex(id, new_hashstr, sizeof(new_hashstr)); err = describe_refchange(&n, &sent_my_capabilites, my_capabilities, buf, sizeof(buf), refname, old_hashstr, new_hashstr);