commit bbc740ac4905ed0d4ba6334f6225c8f8c9f3c394 from: Omar Polo date: Sat Feb 04 07:41:11 2023 UTC introduce got_object_id_hex to replace some got_sha1_digest_to_str() It's an analogous to got_object_id_str but writes to the given buffer. ok + improvements by stsp@ commit - 3931a8a4404d58250d0d16467474bfba2cc215c2 commit + bbc740ac4905ed0d4ba6334f6225c8f8c9f3c394 blob - 9d11c8f4f518f5f911295671d3aafcb494a7ec10 blob + 6a161bc20df5aaa7789395593ab2ffc6fbe4b1fb --- include/got_object.h +++ include/got_object.h @@ -13,6 +13,8 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + +#define GOT_OBJECT_ID_HEX_MAXLEN SHA1_DIGEST_STRING_LENGTH struct got_object_id { u_int8_t sha1[SHA1_DIGEST_LENGTH]; blob - 3be41277d7a85a185d21bb7faa43bebe3b8eae07 blob + 26ad0c1921d76c50b48885cce2fa226b137793d7 --- lib/diff.c +++ lib/diff.c @@ -136,8 +136,8 @@ diff_blobs(struct got_diff_line **lines, size_t *nline enum got_diff_algorithm diff_algo) { const struct got_error *err = NULL, *free_err; - char hex1[SHA1_DIGEST_STRING_LENGTH]; - char hex2[SHA1_DIGEST_STRING_LENGTH]; + char hex1[GOT_OBJECT_ID_HEX_MAXLEN]; + char hex2[GOT_OBJECT_ID_HEX_MAXLEN]; const char *idstr1 = NULL, *idstr2 = NULL; char *modestr1 = NULL, *modestr2 = NULL; off_t size1, size2; @@ -344,7 +344,7 @@ diff_blob_file(struct got_diffreg_result **resultp, int force_text_diff, struct got_diffstat_cb_arg *diffstat, FILE *outfile) { const struct got_error *err = NULL, *free_err; - char hex1[SHA1_DIGEST_STRING_LENGTH]; + char hex1[GOT_OBJECT_ID_HEX_MAXLEN]; const char *idstr1 = NULL; struct got_diffreg_result *result = NULL; blob - 3c84ba7eeb9c88175a7652495f934263b6fd2328 blob + 95d7ae9cb011916744442c02343dafa9e4901bb1 --- lib/error.c +++ lib/error.c @@ -32,7 +32,7 @@ #include "got_lib_delta.h" #include "got_lib_inflate.h" #include "got_lib_object.h" -#include "got_lib_sha1.h" +#include "got_lib_object_parse.h" #ifndef nitems #define nitems(_a) (sizeof(_a) / sizeof((_a)[0])) @@ -367,11 +367,11 @@ got_ferror(FILE *f, int code) const struct got_error * got_error_no_obj(struct got_object_id *id) { - char msg[sizeof("object not found") + SHA1_DIGEST_STRING_LENGTH]; - char id_str[SHA1_DIGEST_STRING_LENGTH]; + char id_str[GOT_OBJECT_ID_HEX_MAXLEN]; + char msg[sizeof("object not found") + sizeof(id_str)]; int ret; - if (!got_sha1_digest_to_str(id->sha1, id_str, sizeof(id_str))) + if (!got_object_id_hex(id, id_str, sizeof(id_str))) return got_error(GOT_ERR_NO_OBJ); ret = snprintf(msg, sizeof(msg), "object %s not found", id_str); blob - 37def8a54e88bcdfbc49e4cc2f7a41fd8175f3b5 blob + 4b96e21f407d84ac399adbccb5d7e21cf86dad1f --- lib/got_lib_object_parse.h +++ lib/got_lib_object_parse.h @@ -16,6 +16,13 @@ struct got_pathlist_head; +/* + * Write the string representation fo an object ID in the given buffer. + * This buffer must be at least GOT_OBJECT_ID_HEX_MAXLEN bytes in size. + * The output depneds on the hash function used by the repository format. + */ +char *got_object_id_hex(struct got_object_id *, char *, size_t); + const struct got_error *got_object_qid_alloc_partial(struct got_object_qid **); struct got_commit_object *got_object_commit_alloc_partial(void); struct got_tree_entry *got_alloc_tree_entry_partial(void); blob - 52e7c967c9cc041ec94d6baa8ab706eb7434b845 blob + 57876d8fb763d7736c0cb4fbb6967718793d2cea --- lib/object.c +++ lib/object.c @@ -374,7 +374,7 @@ got_object_blob_rewind(struct got_blob_object *blob) char * got_object_blob_id_str(struct got_blob_object *blob, char *buf, size_t size) { - return got_sha1_digest_to_str(blob->id.sha1, buf, size); + return got_object_id_hex(&blob->id, buf, size); } size_t blob - c9a711f7c6066bf89187c9058634f85a5a61c2e1 blob + b17d5a9b339c525ac55deed48e604e2b049d96ca --- lib/object_parse.c +++ lib/object_parse.c @@ -88,19 +88,25 @@ got_object_qid_alloc_partial(struct got_object_qid **q const struct got_error * got_object_id_str(char **outbuf, struct got_object_id *id) { - static const size_t len = SHA1_DIGEST_STRING_LENGTH; + static const size_t len = GOT_OBJECT_ID_HEX_MAXLEN; *outbuf = malloc(len); if (*outbuf == NULL) return got_error_from_errno("malloc"); - if (got_sha1_digest_to_str(id->sha1, *outbuf, len) == NULL) { + if (got_object_id_hex(id, *outbuf, len) == NULL) { free(*outbuf); *outbuf = NULL; return got_error(GOT_ERR_BAD_OBJ_ID_STR); } return NULL; +} + +char * +got_object_id_hex(struct got_object_id *id, char *buf, size_t len) +{ + return got_sha1_digest_to_str(id->sha1, buf, len); } void