Download raw body.
prepare got_object_parse_tree for sha256
This is another delicate diff. Since got_object_parse_tree_entry is a function that has to be as fast as possible, my idea to handle both types of hashes is to keep track of the hashing algorithm used and the length of the digest, and then eventually adding a "gap" when sending in privsep.c so that the receiving side can always read a fixed-size buffer. This is to avoid doing memcpy() in the parsing function. ok? diff /home/op/w/got commit - dd96e029a8f0911725a77e589c7b86b2969bc651 path + /home/op/w/got blob - 871d597f71d021f4f8459895c0dd10256623af34 file + lib/dial.c --- lib/dial.c +++ lib/dial.c @@ -39,6 +39,7 @@ #include "got_lib_dial.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_privsep.h" #include "got_dial.h" blob - 05babbcb9ae24c765e1ed59bf0cb51d45de5aec7 file + lib/got_lib_object_parse.h --- lib/got_lib_object_parse.h +++ lib/got_lib_object_parse.h @@ -31,9 +31,11 @@ struct got_parsed_tree_entry { size_t namelen; /* strlen(name) */ mode_t mode; /* Mode parsed from tree buffer. */ uint8_t *id; /* Points to ID in parsed tree buffer. */ + size_t idlen; + int algo; }; const struct got_error *got_object_parse_tree_entry( - struct got_parsed_tree_entry *, size_t *, char *, size_t, size_t); + struct got_parsed_tree_entry *, size_t *, char *, size_t, size_t, enum got_hash_algorithm); const struct got_error *got_object_parse_tree(struct got_parsed_tree_entry **, size_t *, size_t *, uint8_t *, size_t, enum got_hash_algorithm); const struct got_error *got_object_read_tree(struct got_parsed_tree_entry **, blob - 9365381c6d173fbb3fedfb6b7d428db95f6e93f5 file + lib/got_lib_privsep.h --- lib/got_lib_privsep.h +++ lib/got_lib_privsep.h @@ -260,7 +260,8 @@ struct got_imsg_commit_object { } __attribute__((__packed__)); struct got_imsg_tree_entry { - char id[SHA1_DIGEST_LENGTH]; + char id[GOT_HASH_DIGEST_MAXLEN]; + int algo; mode_t mode; size_t namelen; /* Followed by namelen bytes of entry's name, not NUL-terminated. */ blob - a17fad35a4e3a657892518b204167bccb6b24289 file + lib/object_open_privsep.c --- lib/object_open_privsep.c +++ lib/object_open_privsep.c @@ -42,6 +42,7 @@ #include "got_lib_delta.h" #include "got_lib_object.h" +#include "got_lib_hash.h" #include "got_lib_privsep.h" #include "got_lib_object_cache.h" #include "got_lib_pack.h" blob - 0aafbffd522a53c07caf5219f5e6e6133d39d5eb file + lib/object_parse.c --- lib/object_parse.c +++ lib/object_parse.c @@ -764,7 +764,7 @@ got_object_tree_close(struct got_tree_object *tree) const struct got_error * got_object_parse_tree_entry(struct got_parsed_tree_entry *pte, size_t *elen, - char *buf, size_t maxlen, size_t idlen) + char *buf, size_t maxlen, size_t idlen, enum got_hash_algorithm algo) { char *p, *space; @@ -795,6 +795,8 @@ got_object_parse_tree_entry(struct got_parsed_tree_ent pte->namelen = strlen(pte->name); buf += *elen; pte->id = buf; + pte->idlen = idlen; + pte->algo = algo; *elen += idlen; return NULL; } @@ -840,7 +842,7 @@ got_object_parse_tree(struct got_parsed_tree_entry **e pte = &(*entries)[*nentries]; err = got_object_parse_tree_entry(pte, &elen, buf, remain, - digest_len); + digest_len, algo); if (err) goto done; buf += elen; blob - 21a33372de3f7d23116d9edeec23858bec4f935d file + lib/pack_create_privsep.c --- lib/pack_create_privsep.c +++ lib/pack_create_privsep.c @@ -40,6 +40,7 @@ #include "got_path.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_object_cache.h" #include "got_lib_object_idset.h" blob - f4f6c729dd161c635672dc12af8bdf34b2c7721e file + lib/patch.c --- lib/patch.c +++ lib/patch.c @@ -51,9 +51,9 @@ #include "got_lib_delta.h" #include "got_lib_diff.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_privsep.h" -#include "got_lib_hash.h" #ifndef MIN #define MIN(a, b) ((a) < (b) ? (a) : (b)) blob - 9fc1dd22c6d4e2c1868cd493424a0d5b4fe5ed5a file + lib/privsep.c --- lib/privsep.c +++ lib/privsep.c @@ -1452,11 +1452,17 @@ send_tree_entries_batch(struct imsgbuf *ibuf, return got_error_from_errno("imsg_add TREE_ENTRY"); for (i = idx0; i <= idxN; i++) { + static const char gap[12]; /* for sha1 inside sha256 align */ struct got_parsed_tree_entry *pte = &entries[i]; /* Keep in sync with struct got_imsg_tree_entry definition! */ - if (imsg_add(wbuf, pte->id, SHA1_DIGEST_LENGTH) == -1) + if (imsg_add(wbuf, pte->id, pte->idlen) == -1) return got_error_from_errno("imsg_add TREE_ENTRY"); + if (pte->algo == GOT_HASH_SHA1 && + imsg_add(wbuf, gap, sizeof(gap)) == -1) + return got_error_from_errno("imsg_add TREE_ENTRY"); + if (imsg_add(wbuf, &pte->algo, sizeof(pte->algo)) == -1) + return got_error_from_errno("imsg_add TREE_ENTRY"); if (imsg_add(wbuf, &pte->mode, sizeof(pte->mode)) == -1) return got_error_from_errno("imsg_add TREE_ENTRY"); if (imsg_add(wbuf, &pte->namelen, sizeof(pte->namelen)) == -1) @@ -1579,7 +1585,7 @@ recv_tree_entries(void *data, size_t datalen, struct g te_name = buf + sizeof(ite); memcpy(te->name, te_name, ite.namelen); te->name[ite.namelen] = '\0'; - memcpy(te->id.sha1, ite.id, SHA1_DIGEST_LENGTH); + memcpy(te->id.sha1, ite.id, sizeof(te->id.sha1)); te->mode = ite.mode; te->idx = *nentries; (*nentries)++; blob - 6f95c0f3be48676947b73e0f94d3c4cb8f97d06e file + lib/read_gitconfig_privsep.c --- lib/read_gitconfig_privsep.c +++ lib/read_gitconfig_privsep.c @@ -38,6 +38,7 @@ #include "got_path.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_object_cache.h" #include "got_lib_privsep.h" blob - 05502a62412786df6c1eb1c76b4411c0072d3054 file + lib/read_gotconfig_privsep.c --- lib/read_gotconfig_privsep.c +++ lib/read_gotconfig_privsep.c @@ -35,6 +35,7 @@ #include "got_repository.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_privsep.h" #include "got_lib_gotconfig.h" blob - 37bc0f5633b6a62f7d4a4d4b044b9301b502b0bd file + lib/repository.c --- lib/repository.c +++ lib/repository.c @@ -55,13 +55,13 @@ #include "got_lib_delta.h" #include "got_lib_delta_cache.h" +#include "got_lib_hash.h" #include "got_lib_inflate.h" #include "got_lib_object.h" #include "got_lib_object_parse.h" #include "got_lib_object_create.h" #include "got_lib_pack.h" #include "got_lib_privsep.h" -#include "got_lib_hash.h" #include "got_lib_object_cache.h" #include "got_lib_repository.h" #include "got_lib_gotconfig.h" blob - 3e6484604a0fd85e52307e35003a601798197c14 file + lib/repository_admin.c --- lib/repository_admin.c +++ lib/repository_admin.c @@ -46,6 +46,7 @@ #include "got_path.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_object_idset.h" #include "got_lib_object_cache.h" @@ -54,7 +55,6 @@ #include "got_lib_repository.h" #include "got_lib_ratelimit.h" #include "got_lib_pack_create.h" -#include "got_lib_hash.h" #include "got_lib_lockfile.h" #ifndef nitems blob - 7f75afa1f1f24fe910ee48fc4058be6cef03a8ee file + libexec/got-read-commit/got-read-commit.c --- libexec/got-read-commit/got-read-commit.c +++ libexec/got-read-commit/got-read-commit.c @@ -35,12 +35,12 @@ #include "got_object.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_inflate.h" #include "got_lib_object.h" #include "got_lib_object_parse.h" #include "got_lib_object_qid.h" #include "got_lib_privsep.h" -#include "got_lib_hash.h" static volatile sig_atomic_t sigint_received; blob - 9a5bac7eae6301e9090148ee2ec8d0dbdaf69237 file + libexec/got-read-gitconfig/got-read-gitconfig.c --- libexec/got-read-gitconfig/got-read-gitconfig.c +++ libexec/got-read-gitconfig/got-read-gitconfig.c @@ -36,6 +36,7 @@ #include "got_repository.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_privsep.h" #include "got_lib_gitconfig.h" blob - 43d3bfb7594fb0bc0bbe2d802c057ea1f4ec4a5e file + libexec/got-read-gotconfig/got-read-gotconfig.c --- libexec/got-read-gotconfig/got-read-gotconfig.c +++ libexec/got-read-gotconfig/got-read-gotconfig.c @@ -37,6 +37,7 @@ #include "got_repository.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_privsep.h" blob - 0270712db89ff118f330ae2524053b281b8d46e2 file + libexec/got-read-object/got-read-object.c --- libexec/got-read-object/got-read-object.c +++ libexec/got-read-object/got-read-object.c @@ -35,11 +35,11 @@ #include "got_object.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_inflate.h" #include "got_lib_object.h" #include "got_lib_object_parse.h" #include "got_lib_privsep.h" -#include "got_lib_hash.h" #ifndef nitems #define nitems(_a) (sizeof(_a) / sizeof((_a)[0])) blob - 460b92c34a33a3c21a304ba83a835391f3b6db31 file + libexec/got-read-pack/got-read-pack.c --- libexec/got-read-pack/got-read-pack.c +++ libexec/got-read-pack/got-read-pack.c @@ -495,7 +495,7 @@ tree_path_changed(int *changed, uint8_t **buf1, size_t */ while (remain1 > 0) { err = got_object_parse_tree_entry(&pte1, &elen, - next_entry1, remain1, idlen); + next_entry1, remain1, idlen, pack->algo); if (err) return err; next_entry1 += elen; @@ -519,7 +519,7 @@ tree_path_changed(int *changed, uint8_t **buf1, size_t while (remain2 > 0) { err = got_object_parse_tree_entry(&pte2, &elen, - next_entry2, remain2, idlen); + next_entry2, remain2, idlen, pack->algo); if (err) return err; next_entry2 += elen; blob - 83d8af428815b7ef730a8ddf19a89a8505a9bd60 file + libexec/got-read-patch/got-read-patch.c --- libexec/got-read-patch/got-read-patch.c +++ libexec/got-read-patch/got-read-patch.c @@ -55,9 +55,9 @@ #include "got_object.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_object.h" #include "got_lib_privsep.h" -#include "got_lib_hash.h" struct imsgbuf ibuf; blob - 39ff4fdaae7bf2fd23444ef6aae255310a4f2ad1 file + libexec/got-read-tag/got-read-tag.c --- libexec/got-read-tag/got-read-tag.c +++ libexec/got-read-tag/got-read-tag.c @@ -35,11 +35,11 @@ #include "got_object.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_inflate.h" #include "got_lib_object.h" #include "got_lib_object_parse.h" #include "got_lib_privsep.h" -#include "got_lib_hash.h" static volatile sig_atomic_t sigint_received; blob - 500f786f501a74944230154788890612bf220f7c file + libexec/got-read-tree/got-read-tree.c --- libexec/got-read-tree/got-read-tree.c +++ libexec/got-read-tree/got-read-tree.c @@ -36,11 +36,11 @@ #include "got_path.h" #include "got_lib_delta.h" +#include "got_lib_hash.h" #include "got_lib_inflate.h" #include "got_lib_object.h" #include "got_lib_object_parse.h" #include "got_lib_privsep.h" -#include "got_lib_hash.h" static volatile sig_atomic_t sigint_received;
prepare got_object_parse_tree for sha256