{"thread":{"id":"47731","subject":"[PATCH v2 00/12] object_id part 11 (the_hash_algo)","startedAt":"2018-02-01T02:19:04Z","lastAt":"2018-02-08T02:49:13Z","messageCount":19,"participants":["brian m. carlson","Stefan Beller","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":12},"messages":[{"id":"337989","messageId":"20180201021848.533188-1-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":null,"subject":"[PATCH v2 00/12] object_id part 11 (the_hash_algo)","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:36Z","receivedAt":"2018-02-01T02:19:04Z","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\nChanges from v1:\n* Fix comments referring to SHA-1.\n* Switch hash function wrappers to take git_hash_ctx *.\n* Use a const int variable for a constant value.\n* Wrap an overly long line.\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            |  70 +++++++++++++++---------------\n hash.h                   |  40 +++++++++++++++---\n pack-bitmap-write.c      |  30 ++++++-------\n pack-check.c             |  32 +++++++-------\n pack-write.c             |  77 ++++++++++++++++-----------------\n pack.h                   |   4 +-\n read-cache.c             |  58 ++++++++++++-------------\n sha1_file.c              |  72 +++++++++++++++----------------\n 15 files changed, 351 insertions(+), 347 deletions(-)\n\n"},{"id":"337990","messageId":"20180201021848.533188-2-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 01/12] hash: move SHA-1 macros to hash.h","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:37Z","receivedAt":"2018-02-01T02:19:07Z","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":"337991","messageId":"20180201021848.533188-3-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 02/12] hash: create union for hash context allocation","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:38Z","receivedAt":"2018-02-01T02:19:11Z","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.  Use this union for defining\nthe init, update, and final functions to avoid casts.  Remove the ctxsz\nelement for struct 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      | 15 +++++++++------\n sha1_file.c | 20 +++++++++-----------\n 2 files changed, 18 insertions(+), 17 deletions(-)\n\ndiff --git a/hash.h b/hash.h\nindex 7122dea7b3..eb30f59be3 100644\n--- a/hash.h\n+++ b/hash.h\n@@ -55,9 +55,15 @@\n /* Number of algorithms supported (including unknown). */\n #define GIT_HASH_NALGOS (GIT_HASH_SHA1 + 1)\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+/* 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)(git_hash_ctx *ctx);\n+typedef void (*git_hash_update_fn)(git_hash_ctx *ctx, const void *in, size_t len);\n+typedef void (*git_hash_final_fn)(unsigned char *hash, git_hash_ctx *ctx);\n \n struct git_hash_algo {\n \t/*\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..ec6ecea170 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -39,32 +39,32 @@ const struct object_id empty_blob_oid = {\n \tEMPTY_BLOB_SHA1_BIN_LITERAL\n };\n \n-static void git_hash_sha1_init(void *ctx)\n+static void git_hash_sha1_init(git_hash_ctx *ctx)\n {\n-\tgit_SHA1_Init((git_SHA_CTX *)ctx);\n+\tgit_SHA1_Init(&ctx->sha1);\n }\n \n-static void git_hash_sha1_update(void *ctx, const void *data, size_t len)\n+static void git_hash_sha1_update(git_hash_ctx *ctx, const void *data, size_t len)\n {\n-\tgit_SHA1_Update((git_SHA_CTX *)ctx, data, len);\n+\tgit_SHA1_Update(&ctx->sha1, data, len);\n }\n \n-static void git_hash_sha1_final(unsigned char *hash, void *ctx)\n+static void git_hash_sha1_final(unsigned char *hash, git_hash_ctx *ctx)\n {\n-\tgit_SHA1_Final(hash, (git_SHA_CTX *)ctx);\n+\tgit_SHA1_Final(hash, &ctx->sha1);\n }\n \n-static void git_hash_unknown_init(void *ctx)\n+static void git_hash_unknown_init(git_hash_ctx *ctx)\n {\n \tdie(\"trying to init unknown hash\");\n }\n \n-static void git_hash_unknown_update(void *ctx, const void *data, size_t len)\n+static void git_hash_unknown_update(git_hash_ctx *ctx, const void *data, size_t len)\n {\n \tdie(\"trying to update unknown hash\");\n }\n \n-static void git_hash_unknown_final(unsigned char *hash, void *ctx)\n+static void git_hash_unknown_final(unsigned char *hash, git_hash_ctx *ctx)\n {\n \tdie(\"trying to finalize unknown hash\");\n }\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":"337992","messageId":"20180201021848.533188-4-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 03/12] builtin/index-pack: improve hash function abstraction","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:39Z","receivedAt":"2018-02-01T02:19:14Z","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":"337993","messageId":"20180201021848.533188-8-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 07/12] pack-check: convert various uses of SHA-1 to abstract forms","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:43Z","receivedAt":"2018-02-01T02:19:17Z","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":"337994","messageId":"20180201021848.533188-7-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 06/12] fast-import: switch various uses of SHA-1 to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:42Z","receivedAt":"2018-02-01T02:19:19Z","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 | 42 ++++++++++++++++++++++--------------------\n 1 file changed, 22 insertions(+), 20 deletions(-)\n\ndiff --git a/fast-import.c b/fast-import.c\nindex b70ac025e0..f20f30ab62 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,13 @@ 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\n+\t\t&& dat->len > the_hash_algo->rawsz) {\n+\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 +1233,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 +1248,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 +1267,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 +1293,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 +1352,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 +1364,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 +2206,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 +2214,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":"337995","messageId":"20180201021848.533188-9-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 08/12] pack-write: switch various SHA-1 values to abstract forms","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:44Z","receivedAt":"2018-02-01T02:19:20Z","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..5317678c29 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+\tconst int 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":"337996","messageId":"20180201021848.533188-13-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 12/12] bulk-checkin: abstract SHA-1 usage","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:48Z","receivedAt":"2018-02-01T02:19:23Z","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":"337997","messageId":"20180201021848.533188-11-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 10/12] csum-file: rename sha1file to hashfile","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:46Z","receivedAt":"2018-02-01T02:19:26Z","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 f20f30ab62..0f818cd932 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@@ -1182,23 +1182,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@@ -1217,9 +1217,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@@ -1235,7 +1235,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@@ -1243,7 +1243,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@@ -1277,7 +1277,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@@ -1362,7 +1362,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 5317678c29..d775c7406d 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":"337998","messageId":"20180201021848.533188-12-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 11/12] csum-file: abstract uses of SHA-1","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:47Z","receivedAt":"2018-02-01T02:19:29Z","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":"337999","messageId":"20180201021848.533188-10-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 09/12] read-cache: abstract away uses of SHA-1","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:45Z","receivedAt":"2018-02-01T02:19:34Z","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\nAdjust some comments so as not to refer explicitly to SHA-1.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n read-cache.c | 58 +++++++++++++++++++++++++++++-----------------------------\n 1 file changed, 29 insertions(+), 29 deletions(-)\n\ndiff --git a/read-cache.c b/read-cache.c\nindex 2eb81a66b9..15bbb9bab4 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+\t/* Flush first if not enough space for hash signature */\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+\t/* Append the hash signature at the end */\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":"338000","messageId":"20180201021848.533188-5-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 04/12] builtin/unpack-objects: switch uses of SHA-1 to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:40Z","receivedAt":"2018-02-01T02:19:36Z","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":"338001","messageId":"20180201021848.533188-6-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 05/12] sha1_file: switch uses of SHA-1 to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-01T02:18:41Z","receivedAt":"2018-02-01T02:19:39Z","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 ec6ecea170..ff55fb303d 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":"338050","messageId":"CAGZ79kZ5FT7hD4q+=-AVBUzTaHUjR1sQ3ksmJGHfXzon-az2xA@mail.gmail.com","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 00/12] object_id part 11 (the_hash_algo)","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-02-01T22:06:36Z","receivedAt":"2018-02-01T22:06:42Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Jan 31, 2018 at 6:18 PM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> This series includes various changes to adopt the use of the_hash_algo\n> for abstracting hash algorithms away.\n\nThis series looks good to me.\n\n>\n> Changes from v1:\n> * Fix comments referring to SHA-1.\n> * Switch hash function wrappers to take git_hash_ctx *.\n> * Use a const int variable for a constant value.\n> * Wrap an overly long line.\n>\n> brian 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            |  70 +++++++++++++++---------------\n>  hash.h                   |  40 +++++++++++++++---\n>  pack-bitmap-write.c      |  30 ++++++-------\n>  pack-check.c             |  32 +++++++-------\n>  pack-write.c             |  77 ++++++++++++++++-----------------\n>  pack.h                   |   4 +-\n>  read-cache.c             |  58 ++++++++++++-------------\n>  sha1_file.c              |  72 +++++++++++++++----------------\n>  15 files changed, 351 insertions(+), 347 deletions(-)\n>\n"},{"id":"338114","messageId":"xmqqmv0rchat.fsf@gitster-ct.c.googlers.com","threadId":"47731","inReplyTo":"20180201021848.533188-2-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 01/12] hash: move SHA-1 macros to hash.h","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-02T19:39:22Z","receivedAt":"2018-02-02T19:39:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\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\nThis nit has been with us for a long time, but \"Note that including\nSHA1_HEADER may have...\" has been way too stale a comment for quite\nsome time.  It was made different from \"including SHA1_HEADER\" by\nf18f816c (\"hash.h: move SHA-1 implementation selection into a header\nfile\", 2017-03-11).\n\nPerhaps\n\n\tNote that we may have already defined platform_SHA_CTX for our\n\town implementations like block-sha1 and ppc-sha1, so we list\n\t...\n\nor something.\n"},{"id":"338115","messageId":"xmqqinbfcgzo.fsf@gitster-ct.c.googlers.com","threadId":"47731","inReplyTo":"20180201021848.533188-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 00/12] object_id part 11 (the_hash_algo)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-02T19:46:03Z","receivedAt":"2018-02-02T19:46:14Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> This series includes various changes to adopt the use of the_hash_algo\n> for abstracting hash algorithms away.\n>\n> Changes from v1:\n> * Fix comments referring to SHA-1.\n> * Switch hash function wrappers to take git_hash_ctx *.\n> * Use a const int variable for a constant value.\n> * Wrap an overly long line.\n\nThanks for working on this.  All changes looked sensible (even\nthough I spotted one nit in the original, which was moved as-is,\nwhich does not count as a \"change\" ;-)).\n\n"},{"id":"338461","messageId":"20180206003359.GB7904@genre.crustytoothpaste.net","threadId":"47731","inReplyTo":"xmqqinbfcgzo.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH v2 00/12] object_id part 11 (the_hash_algo)","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-06T00:34:00Z","receivedAt":"2018-02-06T00:34:13Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Fri, Feb 02, 2018 at 11:46:03AM -0800, Junio C Hamano wrote:\n> Thanks for working on this.  All changes looked sensible (even\n> though I spotted one nit in the original, which was moved as-is,\n> which does not count as a \"change\" ;-)).\n\nI forgot to ask: do you want a reroll which fixes this, or just a\nfollow-up patch on top to fix the comment?\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":"338514","messageId":"xmqq7erq892l.fsf@gitster-ct.c.googlers.com","threadId":"47731","inReplyTo":"20180206003359.GB7904@genre.crustytoothpaste.net","subject":"Re: [PATCH v2 00/12] object_id part 11 (the_hash_algo)","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-02-06T14:52:02Z","receivedAt":"2018-02-06T14:52:09Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> On Fri, Feb 02, 2018 at 11:46:03AM -0800, Junio C Hamano wrote:\n>> Thanks for working on this.  All changes looked sensible (even\n>> though I spotted one nit in the original, which was moved as-is,\n>> which does not count as a \"change\" ;-)).\n>\n> I forgot to ask: do you want a reroll which fixes this, or just a\n> follow-up patch on top to fix the comment?\n\nI do not think it is in scope of the series, so a follow-up would be\nsufficient.\n\nThanks.\n"},{"id":"338687","messageId":"20180208024858.872624-1-sandals@crustytoothpaste.net","threadId":"47731","inReplyTo":"xmqqinbfcgzo.fsf@gitster-ct.c.googlers.com","subject":"[PATCH v2] hash: update obsolete reference to SHA1_HEADER","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-02-08T02:48:58Z","receivedAt":"2018-02-08T02:49:13Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"We moved away from SHA1_HEADER to a preprocessor if chain, but didn't\nupdate the comment discussing the platform defines.  Update this comment\nso it reflects the current state of our codebase.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n hash.h | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/hash.h b/hash.h\nindex eb30f59be3..7c8238bc2e 100644\n--- a/hash.h\n+++ b/hash.h\n@@ -18,8 +18,8 @@\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+ * blk_SHA, Apple CommonCrypto, etc...  Note that the relevant\n+ * SHA-1 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"}]}