{"thread":{"id":"47706","subject":"[PATCH 00/12] object_id part 11 (the_hash_algo)","startedAt":"2018-01-28T15:57:41Z","lastAt":"2018-01-28T22:00:19Z","messageCount":22,"participants":["brian m. carlson","Eric Sunshine","Patryk Obara"],"isPatch":true,"patchVersion":1,"patchTotal":12},"messages":[{"id":"337611","messageId":"20180128155722.880805-1-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":null,"subject":"[PATCH 00/12] object_id part 11 (the_hash_algo)","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:10Z","receivedAt":"2018-01-28T15:57:41Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"This series includes various changes to adopt the use of the_hash_algo\nfor abstracting hash algorithms away.\n\nThe series moves much of the hash-related code to hash.h from cache.h,\ndrops the ctxsz member in favor of allowing stack-allocated hash\ncontexts, and switches object-related code to use the_hash_algo for\nhashing.\n\nNote that not all instances of calls to git_SHA1_* have been converted.\nThe diff line code, the push cert code, and patch IDs all have been left\nalone for the moment because they are not related to object handling.\nPack checksums, on the other hand, have been converted.\n\nThe series is based off master, and has one minor conflict with Patryk\nObara's recent object_id series.\n\nI will also be sending out preliminary test patches on top of this\nseries that wire up an alternate hash algorithm so that we can see what\ntests break as a result.  (Hint: there's a lot of them.)\n\nbrian m. carlson (12):\n  hash: move SHA-1 macros to hash.h\n  hash: create union for hash context allocation\n  builtin/index-pack: improve hash function abstraction\n  builtin/unpack-objects: switch uses of SHA-1 to the_hash_algo\n  sha1_file: switch uses of SHA-1 to the_hash_algo\n  fast-import: switch various uses of SHA-1 to the_hash_algo\n  pack-check: convert various uses of SHA-1 to abstract forms\n  pack-write: switch various SHA-1 values to abstract forms\n  read-cache: abstract away uses of SHA-1\n  csum-file: rename sha1file to hashfile\n  csum-file: abstract uses of SHA-1\n  bulk-checkin: abstract SHA-1 usage\n\n builtin/index-pack.c     | 108 +++++++++++++++++++++++------------------------\n builtin/pack-objects.c   |  52 +++++++++++------------\n builtin/unpack-objects.c |  18 ++++----\n bulk-checkin.c           |  28 ++++++------\n cache.h                  |  25 -----------\n csum-file.c              |  46 ++++++++++----------\n csum-file.h              |  38 ++++++++---------\n fast-import.c            |  68 ++++++++++++++---------------\n hash.h                   |  34 +++++++++++++--\n pack-bitmap-write.c      |  30 ++++++-------\n pack-check.c             |  32 +++++++-------\n pack-write.c             |  77 ++++++++++++++++-----------------\n pack.h                   |   4 +-\n read-cache.c             |  54 ++++++++++++------------\n sha1_file.c              |  54 ++++++++++++------------\n 15 files changed, 335 insertions(+), 333 deletions(-)\n\n"},{"id":"337612","messageId":"20180128155722.880805-2-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 01/12] hash: move SHA-1 macros to hash.h","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:11Z","receivedAt":"2018-01-28T15:57:43Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Most of the other code dealing with SHA-1 and other hashes is located in\nhash.h, which is in turn loaded by cache.h.  Move the SHA-1 macros to\nhash.h as well, so we can use them in additional hash-related items in\nthe future.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h | 25 -------------------------\n hash.h  | 25 +++++++++++++++++++++++++\n 2 files changed, 25 insertions(+), 25 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex d8b975a571..bfde6f757a 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -16,31 +16,6 @@\n #include \"sha1-array.h\"\n #include \"repository.h\"\n \n-#ifndef platform_SHA_CTX\n-/*\n- * platform's underlying implementation of SHA-1; could be OpenSSL,\n- * blk_SHA, Apple CommonCrypto, etc...  Note that including\n- * SHA1_HEADER may have already defined platform_SHA_CTX for our\n- * own implementations like block-sha1 and ppc-sha1, so we list\n- * the default for OpenSSL compatible SHA-1 implementations here.\n- */\n-#define platform_SHA_CTX\tSHA_CTX\n-#define platform_SHA1_Init\tSHA1_Init\n-#define platform_SHA1_Update\tSHA1_Update\n-#define platform_SHA1_Final    \tSHA1_Final\n-#endif\n-\n-#define git_SHA_CTX\t\tplatform_SHA_CTX\n-#define git_SHA1_Init\t\tplatform_SHA1_Init\n-#define git_SHA1_Update\t\tplatform_SHA1_Update\n-#define git_SHA1_Final\t\tplatform_SHA1_Final\n-\n-#ifdef SHA1_MAX_BLOCK_SIZE\n-#include \"compat/sha1-chunked.h\"\n-#undef git_SHA1_Update\n-#define git_SHA1_Update\t\tgit_SHA1_Update_Chunked\n-#endif\n-\n #include <zlib.h>\n typedef struct git_zstream {\n \tz_stream z;\ndiff --git a/hash.h b/hash.h\nindex 7d7a864f5d..7122dea7b3 100644\n--- a/hash.h\n+++ b/hash.h\n@@ -15,6 +15,31 @@\n #include \"block-sha1/sha1.h\"\n #endif\n \n+#ifndef platform_SHA_CTX\n+/*\n+ * platform's underlying implementation of SHA-1; could be OpenSSL,\n+ * blk_SHA, Apple CommonCrypto, etc...  Note that including\n+ * SHA1_HEADER may have already defined platform_SHA_CTX for our\n+ * own implementations like block-sha1 and ppc-sha1, so we list\n+ * the default for OpenSSL compatible SHA-1 implementations here.\n+ */\n+#define platform_SHA_CTX\tSHA_CTX\n+#define platform_SHA1_Init\tSHA1_Init\n+#define platform_SHA1_Update\tSHA1_Update\n+#define platform_SHA1_Final    \tSHA1_Final\n+#endif\n+\n+#define git_SHA_CTX\t\tplatform_SHA_CTX\n+#define git_SHA1_Init\t\tplatform_SHA1_Init\n+#define git_SHA1_Update\t\tplatform_SHA1_Update\n+#define git_SHA1_Final\t\tplatform_SHA1_Final\n+\n+#ifdef SHA1_MAX_BLOCK_SIZE\n+#include \"compat/sha1-chunked.h\"\n+#undef git_SHA1_Update\n+#define git_SHA1_Update\t\tgit_SHA1_Update_Chunked\n+#endif\n+\n /*\n  * Note that these constants are suitable for indexing the hash_algos array and\n  * comparing against each other, but are otherwise arbitrary, so they should not\n"},{"id":"337613","messageId":"20180128155722.880805-5-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 04/12] builtin/unpack-objects: switch uses of SHA-1 to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:14Z","receivedAt":"2018-01-28T15:57:48Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch various uses of explicit calls to SHA-1 into references to\nthe_hash_algo to better abstract away the various uses of it.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/unpack-objects.c | 18 +++++++++---------\n 1 file changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/unpack-objects.c b/builtin/unpack-objects.c\nindex 62ea264c46..813ca31979 100644\n--- a/builtin/unpack-objects.c\n+++ b/builtin/unpack-objects.c\n@@ -21,7 +21,7 @@ static unsigned char buffer[4096];\n static unsigned int offset, len;\n static off_t consumed_bytes;\n static off_t max_input_size;\n-static git_SHA_CTX ctx;\n+static git_hash_ctx ctx;\n static struct fsck_options fsck_options = FSCK_OPTIONS_STRICT;\n \n /*\n@@ -62,7 +62,7 @@ static void *fill(int min)\n \tif (min > sizeof(buffer))\n \t\tdie(\"cannot fill %d bytes\", min);\n \tif (offset) {\n-\t\tgit_SHA1_Update(&ctx, buffer, offset);\n+\t\tthe_hash_algo->update_fn(&ctx, buffer, offset);\n \t\tmemmove(buffer, buffer + offset, len);\n \t\toffset = 0;\n \t}\n@@ -345,8 +345,8 @@ static void unpack_delta_entry(enum object_type type, unsigned long delta_size,\n \tstruct object_id base_oid;\n \n \tif (type == OBJ_REF_DELTA) {\n-\t\thashcpy(base_oid.hash, fill(GIT_SHA1_RAWSZ));\n-\t\tuse(GIT_SHA1_RAWSZ);\n+\t\thashcpy(base_oid.hash, fill(the_hash_algo->rawsz));\n+\t\tuse(the_hash_algo->rawsz);\n \t\tdelta_data = get_data(delta_size);\n \t\tif (dry_run || !delta_data) {\n \t\t\tfree(delta_data);\n@@ -564,15 +564,15 @@ int cmd_unpack_objects(int argc, const char **argv, const char *prefix)\n \t\t/* We don't take any non-flag arguments now.. Maybe some day */\n \t\tusage(unpack_usage);\n \t}\n-\tgit_SHA1_Init(&ctx);\n+\tthe_hash_algo->init_fn(&ctx);\n \tunpack_all();\n-\tgit_SHA1_Update(&ctx, buffer, offset);\n-\tgit_SHA1_Final(oid.hash, &ctx);\n+\tthe_hash_algo->update_fn(&ctx, buffer, offset);\n+\tthe_hash_algo->final_fn(oid.hash, &ctx);\n \tif (strict)\n \t\twrite_rest();\n-\tif (hashcmp(fill(GIT_SHA1_RAWSZ), oid.hash))\n+\tif (hashcmp(fill(the_hash_algo->rawsz), oid.hash))\n \t\tdie(\"final sha1 did not match\");\n-\tuse(GIT_SHA1_RAWSZ);\n+\tuse(the_hash_algo->rawsz);\n \n \t/* Write the last part of the buffer to stdout */\n \twhile (len) {\n"},{"id":"337614","messageId":"20180128155722.880805-6-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 05/12] sha1_file: switch uses of SHA-1 to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:15Z","receivedAt":"2018-01-28T15:57:49Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch various uses of explicit calls to SHA-1 into references to\nthe_hash_algo for better abstraction.  Convert some calls to use struct\nobject_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n sha1_file.c | 52 ++++++++++++++++++++++++++--------------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex e61d93a6e8..d9e2b1f285 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -786,16 +786,16 @@ void *xmmap(void *start, size_t length,\n int check_sha1_signature(const unsigned char *sha1, void *map,\n \t\t\t unsigned long size, const char *type)\n {\n-\tunsigned char real_sha1[20];\n+\tstruct object_id real_oid;\n \tenum object_type obj_type;\n \tstruct git_istream *st;\n-\tgit_SHA_CTX c;\n+\tgit_hash_ctx c;\n \tchar hdr[32];\n \tint hdrlen;\n \n \tif (map) {\n-\t\thash_sha1_file(map, size, type, real_sha1);\n-\t\treturn hashcmp(sha1, real_sha1) ? -1 : 0;\n+\t\thash_sha1_file(map, size, type, real_oid.hash);\n+\t\treturn hashcmp(sha1, real_oid.hash) ? -1 : 0;\n \t}\n \n \tst = open_istream(sha1, &obj_type, &size, NULL);\n@@ -806,8 +806,8 @@ int check_sha1_signature(const unsigned char *sha1, void *map,\n \thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %lu\", typename(obj_type), size) + 1;\n \n \t/* Sha1.. */\n-\tgit_SHA1_Init(&c);\n-\tgit_SHA1_Update(&c, hdr, hdrlen);\n+\tthe_hash_algo->init_fn(&c);\n+\tthe_hash_algo->update_fn(&c, hdr, hdrlen);\n \tfor (;;) {\n \t\tchar buf[1024 * 16];\n \t\tssize_t readlen = read_istream(st, buf, sizeof(buf));\n@@ -818,11 +818,11 @@ int check_sha1_signature(const unsigned char *sha1, void *map,\n \t\t}\n \t\tif (!readlen)\n \t\t\tbreak;\n-\t\tgit_SHA1_Update(&c, buf, readlen);\n+\t\tthe_hash_algo->update_fn(&c, buf, readlen);\n \t}\n-\tgit_SHA1_Final(real_sha1, &c);\n+\tthe_hash_algo->final_fn(real_oid.hash, &c);\n \tclose_istream(st);\n-\treturn hashcmp(sha1, real_sha1) ? -1 : 0;\n+\treturn hashcmp(sha1, real_oid.hash) ? -1 : 0;\n }\n \n int git_open_cloexec(const char *name, int flags)\n@@ -1421,16 +1421,16 @@ static void write_sha1_file_prepare(const void *buf, unsigned long len,\n                                     const char *type, unsigned char *sha1,\n                                     char *hdr, int *hdrlen)\n {\n-\tgit_SHA_CTX c;\n+\tgit_hash_ctx c;\n \n \t/* Generate the header */\n \t*hdrlen = xsnprintf(hdr, *hdrlen, \"%s %lu\", type, len)+1;\n \n \t/* Sha1.. */\n-\tgit_SHA1_Init(&c);\n-\tgit_SHA1_Update(&c, hdr, *hdrlen);\n-\tgit_SHA1_Update(&c, buf, len);\n-\tgit_SHA1_Final(sha1, &c);\n+\tthe_hash_algo->init_fn(&c);\n+\tthe_hash_algo->update_fn(&c, hdr, *hdrlen);\n+\tthe_hash_algo->update_fn(&c, buf, len);\n+\tthe_hash_algo->final_fn(sha1, &c);\n }\n \n /*\n@@ -1552,8 +1552,8 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,\n \tint fd, ret;\n \tunsigned char compressed[4096];\n \tgit_zstream stream;\n-\tgit_SHA_CTX c;\n-\tunsigned char parano_sha1[20];\n+\tgit_hash_ctx c;\n+\tstruct object_id parano_oid;\n \tstatic struct strbuf tmp_file = STRBUF_INIT;\n \tconst char *filename = sha1_file_name(sha1);\n \n@@ -1569,14 +1569,14 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,\n \tgit_deflate_init(&stream, zlib_compression_level);\n \tstream.next_out = compressed;\n \tstream.avail_out = sizeof(compressed);\n-\tgit_SHA1_Init(&c);\n+\tthe_hash_algo->init_fn(&c);\n \n \t/* First header.. */\n \tstream.next_in = (unsigned char *)hdr;\n \tstream.avail_in = hdrlen;\n \twhile (git_deflate(&stream, 0) == Z_OK)\n \t\t; /* nothing */\n-\tgit_SHA1_Update(&c, hdr, hdrlen);\n+\tthe_hash_algo->update_fn(&c, hdr, hdrlen);\n \n \t/* Then the data itself.. */\n \tstream.next_in = (void *)buf;\n@@ -1584,7 +1584,7 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,\n \tdo {\n \t\tunsigned char *in0 = stream.next_in;\n \t\tret = git_deflate(&stream, Z_FINISH);\n-\t\tgit_SHA1_Update(&c, in0, stream.next_in - in0);\n+\t\tthe_hash_algo->update_fn(&c, in0, stream.next_in - in0);\n \t\tif (write_buffer(fd, compressed, stream.next_out - compressed) < 0)\n \t\t\tdie(\"unable to write sha1 file\");\n \t\tstream.next_out = compressed;\n@@ -1596,8 +1596,8 @@ static int write_loose_object(const unsigned char *sha1, char *hdr, int hdrlen,\n \tret = git_deflate_end_gently(&stream);\n \tif (ret != Z_OK)\n \t\tdie(\"deflateEnd on object %s failed (%d)\", sha1_to_hex(sha1), ret);\n-\tgit_SHA1_Final(parano_sha1, &c);\n-\tif (hashcmp(sha1, parano_sha1) != 0)\n+\tthe_hash_algo->final_fn(parano_oid.hash, &c);\n+\tif (hashcmp(sha1, parano_oid.hash) != 0)\n \t\tdie(\"confused by unstable object source data for %s\", sha1_to_hex(sha1));\n \n \tclose_sha1_file(fd);\n@@ -2091,14 +2091,14 @@ static int check_stream_sha1(git_zstream *stream,\n \t\t\t     const char *path,\n \t\t\t     const unsigned char *expected_sha1)\n {\n-\tgit_SHA_CTX c;\n+\tgit_hash_ctx c;\n \tunsigned char real_sha1[GIT_MAX_RAWSZ];\n \tunsigned char buf[4096];\n \tunsigned long total_read;\n \tint status = Z_OK;\n \n-\tgit_SHA1_Init(&c);\n-\tgit_SHA1_Update(&c, hdr, stream->total_out);\n+\tthe_hash_algo->init_fn(&c);\n+\tthe_hash_algo->update_fn(&c, hdr, stream->total_out);\n \n \t/*\n \t * We already read some bytes into hdr, but the ones up to the NUL\n@@ -2117,7 +2117,7 @@ static int check_stream_sha1(git_zstream *stream,\n \t\tif (size - total_read < stream->avail_out)\n \t\t\tstream->avail_out = size - total_read;\n \t\tstatus = git_inflate(stream, Z_FINISH);\n-\t\tgit_SHA1_Update(&c, buf, stream->next_out - buf);\n+\t\tthe_hash_algo->update_fn(&c, buf, stream->next_out - buf);\n \t\ttotal_read += stream->next_out - buf;\n \t}\n \tgit_inflate_end(stream);\n@@ -2132,7 +2132,7 @@ static int check_stream_sha1(git_zstream *stream,\n \t\treturn -1;\n \t}\n \n-\tgit_SHA1_Final(real_sha1, &c);\n+\tthe_hash_algo->final_fn(real_sha1, &c);\n \tif (hashcmp(expected_sha1, real_sha1)) {\n \t\terror(\"sha1 mismatch for %s (expected %s)\", path,\n \t\t      sha1_to_hex(expected_sha1));\n"},{"id":"337615","messageId":"20180128155722.880805-7-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 06/12] fast-import: switch various uses of SHA-1 to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:16Z","receivedAt":"2018-01-28T15:57:53Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch various uses of explicit calls to SHA-1 to use the_hash_algo.\nConvert various uses of 20 and the GIT_SHA1 constants as well.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n fast-import.c | 40 ++++++++++++++++++++--------------------\n 1 file changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex b70ac025e0..1b8ab8ea29 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -1092,15 +1092,15 @@ static int store_object(\n \tunsigned char hdr[96];\n \tstruct object_id oid;\n \tunsigned long hdrlen, deltalen;\n-\tgit_SHA_CTX c;\n+\tgit_hash_ctx c;\n \tgit_zstream s;\n \n \thdrlen = xsnprintf((char *)hdr, sizeof(hdr), \"%s %lu\",\n \t\t\t   typename(type), (unsigned long)dat->len) + 1;\n-\tgit_SHA1_Init(&c);\n-\tgit_SHA1_Update(&c, hdr, hdrlen);\n-\tgit_SHA1_Update(&c, dat->buf, dat->len);\n-\tgit_SHA1_Final(oid.hash, &c);\n+\tthe_hash_algo->init_fn(&c);\n+\tthe_hash_algo->update_fn(&c, hdr, hdrlen);\n+\tthe_hash_algo->update_fn(&c, dat->buf, dat->len);\n+\tthe_hash_algo->final_fn(oid.hash, &c);\n \tif (oidout)\n \t\toidcpy(oidout, &oid);\n \n@@ -1118,11 +1118,11 @@ static int store_object(\n \t\treturn 1;\n \t}\n \n-\tif (last && last->data.buf && last->depth < max_depth && dat->len > 20) {\n+\tif (last && last->data.buf && last->depth < max_depth && dat->len > the_hash_algo->rawsz) {\n \t\tdelta_count_attempts_by_type[type]++;\n \t\tdelta = diff_delta(last->data.buf, last->data.len,\n \t\t\tdat->buf, dat->len,\n-\t\t\t&deltalen, dat->len - 20);\n+\t\t\t&deltalen, dat->len - the_hash_algo->rawsz);\n \t} else\n \t\tdelta = NULL;\n \n@@ -1231,7 +1231,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)\n \tstruct object_id oid;\n \tunsigned long hdrlen;\n \toff_t offset;\n-\tgit_SHA_CTX c;\n+\tgit_hash_ctx c;\n \tgit_zstream s;\n \tstruct sha1file_checkpoint checkpoint;\n \tint status = Z_OK;\n@@ -1246,8 +1246,8 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)\n \n \thdrlen = xsnprintf((char *)out_buf, out_sz, \"blob %\" PRIuMAX, len) + 1;\n \n-\tgit_SHA1_Init(&c);\n-\tgit_SHA1_Update(&c, out_buf, hdrlen);\n+\tthe_hash_algo->init_fn(&c);\n+\tthe_hash_algo->update_fn(&c, out_buf, hdrlen);\n \n \tcrc32_begin(pack_file);\n \n@@ -1265,7 +1265,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)\n \t\t\tif (!n && feof(stdin))\n \t\t\t\tdie(\"EOF in data (%\" PRIuMAX \" bytes remaining)\", len);\n \n-\t\t\tgit_SHA1_Update(&c, in_buf, n);\n+\t\t\tthe_hash_algo->update_fn(&c, in_buf, n);\n \t\t\ts.next_in = in_buf;\n \t\t\ts.avail_in = n;\n \t\t\tlen -= n;\n@@ -1291,7 +1291,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)\n \t\t}\n \t}\n \tgit_deflate_end(&s);\n-\tgit_SHA1_Final(oid.hash, &c);\n+\tthe_hash_algo->final_fn(oid.hash, &c);\n \n \tif (oidout)\n \t\toidcpy(oidout, &oid);\n@@ -1350,11 +1350,11 @@ static void *gfi_unpack_entry(\n {\n \tenum object_type type;\n \tstruct packed_git *p = all_packs[oe->pack_id];\n-\tif (p == pack_data && p->pack_size < (pack_size + 20)) {\n+\tif (p == pack_data && p->pack_size < (pack_size + the_hash_algo->rawsz)) {\n \t\t/* The object is stored in the packfile we are writing to\n \t\t * and we have modified it since the last time we scanned\n \t\t * back to read a previously written object.  If an old\n-\t\t * window covered [p->pack_size, p->pack_size + 20) its\n+\t\t * window covered [p->pack_size, p->pack_size + rawsz) its\n \t\t * data is stale and is not valid.  Closing all windows\n \t\t * and updating the packfile length ensures we can read\n \t\t * the newly written data.\n@@ -1362,13 +1362,13 @@ static void *gfi_unpack_entry(\n \t\tclose_pack_windows(p);\n \t\tsha1flush(pack_file);\n \n-\t\t/* We have to offer 20 bytes additional on the end of\n+\t\t/* We have to offer rawsz bytes additional on the end of\n \t\t * the packfile as the core unpacker code assumes the\n \t\t * footer is present at the file end and must promise\n-\t\t * at least 20 bytes within any window it maps.  But\n+\t\t * at least rawsz bytes within any window it maps.  But\n \t\t * we don't actually create the footer here.\n \t\t */\n-\t\tp->pack_size = pack_size + 20;\n+\t\tp->pack_size = pack_size + the_hash_algo->rawsz;\n \t}\n \treturn unpack_entry(p, oe->idx.offset, &type, sizep);\n }\n@@ -2204,7 +2204,7 @@ static void construct_path_with_fanout(const char *hex_sha1,\n \t\tunsigned char fanout, char *path)\n {\n \tunsigned int i = 0, j = 0;\n-\tif (fanout >= 20)\n+\tif (fanout >= the_hash_algo->rawsz)\n \t\tdie(\"Too large fanout (%u)\", fanout);\n \twhile (fanout) {\n \t\tpath[i++] = hex_sha1[j++];\n@@ -2212,8 +2212,8 @@ static void construct_path_with_fanout(const char *hex_sha1,\n \t\tpath[i++] = '/';\n \t\tfanout--;\n \t}\n-\tmemcpy(path + i, hex_sha1 + j, GIT_SHA1_HEXSZ - j);\n-\tpath[i + GIT_SHA1_HEXSZ - j] = '\\0';\n+\tmemcpy(path + i, hex_sha1 + j, the_hash_algo->hexsz - j);\n+\tpath[i + the_hash_algo->hexsz - j] = '\\0';\n }\n \n static uintmax_t do_change_note_fanout(\n"},{"id":"337616","messageId":"20180128155722.880805-10-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 09/12] read-cache: abstract away uses of SHA-1","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:19Z","receivedAt":"2018-01-28T15:57:54Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert various uses of direct calls to SHA-1 and 20- and 40-based\nconstants to use the_hash_algo instead.  Don't yet convert the on-disk\ndata structures, which will be handled in a future commit.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n read-cache.c | 54 +++++++++++++++++++++++++++---------------------------\n 1 file changed, 27 insertions(+), 27 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 2eb81a66b9..4f7aac23af 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -1545,8 +1545,8 @@ int verify_ce_order;\n \n static int verify_hdr(struct cache_header *hdr, unsigned long size)\n {\n-\tgit_SHA_CTX c;\n-\tunsigned char sha1[20];\n+\tgit_hash_ctx c;\n+\tunsigned char hash[GIT_MAX_RAWSZ];\n \tint hdr_version;\n \n \tif (hdr->hdr_signature != htonl(CACHE_SIGNATURE))\n@@ -1558,10 +1558,10 @@ static int verify_hdr(struct cache_header *hdr, unsigned long size)\n \tif (!verify_index_checksum)\n \t\treturn 0;\n \n-\tgit_SHA1_Init(&c);\n-\tgit_SHA1_Update(&c, hdr, size - 20);\n-\tgit_SHA1_Final(sha1, &c);\n-\tif (hashcmp(sha1, (unsigned char *)hdr + size - 20))\n+\tthe_hash_algo->init_fn(&c);\n+\tthe_hash_algo->update_fn(&c, hdr, size - the_hash_algo->rawsz);\n+\tthe_hash_algo->final_fn(hash, &c);\n+\tif (hashcmp(hash, (unsigned char *)hdr + size - the_hash_algo->rawsz))\n \t\treturn error(\"bad index file sha1 signature\");\n \treturn 0;\n }\n@@ -1791,7 +1791,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)\n \t\tdie_errno(\"cannot stat the open index\");\n \n \tmmap_size = xsize_t(st.st_size);\n-\tif (mmap_size < sizeof(struct cache_header) + 20)\n+\tif (mmap_size < sizeof(struct cache_header) + the_hash_algo->rawsz)\n \t\tdie(\"index file smaller than expected\");\n \n \tmmap = xmmap(NULL, mmap_size, PROT_READ, MAP_PRIVATE, fd, 0);\n@@ -1803,7 +1803,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)\n \tif (verify_hdr(hdr, mmap_size) < 0)\n \t\tgoto unmap;\n \n-\thashcpy(istate->sha1, (const unsigned char *)hdr + mmap_size - 20);\n+\thashcpy(istate->sha1, (const unsigned char *)hdr + mmap_size - the_hash_algo->rawsz);\n \tistate->version = ntohl(hdr->hdr_version);\n \tistate->cache_nr = ntohl(hdr->hdr_entries);\n \tistate->cache_alloc = alloc_nr(istate->cache_nr);\n@@ -1831,7 +1831,7 @@ int do_read_index(struct index_state *istate, const char *path, int must_exist)\n \tistate->timestamp.sec = st.st_mtime;\n \tistate->timestamp.nsec = ST_MTIME_NSEC(st);\n \n-\twhile (src_offset <= mmap_size - 20 - 8) {\n+\twhile (src_offset <= mmap_size - the_hash_algo->rawsz - 8) {\n \t\t/* After an array of active_nr index entries,\n \t\t * there can be arbitrary number of extended\n \t\t * sections, each of which is prefixed with\n@@ -1957,11 +1957,11 @@ int unmerged_index(const struct index_state *istate)\n static unsigned char write_buffer[WRITE_BUFFER_SIZE];\n static unsigned long write_buffer_len;\n \n-static int ce_write_flush(git_SHA_CTX *context, int fd)\n+static int ce_write_flush(git_hash_ctx *context, int fd)\n {\n \tunsigned int buffered = write_buffer_len;\n \tif (buffered) {\n-\t\tgit_SHA1_Update(context, write_buffer, buffered);\n+\t\tthe_hash_algo->update_fn(context, write_buffer, buffered);\n \t\tif (write_in_full(fd, write_buffer, buffered) < 0)\n \t\t\treturn -1;\n \t\twrite_buffer_len = 0;\n@@ -1969,7 +1969,7 @@ static int ce_write_flush(git_SHA_CTX *context, int fd)\n \treturn 0;\n }\n \n-static int ce_write(git_SHA_CTX *context, int fd, void *data, unsigned int len)\n+static int ce_write(git_hash_ctx *context, int fd, void *data, unsigned int len)\n {\n \twhile (len) {\n \t\tunsigned int buffered = write_buffer_len;\n@@ -1991,7 +1991,7 @@ static int ce_write(git_SHA_CTX *context, int fd, void *data, unsigned int len)\n \treturn 0;\n }\n \n-static int write_index_ext_header(git_SHA_CTX *context, int fd,\n+static int write_index_ext_header(git_hash_ctx *context, int fd,\n \t\t\t\t  unsigned int ext, unsigned int sz)\n {\n \text = htonl(ext);\n@@ -2000,26 +2000,26 @@ static int write_index_ext_header(git_SHA_CTX *context, int fd,\n \t\t(ce_write(context, fd, &sz, 4) < 0)) ? -1 : 0;\n }\n \n-static int ce_flush(git_SHA_CTX *context, int fd, unsigned char *sha1)\n+static int ce_flush(git_hash_ctx *context, int fd, unsigned char *hash)\n {\n \tunsigned int left = write_buffer_len;\n \n \tif (left) {\n \t\twrite_buffer_len = 0;\n-\t\tgit_SHA1_Update(context, write_buffer, left);\n+\t\tthe_hash_algo->update_fn(context, write_buffer, left);\n \t}\n \n \t/* Flush first if not enough space for SHA1 signature */\n-\tif (left + 20 > WRITE_BUFFER_SIZE) {\n+\tif (left + the_hash_algo->rawsz > WRITE_BUFFER_SIZE) {\n \t\tif (write_in_full(fd, write_buffer, left) < 0)\n \t\t\treturn -1;\n \t\tleft = 0;\n \t}\n \n \t/* Append the SHA1 signature at the end */\n-\tgit_SHA1_Final(write_buffer + left, context);\n-\thashcpy(sha1, write_buffer + left);\n-\tleft += 20;\n+\tthe_hash_algo->final_fn(write_buffer + left, context);\n+\thashcpy(hash, write_buffer + left);\n+\tleft += the_hash_algo->rawsz;\n \treturn (write_in_full(fd, write_buffer, left) < 0) ? -1 : 0;\n }\n \n@@ -2100,7 +2100,7 @@ static void copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,\n \t}\n }\n \n-static int ce_write_entry(git_SHA_CTX *c, int fd, struct cache_entry *ce,\n+static int ce_write_entry(git_hash_ctx *c, int fd, struct cache_entry *ce,\n \t\t\t  struct strbuf *previous_name, struct ondisk_cache_entry *ondisk)\n {\n \tint size;\n@@ -2167,7 +2167,7 @@ static int verify_index_from(const struct index_state *istate, const char *path)\n \tint fd;\n \tssize_t n;\n \tstruct stat st;\n-\tunsigned char sha1[20];\n+\tunsigned char hash[GIT_MAX_RAWSZ];\n \n \tif (!istate->initialized)\n \t\treturn 0;\n@@ -2179,14 +2179,14 @@ static int verify_index_from(const struct index_state *istate, const char *path)\n \tif (fstat(fd, &st))\n \t\tgoto out;\n \n-\tif (st.st_size < sizeof(struct cache_header) + 20)\n+\tif (st.st_size < sizeof(struct cache_header) + the_hash_algo->rawsz)\n \t\tgoto out;\n \n-\tn = pread_in_full(fd, sha1, 20, st.st_size - 20);\n-\tif (n != 20)\n+\tn = pread_in_full(fd, hash, the_hash_algo->rawsz, st.st_size - the_hash_algo->rawsz);\n+\tif (n != the_hash_algo->rawsz)\n \t\tgoto out;\n \n-\tif (hashcmp(istate->sha1, sha1))\n+\tif (hashcmp(istate->sha1, hash))\n \t\tgoto out;\n \n \tclose(fd);\n@@ -2235,7 +2235,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,\n \t\t\t  int strip_extensions)\n {\n \tint newfd = tempfile->fd;\n-\tgit_SHA_CTX c;\n+\tgit_hash_ctx c;\n \tstruct cache_header hdr;\n \tint i, err = 0, removed, extended, hdr_version;\n \tstruct cache_entry **cache = istate->cache;\n@@ -2273,7 +2273,7 @@ static int do_write_index(struct index_state *istate, struct tempfile *tempfile,\n \thdr.hdr_version = htonl(hdr_version);\n \thdr.hdr_entries = htonl(entries - removed);\n \n-\tgit_SHA1_Init(&c);\n+\tthe_hash_algo->init_fn(&c);\n \tif (ce_write(&c, newfd, &hdr, sizeof(hdr)) < 0)\n \t\treturn -1;\n \n"},{"id":"337617","messageId":"20180128155722.880805-13-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 12/12] bulk-checkin: abstract SHA-1 usage","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:22Z","receivedAt":"2018-01-28T15:58:00Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert uses of the direct SHA-1 functions to use the_hash_algo instead.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n bulk-checkin.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 5f79ed6ea3..8bcd1c8665 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -93,7 +93,7 @@ static int already_written(struct bulk_checkin_state *state, unsigned char sha1[\n  * with a new pack.\n  */\n static int stream_to_pack(struct bulk_checkin_state *state,\n-\t\t\t  git_SHA_CTX *ctx, off_t *already_hashed_to,\n+\t\t\t  git_hash_ctx *ctx, off_t *already_hashed_to,\n \t\t\t  int fd, size_t size, enum object_type type,\n \t\t\t  const char *path, unsigned flags)\n {\n@@ -127,7 +127,7 @@ static int stream_to_pack(struct bulk_checkin_state *state,\n \t\t\t\tif (rsize < hsize)\n \t\t\t\t\thsize = rsize;\n \t\t\t\tif (hsize)\n-\t\t\t\t\tgit_SHA1_Update(ctx, ibuf, hsize);\n+\t\t\t\t\tthe_hash_algo->update_fn(ctx, ibuf, hsize);\n \t\t\t\t*already_hashed_to = offset;\n \t\t\t}\n \t\t\ts.next_in = ibuf;\n@@ -192,7 +192,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,\n \t\t\t   unsigned flags)\n {\n \toff_t seekback, already_hashed_to;\n-\tgit_SHA_CTX ctx;\n+\tgit_hash_ctx ctx;\n \tunsigned char obuf[16384];\n \tunsigned header_len;\n \tstruct hashfile_checkpoint checkpoint;\n@@ -204,8 +204,8 @@ static int deflate_to_pack(struct bulk_checkin_state *state,\n \n \theader_len = xsnprintf((char *)obuf, sizeof(obuf), \"%s %\" PRIuMAX,\n \t\t\t       typename(type), (uintmax_t)size) + 1;\n-\tgit_SHA1_Init(&ctx);\n-\tgit_SHA1_Update(&ctx, obuf, header_len);\n+\tthe_hash_algo->init_fn(&ctx);\n+\tthe_hash_algo->update_fn(&ctx, obuf, header_len);\n \n \t/* Note: idx is non-NULL when we are writing */\n \tif ((flags & HASH_WRITE_OBJECT) != 0)\n@@ -236,7 +236,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,\n \t\tif (lseek(fd, seekback, SEEK_SET) == (off_t) -1)\n \t\t\treturn error(\"cannot seek back\");\n \t}\n-\tgit_SHA1_Final(result_sha1, &ctx);\n+\tthe_hash_algo->final_fn(result_sha1, &ctx);\n \tif (!idx)\n \t\treturn 0;\n \n"},{"id":"337618","messageId":"20180128155722.880805-4-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 03/12] builtin/index-pack: improve hash function abstraction","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:13Z","receivedAt":"2018-01-28T15:58:02Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert several uses of unsigned char [20] to struct object_id and\nconvert various hard-coded constants and uses of SHA-1 functions to use\nthe_hash_algo.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/index-pack.c | 90 ++++++++++++++++++++++++++--------------------------\n 1 file changed, 45 insertions(+), 45 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 4c51aec81f..40c000aca8 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -91,7 +91,7 @@ static unsigned int input_offset, input_len;\n static off_t consumed_bytes;\n static off_t max_input_size;\n static unsigned deepest_delta;\n-static git_SHA_CTX input_ctx;\n+static git_hash_ctx input_ctx;\n static uint32_t input_crc32;\n static int input_fd, output_fd;\n static const char *curr_pack;\n@@ -253,7 +253,7 @@ static void flush(void)\n \tif (input_offset) {\n \t\tif (output_fd >= 0)\n \t\t\twrite_or_die(output_fd, input_buffer, input_offset);\n-\t\tgit_SHA1_Update(&input_ctx, input_buffer, input_offset);\n+\t\tthe_hash_algo->update_fn(&input_ctx, input_buffer, input_offset);\n \t\tmemmove(input_buffer, input_buffer + input_offset, input_len);\n \t\tinput_offset = 0;\n \t}\n@@ -326,7 +326,7 @@ static const char *open_pack_file(const char *pack_name)\n \t\toutput_fd = -1;\n \t\tnothread_data.pack_fd = input_fd;\n \t}\n-\tgit_SHA1_Init(&input_ctx);\n+\tthe_hash_algo->init_fn(&input_ctx);\n \treturn pack_name;\n }\n \n@@ -437,22 +437,22 @@ static int is_delta_type(enum object_type type)\n }\n \n static void *unpack_entry_data(off_t offset, unsigned long size,\n-\t\t\t       enum object_type type, unsigned char *sha1)\n+\t\t\t       enum object_type type, struct object_id *oid)\n {\n \tstatic char fixed_buf[8192];\n \tint status;\n \tgit_zstream stream;\n \tvoid *buf;\n-\tgit_SHA_CTX c;\n+\tgit_hash_ctx c;\n \tchar hdr[32];\n \tint hdrlen;\n \n \tif (!is_delta_type(type)) {\n \t\thdrlen = xsnprintf(hdr, sizeof(hdr), \"%s %lu\", typename(type), size) + 1;\n-\t\tgit_SHA1_Init(&c);\n-\t\tgit_SHA1_Update(&c, hdr, hdrlen);\n+\t\tthe_hash_algo->init_fn(&c);\n+\t\tthe_hash_algo->update_fn(&c, hdr, hdrlen);\n \t} else\n-\t\tsha1 = NULL;\n+\t\toid = NULL;\n \tif (type == OBJ_BLOB && size > big_file_threshold)\n \t\tbuf = fixed_buf;\n \telse\n@@ -469,8 +469,8 @@ static void *unpack_entry_data(off_t offset, unsigned long size,\n \t\tstream.avail_in = input_len;\n \t\tstatus = git_inflate(&stream, 0);\n \t\tuse(input_len - stream.avail_in);\n-\t\tif (sha1)\n-\t\t\tgit_SHA1_Update(&c, last_out, stream.next_out - last_out);\n+\t\tif (oid)\n+\t\t\tthe_hash_algo->update_fn(&c, last_out, stream.next_out - last_out);\n \t\tif (buf == fixed_buf) {\n \t\t\tstream.next_out = buf;\n \t\t\tstream.avail_out = sizeof(fixed_buf);\n@@ -479,15 +479,15 @@ static void *unpack_entry_data(off_t offset, unsigned long size,\n \tif (stream.total_out != size || status != Z_STREAM_END)\n \t\tbad_object(offset, _(\"inflate returned %d\"), status);\n \tgit_inflate_end(&stream);\n-\tif (sha1)\n-\t\tgit_SHA1_Final(sha1, &c);\n+\tif (oid)\n+\t\tthe_hash_algo->final_fn(oid->hash, &c);\n \treturn buf == fixed_buf ? NULL : buf;\n }\n \n static void *unpack_raw_entry(struct object_entry *obj,\n \t\t\t      off_t *ofs_offset,\n-\t\t\t      unsigned char *ref_sha1,\n-\t\t\t      unsigned char *sha1)\n+\t\t\t      struct object_id *ref_oid,\n+\t\t\t      struct object_id *oid)\n {\n \tunsigned char *p;\n \tunsigned long size, c;\n@@ -515,8 +515,8 @@ static void *unpack_raw_entry(struct object_entry *obj,\n \n \tswitch (obj->type) {\n \tcase OBJ_REF_DELTA:\n-\t\thashcpy(ref_sha1, fill(20));\n-\t\tuse(20);\n+\t\thashcpy(ref_oid->hash, fill(the_hash_algo->rawsz));\n+\t\tuse(the_hash_algo->rawsz);\n \t\tbreak;\n \tcase OBJ_OFS_DELTA:\n \t\tp = fill(1);\n@@ -546,7 +546,7 @@ static void *unpack_raw_entry(struct object_entry *obj,\n \t}\n \tobj->hdr_size = consumed_bytes - obj->idx.offset;\n \n-\tdata = unpack_entry_data(obj->idx.offset, obj->size, obj->type, sha1);\n+\tdata = unpack_entry_data(obj->idx.offset, obj->size, obj->type, oid);\n \tobj->idx.crc32 = input_crc32;\n \treturn data;\n }\n@@ -1119,11 +1119,11 @@ static void *threaded_second_pass(void *data)\n  * - calculate SHA1 of all non-delta objects;\n  * - remember base (SHA1 or offset) for all deltas.\n  */\n-static void parse_pack_objects(unsigned char *sha1)\n+static void parse_pack_objects(unsigned char *hash)\n {\n \tint i, nr_delays = 0;\n \tstruct ofs_delta_entry *ofs_delta = ofs_deltas;\n-\tunsigned char ref_delta_sha1[20];\n+\tstruct object_id ref_delta_oid;\n \tstruct stat st;\n \n \tif (verbose)\n@@ -1133,8 +1133,8 @@ static void parse_pack_objects(unsigned char *sha1)\n \tfor (i = 0; i < nr_objects; i++) {\n \t\tstruct object_entry *obj = &objects[i];\n \t\tvoid *data = unpack_raw_entry(obj, &ofs_delta->offset,\n-\t\t\t\t\t      ref_delta_sha1,\n-\t\t\t\t\t      obj->idx.oid.hash);\n+\t\t\t\t\t      &ref_delta_oid,\n+\t\t\t\t\t      &obj->idx.oid);\n \t\tobj->real_type = obj->type;\n \t\tif (obj->type == OBJ_OFS_DELTA) {\n \t\t\tnr_ofs_deltas++;\n@@ -1142,7 +1142,7 @@ static void parse_pack_objects(unsigned char *sha1)\n \t\t\tofs_delta++;\n \t\t} else if (obj->type == OBJ_REF_DELTA) {\n \t\t\tALLOC_GROW(ref_deltas, nr_ref_deltas + 1, ref_deltas_alloc);\n-\t\t\thashcpy(ref_deltas[nr_ref_deltas].sha1, ref_delta_sha1);\n+\t\t\thashcpy(ref_deltas[nr_ref_deltas].sha1, ref_delta_oid.hash);\n \t\t\tref_deltas[nr_ref_deltas].obj_no = i;\n \t\t\tnr_ref_deltas++;\n \t\t} else if (!data) {\n@@ -1160,10 +1160,10 @@ static void parse_pack_objects(unsigned char *sha1)\n \n \t/* Check pack integrity */\n \tflush();\n-\tgit_SHA1_Final(sha1, &input_ctx);\n-\tif (hashcmp(fill(20), sha1))\n+\tthe_hash_algo->final_fn(hash, &input_ctx);\n+\tif (hashcmp(fill(the_hash_algo->rawsz), hash))\n \t\tdie(_(\"pack is corrupted (SHA1 mismatch)\"));\n-\tuse(20);\n+\tuse(the_hash_algo->rawsz);\n \n \t/* If input_fd is a file, we should have reached its end now. */\n \tif (fstat(input_fd, &st))\n@@ -1239,21 +1239,21 @@ static void resolve_deltas(void)\n /*\n  * Third pass:\n  * - append objects to convert thin pack to full pack if required\n- * - write the final 20-byte SHA-1\n+ * - write the final pack hash\n  */\n static void fix_unresolved_deltas(struct sha1file *f);\n-static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned char *pack_sha1)\n+static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned char *pack_hash)\n {\n \tif (nr_ref_deltas + nr_ofs_deltas == nr_resolved_deltas) {\n \t\tstop_progress(&progress);\n-\t\t/* Flush remaining pack final 20-byte SHA1. */\n+\t\t/* Flush remaining pack final hash. */\n \t\tflush();\n \t\treturn;\n \t}\n \n \tif (fix_thin_pack) {\n \t\tstruct sha1file *f;\n-\t\tunsigned char read_sha1[20], tail_sha1[20];\n+\t\tunsigned char read_hash[GIT_MAX_RAWSZ], tail_hash[GIT_MAX_RAWSZ];\n \t\tstruct strbuf msg = STRBUF_INIT;\n \t\tint nr_unresolved = nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas;\n \t\tint nr_objects_initial = nr_objects;\n@@ -1270,12 +1270,12 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha\n \t\t\t    nr_objects - nr_objects_initial);\n \t\tstop_progress_msg(&progress, msg.buf);\n \t\tstrbuf_release(&msg);\n-\t\tsha1close(f, tail_sha1, 0);\n-\t\thashcpy(read_sha1, pack_sha1);\n-\t\tfixup_pack_header_footer(output_fd, pack_sha1,\n+\t\tsha1close(f, tail_hash, 0);\n+\t\thashcpy(read_hash, pack_hash);\n+\t\tfixup_pack_header_footer(output_fd, pack_hash,\n \t\t\t\t\t curr_pack, nr_objects,\n-\t\t\t\t\t read_sha1, consumed_bytes-20);\n-\t\tif (hashcmp(read_sha1, tail_sha1) != 0)\n+\t\t\t\t\t read_hash, consumed_bytes-the_hash_algo->rawsz);\n+\t\tif (hashcmp(read_hash, tail_hash) != 0)\n \t\t\tdie(_(\"Unexpected tail checksum for %s \"\n \t\t\t      \"(disk corruption?)\"), curr_pack);\n \t}\n@@ -1392,7 +1392,7 @@ static void fix_unresolved_deltas(struct sha1file *f)\n static void final(const char *final_pack_name, const char *curr_pack_name,\n \t\t  const char *final_index_name, const char *curr_index_name,\n \t\t  const char *keep_name, const char *keep_msg,\n-\t\t  unsigned char *sha1)\n+\t\t  unsigned char *hash)\n {\n \tconst char *report = \"pack\";\n \tstruct strbuf pack_name = STRBUF_INIT;\n@@ -1413,7 +1413,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \t\tint keep_fd, keep_msg_len = strlen(keep_msg);\n \n \t\tif (!keep_name)\n-\t\t\tkeep_name = odb_pack_name(&keep_name_buf, sha1, \"keep\");\n+\t\t\tkeep_name = odb_pack_name(&keep_name_buf, hash, \"keep\");\n \n \t\tkeep_fd = odb_pack_keep(keep_name);\n \t\tif (keep_fd < 0) {\n@@ -1434,7 +1434,7 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \n \tif (final_pack_name != curr_pack_name) {\n \t\tif (!final_pack_name)\n-\t\t\tfinal_pack_name = odb_pack_name(&pack_name, sha1, \"pack\");\n+\t\t\tfinal_pack_name = odb_pack_name(&pack_name, hash, \"pack\");\n \t\tif (finalize_object_file(curr_pack_name, final_pack_name))\n \t\t\tdie(_(\"cannot store pack file\"));\n \t} else if (from_stdin)\n@@ -1442,18 +1442,18 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \n \tif (final_index_name != curr_index_name) {\n \t\tif (!final_index_name)\n-\t\t\tfinal_index_name = odb_pack_name(&index_name, sha1, \"idx\");\n+\t\t\tfinal_index_name = odb_pack_name(&index_name, hash, \"idx\");\n \t\tif (finalize_object_file(curr_index_name, final_index_name))\n \t\t\tdie(_(\"cannot store index file\"));\n \t} else\n \t\tchmod(final_index_name, 0444);\n \n \tif (!from_stdin) {\n-\t\tprintf(\"%s\\n\", sha1_to_hex(sha1));\n+\t\tprintf(\"%s\\n\", sha1_to_hex(hash));\n \t} else {\n \t\tstruct strbuf buf = STRBUF_INIT;\n \n-\t\tstrbuf_addf(&buf, \"%s\\t%s\\n\", report, sha1_to_hex(sha1));\n+\t\tstrbuf_addf(&buf, \"%s\\t%s\\n\", report, sha1_to_hex(hash));\n \t\twrite_or_die(1, buf.buf, buf.len);\n \t\tstrbuf_release(&buf);\n \n@@ -1637,7 +1637,7 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)\n \t\t      keep_name_buf = STRBUF_INIT;\n \tstruct pack_idx_entry **idx_objects;\n \tstruct pack_idx_option opts;\n-\tunsigned char pack_sha1[20];\n+\tunsigned char pack_hash[GIT_MAX_RAWSZ];\n \tunsigned foreign_nr = 1;\t/* zero is a \"good\" value, assume bad */\n \tint report_end_of_input = 0;\n \n@@ -1768,11 +1768,11 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)\n \tif (show_stat)\n \t\tobj_stat = xcalloc(st_add(nr_objects, 1), sizeof(struct object_stat));\n \tofs_deltas = xcalloc(nr_objects, sizeof(struct ofs_delta_entry));\n-\tparse_pack_objects(pack_sha1);\n+\tparse_pack_objects(pack_hash);\n \tif (report_end_of_input)\n \t\twrite_in_full(2, \"\\0\", 1);\n \tresolve_deltas();\n-\tconclude_pack(fix_thin_pack, curr_pack, pack_sha1);\n+\tconclude_pack(fix_thin_pack, curr_pack, pack_hash);\n \tfree(ofs_deltas);\n \tfree(ref_deltas);\n \tif (strict)\n@@ -1784,14 +1784,14 @@ int cmd_index_pack(int argc, const char **argv, const char *prefix)\n \tALLOC_ARRAY(idx_objects, nr_objects);\n \tfor (i = 0; i < nr_objects; i++)\n \t\tidx_objects[i] = &objects[i].idx;\n-\tcurr_index = write_idx_file(index_name, idx_objects, nr_objects, &opts, pack_sha1);\n+\tcurr_index = write_idx_file(index_name, idx_objects, nr_objects, &opts, pack_hash);\n \tfree(idx_objects);\n \n \tif (!verify)\n \t\tfinal(pack_name, curr_pack,\n \t\t      index_name, curr_index,\n \t\t      keep_name, keep_msg,\n-\t\t      pack_sha1);\n+\t\t      pack_hash);\n \telse\n \t\tclose(input_fd);\n \tfree(objects);\n"},{"id":"337619","messageId":"20180128155722.880805-12-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 11/12] csum-file: abstract uses of SHA-1","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:21Z","receivedAt":"2018-01-28T15:58:03Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert several direct uses of SHA-1 to use the_hash_algo instead.\nConvert one use of the constant 20 as well.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n csum-file.c | 10 +++++-----\n csum-file.h |  4 ++--\n 2 files changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/csum-file.c b/csum-file.c\nindex e4ad6337dc..5eda7fb6af 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -47,7 +47,7 @@ void hashflush(struct hashfile *f)\n \tunsigned offset = f->offset;\n \n \tif (offset) {\n-\t\tgit_SHA1_Update(&f->ctx, f->buffer, offset);\n+\t\tthe_hash_algo->update_fn(&f->ctx, f->buffer, offset);\n \t\tflush(f, f->buffer, offset);\n \t\tf->offset = 0;\n \t}\n@@ -58,12 +58,12 @@ int hashclose(struct hashfile *f, unsigned char *result, unsigned int flags)\n \tint fd;\n \n \thashflush(f);\n-\tgit_SHA1_Final(f->buffer, &f->ctx);\n+\tthe_hash_algo->final_fn(f->buffer, &f->ctx);\n \tif (result)\n \t\thashcpy(result, f->buffer);\n \tif (flags & (CSUM_CLOSE | CSUM_FSYNC)) {\n \t\t/* write checksum and close fd */\n-\t\tflush(f, f->buffer, 20);\n+\t\tflush(f, f->buffer, the_hash_algo->rawsz);\n \t\tif (flags & CSUM_FSYNC)\n \t\t\tfsync_or_die(f->fd, f->name);\n \t\tif (close(f->fd))\n@@ -110,7 +110,7 @@ void hashwrite(struct hashfile *f, const void *buf, unsigned int count)\n \t\tbuf = (char *) buf + nr;\n \t\tleft -= nr;\n \t\tif (!left) {\n-\t\t\tgit_SHA1_Update(&f->ctx, data, offset);\n+\t\t\tthe_hash_algo->update_fn(&f->ctx, data, offset);\n \t\t\tflush(f, data, offset);\n \t\t\toffset = 0;\n \t\t}\n@@ -149,7 +149,7 @@ struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp\n \tf->tp = tp;\n \tf->name = name;\n \tf->do_crc = 0;\n-\tgit_SHA1_Init(&f->ctx);\n+\tthe_hash_algo->init_fn(&f->ctx);\n \treturn f;\n }\n \ndiff --git a/csum-file.h b/csum-file.h\nindex ceb3e5712d..992e5c0141 100644\n--- a/csum-file.h\n+++ b/csum-file.h\n@@ -8,7 +8,7 @@ struct hashfile {\n \tint fd;\n \tint check_fd;\n \tunsigned int offset;\n-\tgit_SHA_CTX ctx;\n+\tgit_hash_ctx ctx;\n \toff_t total;\n \tstruct progress *tp;\n \tconst char *name;\n@@ -20,7 +20,7 @@ struct hashfile {\n /* Checkpoint */\n struct hashfile_checkpoint {\n \toff_t offset;\n-\tgit_SHA_CTX ctx;\n+\tgit_hash_ctx ctx;\n };\n \n extern void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);\n"},{"id":"337620","messageId":"20180128155722.880805-11-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 10/12] csum-file: rename sha1file to hashfile","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:20Z","receivedAt":"2018-01-28T15:58:07Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Rename struct sha1file to struct hashfile, along with all of its related\nfunctions.\n\nThe transformation in this commit was made by global search-and-replace.\n---\n builtin/index-pack.c   | 20 +++++++++----------\n builtin/pack-objects.c | 52 +++++++++++++++++++++++++-------------------------\n bulk-checkin.c         | 16 ++++++++--------\n csum-file.c            | 36 +++++++++++++++++-----------------\n csum-file.h            | 34 ++++++++++++++++-----------------\n fast-import.c          | 28 +++++++++++++--------------\n pack-bitmap-write.c    | 30 ++++++++++++++---------------\n pack-write.c           | 32 +++++++++++++++----------------\n pack.h                 |  4 ++--\n 9 files changed, 126 insertions(+), 126 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 40c000aca8..0bb520c731 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1241,7 +1241,7 @@ static void resolve_deltas(void)\n  * - append objects to convert thin pack to full pack if required\n  * - write the final pack hash\n  */\n-static void fix_unresolved_deltas(struct sha1file *f);\n+static void fix_unresolved_deltas(struct hashfile *f);\n static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned char *pack_hash)\n {\n \tif (nr_ref_deltas + nr_ofs_deltas == nr_resolved_deltas) {\n@@ -1252,7 +1252,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha\n \t}\n \n \tif (fix_thin_pack) {\n-\t\tstruct sha1file *f;\n+\t\tstruct hashfile *f;\n \t\tunsigned char read_hash[GIT_MAX_RAWSZ], tail_hash[GIT_MAX_RAWSZ];\n \t\tstruct strbuf msg = STRBUF_INIT;\n \t\tint nr_unresolved = nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas;\n@@ -1262,7 +1262,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha\n \t\tREALLOC_ARRAY(objects, nr_objects + nr_unresolved + 1);\n \t\tmemset(objects + nr_objects + 1, 0,\n \t\t       nr_unresolved * sizeof(*objects));\n-\t\tf = sha1fd(output_fd, curr_pack);\n+\t\tf = hashfd(output_fd, curr_pack);\n \t\tfix_unresolved_deltas(f);\n \t\tstrbuf_addf(&msg, Q_(\"completed with %d local object\",\n \t\t\t\t     \"completed with %d local objects\",\n@@ -1270,7 +1270,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha\n \t\t\t    nr_objects - nr_objects_initial);\n \t\tstop_progress_msg(&progress, msg.buf);\n \t\tstrbuf_release(&msg);\n-\t\tsha1close(f, tail_hash, 0);\n+\t\thashclose(f, tail_hash, 0);\n \t\thashcpy(read_hash, pack_hash);\n \t\tfixup_pack_header_footer(output_fd, pack_hash,\n \t\t\t\t\t curr_pack, nr_objects,\n@@ -1286,7 +1286,7 @@ static void conclude_pack(int fix_thin_pack, const char *curr_pack, unsigned cha\n \t\t    nr_ofs_deltas + nr_ref_deltas - nr_resolved_deltas);\n }\n \n-static int write_compressed(struct sha1file *f, void *in, unsigned int size)\n+static int write_compressed(struct hashfile *f, void *in, unsigned int size)\n {\n \tgit_zstream stream;\n \tint status;\n@@ -1300,7 +1300,7 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)\n \t\tstream.next_out = outbuf;\n \t\tstream.avail_out = sizeof(outbuf);\n \t\tstatus = git_deflate(&stream, Z_FINISH);\n-\t\tsha1write(f, outbuf, sizeof(outbuf) - stream.avail_out);\n+\t\thashwrite(f, outbuf, sizeof(outbuf) - stream.avail_out);\n \t} while (status == Z_OK);\n \n \tif (status != Z_STREAM_END)\n@@ -1310,7 +1310,7 @@ static int write_compressed(struct sha1file *f, void *in, unsigned int size)\n \treturn size;\n }\n \n-static struct object_entry *append_obj_to_pack(struct sha1file *f,\n+static struct object_entry *append_obj_to_pack(struct hashfile *f,\n \t\t\t       const unsigned char *sha1, void *buf,\n \t\t\t       unsigned long size, enum object_type type)\n {\n@@ -1327,7 +1327,7 @@ static struct object_entry *append_obj_to_pack(struct sha1file *f,\n \t}\n \theader[n++] = c;\n \tcrc32_begin(f);\n-\tsha1write(f, header, n);\n+\thashwrite(f, header, n);\n \tobj[0].size = size;\n \tobj[0].hdr_size = n;\n \tobj[0].type = type;\n@@ -1335,7 +1335,7 @@ static struct object_entry *append_obj_to_pack(struct sha1file *f,\n \tobj[1].idx.offset = obj[0].idx.offset + n;\n \tobj[1].idx.offset += write_compressed(f, buf, size);\n \tobj[0].idx.crc32 = crc32_end(f);\n-\tsha1flush(f);\n+\thashflush(f);\n \thashcpy(obj->idx.oid.hash, sha1);\n \treturn obj;\n }\n@@ -1347,7 +1347,7 @@ static int delta_pos_compare(const void *_a, const void *_b)\n \treturn a->obj_no - b->obj_no;\n }\n \n-static void fix_unresolved_deltas(struct sha1file *f)\n+static void fix_unresolved_deltas(struct hashfile *f)\n {\n \tstruct ref_delta_entry **sorted_by_pos;\n \tint i;\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 6b9cfc289d..d91cbd460e 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -161,7 +161,7 @@ static unsigned long do_compress(void **pptr, unsigned long size)\n \treturn stream.total_out;\n }\n \n-static unsigned long write_large_blob_data(struct git_istream *st, struct sha1file *f,\n+static unsigned long write_large_blob_data(struct git_istream *st, struct hashfile *f,\n \t\t\t\t\t   const struct object_id *oid)\n {\n \tgit_zstream stream;\n@@ -185,7 +185,7 @@ static unsigned long write_large_blob_data(struct git_istream *st, struct sha1fi\n \t\t\tstream.next_out = obuf;\n \t\t\tstream.avail_out = sizeof(obuf);\n \t\t\tzret = git_deflate(&stream, readlen ? 0 : Z_FINISH);\n-\t\t\tsha1write(f, obuf, stream.next_out - obuf);\n+\t\t\thashwrite(f, obuf, stream.next_out - obuf);\n \t\t\tolen += stream.next_out - obuf;\n \t\t}\n \t\tif (stream.avail_in)\n@@ -230,7 +230,7 @@ static int check_pack_inflate(struct packed_git *p,\n \t\tstream.total_in == len) ? 0 : -1;\n }\n \n-static void copy_pack_data(struct sha1file *f,\n+static void copy_pack_data(struct hashfile *f,\n \t\tstruct packed_git *p,\n \t\tstruct pack_window **w_curs,\n \t\toff_t offset,\n@@ -243,14 +243,14 @@ static void copy_pack_data(struct sha1file *f,\n \t\tin = use_pack(p, w_curs, offset, &avail);\n \t\tif (avail > len)\n \t\t\tavail = (unsigned long)len;\n-\t\tsha1write(f, in, avail);\n+\t\thashwrite(f, in, avail);\n \t\toffset += avail;\n \t\tlen -= avail;\n \t}\n }\n \n /* Return 0 if we will bust the pack-size limit */\n-static unsigned long write_no_reuse_object(struct sha1file *f, struct object_entry *entry,\n+static unsigned long write_no_reuse_object(struct hashfile *f, struct object_entry *entry,\n \t\t\t\t\t   unsigned long limit, int usable_delta)\n {\n \tunsigned long size, datalen;\n@@ -323,8 +323,8 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent\n \t\t\tfree(buf);\n \t\t\treturn 0;\n \t\t}\n-\t\tsha1write(f, header, hdrlen);\n-\t\tsha1write(f, dheader + pos, sizeof(dheader) - pos);\n+\t\thashwrite(f, header, hdrlen);\n+\t\thashwrite(f, dheader + pos, sizeof(dheader) - pos);\n \t\thdrlen += sizeof(dheader) - pos;\n \t} else if (type == OBJ_REF_DELTA) {\n \t\t/*\n@@ -337,8 +337,8 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent\n \t\t\tfree(buf);\n \t\t\treturn 0;\n \t\t}\n-\t\tsha1write(f, header, hdrlen);\n-\t\tsha1write(f, entry->delta->idx.oid.hash, 20);\n+\t\thashwrite(f, header, hdrlen);\n+\t\thashwrite(f, entry->delta->idx.oid.hash, 20);\n \t\thdrlen += 20;\n \t} else {\n \t\tif (limit && hdrlen + datalen + 20 >= limit) {\n@@ -347,13 +347,13 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent\n \t\t\tfree(buf);\n \t\t\treturn 0;\n \t\t}\n-\t\tsha1write(f, header, hdrlen);\n+\t\thashwrite(f, header, hdrlen);\n \t}\n \tif (st) {\n \t\tdatalen = write_large_blob_data(st, f, &entry->idx.oid);\n \t\tclose_istream(st);\n \t} else {\n-\t\tsha1write(f, buf, datalen);\n+\t\thashwrite(f, buf, datalen);\n \t\tfree(buf);\n \t}\n \n@@ -361,7 +361,7 @@ static unsigned long write_no_reuse_object(struct sha1file *f, struct object_ent\n }\n \n /* Return 0 if we will bust the pack-size limit */\n-static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,\n+static off_t write_reuse_object(struct hashfile *f, struct object_entry *entry,\n \t\t\t\tunsigned long limit, int usable_delta)\n {\n \tstruct packed_git *p = entry->in_pack;\n@@ -412,8 +412,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,\n \t\t\tunuse_pack(&w_curs);\n \t\t\treturn 0;\n \t\t}\n-\t\tsha1write(f, header, hdrlen);\n-\t\tsha1write(f, dheader + pos, sizeof(dheader) - pos);\n+\t\thashwrite(f, header, hdrlen);\n+\t\thashwrite(f, dheader + pos, sizeof(dheader) - pos);\n \t\thdrlen += sizeof(dheader) - pos;\n \t\treused_delta++;\n \t} else if (type == OBJ_REF_DELTA) {\n@@ -421,8 +421,8 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,\n \t\t\tunuse_pack(&w_curs);\n \t\t\treturn 0;\n \t\t}\n-\t\tsha1write(f, header, hdrlen);\n-\t\tsha1write(f, entry->delta->idx.oid.hash, 20);\n+\t\thashwrite(f, header, hdrlen);\n+\t\thashwrite(f, entry->delta->idx.oid.hash, 20);\n \t\thdrlen += 20;\n \t\treused_delta++;\n \t} else {\n@@ -430,7 +430,7 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,\n \t\t\tunuse_pack(&w_curs);\n \t\t\treturn 0;\n \t\t}\n-\t\tsha1write(f, header, hdrlen);\n+\t\thashwrite(f, header, hdrlen);\n \t}\n \tcopy_pack_data(f, p, &w_curs, offset, datalen);\n \tunuse_pack(&w_curs);\n@@ -439,7 +439,7 @@ static off_t write_reuse_object(struct sha1file *f, struct object_entry *entry,\n }\n \n /* Return 0 if we will bust the pack-size limit */\n-static off_t write_object(struct sha1file *f,\n+static off_t write_object(struct hashfile *f,\n \t\t\t  struct object_entry *entry,\n \t\t\t  off_t write_offset)\n {\n@@ -512,7 +512,7 @@ enum write_one_status {\n \tWRITE_ONE_RECURSIVE = 2 /* already scheduled to be written */\n };\n \n-static enum write_one_status write_one(struct sha1file *f,\n+static enum write_one_status write_one(struct hashfile *f,\n \t\t\t\t       struct object_entry *e,\n \t\t\t\t       off_t *offset)\n {\n@@ -731,7 +731,7 @@ static struct object_entry **compute_write_order(void)\n \treturn wo;\n }\n \n-static off_t write_reused_pack(struct sha1file *f)\n+static off_t write_reused_pack(struct hashfile *f)\n {\n \tunsigned char buffer[8192];\n \toff_t to_write, total;\n@@ -762,7 +762,7 @@ static off_t write_reused_pack(struct sha1file *f)\n \t\tif (read_pack > to_write)\n \t\t\tread_pack = to_write;\n \n-\t\tsha1write(f, buffer, read_pack);\n+\t\thashwrite(f, buffer, read_pack);\n \t\tto_write -= read_pack;\n \n \t\t/*\n@@ -791,7 +791,7 @@ static const char no_split_warning[] = N_(\n static void write_pack_file(void)\n {\n \tuint32_t i = 0, j;\n-\tstruct sha1file *f;\n+\tstruct hashfile *f;\n \toff_t offset;\n \tuint32_t nr_remaining = nr_result;\n \ttime_t last_mtime = 0;\n@@ -807,7 +807,7 @@ static void write_pack_file(void)\n \t\tchar *pack_tmp_name = NULL;\n \n \t\tif (pack_to_stdout)\n-\t\t\tf = sha1fd_throughput(1, \"<stdout>\", progress_state);\n+\t\t\tf = hashfd_throughput(1, \"<stdout>\", progress_state);\n \t\telse\n \t\t\tf = create_tmp_packfile(&pack_tmp_name);\n \n@@ -834,11 +834,11 @@ static void write_pack_file(void)\n \t\t * If so, rewrite it like in fast-import\n \t\t */\n \t\tif (pack_to_stdout) {\n-\t\t\tsha1close(f, oid.hash, CSUM_CLOSE);\n+\t\t\thashclose(f, oid.hash, CSUM_CLOSE);\n \t\t} else if (nr_written == nr_remaining) {\n-\t\t\tsha1close(f, oid.hash, CSUM_FSYNC);\n+\t\t\thashclose(f, oid.hash, CSUM_FSYNC);\n \t\t} else {\n-\t\t\tint fd = sha1close(f, oid.hash, 0);\n+\t\t\tint fd = hashclose(f, oid.hash, 0);\n \t\t\tfixup_pack_header_footer(fd, oid.hash, pack_tmp_name,\n \t\t\t\t\t\t nr_written, oid.hash, offset);\n \t\t\tclose(fd);\ndiff --git a/bulk-checkin.c b/bulk-checkin.c\nindex 3310fd210a..5f79ed6ea3 100644\n--- a/bulk-checkin.c\n+++ b/bulk-checkin.c\n@@ -12,7 +12,7 @@ static struct bulk_checkin_state {\n \tunsigned plugged:1;\n \n \tchar *pack_tmp_name;\n-\tstruct sha1file *f;\n+\tstruct hashfile *f;\n \toff_t offset;\n \tstruct pack_idx_option pack_idx_opts;\n \n@@ -35,9 +35,9 @@ static void finish_bulk_checkin(struct bulk_checkin_state *state)\n \t\tunlink(state->pack_tmp_name);\n \t\tgoto clear_exit;\n \t} else if (state->nr_written == 1) {\n-\t\tsha1close(state->f, oid.hash, CSUM_FSYNC);\n+\t\thashclose(state->f, oid.hash, CSUM_FSYNC);\n \t} else {\n-\t\tint fd = sha1close(state->f, oid.hash, 0);\n+\t\tint fd = hashclose(state->f, oid.hash, 0);\n \t\tfixup_pack_header_footer(fd, oid.hash, state->pack_tmp_name,\n \t\t\t\t\t state->nr_written, oid.hash,\n \t\t\t\t\t state->offset);\n@@ -149,7 +149,7 @@ static int stream_to_pack(struct bulk_checkin_state *state,\n \t\t\t\t\treturn -1;\n \t\t\t\t}\n \n-\t\t\t\tsha1write(state->f, obuf, written);\n+\t\t\t\thashwrite(state->f, obuf, written);\n \t\t\t\tstate->offset += written;\n \t\t\t}\n \t\t\ts.next_out = obuf;\n@@ -195,7 +195,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,\n \tgit_SHA_CTX ctx;\n \tunsigned char obuf[16384];\n \tunsigned header_len;\n-\tstruct sha1file_checkpoint checkpoint;\n+\tstruct hashfile_checkpoint checkpoint;\n \tstruct pack_idx_entry *idx = NULL;\n \n \tseekback = lseek(fd, 0, SEEK_CUR);\n@@ -216,7 +216,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,\n \twhile (1) {\n \t\tprepare_to_stream(state, flags);\n \t\tif (idx) {\n-\t\t\tsha1file_checkpoint(state->f, &checkpoint);\n+\t\t\thashfile_checkpoint(state->f, &checkpoint);\n \t\t\tidx->offset = state->offset;\n \t\t\tcrc32_begin(state->f);\n \t\t}\n@@ -230,7 +230,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,\n \t\t */\n \t\tif (!idx)\n \t\t\tdie(\"BUG: should not happen\");\n-\t\tsha1file_truncate(state->f, &checkpoint);\n+\t\thashfile_truncate(state->f, &checkpoint);\n \t\tstate->offset = checkpoint.offset;\n \t\tfinish_bulk_checkin(state);\n \t\tif (lseek(fd, seekback, SEEK_SET) == (off_t) -1)\n@@ -242,7 +242,7 @@ static int deflate_to_pack(struct bulk_checkin_state *state,\n \n \tidx->crc32 = crc32_end(state->f);\n \tif (already_written(state, result_sha1)) {\n-\t\tsha1file_truncate(state->f, &checkpoint);\n+\t\thashfile_truncate(state->f, &checkpoint);\n \t\tstate->offset = checkpoint.offset;\n \t\tfree(idx);\n \t} else {\ndiff --git a/csum-file.c b/csum-file.c\nindex 2adae04073..e4ad6337dc 100644\n--- a/csum-file.c\n+++ b/csum-file.c\n@@ -11,7 +11,7 @@\n #include \"progress.h\"\n #include \"csum-file.h\"\n \n-static void flush(struct sha1file *f, const void *buf, unsigned int count)\n+static void flush(struct hashfile *f, const void *buf, unsigned int count)\n {\n \tif (0 <= f->check_fd && count)  {\n \t\tunsigned char check_buffer[8192];\n@@ -42,7 +42,7 @@ static void flush(struct sha1file *f, const void *buf, unsigned int count)\n \t}\n }\n \n-void sha1flush(struct sha1file *f)\n+void hashflush(struct hashfile *f)\n {\n \tunsigned offset = f->offset;\n \n@@ -53,11 +53,11 @@ void sha1flush(struct sha1file *f)\n \t}\n }\n \n-int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)\n+int hashclose(struct hashfile *f, unsigned char *result, unsigned int flags)\n {\n \tint fd;\n \n-\tsha1flush(f);\n+\thashflush(f);\n \tgit_SHA1_Final(f->buffer, &f->ctx);\n \tif (result)\n \t\thashcpy(result, f->buffer);\n@@ -86,7 +86,7 @@ int sha1close(struct sha1file *f, unsigned char *result, unsigned int flags)\n \treturn fd;\n }\n \n-void sha1write(struct sha1file *f, const void *buf, unsigned int count)\n+void hashwrite(struct hashfile *f, const void *buf, unsigned int count)\n {\n \twhile (count) {\n \t\tunsigned offset = f->offset;\n@@ -118,15 +118,15 @@ void sha1write(struct sha1file *f, const void *buf, unsigned int count)\n \t}\n }\n \n-struct sha1file *sha1fd(int fd, const char *name)\n+struct hashfile *hashfd(int fd, const char *name)\n {\n-\treturn sha1fd_throughput(fd, name, NULL);\n+\treturn hashfd_throughput(fd, name, NULL);\n }\n \n-struct sha1file *sha1fd_check(const char *name)\n+struct hashfile *hashfd_check(const char *name)\n {\n \tint sink, check;\n-\tstruct sha1file *f;\n+\tstruct hashfile *f;\n \n \tsink = open(\"/dev/null\", O_WRONLY);\n \tif (sink < 0)\n@@ -134,14 +134,14 @@ struct sha1file *sha1fd_check(const char *name)\n \tcheck = open(name, O_RDONLY);\n \tif (check < 0)\n \t\tdie_errno(\"unable to open '%s'\", name);\n-\tf = sha1fd(sink, name);\n+\tf = hashfd(sink, name);\n \tf->check_fd = check;\n \treturn f;\n }\n \n-struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp)\n+struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp)\n {\n-\tstruct sha1file *f = xmalloc(sizeof(*f));\n+\tstruct hashfile *f = xmalloc(sizeof(*f));\n \tf->fd = fd;\n \tf->check_fd = -1;\n \tf->offset = 0;\n@@ -153,14 +153,14 @@ struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp\n \treturn f;\n }\n \n-void sha1file_checkpoint(struct sha1file *f, struct sha1file_checkpoint *checkpoint)\n+void hashfile_checkpoint(struct hashfile *f, struct hashfile_checkpoint *checkpoint)\n {\n-\tsha1flush(f);\n+\thashflush(f);\n \tcheckpoint->offset = f->total;\n \tcheckpoint->ctx = f->ctx;\n }\n \n-int sha1file_truncate(struct sha1file *f, struct sha1file_checkpoint *checkpoint)\n+int hashfile_truncate(struct hashfile *f, struct hashfile_checkpoint *checkpoint)\n {\n \toff_t offset = checkpoint->offset;\n \n@@ -169,17 +169,17 @@ int sha1file_truncate(struct sha1file *f, struct sha1file_checkpoint *checkpoint\n \t\treturn -1;\n \tf->total = offset;\n \tf->ctx = checkpoint->ctx;\n-\tf->offset = 0; /* sha1flush() was called in checkpoint */\n+\tf->offset = 0; /* hashflush() was called in checkpoint */\n \treturn 0;\n }\n \n-void crc32_begin(struct sha1file *f)\n+void crc32_begin(struct hashfile *f)\n {\n \tf->crc32 = crc32(0, NULL, 0);\n \tf->do_crc = 1;\n }\n \n-uint32_t crc32_end(struct sha1file *f)\n+uint32_t crc32_end(struct hashfile *f)\n {\n \tf->do_crc = 0;\n \treturn f->crc32;\ndiff --git a/csum-file.h b/csum-file.h\nindex 7530927d77..ceb3e5712d 100644\n--- a/csum-file.h\n+++ b/csum-file.h\n@@ -4,7 +4,7 @@\n struct progress;\n \n /* A SHA1-protected file */\n-struct sha1file {\n+struct hashfile {\n \tint fd;\n \tint check_fd;\n \tunsigned int offset;\n@@ -18,36 +18,36 @@ struct sha1file {\n };\n \n /* Checkpoint */\n-struct sha1file_checkpoint {\n+struct hashfile_checkpoint {\n \toff_t offset;\n \tgit_SHA_CTX ctx;\n };\n \n-extern void sha1file_checkpoint(struct sha1file *, struct sha1file_checkpoint *);\n-extern int sha1file_truncate(struct sha1file *, struct sha1file_checkpoint *);\n+extern void hashfile_checkpoint(struct hashfile *, struct hashfile_checkpoint *);\n+extern int hashfile_truncate(struct hashfile *, struct hashfile_checkpoint *);\n \n-/* sha1close flags */\n+/* hashclose flags */\n #define CSUM_CLOSE\t1\n #define CSUM_FSYNC\t2\n \n-extern struct sha1file *sha1fd(int fd, const char *name);\n-extern struct sha1file *sha1fd_check(const char *name);\n-extern struct sha1file *sha1fd_throughput(int fd, const char *name, struct progress *tp);\n-extern int sha1close(struct sha1file *, unsigned char *, unsigned int);\n-extern void sha1write(struct sha1file *, const void *, unsigned int);\n-extern void sha1flush(struct sha1file *f);\n-extern void crc32_begin(struct sha1file *);\n-extern uint32_t crc32_end(struct sha1file *);\n+extern struct hashfile *hashfd(int fd, const char *name);\n+extern struct hashfile *hashfd_check(const char *name);\n+extern struct hashfile *hashfd_throughput(int fd, const char *name, struct progress *tp);\n+extern int hashclose(struct hashfile *, unsigned char *, unsigned int);\n+extern void hashwrite(struct hashfile *, const void *, unsigned int);\n+extern void hashflush(struct hashfile *f);\n+extern void crc32_begin(struct hashfile *);\n+extern uint32_t crc32_end(struct hashfile *);\n \n-static inline void sha1write_u8(struct sha1file *f, uint8_t data)\n+static inline void hashwrite_u8(struct hashfile *f, uint8_t data)\n {\n-\tsha1write(f, &data, sizeof(data));\n+\thashwrite(f, &data, sizeof(data));\n }\n \n-static inline void sha1write_be32(struct sha1file *f, uint32_t data)\n+static inline void hashwrite_be32(struct hashfile *f, uint32_t data)\n {\n \tdata = htonl(data);\n-\tsha1write(f, &data, sizeof(data));\n+\thashwrite(f, &data, sizeof(data));\n }\n \n #endif\ndiff --git a/fast-import.c b/fast-import.c\nindex 1b8ab8ea29..26e071b3d5 100644\n--- a/fast-import.c\n+++ b/fast-import.c\n@@ -316,7 +316,7 @@ static struct atom_str **atom_table;\n /* The .pack file being generated */\n static struct pack_idx_option pack_idx_opts;\n static unsigned int pack_id;\n-static struct sha1file *pack_file;\n+static struct hashfile *pack_file;\n static struct packed_git *pack_data;\n static struct packed_git **all_packs;\n static off_t pack_size;\n@@ -905,12 +905,12 @@ static void start_packfile(void)\n \n \tp->pack_fd = pack_fd;\n \tp->do_not_close = 1;\n-\tpack_file = sha1fd(pack_fd, p->pack_name);\n+\tpack_file = hashfd(pack_fd, p->pack_name);\n \n \thdr.hdr_signature = htonl(PACK_SIGNATURE);\n \thdr.hdr_version = htonl(2);\n \thdr.hdr_entries = 0;\n-\tsha1write(pack_file, &hdr, sizeof(hdr));\n+\thashwrite(pack_file, &hdr, sizeof(hdr));\n \n \tpack_data = p;\n \tpack_size = sizeof(hdr);\n@@ -1016,7 +1016,7 @@ static void end_packfile(void)\n \t\tstruct tag *t;\n \n \t\tclose_pack_windows(pack_data);\n-\t\tsha1close(pack_file, cur_pack_oid.hash, 0);\n+\t\thashclose(pack_file, cur_pack_oid.hash, 0);\n \t\tfixup_pack_header_footer(pack_data->pack_fd, pack_data->sha1,\n \t\t\t\t    pack_data->pack_name, object_count,\n \t\t\t\t    cur_pack_oid.hash, pack_size);\n@@ -1180,23 +1180,23 @@ static int store_object(\n \n \t\thdrlen = encode_in_pack_object_header(hdr, sizeof(hdr),\n \t\t\t\t\t\t      OBJ_OFS_DELTA, deltalen);\n-\t\tsha1write(pack_file, hdr, hdrlen);\n+\t\thashwrite(pack_file, hdr, hdrlen);\n \t\tpack_size += hdrlen;\n \n \t\thdr[pos] = ofs & 127;\n \t\twhile (ofs >>= 7)\n \t\t\thdr[--pos] = 128 | (--ofs & 127);\n-\t\tsha1write(pack_file, hdr + pos, sizeof(hdr) - pos);\n+\t\thashwrite(pack_file, hdr + pos, sizeof(hdr) - pos);\n \t\tpack_size += sizeof(hdr) - pos;\n \t} else {\n \t\te->depth = 0;\n \t\thdrlen = encode_in_pack_object_header(hdr, sizeof(hdr),\n \t\t\t\t\t\t      type, dat->len);\n-\t\tsha1write(pack_file, hdr, hdrlen);\n+\t\thashwrite(pack_file, hdr, hdrlen);\n \t\tpack_size += hdrlen;\n \t}\n \n-\tsha1write(pack_file, out, s.total_out);\n+\thashwrite(pack_file, out, s.total_out);\n \tpack_size += s.total_out;\n \n \te->idx.crc32 = crc32_end(pack_file);\n@@ -1215,9 +1215,9 @@ static int store_object(\n \treturn 0;\n }\n \n-static void truncate_pack(struct sha1file_checkpoint *checkpoint)\n+static void truncate_pack(struct hashfile_checkpoint *checkpoint)\n {\n-\tif (sha1file_truncate(pack_file, checkpoint))\n+\tif (hashfile_truncate(pack_file, checkpoint))\n \t\tdie_errno(\"cannot truncate pack to skip duplicate\");\n \tpack_size = checkpoint->offset;\n }\n@@ -1233,7 +1233,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)\n \toff_t offset;\n \tgit_hash_ctx c;\n \tgit_zstream s;\n-\tstruct sha1file_checkpoint checkpoint;\n+\tstruct hashfile_checkpoint checkpoint;\n \tint status = Z_OK;\n \n \t/* Determine if we should auto-checkpoint. */\n@@ -1241,7 +1241,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)\n \t\t|| (pack_size + 60 + len) < pack_size)\n \t\tcycle_packfile();\n \n-\tsha1file_checkpoint(pack_file, &checkpoint);\n+\thashfile_checkpoint(pack_file, &checkpoint);\n \toffset = checkpoint.offset;\n \n \thdrlen = xsnprintf((char *)out_buf, out_sz, \"blob %\" PRIuMAX, len) + 1;\n@@ -1275,7 +1275,7 @@ static void stream_blob(uintmax_t len, struct object_id *oidout, uintmax_t mark)\n \n \t\tif (!s.avail_out || status == Z_STREAM_END) {\n \t\t\tsize_t n = s.next_out - out_buf;\n-\t\t\tsha1write(pack_file, out_buf, n);\n+\t\t\thashwrite(pack_file, out_buf, n);\n \t\t\tpack_size += n;\n \t\t\ts.next_out = out_buf;\n \t\t\ts.avail_out = out_sz;\n@@ -1360,7 +1360,7 @@ static void *gfi_unpack_entry(\n \t\t * the newly written data.\n \t\t */\n \t\tclose_pack_windows(p);\n-\t\tsha1flush(pack_file);\n+\t\thashflush(pack_file);\n \n \t\t/* We have to offer rawsz bytes additional on the end of\n \t\t * the packfile as the core unpacker code assumes the\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex a8df5ce2ab..e01f992884 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -440,19 +440,19 @@ void bitmap_writer_select_commits(struct commit **indexed_commits,\n }\n \n \n-static int sha1write_ewah_helper(void *f, const void *buf, size_t len)\n+static int hashwrite_ewah_helper(void *f, const void *buf, size_t len)\n {\n-\t/* sha1write will die on error */\n-\tsha1write(f, buf, len);\n+\t/* hashwrite will die on error */\n+\thashwrite(f, buf, len);\n \treturn len;\n }\n \n /**\n  * Write the bitmap index to disk\n  */\n-static inline void dump_bitmap(struct sha1file *f, struct ewah_bitmap *bitmap)\n+static inline void dump_bitmap(struct hashfile *f, struct ewah_bitmap *bitmap)\n {\n-\tif (ewah_serialize_to(bitmap, sha1write_ewah_helper, f) < 0)\n+\tif (ewah_serialize_to(bitmap, hashwrite_ewah_helper, f) < 0)\n \t\tdie(\"Failed to write bitmap index\");\n }\n \n@@ -462,7 +462,7 @@ static const unsigned char *sha1_access(size_t pos, void *table)\n \treturn index[pos]->oid.hash;\n }\n \n-static void write_selected_commits_v1(struct sha1file *f,\n+static void write_selected_commits_v1(struct hashfile *f,\n \t\t\t\t      struct pack_idx_entry **index,\n \t\t\t\t      uint32_t index_nr)\n {\n@@ -477,15 +477,15 @@ static void write_selected_commits_v1(struct sha1file *f,\n \t\tif (commit_pos < 0)\n \t\t\tdie(\"BUG: trying to write commit not in index\");\n \n-\t\tsha1write_be32(f, commit_pos);\n-\t\tsha1write_u8(f, stored->xor_offset);\n-\t\tsha1write_u8(f, stored->flags);\n+\t\thashwrite_be32(f, commit_pos);\n+\t\thashwrite_u8(f, stored->xor_offset);\n+\t\thashwrite_u8(f, stored->flags);\n \n \t\tdump_bitmap(f, stored->write_as);\n \t}\n }\n \n-static void write_hash_cache(struct sha1file *f,\n+static void write_hash_cache(struct hashfile *f,\n \t\t\t     struct pack_idx_entry **index,\n \t\t\t     uint32_t index_nr)\n {\n@@ -494,7 +494,7 @@ static void write_hash_cache(struct sha1file *f,\n \tfor (i = 0; i < index_nr; ++i) {\n \t\tstruct object_entry *entry = (struct object_entry *)index[i];\n \t\tuint32_t hash_value = htonl(entry->hash);\n-\t\tsha1write(f, &hash_value, sizeof(hash_value));\n+\t\thashwrite(f, &hash_value, sizeof(hash_value));\n \t}\n }\n \n@@ -511,13 +511,13 @@ void bitmap_writer_finish(struct pack_idx_entry **index,\n \tstatic uint16_t default_version = 1;\n \tstatic uint16_t flags = BITMAP_OPT_FULL_DAG;\n \tstruct strbuf tmp_file = STRBUF_INIT;\n-\tstruct sha1file *f;\n+\tstruct hashfile *f;\n \n \tstruct bitmap_disk_header header;\n \n \tint fd = odb_mkstemp(&tmp_file, \"pack/tmp_bitmap_XXXXXX\");\n \n-\tf = sha1fd(fd, tmp_file.buf);\n+\tf = hashfd(fd, tmp_file.buf);\n \n \tmemcpy(header.magic, BITMAP_IDX_SIGNATURE, sizeof(BITMAP_IDX_SIGNATURE));\n \theader.version = htons(default_version);\n@@ -525,7 +525,7 @@ void bitmap_writer_finish(struct pack_idx_entry **index,\n \theader.entry_count = htonl(writer.selected_nr);\n \thashcpy(header.checksum, writer.pack_checksum);\n \n-\tsha1write(f, &header, sizeof(header));\n+\thashwrite(f, &header, sizeof(header));\n \tdump_bitmap(f, writer.commits);\n \tdump_bitmap(f, writer.trees);\n \tdump_bitmap(f, writer.blobs);\n@@ -535,7 +535,7 @@ void bitmap_writer_finish(struct pack_idx_entry **index,\n \tif (options & BITMAP_OPT_HASH_CACHE)\n \t\twrite_hash_cache(f, index, index_nr);\n \n-\tsha1close(f, NULL, CSUM_FSYNC);\n+\thashclose(f, NULL, CSUM_FSYNC);\n \n \tif (adjust_shared_perm(tmp_file.buf))\n \t\tdie_errno(\"unable to make temporary bitmap file readable\");\ndiff --git a/pack-write.c b/pack-write.c\nindex fe33f7464c..7c256b5e80 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -46,7 +46,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t\t   int nr_objects, const struct pack_idx_option *opts,\n \t\t\t   const unsigned char *sha1)\n {\n-\tstruct sha1file *f;\n+\tstruct hashfile *f;\n \tstruct pack_idx_entry **sorted_by_sha, **list, **last;\n \toff_t last_obj_offset = 0;\n \tuint32_t array[256];\n@@ -68,7 +68,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \n \tif (opts->flags & WRITE_IDX_VERIFY) {\n \t\tassert(index_name);\n-\t\tf = sha1fd_check(index_name);\n+\t\tf = hashfd_check(index_name);\n \t} else {\n \t\tif (!index_name) {\n \t\t\tstruct strbuf tmp_file = STRBUF_INIT;\n@@ -80,7 +80,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t\tif (fd < 0)\n \t\t\t\tdie_errno(\"unable to create '%s'\", index_name);\n \t\t}\n-\t\tf = sha1fd(fd, index_name);\n+\t\tf = hashfd(fd, index_name);\n \t}\n \n \t/* if last object's offset is >= 2^31 we should use index V2 */\n@@ -91,7 +91,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\tstruct pack_idx_header hdr;\n \t\thdr.idx_signature = htonl(PACK_IDX_SIGNATURE);\n \t\thdr.idx_version = htonl(index_version);\n-\t\tsha1write(f, &hdr, sizeof(hdr));\n+\t\thashwrite(f, &hdr, sizeof(hdr));\n \t}\n \n \t/*\n@@ -110,7 +110,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\tarray[i] = htonl(next - sorted_by_sha);\n \t\tlist = next;\n \t}\n-\tsha1write(f, array, 256 * 4);\n+\thashwrite(f, array, 256 * 4);\n \n \t/*\n \t * Write the actual SHA1 entries..\n@@ -120,9 +120,9 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\tstruct pack_idx_entry *obj = *list++;\n \t\tif (index_version < 2) {\n \t\t\tuint32_t offset = htonl(obj->offset);\n-\t\t\tsha1write(f, &offset, 4);\n+\t\t\thashwrite(f, &offset, 4);\n \t\t}\n-\t\tsha1write(f, obj->oid.hash, the_hash_algo->rawsz);\n+\t\thashwrite(f, obj->oid.hash, the_hash_algo->rawsz);\n \t\tif ((opts->flags & WRITE_IDX_STRICT) &&\n \t\t    (i && !oidcmp(&list[-2]->oid, &obj->oid)))\n \t\t\tdie(\"The same object %s appears twice in the pack\",\n@@ -137,7 +137,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\tfor (i = 0; i < nr_objects; i++) {\n \t\t\tstruct pack_idx_entry *obj = *list++;\n \t\t\tuint32_t crc32_val = htonl(obj->crc32);\n-\t\t\tsha1write(f, &crc32_val, 4);\n+\t\t\thashwrite(f, &crc32_val, 4);\n \t\t}\n \n \t\t/* write the 32-bit offset table */\n@@ -150,7 +150,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t\t\t  ? (0x80000000 | nr_large_offset++)\n \t\t\t\t  : obj->offset);\n \t\t\toffset = htonl(offset);\n-\t\t\tsha1write(f, &offset, 4);\n+\t\t\thashwrite(f, &offset, 4);\n \t\t}\n \n \t\t/* write the large offset table */\n@@ -164,25 +164,25 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t\t\tcontinue;\n \t\t\tsplit[0] = htonl(offset >> 32);\n \t\t\tsplit[1] = htonl(offset & 0xffffffff);\n-\t\t\tsha1write(f, split, 8);\n+\t\t\thashwrite(f, split, 8);\n \t\t\tnr_large_offset--;\n \t\t}\n \t}\n \n-\tsha1write(f, sha1, the_hash_algo->rawsz);\n-\tsha1close(f, NULL, ((opts->flags & WRITE_IDX_VERIFY)\n+\thashwrite(f, sha1, the_hash_algo->rawsz);\n+\thashclose(f, NULL, ((opts->flags & WRITE_IDX_VERIFY)\n \t\t\t    ? CSUM_CLOSE : CSUM_FSYNC));\n \treturn index_name;\n }\n \n-off_t write_pack_header(struct sha1file *f, uint32_t nr_entries)\n+off_t write_pack_header(struct hashfile *f, uint32_t nr_entries)\n {\n \tstruct pack_header hdr;\n \n \thdr.hdr_signature = htonl(PACK_SIGNATURE);\n \thdr.hdr_version = htonl(PACK_VERSION);\n \thdr.hdr_entries = htonl(nr_entries);\n-\tsha1write(f, &hdr, sizeof(hdr));\n+\thashwrite(f, &hdr, sizeof(hdr));\n \treturn sizeof(hdr);\n }\n \n@@ -333,14 +333,14 @@ int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,\n \treturn n;\n }\n \n-struct sha1file *create_tmp_packfile(char **pack_tmp_name)\n+struct hashfile *create_tmp_packfile(char **pack_tmp_name)\n {\n \tstruct strbuf tmpname = STRBUF_INIT;\n \tint fd;\n \n \tfd = odb_mkstemp(&tmpname, \"pack/tmp_pack_XXXXXX\");\n \t*pack_tmp_name = strbuf_detach(&tmpname, NULL);\n-\treturn sha1fd(fd, *pack_tmp_name);\n+\treturn hashfd(fd, *pack_tmp_name);\n }\n \n void finish_tmp_packfile(struct strbuf *name_buffer,\ndiff --git a/pack.h b/pack.h\nindex 8294341af1..34a9d458b4 100644\n--- a/pack.h\n+++ b/pack.h\n@@ -81,7 +81,7 @@ extern const char *write_idx_file(const char *index_name, struct pack_idx_entry\n extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);\n extern int verify_pack_index(struct packed_git *);\n extern int verify_pack(struct packed_git *, verify_fn fn, struct progress *, uint32_t);\n-extern off_t write_pack_header(struct sha1file *f, uint32_t);\n+extern off_t write_pack_header(struct hashfile *f, uint32_t);\n extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);\n extern char *index_pack_lockfile(int fd);\n \n@@ -98,7 +98,7 @@ extern int encode_in_pack_object_header(unsigned char *hdr, int hdr_len,\n #define PH_ERROR_PROTOCOL\t(-3)\n extern int read_pack_header(int fd, struct pack_header *);\n \n-extern struct sha1file *create_tmp_packfile(char **pack_tmp_name);\n+extern struct hashfile *create_tmp_packfile(char **pack_tmp_name);\n extern void finish_tmp_packfile(struct strbuf *name_buffer, const char *pack_tmp_name, struct pack_idx_entry **written_list, uint32_t nr_written, struct pack_idx_option *pack_idx_opts, unsigned char sha1[]);\n \n #endif\n"},{"id":"337621","messageId":"20180128155722.880805-3-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 02/12] hash: create union for hash context allocation","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:12Z","receivedAt":"2018-01-28T15:58:09Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"In various parts of our code, we want to allocate a structure\nrepresenting the internal state of a hash algorithm.  The original\nimplementation of the hash algorithm abstraction assumed we would do\nthat using heap allocations, and added a context size element to struct\ngit_hash_algo.  However, most of the existing code uses stack\nallocations and conversion would needlessly complicate various parts of\nthe code.  Add a union for the purpose of allocating hash contexts on\nthe stack and a typedef for ease of use.  Remove the ctxsz element for\nstruct git_hash_algo, which is no longer very useful.\n\nThis does mean that stack allocations will grow slightly as additional\nhash functions are added, but this should not be a significant problem,\nsince we don't allocate many hash contexts.  The improved usability and\nbenefits from avoiding dynamic allocation outweigh this small downside.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n hash.h      | 9 ++++++---\n sha1_file.c | 2 --\n 2 files changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/hash.h b/hash.h\nindex 7122dea7b3..365846a6b5 100644\n--- a/hash.h\n+++ b/hash.h\n@@ -55,6 +55,12 @@\n /* Number of algorithms supported (including unknown). */\n #define GIT_HASH_NALGOS (GIT_HASH_SHA1 + 1)\n \n+/* A suitably aligned type for stack allocations of hash contexts. */\n+union git_hash_ctx {\n+\tgit_SHA_CTX sha1;\n+};\n+typedef union git_hash_ctx git_hash_ctx;\n+\n typedef void (*git_hash_init_fn)(void *ctx);\n typedef void (*git_hash_update_fn)(void *ctx, const void *in, size_t len);\n typedef void (*git_hash_final_fn)(unsigned char *hash, void *ctx);\n@@ -69,9 +75,6 @@ struct git_hash_algo {\n \t/* A four-byte version identifier, used in pack indices. */\n \tuint32_t format_id;\n \n-\t/* The size of a hash context (e.g. git_SHA_CTX). */\n-\tsize_t ctxsz;\n-\n \t/* The length of the hash in binary. */\n \tsize_t rawsz;\n \ndiff --git a/sha1_file.c b/sha1_file.c\nindex 3da70ac650..e61d93a6e8 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -75,7 +75,6 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {\n \t\t0x00000000,\n \t\t0,\n \t\t0,\n-\t\t0,\n \t\tgit_hash_unknown_init,\n \t\tgit_hash_unknown_update,\n \t\tgit_hash_unknown_final,\n@@ -86,7 +85,6 @@ const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {\n \t\t\"sha-1\",\n \t\t/* \"sha1\", big-endian */\n \t\t0x73686131,\n-\t\tsizeof(git_SHA_CTX),\n \t\tGIT_SHA1_RAWSZ,\n \t\tGIT_SHA1_HEXSZ,\n \t\tgit_hash_sha1_init,\n"},{"id":"337622","messageId":"20180128155722.880805-8-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 07/12] pack-check: convert various uses of SHA-1 to abstract forms","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:17Z","receivedAt":"2018-01-28T15:58:11Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert various explicit calls to use SHA-1 functions and constants to\nreferences to the_hash_algo.  Make several strings more generic with\nrespect to the hash algorithm used.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n pack-check.c | 32 ++++++++++++++++----------------\n 1 file changed, 16 insertions(+), 16 deletions(-)\n\ndiff --git a/pack-check.c b/pack-check.c\nindex 073c1fbd46..403a572567 100644\n--- a/pack-check.c\n+++ b/pack-check.c\n@@ -41,7 +41,7 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,\n \t} while (len);\n \n \tindex_crc = p->index_data;\n-\tindex_crc += 2 + 256 + p->num_objects * (20/4) + nr;\n+\tindex_crc += 2 + 256 + p->num_objects * (the_hash_algo->rawsz/4) + nr;\n \n \treturn data_crc != ntohl(*index_crc);\n }\n@@ -54,7 +54,7 @@ static int verify_packfile(struct packed_git *p,\n {\n \toff_t index_size = p->index_size;\n \tconst unsigned char *index_base = p->index_data;\n-\tgit_SHA_CTX ctx;\n+\tgit_hash_ctx ctx;\n \tunsigned char hash[GIT_MAX_RAWSZ], *pack_sig;\n \toff_t offset = 0, pack_sig_ofs = 0;\n \tuint32_t nr_objects, i;\n@@ -64,24 +64,24 @@ static int verify_packfile(struct packed_git *p,\n \tif (!is_pack_valid(p))\n \t\treturn error(\"packfile %s cannot be accessed\", p->pack_name);\n \n-\tgit_SHA1_Init(&ctx);\n+\tthe_hash_algo->init_fn(&ctx);\n \tdo {\n \t\tunsigned long remaining;\n \t\tunsigned char *in = use_pack(p, w_curs, offset, &remaining);\n \t\toffset += remaining;\n \t\tif (!pack_sig_ofs)\n-\t\t\tpack_sig_ofs = p->pack_size - 20;\n+\t\t\tpack_sig_ofs = p->pack_size - the_hash_algo->rawsz;\n \t\tif (offset > pack_sig_ofs)\n \t\t\tremaining -= (unsigned int)(offset - pack_sig_ofs);\n-\t\tgit_SHA1_Update(&ctx, in, remaining);\n+\t\tthe_hash_algo->update_fn(&ctx, in, remaining);\n \t} while (offset < pack_sig_ofs);\n-\tgit_SHA1_Final(hash, &ctx);\n+\tthe_hash_algo->final_fn(hash, &ctx);\n \tpack_sig = use_pack(p, w_curs, pack_sig_ofs, NULL);\n \tif (hashcmp(hash, pack_sig))\n-\t\terr = error(\"%s SHA1 checksum mismatch\",\n+\t\terr = error(\"%s pack checksum mismatch\",\n \t\t\t    p->pack_name);\n-\tif (hashcmp(index_base + index_size - 40, pack_sig))\n-\t\terr = error(\"%s SHA1 does not match its index\",\n+\tif (hashcmp(index_base + index_size - the_hash_algo->hexsz, pack_sig))\n+\t\terr = error(\"%s pack checksum does not match its index\",\n \t\t\t    p->pack_name);\n \tunuse_pack(w_curs);\n \n@@ -165,8 +165,8 @@ int verify_pack_index(struct packed_git *p)\n {\n \toff_t index_size;\n \tconst unsigned char *index_base;\n-\tgit_SHA_CTX ctx;\n-\tunsigned char sha1[20];\n+\tgit_hash_ctx ctx;\n+\tunsigned char hash[GIT_MAX_RAWSZ];\n \tint err = 0;\n \n \tif (open_pack_index(p))\n@@ -175,11 +175,11 @@ int verify_pack_index(struct packed_git *p)\n \tindex_base = p->index_data;\n \n \t/* Verify SHA1 sum of the index file */\n-\tgit_SHA1_Init(&ctx);\n-\tgit_SHA1_Update(&ctx, index_base, (unsigned int)(index_size - 20));\n-\tgit_SHA1_Final(sha1, &ctx);\n-\tif (hashcmp(sha1, index_base + index_size - 20))\n-\t\terr = error(\"Packfile index for %s SHA1 mismatch\",\n+\tthe_hash_algo->init_fn(&ctx);\n+\tthe_hash_algo->update_fn(&ctx, index_base, (unsigned int)(index_size - the_hash_algo->rawsz));\n+\tthe_hash_algo->final_fn(hash, &ctx);\n+\tif (hashcmp(hash, index_base + index_size - the_hash_algo->rawsz))\n+\t\terr = error(\"Packfile index for %s hash mismatch\",\n \t\t\t    p->pack_name);\n \treturn err;\n }\n"},{"id":"337623","messageId":"20180128155722.880805-9-sandals@crustytoothpaste.net","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"[PATCH 08/12] pack-write: switch various SHA-1 values to abstract forms","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T15:57:18Z","receivedAt":"2018-01-28T15:58:13Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert various uses of hardcoded 20- and 40-based numbers to use\nthe_hash_algo, along with direct calls to SHA-1.  Adjust the names of\nvariables to refer to \"hash\" instead of \"sha1\".\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n pack-write.c | 49 +++++++++++++++++++++++++------------------------\n 1 file changed, 25 insertions(+), 24 deletions(-)\n\ndiff --git a/pack-write.c b/pack-write.c\nindex fea6284192..fe33f7464c 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -122,7 +122,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t\tuint32_t offset = htonl(obj->offset);\n \t\t\tsha1write(f, &offset, 4);\n \t\t}\n-\t\tsha1write(f, obj->oid.hash, 20);\n+\t\tsha1write(f, obj->oid.hash, the_hash_algo->rawsz);\n \t\tif ((opts->flags & WRITE_IDX_STRICT) &&\n \t\t    (i && !oidcmp(&list[-2]->oid, &obj->oid)))\n \t\t\tdie(\"The same object %s appears twice in the pack\",\n@@ -169,7 +169,7 @@ const char *write_idx_file(const char *index_name, struct pack_idx_entry **objec\n \t\t}\n \t}\n \n-\tsha1write(f, sha1, 20);\n+\tsha1write(f, sha1, the_hash_algo->rawsz);\n \tsha1close(f, NULL, ((opts->flags & WRITE_IDX_VERIFY)\n \t\t\t    ? CSUM_CLOSE : CSUM_FSYNC));\n \treturn index_name;\n@@ -203,20 +203,20 @@ off_t write_pack_header(struct sha1file *f, uint32_t nr_entries)\n  * interested in the resulting SHA1 of pack data above partial_pack_offset.\n  */\n void fixup_pack_header_footer(int pack_fd,\n-\t\t\t unsigned char *new_pack_sha1,\n+\t\t\t unsigned char *new_pack_hash,\n \t\t\t const char *pack_name,\n \t\t\t uint32_t object_count,\n-\t\t\t unsigned char *partial_pack_sha1,\n+\t\t\t unsigned char *partial_pack_hash,\n \t\t\t off_t partial_pack_offset)\n {\n \tint aligned_sz, buf_sz = 8 * 1024;\n-\tgit_SHA_CTX old_sha1_ctx, new_sha1_ctx;\n+\tgit_hash_ctx old_hash_ctx, new_hash_ctx;\n \tstruct pack_header hdr;\n \tchar *buf;\n \tssize_t read_result;\n \n-\tgit_SHA1_Init(&old_sha1_ctx);\n-\tgit_SHA1_Init(&new_sha1_ctx);\n+\tthe_hash_algo->init_fn(&old_hash_ctx);\n+\tthe_hash_algo->init_fn(&new_hash_ctx);\n \n \tif (lseek(pack_fd, 0, SEEK_SET) != 0)\n \t\tdie_errno(\"Failed seeking to start of '%s'\", pack_name);\n@@ -228,9 +228,9 @@ void fixup_pack_header_footer(int pack_fd,\n \t\t\t  pack_name);\n \tif (lseek(pack_fd, 0, SEEK_SET) != 0)\n \t\tdie_errno(\"Failed seeking to start of '%s'\", pack_name);\n-\tgit_SHA1_Update(&old_sha1_ctx, &hdr, sizeof(hdr));\n+\tthe_hash_algo->update_fn(&old_hash_ctx, &hdr, sizeof(hdr));\n \thdr.hdr_entries = htonl(object_count);\n-\tgit_SHA1_Update(&new_sha1_ctx, &hdr, sizeof(hdr));\n+\tthe_hash_algo->update_fn(&new_hash_ctx, &hdr, sizeof(hdr));\n \twrite_or_die(pack_fd, &hdr, sizeof(hdr));\n \tpartial_pack_offset -= sizeof(hdr);\n \n@@ -238,28 +238,28 @@ void fixup_pack_header_footer(int pack_fd,\n \taligned_sz = buf_sz - sizeof(hdr);\n \tfor (;;) {\n \t\tssize_t m, n;\n-\t\tm = (partial_pack_sha1 && partial_pack_offset < aligned_sz) ?\n+\t\tm = (partial_pack_hash && partial_pack_offset < aligned_sz) ?\n \t\t\tpartial_pack_offset : aligned_sz;\n \t\tn = xread(pack_fd, buf, m);\n \t\tif (!n)\n \t\t\tbreak;\n \t\tif (n < 0)\n \t\t\tdie_errno(\"Failed to checksum '%s'\", pack_name);\n-\t\tgit_SHA1_Update(&new_sha1_ctx, buf, n);\n+\t\tthe_hash_algo->update_fn(&new_hash_ctx, buf, n);\n \n \t\taligned_sz -= n;\n \t\tif (!aligned_sz)\n \t\t\taligned_sz = buf_sz;\n \n-\t\tif (!partial_pack_sha1)\n+\t\tif (!partial_pack_hash)\n \t\t\tcontinue;\n \n-\t\tgit_SHA1_Update(&old_sha1_ctx, buf, n);\n+\t\tthe_hash_algo->update_fn(&old_hash_ctx, buf, n);\n \t\tpartial_pack_offset -= n;\n \t\tif (partial_pack_offset == 0) {\n-\t\t\tunsigned char sha1[20];\n-\t\t\tgit_SHA1_Final(sha1, &old_sha1_ctx);\n-\t\t\tif (hashcmp(sha1, partial_pack_sha1) != 0)\n+\t\t\tunsigned char hash[GIT_MAX_RAWSZ];\n+\t\t\tthe_hash_algo->final_fn(hash, &old_hash_ctx);\n+\t\t\tif (hashcmp(hash, partial_pack_hash) != 0)\n \t\t\t\tdie(\"Unexpected checksum for %s \"\n \t\t\t\t    \"(disk corruption?)\", pack_name);\n \t\t\t/*\n@@ -267,23 +267,24 @@ void fixup_pack_header_footer(int pack_fd,\n \t\t\t * pack, which also means making partial_pack_offset\n \t\t\t * big enough not to matter anymore.\n \t\t\t */\n-\t\t\tgit_SHA1_Init(&old_sha1_ctx);\n+\t\t\tthe_hash_algo->init_fn(&old_hash_ctx);\n \t\t\tpartial_pack_offset = ~partial_pack_offset;\n \t\t\tpartial_pack_offset -= MSB(partial_pack_offset, 1);\n \t\t}\n \t}\n \tfree(buf);\n \n-\tif (partial_pack_sha1)\n-\t\tgit_SHA1_Final(partial_pack_sha1, &old_sha1_ctx);\n-\tgit_SHA1_Final(new_pack_sha1, &new_sha1_ctx);\n-\twrite_or_die(pack_fd, new_pack_sha1, 20);\n+\tif (partial_pack_hash)\n+\t\tthe_hash_algo->final_fn(partial_pack_hash, &old_hash_ctx);\n+\tthe_hash_algo->final_fn(new_pack_hash, &new_hash_ctx);\n+\twrite_or_die(pack_fd, new_pack_hash, the_hash_algo->rawsz);\n \tfsync_or_die(pack_fd, pack_name);\n }\n \n char *index_pack_lockfile(int ip_out)\n {\n-\tchar packname[46];\n+\tchar packname[GIT_MAX_HEXSZ + 6];\n+\tint len = the_hash_algo->hexsz + 6;\n \n \t/*\n \t * The first thing we expect from index-pack's output\n@@ -292,9 +293,9 @@ char *index_pack_lockfile(int ip_out)\n \t * case, we need it to remove the corresponding .keep file\n \t * later on.  If we don't get that then tough luck with it.\n \t */\n-\tif (read_in_full(ip_out, packname, 46) == 46 && packname[45] == '\\n') {\n+\tif (read_in_full(ip_out, packname, len) == len && packname[len-1] == '\\n') {\n \t\tconst char *name;\n-\t\tpackname[45] = 0;\n+\t\tpackname[len-1] = 0;\n \t\tif (skip_prefix(packname, \"keep\\t\", &name))\n \t\t\treturn xstrfmt(\"%s/pack/pack-%s.keep\",\n \t\t\t\t       get_object_directory(), name);\n"},{"id":"337631","messageId":"CAPig+cQ6UZJh5sZJURTiZ+T8eV8pyBSMTM8Re-BN7ZVwGc60+A@mail.gmail.com","threadId":"47706","inReplyTo":"20180128155722.880805-10-sandals@crustytoothpaste.net","subject":"Re: [PATCH 09/12] read-cache: abstract away uses of SHA-1","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-01-28T19:50:18Z","receivedAt":"2018-01-28T19:50:24Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Sun, Jan 28, 2018 at 10:57 AM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> Convert various uses of direct calls to SHA-1 and 20- and 40-based\n> constants to use the_hash_algo instead.  Don't yet convert the on-disk\n> data structures, which will be handled in a future commit.\n>\n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n> diff --git a/read-cache.c b/read-cache.c\n> @@ -2000,26 +2000,26 @@ static int write_index_ext_header(git_SHA_CTX *context, int fd,\n>         /* Flush first if not enough space for SHA1 signature */\n\nDid you want to update the comment to remove the SHA1 reference also?\n(Or was the omission intentional per the commit message?)\n\n> -       if (left + 20 > WRITE_BUFFER_SIZE) {\n> +       if (left + the_hash_algo->rawsz > WRITE_BUFFER_SIZE) {\n>                 if (write_in_full(fd, write_buffer, left) < 0)\n>                         return -1;\n>                 left = 0;\n>         }\n>\n>         /* Append the SHA1 signature at the end */\n\nDitto.\n\n> -       git_SHA1_Final(write_buffer + left, context);\n> -       hashcpy(sha1, write_buffer + left);\n> -       left += 20;\n> +       the_hash_algo->final_fn(write_buffer + left, context);\n> +       hashcpy(hash, write_buffer + left);\n> +       left += the_hash_algo->rawsz;\n"},{"id":"337633","messageId":"54b29396-d994-7afd-9c18-83fca8e4ad6f@gmail.com","threadId":"47706","inReplyTo":"20180128155722.880805-3-sandals@crustytoothpaste.net","subject":"Re: [PATCH 02/12] hash: create union for hash context allocation","fromName":"Patryk Obara","fromEmail":"patryk.obara@gmail.com","sentAt":"2018-01-28T19:57:21Z","receivedAt":"2018-01-28T19:57:28Z","isPatch":true,"sender":{"key":"patryk.obara@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3967?v=4"},"body":"On 28/01/2018 16:57, brian m. carlson wrote:\n> In various parts of our code, we want to allocate a structure\n> representing the internal state of a hash algorithm.  The original\n> implementation of the hash algorithm abstraction assumed we would do\n> that using heap allocations, and added a context size element to struct\n> git_hash_algo.  However, most of the existing code uses stack\n> allocations and conversion would needlessly complicate various parts of\n> the code.  Add a union for the purpose of allocating hash contexts on\n> the stack and a typedef for ease of use.  Remove the ctxsz element for\n> struct git_hash_algo, which is no longer very useful.\n\nOverall, I am OK with this approach (it's straightforward change and \ncleanest way to replace direct calls to git_SHA1_* functions), but just \nto play devil's advocate: OpenSSL decided to sway users into heap \nallocated contexts, citing binary compatibility issues if they change \nthe size of context structure. [1]\n\nI think we might need to revisit this design decision in future - \nperhaps as soon as we'll transition away from calling git_SHA1_* \nfunctions directly.\n\n> +/* A suitably aligned type for stack allocations of hash contexts. */\n> +union git_hash_ctx {\n> +\tgit_SHA_CTX sha1;\n> +};\n> +typedef union git_hash_ctx git_hash_ctx;\n> +\n>   typedef void (*git_hash_init_fn)(void *ctx);\n>   typedef void (*git_hash_update_fn)(void *ctx, const void *in, size_t len);\n>   typedef void (*git_hash_final_fn)(unsigned char *hash, void *ctx);\n\nI think it would be appropriate to replace \"void *ctx\" with \n\"git_hash_ctx *ctx\". This way we can avoid unnecessary casting in \ngit_hash_sha1_* functions.\n\n[1] https://wiki.openssl.org/index.php/Manual:EVP_DigestInit(3)#NOTES\n\n-- \n| ← Ceci n'est pas une pipe\nPatryk Obara\n"},{"id":"337634","messageId":"eb5b2319-a67c-8a49-81f4-1b981673459a@gmail.com","threadId":"47706","inReplyTo":"20180128155722.880805-7-sandals@crustytoothpaste.net","subject":"Re: [PATCH 06/12] fast-import: switch various uses of SHA-1 to the_hash_algo","fromName":"Patryk Obara","fromEmail":"patryk.obara@gmail.com","sentAt":"2018-01-28T20:10:12Z","receivedAt":"2018-01-28T20:10:19Z","isPatch":true,"sender":{"key":"patryk.obara@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3967?v=4"},"body":"On 28/01/2018 16:57, brian m. carlson wrote:\n> -\tif (last && last->data.buf && last->depth < max_depth && dat->len > 20) {\n> +\tif (last && last->data.buf && last->depth < max_depth && dat->len > the_hash_algo->rawsz) {\n\nAt this point line is almost 100 characters long - maybe it's time to\nbreak it ;)\n\n-- \n| ← Ceci n'est pas une pipe\nPatryk Obara\n"},{"id":"337635","messageId":"20180128201032.GJ431130@genre.crustytoothpaste.net","threadId":"47706","inReplyTo":"CAPig+cQ6UZJh5sZJURTiZ+T8eV8pyBSMTM8Re-BN7ZVwGc60+A@mail.gmail.com","subject":"Re: [PATCH 09/12] read-cache: abstract away uses of SHA-1","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T20:10:32Z","receivedAt":"2018-01-28T20:10:46Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Jan 28, 2018 at 02:50:18PM -0500, Eric Sunshine wrote:\n> On Sun, Jan 28, 2018 at 10:57 AM, brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> > Convert various uses of direct calls to SHA-1 and 20- and 40-based\n> > constants to use the_hash_algo instead.  Don't yet convert the on-disk\n> > data structures, which will be handled in a future commit.\n> >\n> > Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> > ---\n> > diff --git a/read-cache.c b/read-cache.c\n> > @@ -2000,26 +2000,26 @@ static int write_index_ext_header(git_SHA_CTX *context, int fd,\n> >         /* Flush first if not enough space for SHA1 signature */\n> \n> Did you want to update the comment to remove the SHA1 reference also?\n> (Or was the omission intentional per the commit message?)\n\nThese weren't intentional, so I'll fix them in a reroll.\n\nThe only reason I didn't touch the ondisk data structures is because\nthey're directly mmap'd.  So if I change them to use struct object_id,\nas soon as we expand the structure size, the ondisk structures become\nunusable.  Some sort of union hack or multiple subroutines will probably\nbe required.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"337636","messageId":"20180128201648.GK431130@genre.crustytoothpaste.net","threadId":"47706","inReplyTo":"54b29396-d994-7afd-9c18-83fca8e4ad6f@gmail.com","subject":"Re: [PATCH 02/12] hash: create union for hash context allocation","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T20:16:49Z","receivedAt":"2018-01-28T20:17:01Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Jan 28, 2018 at 08:57:21PM +0100, Patryk Obara wrote:\n> On 28/01/2018 16:57, brian m. carlson wrote:\n> > In various parts of our code, we want to allocate a structure\n> > representing the internal state of a hash algorithm.  The original\n> > implementation of the hash algorithm abstraction assumed we would do\n> > that using heap allocations, and added a context size element to struct\n> > git_hash_algo.  However, most of the existing code uses stack\n> > allocations and conversion would needlessly complicate various parts of\n> > the code.  Add a union for the purpose of allocating hash contexts on\n> > the stack and a typedef for ease of use.  Remove the ctxsz element for\n> > struct git_hash_algo, which is no longer very useful.\n> \n> Overall, I am OK with this approach (it's straightforward change and\n> cleanest way to replace direct calls to git_SHA1_* functions), but just to\n> play devil's advocate: OpenSSL decided to sway users into heap allocated\n> contexts, citing binary compatibility issues if they change the size of\n> context structure. [1]\n> \n> I think we might need to revisit this design decision in future - perhaps as\n> soon as we'll transition away from calling git_SHA1_* functions directly.\n\nThe approach I took was to keep the code as similar as possible to\nwhat's there already.  If our hash implementation wants to use pointers,\nit's okay for it to define git_SHA1_CTX to a pointer type, and\neverything should still work.  We treat the type as fully opaque anyway\n(outside of the actual hash implementation).\n\n> > +/* A suitably aligned type for stack allocations of hash contexts. */\n> > +union git_hash_ctx {\n> > +\tgit_SHA_CTX sha1;\n> > +};\n> > +typedef union git_hash_ctx git_hash_ctx;\n> > +\n> >   typedef void (*git_hash_init_fn)(void *ctx);\n> >   typedef void (*git_hash_update_fn)(void *ctx, const void *in, size_t len);\n> >   typedef void (*git_hash_final_fn)(unsigned char *hash, void *ctx);\n> \n> I think it would be appropriate to replace \"void *ctx\" with \"git_hash_ctx\n> *ctx\". This way we can avoid unnecessary casting in git_hash_sha1_*\n> functions.\n\nYeah, that does make more sense.  I'll make that change.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"337637","messageId":"76f6c291-9c48-279d-3bb6-fc42a8e0eb9b@gmail.com","threadId":"47706","inReplyTo":"20180128155722.880805-9-sandals@crustytoothpaste.net","subject":"Re: [PATCH 08/12] pack-write: switch various SHA-1 values to abstract forms","fromName":"Patryk Obara","fromEmail":"patryk.obara@gmail.com","sentAt":"2018-01-28T20:30:36Z","receivedAt":"2018-01-28T20:30:44Z","isPatch":true,"sender":{"key":"patryk.obara@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3967?v=4"},"body":"On 28/01/2018 16:57, brian m. carlson wrote:\n>   \t\tif (partial_pack_offset == 0) {\n> -\t\t\tunsigned char sha1[20];\n> -\t\t\tgit_SHA1_Final(sha1, &old_sha1_ctx);\n> -\t\t\tif (hashcmp(sha1, partial_pack_sha1) != 0)\n> +\t\t\tunsigned char hash[GIT_MAX_RAWSZ];\n> +\t\t\tthe_hash_algo->final_fn(hash, &old_hash_ctx);\n> +\t\t\tif (hashcmp(hash, partial_pack_hash) != 0)\n\nMaybe \"hash\" should be struct object_id here?\n\n>   char *index_pack_lockfile(int ip_out)\n>   {\n> -\tchar packname[46];\n> +\tchar packname[GIT_MAX_HEXSZ + 6];\n> +\tint len = the_hash_algo->hexsz + 6;\n\nJust me nitpicking, but \"len\" can be const :)\n\n-- \n| ← Ceci n'est pas une pipe\nPatryk Obara\n"},{"id":"337639","messageId":"1f464382-51f7-1e3b-509b-73f7fa49488f@gmail.com","threadId":"47706","inReplyTo":"20180128155722.880805-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH 00/12] object_id part 11 (the_hash_algo)","fromName":"Patryk Obara","fromEmail":"patryk.obara@gmail.com","sentAt":"2018-01-28T20:48:28Z","receivedAt":"2018-01-28T20:48:37Z","isPatch":true,"sender":{"key":"patryk.obara@gmail.com","avatar":"https://avatars.githubusercontent.com/u/3967?v=4"},"body":"I looked at your branch object-id-part-12, and it conflicts with my next\nbatch of object_id conversions in quite many places (mostly through\nformatting). Therefore I'll hold my horses and postpone my conversion\npatches at least until part 12 will be sent.\n\n-- \n| ← Ceci n'est pas une pipe\nPatryk Obara\n"},{"id":"337640","messageId":"20180128215207.GL431130@genre.crustytoothpaste.net","threadId":"47706","inReplyTo":"76f6c291-9c48-279d-3bb6-fc42a8e0eb9b@gmail.com","subject":"Re: [PATCH 08/12] pack-write: switch various SHA-1 values to abstract forms","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T21:52:07Z","receivedAt":"2018-01-28T21:52:20Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Jan 28, 2018 at 09:30:36PM +0100, Patryk Obara wrote:\n> On 28/01/2018 16:57, brian m. carlson wrote:\n> >   \t\tif (partial_pack_offset == 0) {\n> > -\t\t\tunsigned char sha1[20];\n> > -\t\t\tgit_SHA1_Final(sha1, &old_sha1_ctx);\n> > -\t\t\tif (hashcmp(sha1, partial_pack_sha1) != 0)\n> > +\t\t\tunsigned char hash[GIT_MAX_RAWSZ];\n> > +\t\t\tthe_hash_algo->final_fn(hash, &old_hash_ctx);\n> > +\t\t\tif (hashcmp(hash, partial_pack_hash) != 0)\n> \n> Maybe \"hash\" should be struct object_id here?\n\nIn this case, I opted not to do that because it's specifically not an\nobject ID.  It's a checksum for the pack, which isn't a normal Git\nobject, so I tried to preserve that distinction.\n\n> >   char *index_pack_lockfile(int ip_out)\n> >   {\n> > -\tchar packname[46];\n> > +\tchar packname[GIT_MAX_HEXSZ + 6];\n> > +\tint len = the_hash_algo->hexsz + 6;\n> \n> Just me nitpicking, but \"len\" can be const :)\n\nI wanted it to be const, too, but I recall getting feedback discouraging\nit.  I\"m happy to make the change; after all, it can only help the\ncompiler and any future readers.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"337641","messageId":"20180128220008.GM431130@genre.crustytoothpaste.net","threadId":"47706","inReplyTo":"1f464382-51f7-1e3b-509b-73f7fa49488f@gmail.com","subject":"Re: [PATCH 00/12] object_id part 11 (the_hash_algo)","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-01-28T22:00:09Z","receivedAt":"2018-01-28T22:00:19Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Jan 28, 2018 at 09:48:28PM +0100, Patryk Obara wrote:\n> I looked at your branch object-id-part-12, and it conflicts with my next\n> batch of object_id conversions in quite many places (mostly through\n> formatting). Therefore I'll hold my horses and postpone my conversion\n> patches at least until part 12 will be sent.\n\nOkay.  I've just rebased it on top of your object_id series, so I'll\nreroll this series and then once both series get picked up, rebase and\nsubmit it on top.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\nhttps://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"}]}