{"thread":{"id":"51668","subject":"[PATCH 00/26] object_id part 17","startedAt":"2019-08-18T20:05:35Z","lastAt":"2019-08-23T11:53:42Z","messageCount":33,"participants":["brian m. carlson","René Scharfe","Derrick Stolee","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":26},"messages":[{"id":"380650","messageId":"20190818200427.870753-1-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":null,"subject":"[PATCH 00/26] object_id part 17","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:01Z","receivedAt":"2019-08-18T20:05:35Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"This is the seventeenth and final object_id series. The patches mostly\nswitch sha1_to_hex to hash_to_hex, remove null_sha1 in favor of\nnull_oid, and replace some hard-coded constants (along with\nGIT_SHA1_HEXSZ) to use the_hash_algo.\n\nThis series may downloaded from the normal places as \"object-id-part17\".\n\nAdditional patches for test fixes will be required, but beyond that, the\nnext series of actual code changes will involve introducing the\n`extensions.objectFormat` flag and the ability to create repositories\nand run the testsuite with SHA-256.  A preview of this work may be seen\nin the \"transition-stage-4\" branch.\n\nbrian m. carlson (26):\n  builtin/replace: make hash size independent\n  patch-id: convert to use the_hash_algo\n  fetch-pack: use parse_oid_hex\n  builtin/receive-pack: switch to use the_hash_algo\n  builtin/blame: switch uses of GIT_SHA1_HEXSZ to the_hash_algo\n  builtin/rev-parse: switch to use the_hash_algo\n  blame: remove needless comparison with GIT_SHA1_HEXSZ\n  show-index: switch hard-coded constants to the_hash_algo\n  connected: switch GIT_SHA1_HEXSZ to the_hash_algo\n  bundle: switch to use the_hash_algo\n  combine-diff: replace GIT_SHA1_HEXSZ with the_hash_algo\n  config: use the_hash_algo in abbrev comparison\n  sha1-lookup: switch hard-coded constants to the_hash_algo\n  bisect: switch to using the_hash_algo\n  sequencer: convert to use the_hash_algo\n  pack-write: use hash_to_hex when writing checksums\n  builtin/repack: write object IDs of the proper length\n  builtin/worktree: switch null_sha1 to null_oid\n  cache: remove null_sha1\n  wt-status: convert struct wt_status to object_id\n  packfile: replace sha1_to_hex\n  builtin/index-pack: replace sha1_to_hex\n  builtin/receive-pack: replace sha1_to_hex\n  rerere: replace sha1_to_hex\n  builtin/show-index: replace sha1_to_hex\n  midx: switch to using the_hash_algo\n\n bisect.c                    |  2 +-\n blame.c                     |  2 +-\n builtin/blame.c             |  7 +++---\n builtin/clone.c             |  2 +-\n builtin/commit.c            |  4 +--\n builtin/index-pack.c        |  4 +--\n builtin/patch-id.c          | 11 ++++----\n builtin/receive-pack.c      | 50 ++++++++++++++++++-------------------\n builtin/repack.c            |  2 +-\n builtin/replace.c           |  7 +++---\n builtin/rev-parse.c         |  5 ++--\n builtin/show-index.c        | 13 +++++-----\n builtin/submodule--helper.c |  2 +-\n builtin/worktree.c          |  2 +-\n bundle.c                    |  4 +--\n cache.h                     |  8 +-----\n combine-diff.c              |  2 +-\n config.c                    |  2 +-\n connected.c                 |  7 +++---\n diff.c                      | 46 +++++++++++++++++-----------------\n diff.h                      |  2 +-\n fetch-pack.c                | 12 ++++-----\n midx.c                      | 11 ++++----\n pack-write.c                |  8 +++---\n packfile.c                  |  4 +--\n rerere.c                    |  8 +++---\n sequencer.c                 |  6 ++---\n sha1-file.c                 |  1 -\n sha1-lookup.c               |  8 +++---\n wt-status.c                 |  2 +-\n wt-status.h                 |  2 +-\n 31 files changed, 121 insertions(+), 125 deletions(-)\n\n"},{"id":"380651","messageId":"20190818200427.870753-2-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 01/26] builtin/replace: make hash size independent","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:02Z","receivedAt":"2019-08-18T20:05:35Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Instead of using GIT_SHA1_HEXSZ and hard-coded constants, switch to\nusing the_hash_algo.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/replace.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 644b21ca8d..4b00f1d84e 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -272,7 +272,7 @@ static int import_object(struct object_id *oid, enum object_type type,\n \t\t\treturn error(_(\"unable to spawn mktree\"));\n \t\t}\n \n-\t\tif (strbuf_read(&result, cmd.out, 41) < 0) {\n+\t\tif (strbuf_read(&result, cmd.out, the_hash_algo->hexsz + 1) < 0) {\n \t\t\terror_errno(_(\"unable to read from mktree\"));\n \t\t\tclose(fd);\n \t\t\tclose(cmd.out);\n@@ -358,14 +358,15 @@ static int replace_parents(struct strbuf *buf, int argc, const char **argv)\n \tstruct strbuf new_parents = STRBUF_INIT;\n \tconst char *parent_start, *parent_end;\n \tint i;\n+\tconst unsigned hexsz = the_hash_algo->hexsz;\n \n \t/* find existing parents */\n \tparent_start = buf->buf;\n-\tparent_start += GIT_SHA1_HEXSZ + 6; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n+\tparent_start += hexsz + 6; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tparent_end = parent_start;\n \n \twhile (starts_with(parent_end, \"parent \"))\n-\t\tparent_end += 48; /* \"parent \" + \"hex sha1\" + \"\\n\" */\n+\t\tparent_end += hexsz + 8; /* \"parent \" + \"hex sha1\" + \"\\n\" */\n \n \t/* prepare new parents */\n \tfor (i = 0; i < argc; i++) {\n"},{"id":"380652","messageId":"20190818200427.870753-5-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 04/26] builtin/receive-pack: switch to use the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:05Z","receivedAt":"2019-08-18T20:05:36Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"The push cert code uses HMAC-SHA-1 to create a nonce.  This is a secure\nuse of SHA-1 which is not affected by its collision resistance (or lack\nthereof).  However, it makes sense for us to use a better algorithm if\none is available, one which may even be more performant.  Futhermore,\nuntil we have specialized functions for computing the hex value of an\narbitrary function, it simplifies the code greatly to use the same hash\nalgorithm everywhere.\n\nSwitch this code to use GIT_MAX_BLKSZ and the_hash_algo for computing\nthe push cert nonce, and rename the hmac_sha1 function to simply \"hmac\".\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/receive-pack.c | 44 ++++++++++++++++++++----------------------\n 1 file changed, 21 insertions(+), 23 deletions(-)\n\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex dcf385511f..402edf34d8 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -417,24 +417,22 @@ static int copy_to_sideband(int in, int out, void *arg)\n \treturn 0;\n }\n \n-#define HMAC_BLOCK_SIZE 64\n-\n-static void hmac_sha1(unsigned char *out,\n+static void hmac(unsigned char *out,\n \t\t      const char *key_in, size_t key_len,\n \t\t      const char *text, size_t text_len)\n {\n-\tunsigned char key[HMAC_BLOCK_SIZE];\n-\tunsigned char k_ipad[HMAC_BLOCK_SIZE];\n-\tunsigned char k_opad[HMAC_BLOCK_SIZE];\n+\tunsigned char key[GIT_MAX_BLKSZ];\n+\tunsigned char k_ipad[GIT_MAX_BLKSZ];\n+\tunsigned char k_opad[GIT_MAX_BLKSZ];\n \tint i;\n-\tgit_SHA_CTX ctx;\n+\tgit_hash_ctx ctx;\n \n \t/* RFC 2104 2. (1) */\n-\tmemset(key, '\\0', HMAC_BLOCK_SIZE);\n-\tif (HMAC_BLOCK_SIZE < key_len) {\n-\t\tgit_SHA1_Init(&ctx);\n-\t\tgit_SHA1_Update(&ctx, key_in, key_len);\n-\t\tgit_SHA1_Final(key, &ctx);\n+\tmemset(key, '\\0', GIT_MAX_BLKSZ);\n+\tif (the_hash_algo->blksz < key_len) {\n+\t\tthe_hash_algo->init_fn(&ctx);\n+\t\tthe_hash_algo->update_fn(&ctx, key_in, key_len);\n+\t\tthe_hash_algo->final_fn(key, &ctx);\n \t} else {\n \t\tmemcpy(key, key_in, key_len);\n \t}\n@@ -446,29 +444,29 @@ static void hmac_sha1(unsigned char *out,\n \t}\n \n \t/* RFC 2104 2. (3) & (4) */\n-\tgit_SHA1_Init(&ctx);\n-\tgit_SHA1_Update(&ctx, k_ipad, sizeof(k_ipad));\n-\tgit_SHA1_Update(&ctx, text, text_len);\n-\tgit_SHA1_Final(out, &ctx);\n+\tthe_hash_algo->init_fn(&ctx);\n+\tthe_hash_algo->update_fn(&ctx, k_ipad, sizeof(k_ipad));\n+\tthe_hash_algo->update_fn(&ctx, text, text_len);\n+\tthe_hash_algo->final_fn(out, &ctx);\n \n \t/* RFC 2104 2. (6) & (7) */\n-\tgit_SHA1_Init(&ctx);\n-\tgit_SHA1_Update(&ctx, k_opad, sizeof(k_opad));\n-\tgit_SHA1_Update(&ctx, out, GIT_SHA1_RAWSZ);\n-\tgit_SHA1_Final(out, &ctx);\n+\tthe_hash_algo->init_fn(&ctx);\n+\tthe_hash_algo->update_fn(&ctx, k_opad, sizeof(k_opad));\n+\tthe_hash_algo->update_fn(&ctx, out, the_hash_algo->rawsz);\n+\tthe_hash_algo->final_fn(out, &ctx);\n }\n \n static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n-\tunsigned char sha1[GIT_SHA1_RAWSZ];\n+\tunsigned char hash[GIT_MAX_RAWSZ];\n \n \tstrbuf_addf(&buf, \"%s:%\"PRItime, path, stamp);\n-\thmac_sha1(sha1, buf.buf, buf.len, cert_nonce_seed, strlen(cert_nonce_seed));\n+\thmac(hash, buf.buf, buf.len, cert_nonce_seed, strlen(cert_nonce_seed));\n \tstrbuf_release(&buf);\n \n \t/* RFC 2104 5. HMAC-SHA1-80 */\n-\tstrbuf_addf(&buf, \"%\"PRItime\"-%.*s\", stamp, GIT_SHA1_HEXSZ, sha1_to_hex(sha1));\n+\tstrbuf_addf(&buf, \"%\"PRItime\"-%.*s\", stamp, (int)the_hash_algo->hexsz, sha1_to_hex(hash));\n \treturn strbuf_detach(&buf, NULL);\n }\n \n"},{"id":"380653","messageId":"20190818200427.870753-4-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 03/26] fetch-pack: use parse_oid_hex","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:04Z","receivedAt":"2019-08-18T20:05:37Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Instead of hard-coding constants, use parse_oid_hex to compute a pointer\nand use it in further parsing operations.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n fetch-pack.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 65be043f2a..1f56b8a6d7 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -168,16 +168,16 @@ static enum ack_type get_ack(struct packet_reader *reader,\n \tif (!strcmp(reader->line, \"NAK\"))\n \t\treturn NAK;\n \tif (skip_prefix(reader->line, \"ACK \", &arg)) {\n-\t\tif (!get_oid_hex(arg, result_oid)) {\n-\t\t\targ += 40;\n-\t\t\tlen -= arg - reader->line;\n+\t\tconst char *p;\n+\t\tif (!parse_oid_hex(arg, result_oid, &p)) {\n+\t\t\tlen -= p - reader->line;\n \t\t\tif (len < 1)\n \t\t\t\treturn ACK;\n-\t\t\tif (strstr(arg, \"continue\"))\n+\t\t\tif (strstr(p, \"continue\"))\n \t\t\t\treturn ACK_continue;\n-\t\t\tif (strstr(arg, \"common\"))\n+\t\t\tif (strstr(p, \"common\"))\n \t\t\t\treturn ACK_common;\n-\t\t\tif (strstr(arg, \"ready\"))\n+\t\t\tif (strstr(p, \"ready\"))\n \t\t\t\treturn ACK_ready;\n \t\t\treturn ACK;\n \t\t}\n"},{"id":"380654","messageId":"20190818200427.870753-3-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 02/26] patch-id: convert to use the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:03Z","receivedAt":"2019-08-18T20:05:38Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert the two separate patch-id implementations to use the_hash_algo\nin their implementation.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/patch-id.c | 11 ++++++-----\n diff.c             | 46 +++++++++++++++++++++++-----------------------\n diff.h             |  2 +-\n 3 files changed, 30 insertions(+), 29 deletions(-)\n\ndiff --git a/builtin/patch-id.c b/builtin/patch-id.c\nindex bd28b80b2d..3059e525b8 100644\n--- a/builtin/patch-id.c\n+++ b/builtin/patch-id.c\n@@ -1,15 +1,16 @@\n+#include \"cache.h\"\n #include \"builtin.h\"\n #include \"config.h\"\n #include \"diff.h\"\n \n static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)\n {\n-\tchar name[50];\n+\tchar name[GIT_MAX_HEXSZ + 1];\n \n \tif (!patchlen)\n \t\treturn;\n \n-\tmemcpy(name, oid_to_hex(id), GIT_SHA1_HEXSZ + 1);\n+\tmemcpy(name, oid_to_hex(id), the_hash_algo->hexsz + 1);\n \tprintf(\"%s %s\\n\", oid_to_hex(result), name);\n }\n \n@@ -60,9 +61,9 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,\n {\n \tint patchlen = 0, found_next = 0;\n \tint before = -1, after = -1;\n-\tgit_SHA_CTX ctx;\n+\tgit_hash_ctx ctx;\n \n-\tgit_SHA1_Init(&ctx);\n+\tthe_hash_algo->init_fn(&ctx);\n \toidclr(result);\n \n \twhile (strbuf_getwholeline(line_buf, stdin, '\\n') != EOF) {\n@@ -122,7 +123,7 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,\n \t\t/* Compute the sha without whitespace */\n \t\tlen = remove_space(line);\n \t\tpatchlen += len;\n-\t\tgit_SHA1_Update(&ctx, line, len);\n+\t\tthe_hash_algo->update_fn(&ctx, line, len);\n \t}\n \n \tif (!found_next)\ndiff --git a/diff.c b/diff.c\nindex efe42b341a..bf51c94804 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -5978,7 +5978,7 @@ static void diff_summary(struct diff_options *opt, struct diff_filepair *p)\n }\n \n struct patch_id_t {\n-\tgit_SHA_CTX *ctx;\n+\tgit_hash_ctx *ctx;\n \tint patchlen;\n };\n \n@@ -5995,16 +5995,16 @@ static int remove_space(char *line, int len)\n \treturn dst - line;\n }\n \n-void flush_one_hunk(struct object_id *result, git_SHA_CTX *ctx)\n+void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx)\n {\n \tunsigned char hash[GIT_MAX_RAWSZ];\n \tunsigned short carry = 0;\n \tint i;\n \n-\tgit_SHA1_Final(hash, ctx);\n-\tgit_SHA1_Init(ctx);\n+\tthe_hash_algo->final_fn(hash, ctx);\n+\tthe_hash_algo->init_fn(ctx);\n \t/* 20-byte sum, with carry */\n-\tfor (i = 0; i < GIT_SHA1_RAWSZ; ++i) {\n+\tfor (i = 0; i < the_hash_algo->rawsz; ++i) {\n \t\tcarry += result->hash[i] + hash[i];\n \t\tresult->hash[i] = carry;\n \t\tcarry >>= 8;\n@@ -6018,21 +6018,21 @@ static void patch_id_consume(void *priv, char *line, unsigned long len)\n \n \tnew_len = remove_space(line, len);\n \n-\tgit_SHA1_Update(data->ctx, line, new_len);\n+\tthe_hash_algo->update_fn(data->ctx, line, new_len);\n \tdata->patchlen += new_len;\n }\n \n-static void patch_id_add_string(git_SHA_CTX *ctx, const char *str)\n+static void patch_id_add_string(git_hash_ctx *ctx, const char *str)\n {\n-\tgit_SHA1_Update(ctx, str, strlen(str));\n+\tthe_hash_algo->update_fn(ctx, str, strlen(str));\n }\n \n-static void patch_id_add_mode(git_SHA_CTX *ctx, unsigned mode)\n+static void patch_id_add_mode(git_hash_ctx *ctx, unsigned mode)\n {\n \t/* large enough for 2^32 in octal */\n \tchar buf[12];\n \tint len = xsnprintf(buf, sizeof(buf), \"%06o\", mode);\n-\tgit_SHA1_Update(ctx, buf, len);\n+\tthe_hash_algo->update_fn(ctx, buf, len);\n }\n \n /* returns 0 upon success, and writes result into oid */\n@@ -6040,10 +6040,10 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid\n {\n \tstruct diff_queue_struct *q = &diff_queued_diff;\n \tint i;\n-\tgit_SHA_CTX ctx;\n+\tgit_hash_ctx ctx;\n \tstruct patch_id_t data;\n \n-\tgit_SHA1_Init(&ctx);\n+\tthe_hash_algo->init_fn(&ctx);\n \tmemset(&data, 0, sizeof(struct patch_id_t));\n \tdata.ctx = &ctx;\n \toidclr(oid);\n@@ -6076,27 +6076,27 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid\n \t\tlen2 = remove_space(p->two->path, strlen(p->two->path));\n \t\tpatch_id_add_string(&ctx, \"diff--git\");\n \t\tpatch_id_add_string(&ctx, \"a/\");\n-\t\tgit_SHA1_Update(&ctx, p->one->path, len1);\n+\t\tthe_hash_algo->update_fn(&ctx, p->one->path, len1);\n \t\tpatch_id_add_string(&ctx, \"b/\");\n-\t\tgit_SHA1_Update(&ctx, p->two->path, len2);\n+\t\tthe_hash_algo->update_fn(&ctx, p->two->path, len2);\n \n \t\tif (p->one->mode == 0) {\n \t\t\tpatch_id_add_string(&ctx, \"newfilemode\");\n \t\t\tpatch_id_add_mode(&ctx, p->two->mode);\n \t\t\tpatch_id_add_string(&ctx, \"---/dev/null\");\n \t\t\tpatch_id_add_string(&ctx, \"+++b/\");\n-\t\t\tgit_SHA1_Update(&ctx, p->two->path, len2);\n+\t\t\tthe_hash_algo->update_fn(&ctx, p->two->path, len2);\n \t\t} else if (p->two->mode == 0) {\n \t\t\tpatch_id_add_string(&ctx, \"deletedfilemode\");\n \t\t\tpatch_id_add_mode(&ctx, p->one->mode);\n \t\t\tpatch_id_add_string(&ctx, \"---a/\");\n-\t\t\tgit_SHA1_Update(&ctx, p->one->path, len1);\n+\t\t\tthe_hash_algo->update_fn(&ctx, p->one->path, len1);\n \t\t\tpatch_id_add_string(&ctx, \"+++/dev/null\");\n \t\t} else {\n \t\t\tpatch_id_add_string(&ctx, \"---a/\");\n-\t\t\tgit_SHA1_Update(&ctx, p->one->path, len1);\n+\t\t\tthe_hash_algo->update_fn(&ctx, p->one->path, len1);\n \t\t\tpatch_id_add_string(&ctx, \"+++b/\");\n-\t\t\tgit_SHA1_Update(&ctx, p->two->path, len2);\n+\t\t\tthe_hash_algo->update_fn(&ctx, p->two->path, len2);\n \t\t}\n \n \t\tif (diff_header_only)\n@@ -6108,10 +6108,10 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid\n \n \t\tif (diff_filespec_is_binary(options->repo, p->one) ||\n \t\t    diff_filespec_is_binary(options->repo, p->two)) {\n-\t\t\tgit_SHA1_Update(&ctx, oid_to_hex(&p->one->oid),\n-\t\t\t\t\tGIT_SHA1_HEXSZ);\n-\t\t\tgit_SHA1_Update(&ctx, oid_to_hex(&p->two->oid),\n-\t\t\t\t\tGIT_SHA1_HEXSZ);\n+\t\t\tthe_hash_algo->update_fn(&ctx, oid_to_hex(&p->one->oid),\n+\t\t\t\t\tthe_hash_algo->hexsz);\n+\t\t\tthe_hash_algo->update_fn(&ctx, oid_to_hex(&p->two->oid),\n+\t\t\t\t\tthe_hash_algo->hexsz);\n \t\t\tcontinue;\n \t\t}\n \n@@ -6128,7 +6128,7 @@ static int diff_get_patch_id(struct diff_options *options, struct object_id *oid\n \t}\n \n \tif (!stable)\n-\t\tgit_SHA1_Final(oid->hash, &ctx);\n+\t\tthe_hash_algo->final_fn(oid->hash, &ctx);\n \n \treturn 0;\n }\ndiff --git a/diff.h b/diff.h\nindex c2c3056810..7f8f024feb 100644\n--- a/diff.h\n+++ b/diff.h\n@@ -438,7 +438,7 @@ int run_diff_index(struct rev_info *revs, int cached);\n \n int do_diff_cache(const struct object_id *, struct diff_options *);\n int diff_flush_patch_id(struct diff_options *, struct object_id *, int, int);\n-void flush_one_hunk(struct object_id *, git_SHA_CTX *);\n+void flush_one_hunk(struct object_id *result, git_hash_ctx *ctx);\n \n int diff_result_code(struct diff_options *, int);\n \n"},{"id":"380655","messageId":"20190818200427.870753-8-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 07/26] blame: remove needless comparison with GIT_SHA1_HEXSZ","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:08Z","receivedAt":"2019-08-18T20:05:38Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"When faking a working tree commit, we read in lines from MERGE_HEAD into\na strbuf.  Because the strbuf is NUL-terminated and get_oid_hex will\nfail if it unexpectedly encounters a NUL, the check for the length of\nthe line is unnecessary.  There is no optimization benefit from this\ncase, either, since on failure we call die.  Remove this check, since it\nis no longer needed.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n blame.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/blame.c b/blame.c\nindex 36a2e7ef11..6596d8de88 100644\n--- a/blame.c\n+++ b/blame.c\n@@ -144,7 +144,7 @@ static void append_merge_parents(struct repository *r,\n \n \twhile (!strbuf_getwholeline_fd(&line, merge_head, '\\n')) {\n \t\tstruct object_id oid;\n-\t\tif (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))\n+\t\tif (get_oid_hex(line.buf, &oid))\n \t\t\tdie(\"unknown line in '%s': %s\",\n \t\t\t    git_path_merge_head(r), line.buf);\n \t\ttail = append_parent(r, tail, &oid);\n"},{"id":"380656","messageId":"20190818200427.870753-12-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 11/26] combine-diff: replace GIT_SHA1_HEXSZ with the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:12Z","receivedAt":"2019-08-18T20:05:41Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n combine-diff.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/combine-diff.c b/combine-diff.c\nindex 3e49f3bda8..d5c4d839dc 100644\n--- a/combine-diff.c\n+++ b/combine-diff.c\n@@ -930,7 +930,7 @@ static void show_combined_header(struct combine_diff_path *elem,\n \t\t\t\t int show_file_header)\n {\n \tstruct diff_options *opt = &rev->diffopt;\n-\tint abbrev = opt->flags.full_index ? GIT_SHA1_HEXSZ : DEFAULT_ABBREV;\n+\tint abbrev = opt->flags.full_index ? the_hash_algo->hexsz : DEFAULT_ABBREV;\n \tconst char *a_prefix = opt->a_prefix ? opt->a_prefix : \"a/\";\n \tconst char *b_prefix = opt->b_prefix ? opt->b_prefix : \"b/\";\n \tconst char *c_meta = diff_get_color_opt(opt, DIFF_METAINFO);\n"},{"id":"380657","messageId":"20190818200427.870753-11-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 10/26] bundle: switch to use the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:11Z","receivedAt":"2019-08-18T20:05:43Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch a use of the constant 40 and a use of GIT_SHA1_HEXSZ to use\nthe_hash_algo instead.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n bundle.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/bundle.c b/bundle.c\nindex b5d21cd80f..a85ed3f7bc 100644\n--- a/bundle.c\n+++ b/bundle.c\n@@ -282,7 +282,7 @@ static int write_pack_data(int bundle_fd, struct rev_info *revs)\n \t\tstruct object *object = revs->pending.objects[i].item;\n \t\tif (object->flags & UNINTERESTING)\n \t\t\twrite_or_die(pack_objects.in, \"^\", 1);\n-\t\twrite_or_die(pack_objects.in, oid_to_hex(&object->oid), GIT_SHA1_HEXSZ);\n+\t\twrite_or_die(pack_objects.in, oid_to_hex(&object->oid), the_hash_algo->hexsz);\n \t\twrite_or_die(pack_objects.in, \"\\n\", 1);\n \t}\n \tclose(pack_objects.in);\n@@ -414,7 +414,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs)\n \t\t}\n \n \t\tref_count++;\n-\t\twrite_or_die(bundle_fd, oid_to_hex(&e->item->oid), 40);\n+\t\twrite_or_die(bundle_fd, oid_to_hex(&e->item->oid), the_hash_algo->hexsz);\n \t\twrite_or_die(bundle_fd, \" \", 1);\n \t\twrite_or_die(bundle_fd, display_ref, strlen(display_ref));\n \t\twrite_or_die(bundle_fd, \"\\n\", 1);\n"},{"id":"380658","messageId":"20190818200427.870753-10-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 09/26] connected: switch GIT_SHA1_HEXSZ to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:10Z","receivedAt":"2019-08-18T20:05:44Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch various uses of GIT_SHA1_HEXSZ to reference the_hash_algo\ninstead.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n connected.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/connected.c b/connected.c\nindex cd9b324afa..7cd3bc9979 100644\n--- a/connected.c\n+++ b/connected.c\n@@ -28,6 +28,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,\n \tstruct packed_git *new_pack = NULL;\n \tstruct transport *transport;\n \tsize_t base_len;\n+\tconst unsigned hexsz = the_hash_algo->hexsz;\n \n \tif (!opt)\n \t\topt = &defaults;\n@@ -99,7 +100,7 @@ int check_connected(oid_iterate_fn fn, void *cb_data,\n \n \tsigchain_push(SIGPIPE, SIG_IGN);\n \n-\tcommit[GIT_SHA1_HEXSZ] = '\\n';\n+\tcommit[hexsz] = '\\n';\n \tdo {\n \t\t/*\n \t\t * If index-pack already checked that:\n@@ -112,8 +113,8 @@ int check_connected(oid_iterate_fn fn, void *cb_data,\n \t\tif (new_pack && find_pack_entry_one(oid.hash, new_pack))\n \t\t\tcontinue;\n \n-\t\tmemcpy(commit, oid_to_hex(&oid), GIT_SHA1_HEXSZ);\n-\t\tif (write_in_full(rev_list.in, commit, GIT_SHA1_HEXSZ + 1) < 0) {\n+\t\tmemcpy(commit, oid_to_hex(&oid), hexsz);\n+\t\tif (write_in_full(rev_list.in, commit, hexsz + 1) < 0) {\n \t\t\tif (errno != EPIPE && errno != EINVAL)\n \t\t\t\terror_errno(_(\"failed write to rev-list\"));\n \t\t\terr = -1;\n"},{"id":"380659","messageId":"20190818200427.870753-6-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 05/26] builtin/blame: switch uses of GIT_SHA1_HEXSZ to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:06Z","receivedAt":"2019-08-18T20:05:44Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch several uses of GIT_SHA1_HEXSZ to the_hash_algo.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/blame.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex b6534d4dea..5a0c0c2312 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -460,7 +460,7 @@ static void emit_other(struct blame_scoreboard *sb, struct blame_entry *ent, int\n \n \tfor (cnt = 0; cnt < ent->num_lines; cnt++) {\n \t\tchar ch;\n-\t\tint length = (opt & OUTPUT_LONG_OBJECT_NAME) ? GIT_SHA1_HEXSZ : abbrev;\n+\t\tint length = (opt & OUTPUT_LONG_OBJECT_NAME) ? the_hash_algo->hexsz : abbrev;\n \n \t\tif (opt & OUTPUT_COLOR_LINE) {\n \t\t\tif (cnt > 0) {\n@@ -885,6 +885,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \tstruct range_set ranges;\n \tunsigned int range_i;\n \tlong anchor;\n+\tconst int hexsz = the_hash_algo->hexsz;\n \n \tsetup_default_color_by_age();\n \tgit_config(git_blame_config, &output_option);\n@@ -931,11 +932,11 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t} else if (show_progress < 0)\n \t\tshow_progress = isatty(2);\n \n-\tif (0 < abbrev && abbrev < GIT_SHA1_HEXSZ)\n+\tif (0 < abbrev && abbrev < hexsz)\n \t\t/* one more abbrev length is needed for the boundary commit */\n \t\tabbrev++;\n \telse if (!abbrev)\n-\t\tabbrev = GIT_SHA1_HEXSZ;\n+\t\tabbrev = hexsz;\n \n \tif (revs_file && read_ancestry(revs_file))\n \t\tdie_errno(\"reading graft file '%s' failed\", revs_file);\n"},{"id":"380660","messageId":"20190818200427.870753-7-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 06/26] builtin/rev-parse: switch to use the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:07Z","receivedAt":"2019-08-18T20:05:46Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch several hard-coded uses of the constant 40 to references to\nthe_hash_algo.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/rev-parse.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex f8bbe6d47e..308c67e4fc 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -593,6 +593,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \tconst char *name = NULL;\n \tstruct object_context unused;\n \tstruct strbuf buf = STRBUF_INIT;\n+\tconst int hexsz = the_hash_algo->hexsz;\n \n \tif (argc > 1 && !strcmp(\"--parseopt\", argv[1]))\n \t\treturn cmd_parseopt(argc - 1, argv + 1, prefix);\n@@ -730,8 +731,8 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tabbrev = strtoul(arg, NULL, 10);\n \t\t\t\tif (abbrev < MINIMUM_ABBREV)\n \t\t\t\t\tabbrev = MINIMUM_ABBREV;\n-\t\t\t\telse if (40 <= abbrev)\n-\t\t\t\t\tabbrev = 40;\n+\t\t\t\telse if (hexsz <= abbrev)\n+\t\t\t\t\tabbrev = hexsz;\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--sq\")) {\n"},{"id":"380661","messageId":"20190818200427.870753-17-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 16/26] pack-write: use hash_to_hex when writing checksums","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:17Z","receivedAt":"2019-08-18T20:05:47Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Pack checksums always use the current hash algorithm in use, so switch\nfrom sha1_to_hex to hash_to_hex.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n pack-write.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/pack-write.c b/pack-write.c\nindex 29d17a9bec..f0017beb9d 100644\n--- a/pack-write.c\n+++ b/pack-write.c\n@@ -349,7 +349,7 @@ void finish_tmp_packfile(struct strbuf *name_buffer,\n \t\t\t struct pack_idx_entry **written_list,\n \t\t\t uint32_t nr_written,\n \t\t\t struct pack_idx_option *pack_idx_opts,\n-\t\t\t unsigned char sha1[])\n+\t\t\t unsigned char hash[])\n {\n \tconst char *idx_tmp_name;\n \tint basename_len = name_buffer->len;\n@@ -358,18 +358,18 @@ void finish_tmp_packfile(struct strbuf *name_buffer,\n \t\tdie_errno(\"unable to make temporary pack file readable\");\n \n \tidx_tmp_name = write_idx_file(NULL, written_list, nr_written,\n-\t\t\t\t      pack_idx_opts, sha1);\n+\t\t\t\t      pack_idx_opts, hash);\n \tif (adjust_shared_perm(idx_tmp_name))\n \t\tdie_errno(\"unable to make temporary index file readable\");\n \n-\tstrbuf_addf(name_buffer, \"%s.pack\", sha1_to_hex(sha1));\n+\tstrbuf_addf(name_buffer, \"%s.pack\", hash_to_hex(hash));\n \n \tif (rename(pack_tmp_name, name_buffer->buf))\n \t\tdie_errno(\"unable to rename temporary pack file\");\n \n \tstrbuf_setlen(name_buffer, basename_len);\n \n-\tstrbuf_addf(name_buffer, \"%s.idx\", sha1_to_hex(sha1));\n+\tstrbuf_addf(name_buffer, \"%s.idx\", hash_to_hex(hash));\n \tif (rename(idx_tmp_name, name_buffer->buf))\n \t\tdie_errno(\"unable to rename temporary index file\");\n \n"},{"id":"380662","messageId":"20190818200427.870753-18-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 17/26] builtin/repack: write object IDs of the proper length","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:18Z","receivedAt":"2019-08-18T20:05:50Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Use the_hash_algo when calling xwrite with a hex object ID so that the\nproper amount of data is written.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/repack.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex 632c0c0a79..5830f796e0 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -190,7 +190,7 @@ static int write_oid(const struct object_id *oid, struct packed_git *pack,\n \t\t\tdie(_(\"could not start pack-objects to repack promisor objects\"));\n \t}\n \n-\txwrite(cmd->in, oid_to_hex(oid), GIT_SHA1_HEXSZ);\n+\txwrite(cmd->in, oid_to_hex(oid), the_hash_algo->hexsz);\n \txwrite(cmd->in, \"\\n\", 1);\n \treturn 0;\n }\n"},{"id":"380663","messageId":"20190818200427.870753-20-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 19/26] cache: remove null_sha1","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:20Z","receivedAt":"2019-08-18T20:05:51Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"All of the existing uses of null_sha1 can be converted into uses of\nnull_oid, so do so.  Remove null_sha1 and is_null_sha1, and define\nis_null_oid in terms of null_oid.  This also has the additional benefit\nof removing several uses of sha1_to_hex.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/clone.c             | 2 +-\n builtin/submodule--helper.c | 2 +-\n cache.h                     | 8 +-------\n sha1-file.c                 | 1 -\n 4 files changed, 3 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex f665b28ccc..eabd02846a 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -785,7 +785,7 @@ static int checkout(int submodule_progress)\n \tif (write_locked_index(&the_index, &lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n-\terr |= run_hook_le(NULL, \"post-checkout\", sha1_to_hex(null_sha1),\n+\terr |= run_hook_le(NULL, \"post-checkout\", oid_to_hex(&null_oid),\n \t\t\t   oid_to_hex(&oid), \"1\", NULL);\n \n \tif (!err && (option_recurse_submodules.nr > 0)) {\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex 909e77e802..8a6f2abce4 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -424,7 +424,7 @@ static int module_list(int argc, const char **argv, const char *prefix)\n \t\tconst struct cache_entry *ce = list.entries[i];\n \n \t\tif (ce_stage(ce))\n-\t\t\tprintf(\"%06o %s U\\t\", ce->ce_mode, sha1_to_hex(null_sha1));\n+\t\t\tprintf(\"%06o %s U\\t\", ce->ce_mode, oid_to_hex(&null_oid));\n \t\telse\n \t\t\tprintf(\"%06o %s %d\\t\", ce->ce_mode,\n \t\t\t       oid_to_hex(&ce->oid), ce_stage(ce));\ndiff --git a/cache.h b/cache.h\nindex b1da1ab08f..79efd2168f 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1029,7 +1029,6 @@ const char *repo_find_unique_abbrev(struct repository *r, const struct object_id\n int repo_find_unique_abbrev_r(struct repository *r, char *hex, const struct object_id *oid, int len);\n #define find_unique_abbrev_r(hex, oid, len) repo_find_unique_abbrev_r(the_repository, hex, oid, len)\n \n-extern const unsigned char null_sha1[GIT_MAX_RAWSZ];\n extern const struct object_id null_oid;\n \n static inline int hashcmp(const unsigned char *sha1, const unsigned char *sha2)\n@@ -1064,14 +1063,9 @@ static inline int oideq(const struct object_id *oid1, const struct object_id *oi\n \treturn hasheq(oid1->hash, oid2->hash);\n }\n \n-static inline int is_null_sha1(const unsigned char *sha1)\n-{\n-\treturn hasheq(sha1, null_sha1);\n-}\n-\n static inline int is_null_oid(const struct object_id *oid)\n {\n-\treturn hasheq(oid->hash, null_sha1);\n+\treturn oideq(oid, &null_oid);\n }\n \n static inline void hashcpy(unsigned char *sha_dst, const unsigned char *sha_src)\ndiff --git a/sha1-file.c b/sha1-file.c\nindex 487ea35d2d..0ea28f7da3 100644\n--- a/sha1-file.c\n+++ b/sha1-file.c\n@@ -55,7 +55,6 @@\n \t\"\\x6f\\xe1\\x41\\xf7\\x74\\x91\\x20\\xa3\\x03\\x72\" \\\n \t\"\\x18\\x13\"\n \n-const unsigned char null_sha1[GIT_MAX_RAWSZ];\n const struct object_id null_oid;\n static const struct object_id empty_tree_oid = {\n \tEMPTY_TREE_SHA1_BIN_LITERAL\n"},{"id":"380664","messageId":"20190818200427.870753-19-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 18/26] builtin/worktree: switch null_sha1 to null_oid","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:19Z","receivedAt":"2019-08-18T20:05:51Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch the remaining use of null_sha1 to null_oid.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/worktree.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/worktree.c b/builtin/worktree.c\nindex a5bb02b207..0c0df3b0b8 100644\n--- a/builtin/worktree.c\n+++ b/builtin/worktree.c\n@@ -350,7 +350,7 @@ static int add_worktree(const char *path, const char *refname,\n \t */\n \tstrbuf_reset(&sb);\n \tstrbuf_addf(&sb, \"%s/HEAD\", sb_repo.buf);\n-\twrite_file(sb.buf, \"%s\", sha1_to_hex(null_sha1));\n+\twrite_file(sb.buf, \"%s\", oid_to_hex(&null_oid));\n \tstrbuf_reset(&sb);\n \tstrbuf_addf(&sb, \"%s/commondir\", sb_repo.buf);\n \twrite_file(sb.buf, \"../..\");\n"},{"id":"380665","messageId":"20190818200427.870753-21-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 20/26] wt-status: convert struct wt_status to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:21Z","receivedAt":"2019-08-18T20:05:54Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Change struct wt_status to use struct object_id instead of an array of\nunsigned char.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/commit.c | 4 ++--\n wt-status.c      | 2 +-\n wt-status.h      | 2 +-\n 3 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex ae7aaf6dc6..e588bc6ad3 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -510,7 +510,7 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int\n \ts->nowarn = nowarn;\n \ts->is_initial = get_oid(s->reference, &oid) ? 1 : 0;\n \tif (!s->is_initial)\n-\t\thashcpy(s->sha1_commit, oid.hash);\n+\t\toidcpy(&s->oid_commit, &oid);\n \ts->status_format = status_format;\n \ts->ignore_submodule_arg = ignore_submodule_arg;\n \n@@ -1406,7 +1406,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \n \ts.is_initial = get_oid(s.reference, &oid) ? 1 : 0;\n \tif (!s.is_initial)\n-\t\thashcpy(s.sha1_commit, oid.hash);\n+\t\toidcpy(&s.oid_commit, &oid);\n \n \ts.ignore_submodule_arg = ignore_submodule_arg;\n \ts.status_format = status_format;\ndiff --git a/wt-status.c b/wt-status.c\nindex 9f6c65a580..7cf220fed4 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -2025,7 +2025,7 @@ static void wt_porcelain_v2_print_tracking(struct wt_status *s)\n \tchar eol = s->null_termination ? '\\0' : '\\n';\n \n \tfprintf(s->fp, \"# branch.oid %s%c\",\n-\t\t\t(s->is_initial ? \"(initial)\" : sha1_to_hex(s->sha1_commit)),\n+\t\t\t(s->is_initial ? \"(initial)\" : oid_to_hex(&s->oid_commit)),\n \t\t\teol);\n \n \tif (!s->branch)\ndiff --git a/wt-status.h b/wt-status.h\nindex 77dad5b920..71c3f25f43 100644\n--- a/wt-status.h\n+++ b/wt-status.h\n@@ -116,7 +116,7 @@ struct wt_status {\n \tint rename_limit;\n \tenum wt_status_format status_format;\n \tstruct wt_status_state state;\n-\tunsigned char sha1_commit[GIT_MAX_RAWSZ]; /* when not Initial */\n+\tstruct object_id oid_commit; /* when not Initial */\n \n \t/* These are computed during processing of the individual sections */\n \tint committable;\n"},{"id":"380667","messageId":"20190818200427.870753-16-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 15/26] sequencer: convert to use the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:16Z","receivedAt":"2019-08-18T20:05:54Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert several uses of GIT_SHA1_HEXSZ constants to be references to\nthe_hash_algo.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n sequencer.c | 6 +++---\n 1 file changed, 3 insertions(+), 3 deletions(-)\n\ndiff --git a/sequencer.c b/sequencer.c\nindex 34ebf8ed94..4d25e79137 100644\n--- a/sequencer.c\n+++ b/sequencer.c\n@@ -3568,7 +3568,7 @@ static int do_merge(struct repository *r,\n \t\tgoto leave_merge;\n \t}\n \n-\twrite_message(oid_to_hex(&merge_commit->object.oid), GIT_SHA1_HEXSZ,\n+\twrite_message(oid_to_hex(&merge_commit->object.oid), the_hash_algo->hexsz,\n \t\t      git_path_merge_head(r), 0);\n \twrite_message(\"no-ff\", 5, git_path_merge_mode(r), 0);\n \n@@ -4487,7 +4487,7 @@ static const char *label_oid(struct object_id *oid, const char *label,\n \t\tchar *p;\n \n \t\tstrbuf_reset(&state->buf);\n-\t\tstrbuf_grow(&state->buf, GIT_SHA1_HEXSZ);\n+\t\tstrbuf_grow(&state->buf, GIT_MAX_HEXSZ);\n \t\tlabel = p = state->buf.buf;\n \n \t\tfind_unique_abbrev_r(p, oid, default_abbrev);\n@@ -4500,7 +4500,7 @@ static const char *label_oid(struct object_id *oid, const char *label,\n \t\t\tsize_t i = strlen(p) + 1;\n \n \t\t\toid_to_hex_r(p, oid);\n-\t\t\tfor (; i < GIT_SHA1_HEXSZ; i++) {\n+\t\t\tfor (; i < the_hash_algo->hexsz; i++) {\n \t\t\t\tchar save = p[i];\n \t\t\t\tp[i] = '\\0';\n \t\t\t\tif (!hashmap_get_from_hash(&state->labels,\n"},{"id":"380666","messageId":"20190818200427.870753-13-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 12/26] config: use the_hash_algo in abbrev comparison","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:13Z","receivedAt":"2019-08-18T20:05:55Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch one use of a hard-coded 40 constant to use the_hash_algo.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n config.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/config.c b/config.c\nindex 3900e4947b..b0f79aab21 100644\n--- a/config.c\n+++ b/config.c\n@@ -1204,7 +1204,7 @@ static int git_default_core_config(const char *var, const char *value, void *cb)\n \t\t\tdefault_abbrev = -1;\n \t\telse {\n \t\t\tint abbrev = git_config_int(var, value);\n-\t\t\tif (abbrev < minimum_abbrev || abbrev > 40)\n+\t\t\tif (abbrev < minimum_abbrev || abbrev > the_hash_algo->hexsz)\n \t\t\t\treturn error(_(\"abbrev length out of range: %d\"), abbrev);\n \t\t\tdefault_abbrev = abbrev;\n \t\t}\n"},{"id":"380668","messageId":"20190818200427.870753-22-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 21/26] packfile: replace sha1_to_hex","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:22Z","receivedAt":"2019-08-18T20:05:56Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Replace a use of sha1_to_hex with hash_to_hex so that this code works\nwith a hash algorithm other than SHA-1.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n packfile.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex fc43a6c52c..52dea88997 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -19,12 +19,12 @@\n #include \"commit-graph.h\"\n \n char *odb_pack_name(struct strbuf *buf,\n-\t\t    const unsigned char *sha1,\n+\t\t    const unsigned char *hash,\n \t\t    const char *ext)\n {\n \tstrbuf_reset(buf);\n \tstrbuf_addf(buf, \"%s/pack/pack-%s.%s\", get_object_directory(),\n-\t\t    sha1_to_hex(sha1), ext);\n+\t\t    hash_to_hex(hash), ext);\n \treturn buf->buf;\n }\n \n"},{"id":"380669","messageId":"20190818200427.870753-15-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 14/26] bisect: switch to using the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:15Z","receivedAt":"2019-08-18T20:05:57Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Instead of using GIT_SHA1_HEXSZ, use the_hash_algo so that the code is\nhash size independent.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n bisect.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex e87ac29a51..e81c91d02c 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -707,7 +707,7 @@ static int bisect_checkout(const struct object_id *bisect_rev, int no_checkout)\n {\n \tchar bisect_rev_hex[GIT_MAX_HEXSZ + 1];\n \n-\tmemcpy(bisect_rev_hex, oid_to_hex(bisect_rev), GIT_SHA1_HEXSZ + 1);\n+\tmemcpy(bisect_rev_hex, oid_to_hex(bisect_rev), the_hash_algo->hexsz + 1);\n \tupdate_ref(NULL, \"BISECT_EXPECTED_REV\", bisect_rev, NULL, 0, UPDATE_REFS_DIE_ON_ERR);\n \n \targv_checkout[2] = bisect_rev_hex;\n"},{"id":"380670","messageId":"20190818200427.870753-23-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 22/26] builtin/index-pack: replace sha1_to_hex","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:23Z","receivedAt":"2019-08-18T20:05:58Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Since sha1_to_hex is limited to SHA-1, replace it with hash_to_hex so\nthis code works with other algorithms.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/index-pack.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/index-pack.c b/builtin/index-pack.c\nindex 0d55f73b0b..2abd550ce2 100644\n--- a/builtin/index-pack.c\n+++ b/builtin/index-pack.c\n@@ -1490,11 +1490,11 @@ static void final(const char *final_pack_name, const char *curr_pack_name,\n \t}\n \n \tif (!from_stdin) {\n-\t\tprintf(\"%s\\n\", sha1_to_hex(hash));\n+\t\tprintf(\"%s\\n\", hash_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(hash));\n+\t\tstrbuf_addf(&buf, \"%s\\t%s\\n\", report, hash_to_hex(hash));\n \t\twrite_or_die(1, buf.buf, buf.len);\n \t\tstrbuf_release(&buf);\n \n"},{"id":"380671","messageId":"20190818200427.870753-26-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 25/26] builtin/show-index: replace sha1_to_hex","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:26Z","receivedAt":"2019-08-18T20:05:59Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"In this code path, we use sha1_to_hex to display the contents of a v1\npack index.  While we plan to switch to v3 indices for SHA-256, the v1\npack indices still function, so to support both algorithms, switch\nsha1_to_hex to hash_to_hex.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/show-index.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex e95b84e8eb..0826f6a5a2 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -42,7 +42,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)\n \t\t\tif (fread(entry, 4 + hashsz, 1, stdin) != 1)\n \t\t\t\tdie(\"unable to read entry %u/%u\", i, nr);\n \t\t\toffset = ntohl(entry[0]);\n-\t\t\tprintf(\"%u %s\\n\", offset, sha1_to_hex((void *)(entry+1)));\n+\t\t\tprintf(\"%u %s\\n\", offset, hash_to_hex((void *)(entry+1)));\n \t\t}\n \t} else {\n \t\tunsigned off64_nr = 0;\n"},{"id":"380672","messageId":"20190818200427.870753-25-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 24/26] rerere: replace sha1_to_hex","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:25Z","receivedAt":"2019-08-18T20:06:01Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Replace the uses of sha1_to_hex in this function with hash_to_hex to\nallow the use of SHA-256 as well.  Rename a variable since it is no\nlonger limited to SHA-1.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n rerere.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex 17abb47321..3e51fdfe58 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -52,7 +52,7 @@ static void free_rerere_id(struct string_list_item *item)\n \n static const char *rerere_id_hex(const struct rerere_id *id)\n {\n-\treturn sha1_to_hex(id->collection->hash);\n+\treturn hash_to_hex(id->collection->hash);\n }\n \n static void fit_variant(struct rerere_dir *rr_dir, int variant)\n@@ -115,7 +115,7 @@ static int is_rr_file(const char *name, const char *filename, int *variant)\n static void scan_rerere_dir(struct rerere_dir *rr_dir)\n {\n \tstruct dirent *de;\n-\tDIR *dir = opendir(git_path(\"rr-cache/%s\", sha1_to_hex(rr_dir->hash)));\n+\tDIR *dir = opendir(git_path(\"rr-cache/%s\", hash_to_hex(rr_dir->hash)));\n \n \tif (!dir)\n \t\treturn;\n@@ -186,9 +186,9 @@ static struct rerere_id *new_rerere_id_hex(char *hex)\n \treturn id;\n }\n \n-static struct rerere_id *new_rerere_id(unsigned char *sha1)\n+static struct rerere_id *new_rerere_id(unsigned char *hash)\n {\n-\treturn new_rerere_id_hex(sha1_to_hex(sha1));\n+\treturn new_rerere_id_hex(hash_to_hex(hash));\n }\n \n /*\n"},{"id":"380673","messageId":"20190818200427.870753-9-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 08/26] show-index: switch hard-coded constants to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:09Z","receivedAt":"2019-08-18T20:06:01Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"show-index uses a variety of hard-coded constants to enumerate the\nvalues in pack indices.  Switch these hard-coded constants to use\nthe_hash_algo or GIT_MAX_RAWSZ, as appropriate, and convert one instance\nof an unsigned char array to struct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/show-index.c | 11 ++++++-----\n 1 file changed, 6 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/show-index.c b/builtin/show-index.c\nindex a6e678809e..e95b84e8eb 100644\n--- a/builtin/show-index.c\n+++ b/builtin/show-index.c\n@@ -11,6 +11,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)\n \tunsigned nr;\n \tunsigned int version;\n \tstatic unsigned int top_index[256];\n+\tconst unsigned hashsz = the_hash_algo->rawsz;\n \n \tif (argc != 1)\n \t\tusage(show_index_usage);\n@@ -36,9 +37,9 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)\n \t}\n \tif (version == 1) {\n \t\tfor (i = 0; i < nr; i++) {\n-\t\t\tunsigned int offset, entry[6];\n+\t\t\tunsigned int offset, entry[(GIT_MAX_RAWSZ + 4) / sizeof(unsigned int)];\n \n-\t\t\tif (fread(entry, 4 + 20, 1, stdin) != 1)\n+\t\t\tif (fread(entry, 4 + hashsz, 1, stdin) != 1)\n \t\t\t\tdie(\"unable to read entry %u/%u\", i, nr);\n \t\t\toffset = ntohl(entry[0]);\n \t\t\tprintf(\"%u %s\\n\", offset, sha1_to_hex((void *)(entry+1)));\n@@ -46,13 +47,13 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)\n \t} else {\n \t\tunsigned off64_nr = 0;\n \t\tstruct {\n-\t\t\tunsigned char sha1[20];\n+\t\t\tstruct object_id oid;\n \t\t\tuint32_t crc;\n \t\t\tuint32_t off;\n \t\t} *entries;\n \t\tALLOC_ARRAY(entries, nr);\n \t\tfor (i = 0; i < nr; i++)\n-\t\t\tif (fread(entries[i].sha1, 20, 1, stdin) != 1)\n+\t\t\tif (fread(entries[i].oid.hash, hashsz, 1, stdin) != 1)\n \t\t\t\tdie(\"unable to read sha1 %u/%u\", i, nr);\n \t\tfor (i = 0; i < nr; i++)\n \t\t\tif (fread(&entries[i].crc, 4, 1, stdin) != 1)\n@@ -77,7 +78,7 @@ int cmd_show_index(int argc, const char **argv, const char *prefix)\n \t\t\t}\n \t\t\tprintf(\"%\" PRIuMAX \" %s (%08\"PRIx32\")\\n\",\n \t\t\t       (uintmax_t) offset,\n-\t\t\t       sha1_to_hex(entries[i].sha1),\n+\t\t\t       oid_to_hex(&entries[i].oid),\n \t\t\t       ntohl(entries[i].crc));\n \t\t}\n \t\tfree(entries);\n"},{"id":"380674","messageId":"20190818200427.870753-24-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 23/26] builtin/receive-pack: replace sha1_to_hex","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:24Z","receivedAt":"2019-08-18T20:06:03Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Since sha1_to_hex is limited to SHA-1, replace it with hash_to_hex.\nRename several variables to indicate that they can contain any hash.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/receive-pack.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 402edf34d8..411e0b4d99 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -466,7 +466,7 @@ static char *prepare_push_cert_nonce(const char *path, timestamp_t stamp)\n \tstrbuf_release(&buf);\n \n \t/* RFC 2104 5. HMAC-SHA1-80 */\n-\tstrbuf_addf(&buf, \"%\"PRItime\"-%.*s\", stamp, (int)the_hash_algo->hexsz, sha1_to_hex(hash));\n+\tstrbuf_addf(&buf, \"%\"PRItime\"-%.*s\", stamp, (int)the_hash_algo->hexsz, hash_to_hex(hash));\n \treturn strbuf_detach(&buf, NULL);\n }\n \n@@ -968,7 +968,7 @@ static const char *push_to_deploy(unsigned char *sha1,\n \tif (run_command(&child))\n \t\treturn \"Working directory has staged changes\";\n \n-\tread_tree[3] = sha1_to_hex(sha1);\n+\tread_tree[3] = hash_to_hex(sha1);\n \tchild_process_init(&child);\n \tchild.argv = read_tree;\n \tchild.env = env->argv;\n@@ -985,13 +985,13 @@ static const char *push_to_deploy(unsigned char *sha1,\n \n static const char *push_to_checkout_hook = \"push-to-checkout\";\n \n-static const char *push_to_checkout(unsigned char *sha1,\n+static const char *push_to_checkout(unsigned char *hash,\n \t\t\t\t    struct argv_array *env,\n \t\t\t\t    const char *work_tree)\n {\n \targv_array_pushf(env, \"GIT_WORK_TREE=%s\", absolute_path(work_tree));\n \tif (run_hook_le(env->argv, push_to_checkout_hook,\n-\t\t\tsha1_to_hex(sha1), NULL))\n+\t\t\thash_to_hex(hash), NULL))\n \t\treturn \"push-to-checkout hook declined\";\n \telse\n \t\treturn NULL;\n"},{"id":"380675","messageId":"20190818200427.870753-27-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 26/26] midx: switch to using the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:27Z","receivedAt":"2019-08-18T20:06:04Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Instead of hard-coding the hash size, use the_hash_algo to look up the\nhash size at runtime.  Remove the #define constant which was used to\nhold the hash length, since writing the expression with the_hash_algo\nprovide enough documentary value on its own.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n midx.c | 11 +++++------\n 1 file changed, 5 insertions(+), 6 deletions(-)\n\ndiff --git a/midx.c b/midx.c\nindex d649644420..f29afc0d2d 100644\n--- a/midx.c\n+++ b/midx.c\n@@ -19,8 +19,7 @@\n #define MIDX_BYTE_NUM_PACKS 8\n #define MIDX_HASH_VERSION 1\n #define MIDX_HEADER_SIZE 12\n-#define MIDX_HASH_LEN 20\n-#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + MIDX_HASH_LEN)\n+#define MIDX_MIN_SIZE (MIDX_HEADER_SIZE + the_hash_algo->rawsz)\n \n #define MIDX_MAX_CHUNKS 5\n #define MIDX_CHUNK_ALIGNMENT 4\n@@ -93,7 +92,7 @@ struct multi_pack_index *load_multi_pack_index(const char *object_dir, int local\n \thash_version = m->data[MIDX_BYTE_HASH_VERSION];\n \tif (hash_version != MIDX_HASH_VERSION)\n \t\tdie(_(\"hash version %u does not match\"), hash_version);\n-\tm->hash_len = MIDX_HASH_LEN;\n+\tm->hash_len = the_hash_algo->rawsz;\n \n \tm->num_chunks = m->data[MIDX_BYTE_NUM_CHUNKS];\n \n@@ -234,7 +233,7 @@ int prepare_midx_pack(struct repository *r, struct multi_pack_index *m, uint32_t\n int bsearch_midx(const struct object_id *oid, struct multi_pack_index *m, uint32_t *result)\n {\n \treturn bsearch_hash(oid->hash, m->chunk_oid_fanout, m->chunk_oid_lookup,\n-\t\t\t    MIDX_HASH_LEN, result);\n+\t\t\t    the_hash_algo->rawsz, result);\n }\n \n struct object_id *nth_midxed_object_oid(struct object_id *oid,\n@@ -928,7 +927,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *\n \n \tcur_chunk++;\n \tchunk_ids[cur_chunk] = MIDX_CHUNKID_OBJECTOFFSETS;\n-\tchunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * MIDX_HASH_LEN;\n+\tchunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * the_hash_algo->rawsz;\n \n \tcur_chunk++;\n \tchunk_offsets[cur_chunk] = chunk_offsets[cur_chunk - 1] + nr_entries * MIDX_CHUNK_OFFSET_WIDTH;\n@@ -976,7 +975,7 @@ static int write_midx_internal(const char *object_dir, struct multi_pack_index *\n \t\t\t\tbreak;\n \n \t\t\tcase MIDX_CHUNKID_OIDLOOKUP:\n-\t\t\t\twritten += write_midx_oid_lookup(f, MIDX_HASH_LEN, entries, nr_entries);\n+\t\t\t\twritten += write_midx_oid_lookup(f, the_hash_algo->rawsz, entries, nr_entries);\n \t\t\t\tbreak;\n \n \t\t\tcase MIDX_CHUNKID_OBJECTOFFSETS:\n"},{"id":"380676","messageId":"20190818200427.870753-14-sandals@crustytoothpaste.net","threadId":"51668","inReplyTo":"20190818200427.870753-1-sandals@crustytoothpaste.net","subject":"[PATCH 13/26] sha1-lookup: switch hard-coded constants to the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-18T20:04:14Z","receivedAt":"2019-08-18T20:06:05Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch a hard-coded 18 to be a reference to the_hash_algo.  Rename the\nsha1 parameter to be called hash instead.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n sha1-lookup.c | 8 ++++----\n 1 file changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/sha1-lookup.c b/sha1-lookup.c\nindex 796ab68da8..93d9af0805 100644\n--- a/sha1-lookup.c\n+++ b/sha1-lookup.c\n@@ -50,7 +50,7 @@ static uint32_t take2(const unsigned char *sha1)\n  * The sha1 of element i (between 0 and nr - 1) should be returned\n  * by \"fn(i, table)\".\n  */\n-int sha1_pos(const unsigned char *sha1, void *table, size_t nr,\n+int sha1_pos(const unsigned char *hash, void *table, size_t nr,\n \t     sha1_access_fn fn)\n {\n \tsize_t hi = nr;\n@@ -63,10 +63,10 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,\n \tif (nr != 1) {\n \t\tsize_t lov, hiv, miv, ofs;\n \n-\t\tfor (ofs = 0; ofs < 18; ofs += 2) {\n+\t\tfor (ofs = 0; ofs < the_hash_algo->rawsz - 2; ofs += 2) {\n \t\t\tlov = take2(fn(0, table) + ofs);\n \t\t\thiv = take2(fn(nr - 1, table) + ofs);\n-\t\t\tmiv = take2(sha1 + ofs);\n+\t\t\tmiv = take2(hash + ofs);\n \t\t\tif (miv < lov)\n \t\t\t\treturn -1;\n \t\t\tif (hiv < miv)\n@@ -88,7 +88,7 @@ int sha1_pos(const unsigned char *sha1, void *table, size_t nr,\n \n \tdo {\n \t\tint cmp;\n-\t\tcmp = hashcmp(fn(mi, table), sha1);\n+\t\tcmp = hashcmp(fn(mi, table), hash);\n \t\tif (!cmp)\n \t\t\treturn mi;\n \t\tif (cmp > 0)\n"},{"id":"380860","messageId":"1d3b46de-155a-6072-5e44-2622ac821230@web.de","threadId":"51668","inReplyTo":"20190818200427.870753-3-sandals@crustytoothpaste.net","subject":"Re: [PATCH 02/26] patch-id: convert to use the_hash_algo","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-08-20T21:12:00Z","receivedAt":"2019-08-20T21:12:18Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Am 18.08.19 um 22:04 schrieb brian m. carlson:\n> diff --git a/builtin/patch-id.c b/builtin/patch-id.c\n> index bd28b80b2d..3059e525b8 100644\n> --- a/builtin/patch-id.c\n> +++ b/builtin/patch-id.c\n> @@ -1,15 +1,16 @@\n> +#include \"cache.h\"\n>  #include \"builtin.h\"\n>  #include \"config.h\"\n>  #include \"diff.h\"\n>\n>  static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)\n>  {\n> -\tchar name[50];\n> +\tchar name[GIT_MAX_HEXSZ + 1];\n>\n>  \tif (!patchlen)\n>  \t\treturn;\n>\n> -\tmemcpy(name, oid_to_hex(id), GIT_SHA1_HEXSZ + 1);\n> +\tmemcpy(name, oid_to_hex(id), the_hash_algo->hexsz + 1);\n>  \tprintf(\"%s %s\\n\", oid_to_hex(result), name);\n>  }\n\nOK.  But why do we need our own buffer?  oid_to_hex() provides four of\nthem for us, so the body could become just:\n\n\tif (patchlen)\n\t\tprintf(\"%s %s\\n\", oid_to_hex(result), oid_to_hex(id));\n\n\nRight?  Well, this buffer comes from f97672225b («Add \"git-patch-id\"\nprogram to generate patch ID's.», 2005-06-23), which predates the\nintroduction of the four-buffer feature in dcb3450fd8 («sha1_to_hex()\nusage cleanup», 2006-05-03).\n\nAnd with 30e12b924b («patch-id: make it stable against hunk reordering»,\n2014-04-27) the function's name became a bit misleading, because it\nstopped being responsible for flushing the hash calculation.\n\nSo perhaps this on top?  (Or squash it in, if you like, but it's\ncertainly not worth a re-roll.)\n\n-- >8 --\nSubject: [PATCH] patch-id: inline flush_current_id()\n\nThe function hasn't been flushing the hash calculation since 30e12b924b\n(\"patch-id: make it stable against hunk reordering\", 2014-04-27), and\nthere is no need for a private copy of the second hexadecimal hash value\nsince dcb3450fd8 (\"sha1_to_hex() usage cleanup\", 2006-05-03) added\nsupport for up to four sha1_to_hex() results to be used in the same\nprintf(3) call, which oid_to_hex() inherited.  So print both hash values\ndirectly and get rid of the function with the outdated name.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n builtin/patch-id.c | 16 ++--------------\n 1 file changed, 2 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/patch-id.c b/builtin/patch-id.c\nindex 3059e525b8..d328714af7 100644\n--- a/builtin/patch-id.c\n+++ b/builtin/patch-id.c\n@@ -3,17 +3,6 @@\n #include \"config.h\"\n #include \"diff.h\"\n\n-static void flush_current_id(int patchlen, struct object_id *id, struct object_id *result)\n-{\n-\tchar name[GIT_MAX_HEXSZ + 1];\n-\n-\tif (!patchlen)\n-\t\treturn;\n-\n-\tmemcpy(name, oid_to_hex(id), the_hash_algo->hexsz + 1);\n-\tprintf(\"%s %s\\n\", oid_to_hex(result), name);\n-}\n-\n static int remove_space(char *line)\n {\n \tchar *src = line;\n@@ -137,13 +126,12 @@ static int get_one_patchid(struct object_id *next_oid, struct object_id *result,\n static void generate_id_list(int stable)\n {\n \tstruct object_id oid, n, result;\n-\tint patchlen;\n \tstruct strbuf line_buf = STRBUF_INIT;\n\n \toidclr(&oid);\n \twhile (!feof(stdin)) {\n-\t\tpatchlen = get_one_patchid(&n, &result, &line_buf, stable);\n-\t\tflush_current_id(patchlen, &oid, &result);\n+\t\tif (get_one_patchid(&n, &result, &line_buf, stable))\n+\t\t\tprintf(\"%s %s\\n\", oid_to_hex(&result), oid_to_hex(&oid));\n \t\toidcpy(&oid, &n);\n \t}\n \tstrbuf_release(&line_buf);\n--\n2.23.0\n"},{"id":"380867","messageId":"20190820223606.GJ365197@genre.crustytoothpaste.net","threadId":"51668","inReplyTo":"1d3b46de-155a-6072-5e44-2622ac821230@web.de","subject":"Re: [PATCH 02/26] patch-id: convert to use the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-20T22:36:06Z","receivedAt":"2019-08-20T22:36:18Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2019-08-20 at 21:12:00, René Scharfe wrote:\n> So perhaps this on top?  (Or squash it in, if you like, but it's\n> certainly not worth a re-roll.)\n\nYeah, this seems sensible.  I'll include it if I do a re-roll.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"380933","messageId":"4f6b781b-68b8-5bc4-92a2-67caff32024f@gmail.com","threadId":"51668","inReplyTo":"20190818200427.870753-27-sandals@crustytoothpaste.net","subject":"Re: [PATCH 26/26] midx: switch to using the_hash_algo","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-08-22T14:04:16Z","receivedAt":"2019-08-22T14:04:20Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/18/2019 4:04 PM, brian m. carlson wrote:\n> Instead of hard-coding the hash size, use the_hash_algo to look up the\n> hash size at runtime.  Remove the #define constant which was used to\n> hold the hash length, since writing the expression with the_hash_algo\n> provide enough documentary value on its own.\n\nThanks for this change! It seems to be very similar to the one\nincluded in the commit-graph, barring one small issue below\n(that we can follow-up on later).\n\n> diff --git a/midx.c b/midx.c\n> index d649644420..f29afc0d2d 100644\n> --- a/midx.c\n> +++ b/midx.c\n> @@ -19,8 +19,7 @@\n>  #define MIDX_BYTE_NUM_PACKS 8\n>  #define MIDX_HASH_VERSION 1\n\nThis hash version \"1\" is the same as we used in the commit-graph. It's\na byte value from the file format, and we've already discussed how it\nwould have been better to use the 4-byte identifier, but that ship has\nsailed. I'm just pointing this out to say that we are not done in this\nfile yet, but we can get to that when we want to test the midx with\nmultiple hash lengths.\n\n>  #define MIDX_HEADER_SIZE 12\n> -#define MIDX_HASH_LEN 20\n\nThe replacements of MIDX_HASH_LEN make sense. Thanks!\n\n-Stolee\n"},{"id":"380940","messageId":"xmqqblwhqjqo.fsf@gitster-ct.c.googlers.com","threadId":"51668","inReplyTo":"20190820223606.GJ365197@genre.crustytoothpaste.net","subject":"Re: [PATCH 02/26] patch-id: convert to use the_hash_algo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2019-08-22T15:53:51Z","receivedAt":"2019-08-22T15:53:59Z","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 2019-08-20 at 21:12:00, René Scharfe wrote:\n>> So perhaps this on top?  (Or squash it in, if you like, but it's\n>> certainly not worth a re-roll.)\n>\n> Yeah, this seems sensible.  I'll include it if I do a re-roll.\n\nThanks.\n"},{"id":"380992","messageId":"20190823021757.GL365197@genre.crustytoothpaste.net","threadId":"51668","inReplyTo":"4f6b781b-68b8-5bc4-92a2-67caff32024f@gmail.com","subject":"Re: [PATCH 26/26] midx: switch to using the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2019-08-23T02:17:57Z","receivedAt":"2019-08-23T02:18:06Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2019-08-22 at 14:04:16, Derrick Stolee wrote:\n> On 8/18/2019 4:04 PM, brian m. carlson wrote:\n> > diff --git a/midx.c b/midx.c\n> > index d649644420..f29afc0d2d 100644\n> > --- a/midx.c\n> > +++ b/midx.c\n> > @@ -19,8 +19,7 @@\n> >  #define MIDX_BYTE_NUM_PACKS 8\n> >  #define MIDX_HASH_VERSION 1\n> \n> This hash version \"1\" is the same as we used in the commit-graph. It's\n> a byte value from the file format, and we've already discussed how it\n> would have been better to use the 4-byte identifier, but that ship has\n> sailed. I'm just pointing this out to say that we are not done in this\n> file yet, but we can get to that when we want to test the midx with\n> multiple hash lengths.\n\nMy approach so far has been to assume everything in the .git directory\nis in the same hash except for the translation functionality. Therefore,\nit doesn't make sense to distinguish between hashes in the midx files,\nbecause we'll never have files that differ in hash.  So essentially the\nMIDX_HASH_VERSION being 1 is \"whatever hash is being used in the .git\ndirectory\", not just SHA-1.\n\nIn addition, the current multi-pack index format isn't capable (from my\nreading of the documentation, at least) of handling multiple hash\nalgorithms at once.  So we'd need a midx v2 format for folks who are\nusing SHA-256 with SHA-1 compatibility and we could then write separate\nsets of object chunks with an appropriate format identifier, much like\nthe proposed pack index v3.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"381008","messageId":"244c8006-d8fa-8440-e799-ba8e41eb40cb@gmail.com","threadId":"51668","inReplyTo":"20190823021757.GL365197@genre.crustytoothpaste.net","subject":"Re: [PATCH 26/26] midx: switch to using the_hash_algo","fromName":"Derrick Stolee","fromEmail":"stolee@gmail.com","sentAt":"2019-08-23T11:53:38Z","receivedAt":"2019-08-23T11:53:42Z","isPatch":true,"sender":{"key":"stolee@gmail.com","avatar":"https://avatars.githubusercontent.com/u/570044?v=4"},"body":"On 8/22/2019 10:17 PM, brian m. carlson wrote:\n> On 2019-08-22 at 14:04:16, Derrick Stolee wrote:\n>> On 8/18/2019 4:04 PM, brian m. carlson wrote:\n>>> diff --git a/midx.c b/midx.c\n>>> index d649644420..f29afc0d2d 100644\n>>> --- a/midx.c\n>>> +++ b/midx.c\n>>> @@ -19,8 +19,7 @@\n>>>  #define MIDX_BYTE_NUM_PACKS 8\n>>>  #define MIDX_HASH_VERSION 1\n>>\n>> This hash version \"1\" is the same as we used in the commit-graph. It's\n>> a byte value from the file format, and we've already discussed how it\n>> would have been better to use the 4-byte identifier, but that ship has\n>> sailed. I'm just pointing this out to say that we are not done in this\n>> file yet, but we can get to that when we want to test the midx with\n>> multiple hash lengths.\n> \n> My approach so far has been to assume everything in the .git directory\n> is in the same hash except for the translation functionality. Therefore,\n> it doesn't make sense to distinguish between hashes in the midx files,\n> because we'll never have files that differ in hash.  So essentially the\n> MIDX_HASH_VERSION being 1 is \"whatever hash is being used in the .git\n> directory\", not just SHA-1.\n> \n> In addition, the current multi-pack index format isn't capable (from my\n> reading of the documentation, at least) of handling multiple hash\n> algorithms at once.  So we'd need a midx v2 format for folks who are\n> using SHA-256 with SHA-1 compatibility and we could then write separate\n> sets of object chunks with an appropriate format identifier, much like\n> the proposed pack index v3.\n\nAbsolutely, it is not. It would be a great place to store a transition\ntable, when that is needed.\n\nIf we _never_ allow both hashes in the .git folder, then maybe we won't\never need this and can rely on config options. I imagine that will be\ntricky, and updating this byte should only help. We are not ready for\nthat, anyway.\n\nThanks,\n-Stolee\n"}]}