commit b6a31527a3cd044797b16afc12e9125a6b81e36f from: Omar Polo via: Thomas Adam date: Fri Jul 12 06:00:18 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 - 9772fc4b6b62f40cb3134a8ada6b5592b3ce8e1d commit + b6a31527a3cd044797b16afc12e9125a6b81e36f blob - e1a4ecc9f687a70322792d5accac679ce6a5b1cd blob + 920415a39d4094153e27c40adf44b4ea892e8047 --- 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 - 40a6ec66b5c03902bdeea209716d3ca59c03a19f blob + 9f73d5a2b5046ef57073e391e085ef3b588be768 --- gotd/repo_read.c +++ gotd/repo_read.c @@ -417,7 +417,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); @@ -462,7 +462,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 - 7ae97a2ea2c9ad104e9bf109f4f1f342448ad8c8 blob + 84f88571ad73fa856c0d868813941d3bdc298cd9 --- gotd/repo_write.c +++ gotd/repo_write.c @@ -365,7 +365,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); } @@ -376,7 +376,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); @@ -435,7 +435,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; @@ -490,8 +490,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; @@ -503,8 +502,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); @@ -1422,7 +1420,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 - 1be3e818e2d7cb83aca8e3e5cca2998563e4668c blob + 1cec0cd435a0d394a741e60135ee5b6afcb46ed6 --- lib/patch.c +++ lib/patch.c @@ -795,8 +795,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 - 18ab5b10d5415ba969c09b492b674e9da5a53871 blob + b1884703bebb5f64b4cffe14fa4d2113a1adb636 --- libexec/got-fetch-pack/got-fetch-pack.c +++ libexec/got-fetch-pack/got-fetch-pack.c @@ -554,7 +554,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); @@ -577,7 +577,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 - 3aff91faa19fba80b86263b1b2e3c9dc46873bc9 blob + 3296812795588de5596d3dcd6dcdd3fbb4628182 --- libexec/got-send-pack/got-send-pack.c +++ libexec/got-send-pack/got-send-pack.c @@ -461,7 +461,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)); @@ -503,14 +503,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);