{"thread":{"id":"49511","subject":"[PATCH 00/14] Hash function transition part 15","startedAt":"2018-10-08T21:57:10Z","lastAt":"2018-10-15T04:24:10Z","messageCount":30,"participants":["brian m. carlson","Stefan Beller","Eric Sunshine","SZEDER Gábor","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":14},"messages":[{"id":"359856","messageId":"20181008215701.779099-1-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":null,"subject":"[PATCH 00/14] Hash function transition part 15","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:47Z","receivedAt":"2018-10-08T21:57:10Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"This is the fifteenth series in the ongoing hash function transition.\n\nThis series includes several conversions to use the_hash_algo, combined\nwith some use of parse_oid_hex and GIT_MAX_RAWSZ.  None of the\ntransformations here are especially surprising.\n\nbrian m. carlson (14):\n  pack-bitmap-write: use GIT_MAX_RAWSZ for allocation\n  builtin/repack: replace hard-coded constant\n  builtin/mktree: remove hard-coded constant\n  builtin/fetch-pack: remove constants with parse_oid_hex\n  pack-revindex: express constants in terms of the_hash_algo\n  packfile: express constants in terms of the_hash_algo\n  refs/packed-backend: express constants using the_hash_algo\n  upload-pack: express constants in terms of the_hash_algo\n  transport: use parse_oid_hex instead of a constant\n  tag: express constant in terms of the_hash_algo\n  apply: replace hard-coded constants\n  apply: rename new_sha1_prefix and old_sha1_prefix\n  submodule: make zero-oid comparison hash function agnostic\n  rerere: convert to use the_hash_algo\n\n apply.c               | 50 +++++++++++++-------------\n builtin/fetch-pack.c  | 13 +++----\n builtin/mktree.c      |  2 +-\n builtin/repack.c      |  4 +--\n git-submodule.sh      |  7 +++-\n pack-bitmap-write.c   |  2 +-\n pack-revindex.c       |  9 ++---\n packfile.c            |  5 +--\n refs/packed-backend.c | 14 ++++----\n rerere.c              | 81 ++++++++++++++++++++++---------------------\n tag.c                 |  2 +-\n transport.c           |  7 ++--\n upload-pack.c         | 13 +++----\n 13 files changed, 112 insertions(+), 97 deletions(-)\n\n"},{"id":"359857","messageId":"20181008215701.779099-2-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 01/14] pack-bitmap-write: use GIT_MAX_RAWSZ for allocation","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:48Z","receivedAt":"2018-10-08T21:57:14Z","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 pack-bitmap-write.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/pack-bitmap-write.c b/pack-bitmap-write.c\nindex fc82f37a02..6f0c78d6aa 100644\n--- a/pack-bitmap-write.c\n+++ b/pack-bitmap-write.c\n@@ -37,7 +37,7 @@ struct bitmap_writer {\n \n \tstruct progress *progress;\n \tint show_progress;\n-\tunsigned char pack_checksum[20];\n+\tunsigned char pack_checksum[GIT_MAX_RAWSZ];\n };\n \n static struct bitmap_writer writer;\n"},{"id":"359860","messageId":"20181008215701.779099-3-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 02/14] builtin/repack: replace hard-coded constant","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:49Z","receivedAt":"2018-10-08T21:57:14Z","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 builtin/repack.c | 4 ++--\n 1 file changed, 2 insertions(+), 2 deletions(-)\n\ndiff --git a/builtin/repack.c b/builtin/repack.c\nindex c6a7943d5c..e77859062d 100644\n--- a/builtin/repack.c\n+++ b/builtin/repack.c\n@@ -407,8 +407,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)\n \n \tout = xfdopen(cmd.out, \"r\");\n \twhile (strbuf_getline_lf(&line, out) != EOF) {\n-\t\tif (line.len != 40)\n-\t\t\tdie(\"repack: Expecting 40 character sha1 lines only from pack-objects.\");\n+\t\tif (line.len != the_hash_algo->hexsz)\n+\t\t\tdie(\"repack: Expecting full hex object ID lines only from pack-objects.\");\n \t\tstring_list_append(&names, line.buf);\n \t}\n \tfclose(out);\n"},{"id":"359858","messageId":"20181008215701.779099-7-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 06/14] packfile: express constants in terms of the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:53Z","receivedAt":"2018-10-08T21:57:15Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Replace uses of GIT_SHA1_RAWSZ with references to the_hash_algo to avoid\ndependence on a particular hash length.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n packfile.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/packfile.c b/packfile.c\nindex 841b36182f..17f993b5bf 100644\n--- a/packfile.c\n+++ b/packfile.c\n@@ -1121,13 +1121,14 @@ int unpack_object_header(struct packed_git *p,\n void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)\n {\n \tunsigned i;\n+\tconst unsigned hashsz = the_hash_algo->rawsz;\n \tfor (i = 0; i < p->num_bad_objects; i++)\n-\t\tif (hasheq(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))\n+\t\tif (hasheq(sha1, p->bad_object_sha1 + hashsz * i))\n \t\t\treturn;\n \tp->bad_object_sha1 = xrealloc(p->bad_object_sha1,\n \t\t\t\t      st_mult(GIT_MAX_RAWSZ,\n \t\t\t\t\t      st_add(p->num_bad_objects, 1)));\n-\thashcpy(p->bad_object_sha1 + GIT_SHA1_RAWSZ * p->num_bad_objects, sha1);\n+\thashcpy(p->bad_object_sha1 + hashsz * p->num_bad_objects, sha1);\n \tp->num_bad_objects++;\n }\n \n"},{"id":"359859","messageId":"20181008215701.779099-4-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 03/14] builtin/mktree: remove hard-coded constant","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:50Z","receivedAt":"2018-10-08T21:57:15Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Instead of using a hard-coded constant for the size of a hex object ID,\nswitch to use the computed pointer from parse_oid_hex that points after\nthe parsed object ID.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/mktree.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/builtin/mktree.c b/builtin/mktree.c\nindex 2dc4ad6ba8..94e82b8504 100644\n--- a/builtin/mktree.c\n+++ b/builtin/mktree.c\n@@ -98,7 +98,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss\n \n \t*ntr++ = 0; /* now at the beginning of SHA1 */\n \n-\tpath = ntr + 41;  /* at the beginning of name */\n+\tpath = (char *)p + 1;  /* at the beginning of name */\n \tif (!nul_term_line && path[0] == '\"') {\n \t\tstruct strbuf p_uq = STRBUF_INIT;\n \t\tif (unquote_c_style(&p_uq, path, NULL))\n"},{"id":"359861","messageId":"20181008215701.779099-5-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 04/14] builtin/fetch-pack: remove constants with parse_oid_hex","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:51Z","receivedAt":"2018-10-08T21:57:15Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Instead of using GIT_SHA1_HEXSZ, use parse_oid_hex to compute a pointer\nand use that in comparisons.  This is both simpler to read and works\nindependent of the hash length.  Update references to SHA-1 in the same\nfunction to refer to object IDs instead.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/fetch-pack.c | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/builtin/fetch-pack.c b/builtin/fetch-pack.c\nindex 1a1bc63566..63e69a5801 100644\n--- a/builtin/fetch-pack.c\n+++ b/builtin/fetch-pack.c\n@@ -16,13 +16,14 @@ static void add_sought_entry(struct ref ***sought, int *nr, int *alloc,\n {\n \tstruct ref *ref;\n \tstruct object_id oid;\n+\tconst char *p;\n \n-\tif (!get_oid_hex(name, &oid)) {\n-\t\tif (name[GIT_SHA1_HEXSZ] == ' ') {\n-\t\t\t/* <sha1> <ref>, find refname */\n-\t\t\tname += GIT_SHA1_HEXSZ + 1;\n-\t\t} else if (name[GIT_SHA1_HEXSZ] == '\\0') {\n-\t\t\t; /* <sha1>, leave sha1 as name */\n+\tif (!parse_oid_hex(name, &oid, &p)) {\n+\t\tif (*p == ' ') {\n+\t\t\t/* <oid> <ref>, find refname */\n+\t\t\tname = p + 1;\n+\t\t} else if (*p == '\\0') {\n+\t\t\t; /* <oid>, leave oid as name */\n \t\t} else {\n \t\t\t/* <ref>, clear cruft from oid */\n \t\t\toidclr(&oid);\n"},{"id":"359862","messageId":"20181008215701.779099-6-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 05/14] pack-revindex: express constants in terms of the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:52Z","receivedAt":"2018-10-08T21:57:15Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Express the various constants used in terms of the_hash_algo.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n pack-revindex.c | 9 +++++----\n 1 file changed, 5 insertions(+), 4 deletions(-)\n\ndiff --git a/pack-revindex.c b/pack-revindex.c\nindex bb521cf7fb..3756ec71a8 100644\n--- a/pack-revindex.c\n+++ b/pack-revindex.c\n@@ -122,13 +122,14 @@ static void create_pack_revindex(struct packed_git *p)\n \tunsigned num_ent = p->num_objects;\n \tunsigned i;\n \tconst char *index = p->index_data;\n+\tconst unsigned hashsz = the_hash_algo->rawsz;\n \n \tALLOC_ARRAY(p->revindex, num_ent + 1);\n \tindex += 4 * 256;\n \n \tif (p->index_version > 1) {\n \t\tconst uint32_t *off_32 =\n-\t\t\t(uint32_t *)(index + 8 + p->num_objects * (20 + 4));\n+\t\t\t(uint32_t *)(index + 8 + p->num_objects * (hashsz + 4));\n \t\tconst uint32_t *off_64 = off_32 + p->num_objects;\n \t\tfor (i = 0; i < num_ent; i++) {\n \t\t\tuint32_t off = ntohl(*off_32++);\n@@ -142,16 +143,16 @@ static void create_pack_revindex(struct packed_git *p)\n \t\t}\n \t} else {\n \t\tfor (i = 0; i < num_ent; i++) {\n-\t\t\tuint32_t hl = *((uint32_t *)(index + 24 * i));\n+\t\t\tuint32_t hl = *((uint32_t *)(index + (hashsz + 4) * i));\n \t\t\tp->revindex[i].offset = ntohl(hl);\n \t\t\tp->revindex[i].nr = i;\n \t\t}\n \t}\n \n-\t/* This knows the pack format -- the 20-byte trailer\n+\t/* This knows the pack format -- the hash trailer\n \t * follows immediately after the last object data.\n \t */\n-\tp->revindex[num_ent].offset = p->pack_size - 20;\n+\tp->revindex[num_ent].offset = p->pack_size - hashsz;\n \tp->revindex[num_ent].nr = -1;\n \tsort_revindex(p->revindex, num_ent, p->pack_size);\n }\n"},{"id":"359863","messageId":"20181008215701.779099-8-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 07/14] refs/packed-backend: express constants using the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:54Z","receivedAt":"2018-10-08T21:57:16Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Switch uses of GIT_SHA1_HEXSZ to use the_hash_algo so that they are\nappropriate for the any given hash length.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n refs/packed-backend.c | 14 +++++++-------\n 1 file changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/refs/packed-backend.c b/refs/packed-backend.c\nindex 74e2996e93..c01c7f5901 100644\n--- a/refs/packed-backend.c\n+++ b/refs/packed-backend.c\n@@ -274,8 +274,8 @@ struct snapshot_record {\n static int cmp_packed_ref_records(const void *v1, const void *v2)\n {\n \tconst struct snapshot_record *e1 = v1, *e2 = v2;\n-\tconst char *r1 = e1->start + GIT_SHA1_HEXSZ + 1;\n-\tconst char *r2 = e2->start + GIT_SHA1_HEXSZ + 1;\n+\tconst char *r1 = e1->start + the_hash_algo->hexsz + 1;\n+\tconst char *r2 = e2->start + the_hash_algo->hexsz + 1;\n \n \twhile (1) {\n \t\tif (*r1 == '\\n')\n@@ -297,7 +297,7 @@ static int cmp_packed_ref_records(const void *v1, const void *v2)\n  */\n static int cmp_record_to_refname(const char *rec, const char *refname)\n {\n-\tconst char *r1 = rec + GIT_SHA1_HEXSZ + 1;\n+\tconst char *r1 = rec + the_hash_algo->hexsz + 1;\n \tconst char *r2 = refname;\n \n \twhile (1) {\n@@ -344,7 +344,7 @@ static void sort_snapshot(struct snapshot *snapshot)\n \t\tif (!eol)\n \t\t\t/* The safety check should prevent this. */\n \t\t\tBUG(\"unterminated line found in packed-refs\");\n-\t\tif (eol - pos < GIT_SHA1_HEXSZ + 2)\n+\t\tif (eol - pos < the_hash_algo->hexsz + 2)\n \t\t\tdie_invalid_line(snapshot->refs->path,\n \t\t\t\t\t pos, eof - pos);\n \t\teol++;\n@@ -456,7 +456,7 @@ static void verify_buffer_safe(struct snapshot *snapshot)\n \t\treturn;\n \n \tlast_line = find_start_of_record(start, eof - 1);\n-\tif (*(eof - 1) != '\\n' || eof - last_line < GIT_SHA1_HEXSZ + 2)\n+\tif (*(eof - 1) != '\\n' || eof - last_line < the_hash_algo->hexsz + 2)\n \t\tdie_invalid_line(snapshot->refs->path,\n \t\t\t\t last_line, eof - last_line);\n }\n@@ -796,7 +796,7 @@ static int next_record(struct packed_ref_iterator *iter)\n \n \titer->base.flags = REF_ISPACKED;\n \n-\tif (iter->eof - p < GIT_SHA1_HEXSZ + 2 ||\n+\tif (iter->eof - p < the_hash_algo->hexsz + 2 ||\n \t    parse_oid_hex(p, &iter->oid, &p) ||\n \t    !isspace(*p++))\n \t\tdie_invalid_line(iter->snapshot->refs->path,\n@@ -826,7 +826,7 @@ static int next_record(struct packed_ref_iterator *iter)\n \n \tif (iter->pos < iter->eof && *iter->pos == '^') {\n \t\tp = iter->pos + 1;\n-\t\tif (iter->eof - p < GIT_SHA1_HEXSZ + 1 ||\n+\t\tif (iter->eof - p < the_hash_algo->hexsz + 1 ||\n \t\t    parse_oid_hex(p, &iter->peeled, &p) ||\n \t\t    *p++ != '\\n')\n \t\t\tdie_invalid_line(iter->snapshot->refs->path,\n"},{"id":"359864","messageId":"20181008215701.779099-9-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 08/14] upload-pack: express constants in terms of the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:55Z","receivedAt":"2018-10-08T21:57:18Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert all uses of the GIT_SHA1_HEXSZ to use the_hash_algo so that they\nare appropriate for any given hash length.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n upload-pack.c | 13 +++++++------\n 1 file changed, 7 insertions(+), 6 deletions(-)\n\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 62a1000f44..1aae5dd828 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -443,6 +443,7 @@ static int do_reachable_revlist(struct child_process *cmd,\n \tstruct object *o;\n \tchar namebuf[GIT_MAX_HEXSZ + 2]; /* ^ + hash + LF */\n \tint i;\n+\tconst unsigned hexsz = the_hash_algo->hexsz;\n \n \tcmd->argv = argv;\n \tcmd->git_cmd = 1;\n@@ -461,7 +462,7 @@ static int do_reachable_revlist(struct child_process *cmd,\n \t\tgoto error;\n \n \tnamebuf[0] = '^';\n-\tnamebuf[GIT_SHA1_HEXSZ + 1] = '\\n';\n+\tnamebuf[hexsz + 1] = '\\n';\n \tfor (i = get_max_object_index(); 0 < i; ) {\n \t\to = get_indexed_object(--i);\n \t\tif (!o)\n@@ -470,11 +471,11 @@ static int do_reachable_revlist(struct child_process *cmd,\n \t\t\to->flags &= ~TMP_MARK;\n \t\tif (!is_our_ref(o))\n \t\t\tcontinue;\n-\t\tmemcpy(namebuf + 1, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);\n-\t\tif (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 2) < 0)\n+\t\tmemcpy(namebuf + 1, oid_to_hex(&o->oid), hexsz);\n+\t\tif (write_in_full(cmd->in, namebuf, hexsz + 2) < 0)\n \t\t\tgoto error;\n \t}\n-\tnamebuf[GIT_SHA1_HEXSZ] = '\\n';\n+\tnamebuf[hexsz] = '\\n';\n \tfor (i = 0; i < src->nr; i++) {\n \t\to = src->objects[i].item;\n \t\tif (is_our_ref(o)) {\n@@ -484,8 +485,8 @@ static int do_reachable_revlist(struct child_process *cmd,\n \t\t}\n \t\tif (reachable && o->type == OBJ_COMMIT)\n \t\t\to->flags |= TMP_MARK;\n-\t\tmemcpy(namebuf, oid_to_hex(&o->oid), GIT_SHA1_HEXSZ);\n-\t\tif (write_in_full(cmd->in, namebuf, GIT_SHA1_HEXSZ + 1) < 0)\n+\t\tmemcpy(namebuf, oid_to_hex(&o->oid), hexsz);\n+\t\tif (write_in_full(cmd->in, namebuf, hexsz + 1) < 0)\n \t\t\tgoto error;\n \t}\n \tclose(cmd->in);\n"},{"id":"359865","messageId":"20181008215701.779099-11-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 10/14] tag: express constant in terms of the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:57Z","receivedAt":"2018-10-08T21:57:20Z","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 tag.c | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/tag.c b/tag.c\nindex 1db663d716..7445b8f6ea 100644\n--- a/tag.c\n+++ b/tag.c\n@@ -144,7 +144,7 @@ int parse_tag_buffer(struct repository *r, struct tag *item, const void *data, u\n \t\treturn 0;\n \titem->object.parsed = 1;\n \n-\tif (size < GIT_SHA1_HEXSZ + 24)\n+\tif (size < the_hash_algo->hexsz + 24)\n \t\treturn -1;\n \tif (memcmp(\"object \", bufptr, 7) || parse_oid_hex(bufptr + 7, &oid, &bufptr) || *bufptr++ != '\\n')\n \t\treturn -1;\n"},{"id":"359866","messageId":"20181008215701.779099-10-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 09/14] transport: use parse_oid_hex instead of a constant","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:56Z","receivedAt":"2018-10-08T21:57:22Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Use parse_oid_hex to compute a pointer instead of using GIT_SHA1_HEXSZ.\nThis simplifies the code and makes it independent of the hash length.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n transport.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git a/transport.c b/transport.c\nindex 1c76d64aba..44b9ddf670 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -1346,15 +1346,16 @@ static void read_alternate_refs(const char *path,\n \tfh = xfdopen(cmd.out, \"r\");\n \twhile (strbuf_getline_lf(&line, fh) != EOF) {\n \t\tstruct object_id oid;\n+\t\tconst char *p;\n \n-\t\tif (get_oid_hex(line.buf, &oid) ||\n-\t\t    line.buf[GIT_SHA1_HEXSZ] != ' ') {\n+\t\tif (parse_oid_hex(line.buf, &oid, &p) ||\n+\t\t    *p != ' ') {\n \t\t\twarning(_(\"invalid line while parsing alternate refs: %s\"),\n \t\t\t\tline.buf);\n \t\t\tbreak;\n \t\t}\n \n-\t\tcb(line.buf + GIT_SHA1_HEXSZ + 1, &oid, data);\n+\t\tcb(p + 1, &oid, data);\n \t}\n \n \tfclose(fh);\n"},{"id":"359867","messageId":"20181008215701.779099-12-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 11/14] apply: replace hard-coded constants","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:58Z","receivedAt":"2018-10-08T21:57:22Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Replace several 40-based constants with references to GIT_MAX_HEXSZ or\nthe_hash_algo, as appropriate.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n apply.c | 18 ++++++++++--------\n 1 file changed, 10 insertions(+), 8 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex e485fbc6bc..792ecea36a 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -223,8 +223,8 @@ struct patch {\n \tstruct fragment *fragments;\n \tchar *result;\n \tsize_t resultsize;\n-\tchar old_sha1_prefix[41];\n-\tchar new_sha1_prefix[41];\n+\tchar old_sha1_prefix[GIT_MAX_HEXSZ + 1];\n+\tchar new_sha1_prefix[GIT_MAX_HEXSZ + 1];\n \tstruct patch *next;\n \n \t/* three-way fallback result */\n@@ -1093,9 +1093,10 @@ static int gitdiff_index(struct apply_state *state,\n \t */\n \tconst char *ptr, *eol;\n \tint len;\n+\tconst unsigned hexsz = the_hash_algo->hexsz;\n \n \tptr = strchr(line, '.');\n-\tif (!ptr || ptr[1] != '.' || 40 < ptr - line)\n+\tif (!ptr || ptr[1] != '.' || hexsz < ptr - line)\n \t\treturn 0;\n \tlen = ptr - line;\n \tmemcpy(patch->old_sha1_prefix, line, len);\n@@ -1109,7 +1110,7 @@ static int gitdiff_index(struct apply_state *state,\n \t\tptr = eol;\n \tlen = ptr - line;\n \n-\tif (40 < len)\n+\tif (hexsz < len)\n \t\treturn 0;\n \tmemcpy(patch->new_sha1_prefix, line, len);\n \tpatch->new_sha1_prefix[len] = 0;\n@@ -3142,13 +3143,14 @@ static int apply_binary(struct apply_state *state,\n {\n \tconst char *name = patch->old_name ? patch->old_name : patch->new_name;\n \tstruct object_id oid;\n+\tconst unsigned hexsz = the_hash_algo->hexsz;\n \n \t/*\n \t * For safety, we require patch index line to contain\n-\t * full 40-byte textual SHA1 for old and new, at least for now.\n+\t * full hex textual object ID for old and new, at least for now.\n \t */\n-\tif (strlen(patch->old_sha1_prefix) != 40 ||\n-\t    strlen(patch->new_sha1_prefix) != 40 ||\n+\tif (strlen(patch->old_sha1_prefix) != hexsz ||\n+\t    strlen(patch->new_sha1_prefix) != hexsz ||\n \t    get_oid_hex(patch->old_sha1_prefix, &oid) ||\n \t    get_oid_hex(patch->new_sha1_prefix, &oid))\n \t\treturn error(_(\"cannot apply binary patch to '%s' \"\n@@ -4055,7 +4057,7 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)\n \t    starts_with(++preimage, heading) &&\n \t    /* does it record full SHA-1? */\n \t    !get_oid_hex(preimage + sizeof(heading) - 1, oid) &&\n-\t    preimage[sizeof(heading) + GIT_SHA1_HEXSZ - 1] == '\\n' &&\n+\t    preimage[sizeof(heading) + the_hash_algo->hexsz - 1] == '\\n' &&\n \t    /* does the abbreviated name on the index line agree with it? */\n \t    starts_with(preimage + sizeof(heading) - 1, p->old_sha1_prefix))\n \t\treturn 0; /* it all looks fine */\n"},{"id":"359868","messageId":"20181008215701.779099-13-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 12/14] apply: rename new_sha1_prefix and old_sha1_prefix","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:56:59Z","receivedAt":"2018-10-08T21:57:24Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Rename these structure members to \"new_oid_prefix\" and \"old_oid_prefix\".\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n apply.c | 40 ++++++++++++++++++++--------------------\n 1 file changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/apply.c b/apply.c\nindex 792ecea36a..b9eb02ec12 100644\n--- a/apply.c\n+++ b/apply.c\n@@ -223,8 +223,8 @@ struct patch {\n \tstruct fragment *fragments;\n \tchar *result;\n \tsize_t resultsize;\n-\tchar old_sha1_prefix[GIT_MAX_HEXSZ + 1];\n-\tchar new_sha1_prefix[GIT_MAX_HEXSZ + 1];\n+\tchar old_oid_prefix[GIT_MAX_HEXSZ + 1];\n+\tchar new_oid_prefix[GIT_MAX_HEXSZ + 1];\n \tstruct patch *next;\n \n \t/* three-way fallback result */\n@@ -1099,8 +1099,8 @@ static int gitdiff_index(struct apply_state *state,\n \tif (!ptr || ptr[1] != '.' || hexsz < ptr - line)\n \t\treturn 0;\n \tlen = ptr - line;\n-\tmemcpy(patch->old_sha1_prefix, line, len);\n-\tpatch->old_sha1_prefix[len] = 0;\n+\tmemcpy(patch->old_oid_prefix, line, len);\n+\tpatch->old_oid_prefix[len] = 0;\n \n \tline = ptr + 2;\n \tptr = strchr(line, ' ');\n@@ -1112,8 +1112,8 @@ static int gitdiff_index(struct apply_state *state,\n \n \tif (hexsz < len)\n \t\treturn 0;\n-\tmemcpy(patch->new_sha1_prefix, line, len);\n-\tpatch->new_sha1_prefix[len] = 0;\n+\tmemcpy(patch->new_oid_prefix, line, len);\n+\tpatch->new_oid_prefix[len] = 0;\n \tif (*ptr == ' ')\n \t\treturn gitdiff_oldmode(state, ptr + 1, patch);\n \treturn 0;\n@@ -2205,7 +2205,7 @@ static void reverse_patches(struct patch *p)\n \t\tSWAP(p->new_mode, p->old_mode);\n \t\tSWAP(p->is_new, p->is_delete);\n \t\tSWAP(p->lines_added, p->lines_deleted);\n-\t\tSWAP(p->old_sha1_prefix, p->new_sha1_prefix);\n+\t\tSWAP(p->old_oid_prefix, p->new_oid_prefix);\n \n \t\tfor (; frag; frag = frag->next) {\n \t\t\tSWAP(frag->newpos, frag->oldpos);\n@@ -3149,10 +3149,10 @@ static int apply_binary(struct apply_state *state,\n \t * For safety, we require patch index line to contain\n \t * full hex textual object ID for old and new, at least for now.\n \t */\n-\tif (strlen(patch->old_sha1_prefix) != hexsz ||\n-\t    strlen(patch->new_sha1_prefix) != hexsz ||\n-\t    get_oid_hex(patch->old_sha1_prefix, &oid) ||\n-\t    get_oid_hex(patch->new_sha1_prefix, &oid))\n+\tif (strlen(patch->old_oid_prefix) != hexsz ||\n+\t    strlen(patch->new_oid_prefix) != hexsz ||\n+\t    get_oid_hex(patch->old_oid_prefix, &oid) ||\n+\t    get_oid_hex(patch->new_oid_prefix, &oid))\n \t\treturn error(_(\"cannot apply binary patch to '%s' \"\n \t\t\t       \"without full index line\"), name);\n \n@@ -3162,7 +3162,7 @@ static int apply_binary(struct apply_state *state,\n \t\t * applies to.\n \t\t */\n \t\thash_object_file(img->buf, img->len, blob_type, &oid);\n-\t\tif (strcmp(oid_to_hex(&oid), patch->old_sha1_prefix))\n+\t\tif (strcmp(oid_to_hex(&oid), patch->old_oid_prefix))\n \t\t\treturn error(_(\"the patch applies to '%s' (%s), \"\n \t\t\t\t       \"which does not match the \"\n \t\t\t\t       \"current contents.\"),\n@@ -3175,7 +3175,7 @@ static int apply_binary(struct apply_state *state,\n \t\t\t\t       \"'%s' but it is not empty\"), name);\n \t}\n \n-\tget_oid_hex(patch->new_sha1_prefix, &oid);\n+\tget_oid_hex(patch->new_oid_prefix, &oid);\n \tif (is_null_oid(&oid)) {\n \t\tclear_image(img);\n \t\treturn 0; /* deletion patch */\n@@ -3191,7 +3191,7 @@ static int apply_binary(struct apply_state *state,\n \t\tif (!result)\n \t\t\treturn error(_(\"the necessary postimage %s for \"\n \t\t\t\t       \"'%s' cannot be read\"),\n-\t\t\t\t     patch->new_sha1_prefix, name);\n+\t\t\t\t     patch->new_oid_prefix, name);\n \t\tclear_image(img);\n \t\timg->buf = result;\n \t\timg->len = size;\n@@ -3207,9 +3207,9 @@ static int apply_binary(struct apply_state *state,\n \n \t\t/* verify that the result matches */\n \t\thash_object_file(img->buf, img->len, blob_type, &oid);\n-\t\tif (strcmp(oid_to_hex(&oid), patch->new_sha1_prefix))\n+\t\tif (strcmp(oid_to_hex(&oid), patch->new_oid_prefix))\n \t\t\treturn error(_(\"binary patch to '%s' creates incorrect result (expecting %s, got %s)\"),\n-\t\t\t\tname, patch->new_sha1_prefix, oid_to_hex(&oid));\n+\t\t\t\tname, patch->new_oid_prefix, oid_to_hex(&oid));\n \t}\n \n \treturn 0;\n@@ -3565,7 +3565,7 @@ static int try_threeway(struct apply_state *state,\n \t/* Preimage the patch was prepared for */\n \tif (patch->is_new)\n \t\twrite_object_file(\"\", 0, blob_type, &pre_oid);\n-\telse if (get_oid(patch->old_sha1_prefix, &pre_oid) ||\n+\telse if (get_oid(patch->old_oid_prefix, &pre_oid) ||\n \t\t read_blob_object(&buf, &pre_oid, patch->old_mode))\n \t\treturn error(_(\"repository lacks the necessary blob to fall back on 3-way merge.\"));\n \n@@ -4059,11 +4059,11 @@ static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)\n \t    !get_oid_hex(preimage + sizeof(heading) - 1, oid) &&\n \t    preimage[sizeof(heading) + the_hash_algo->hexsz - 1] == '\\n' &&\n \t    /* does the abbreviated name on the index line agree with it? */\n-\t    starts_with(preimage + sizeof(heading) - 1, p->old_sha1_prefix))\n+\t    starts_with(preimage + sizeof(heading) - 1, p->old_oid_prefix))\n \t\treturn 0; /* it all looks fine */\n \n \t/* we may have full object name on the index line */\n-\treturn get_oid_hex(p->old_sha1_prefix, oid);\n+\treturn get_oid_hex(p->old_oid_prefix, oid);\n }\n \n /* Build an index that contains just the files needed for a 3way merge */\n@@ -4092,7 +4092,7 @@ static int build_fake_ancestor(struct apply_state *state, struct patch *list)\n \t\t\telse\n \t\t\t\treturn error(_(\"sha1 information is lacking or \"\n \t\t\t\t\t       \"useless for submodule %s\"), name);\n-\t\t} else if (!get_oid_blob(patch->old_sha1_prefix, &oid)) {\n+\t\t} else if (!get_oid_blob(patch->old_oid_prefix, &oid)) {\n \t\t\t; /* ok */\n \t\t} else if (!patch->lines_added && !patch->lines_deleted) {\n \t\t\t/* mode-only change: update the current */\n"},{"id":"359869","messageId":"20181008215701.779099-14-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 13/14] submodule: make zero-oid comparison hash function agnostic","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:57:00Z","receivedAt":"2018-10-08T21:57:24Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"With SHA-256, the length of the all-zeros object ID is longer.  Add a\nfunction to git-submodule.sh to check if a full hex object ID is the\nall-zeros value, and use it to check the output we're parsing from git\ndiff-files or diff-index.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n git-submodule.sh | 7 ++++++-\n 1 file changed, 6 insertions(+), 1 deletion(-)\n\ndiff --git a/git-submodule.sh b/git-submodule.sh\nindex 1b568e29b9..c09eb3e03d 100755\n--- a/git-submodule.sh\n+++ b/git-submodule.sh\n@@ -82,6 +82,11 @@ isnumber()\n \tn=$(($1 + 0)) 2>/dev/null && test \"$n\" = \"$1\"\n }\n \n+# Given a full hex object ID, is this the zero OID?\n+is_zero_oid () {\n+\techo \"$1\" | sane_egrep '^0+$' >/dev/null 2>&1\n+}\n+\n # Sanitize the local git environment for use within a submodule. We\n # can't simply use clear_local_git_env since we want to preserve some\n # of the settings from GIT_CONFIG_PARAMETERS.\n@@ -780,7 +785,7 @@ cmd_summary() {\n \twhile read -r mod_src mod_dst sha1_src sha1_dst status name\n \tdo\n \t\tif test -z \"$cached\" &&\n-\t\t\ttest $sha1_dst = 0000000000000000000000000000000000000000\n+\t\t\tis_zero_oid $sha1_dst\n \t\tthen\n \t\t\tcase \"$mod_dst\" in\n \t\t\t160000)\n"},{"id":"359870","messageId":"20181008215701.779099-15-sandals@crustytoothpaste.net","threadId":"49511","inReplyTo":"20181008215701.779099-1-sandals@crustytoothpaste.net","subject":"[PATCH 14/14] rerere: convert to use the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-08T21:57:01Z","receivedAt":"2018-10-08T21:57:28Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Since this data is stored in the .git directory, it makes sense for us\nto use the same hash algorithm for it as for everything else.  Convert\nthe remaining uses of SHA-1 to use the_hash_algo.  Use GIT_MAX_RAWSZ for\nallocations.  Rename various struct members, local variables, and a\nfunction to be named \"hash\" instead of \"sha1\".\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n rerere.c | 81 +++++++++++++++++++++++++++++---------------------------\n 1 file changed, 42 insertions(+), 39 deletions(-)\n\ndiff --git a/rerere.c b/rerere.c\nindex 7aa149e849..ceb98015ff 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -29,7 +29,7 @@ static int rerere_dir_alloc;\n #define RR_HAS_POSTIMAGE 1\n #define RR_HAS_PREIMAGE 2\n static struct rerere_dir {\n-\tunsigned char sha1[20];\n+\tunsigned char hash[GIT_MAX_HEXSZ];\n \tint status_alloc, status_nr;\n \tunsigned char *status;\n } **rerere_dir;\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->sha1);\n+\treturn sha1_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->sha1)));\n+\tDIR *dir = opendir(git_path(\"rr-cache/%s\", sha1_to_hex(rr_dir->hash)));\n \n \tif (!dir)\n \t\treturn;\n@@ -133,24 +133,24 @@ static void scan_rerere_dir(struct rerere_dir *rr_dir)\n \tclosedir(dir);\n }\n \n-static const unsigned char *rerere_dir_sha1(size_t i, void *table)\n+static const unsigned char *rerere_dir_hash(size_t i, void *table)\n {\n \tstruct rerere_dir **rr_dir = table;\n-\treturn rr_dir[i]->sha1;\n+\treturn rr_dir[i]->hash;\n }\n \n static struct rerere_dir *find_rerere_dir(const char *hex)\n {\n-\tunsigned char sha1[20];\n+\tunsigned char hash[GIT_MAX_RAWSZ];\n \tstruct rerere_dir *rr_dir;\n \tint pos;\n \n-\tif (get_sha1_hex(hex, sha1))\n+\tif (get_sha1_hex(hex, hash))\n \t\treturn NULL; /* BUG */\n-\tpos = sha1_pos(sha1, rerere_dir, rerere_dir_nr, rerere_dir_sha1);\n+\tpos = sha1_pos(hash, rerere_dir, rerere_dir_nr, rerere_dir_hash);\n \tif (pos < 0) {\n \t\trr_dir = xmalloc(sizeof(*rr_dir));\n-\t\thashcpy(rr_dir->sha1, sha1);\n+\t\thashcpy(rr_dir->hash, hash);\n \t\trr_dir->status = NULL;\n \t\trr_dir->status_nr = 0;\n \t\trr_dir->status_alloc = 0;\n@@ -207,26 +207,27 @@ static void read_rr(struct string_list *rr)\n \t\treturn;\n \twhile (!strbuf_getwholeline(&buf, in, '\\0')) {\n \t\tchar *path;\n-\t\tunsigned char sha1[20];\n+\t\tunsigned char hash[GIT_MAX_RAWSZ];\n \t\tstruct rerere_id *id;\n \t\tint variant;\n+\t\tconst unsigned hexsz = the_hash_algo->hexsz;\n \n \t\t/* There has to be the hash, tab, path and then NUL */\n-\t\tif (buf.len < 42 || get_sha1_hex(buf.buf, sha1))\n+\t\tif (buf.len < hexsz + 2 || get_sha1_hex(buf.buf, hash))\n \t\t\tdie(_(\"corrupt MERGE_RR\"));\n \n-\t\tif (buf.buf[40] != '.') {\n+\t\tif (buf.buf[hexsz] != '.') {\n \t\t\tvariant = 0;\n-\t\t\tpath = buf.buf + 40;\n+\t\t\tpath = buf.buf + hexsz;\n \t\t} else {\n \t\t\terrno = 0;\n-\t\t\tvariant = strtol(buf.buf + 41, &path, 10);\n+\t\t\tvariant = strtol(buf.buf + hexsz + 1, &path, 10);\n \t\t\tif (errno)\n \t\t\t\tdie(_(\"corrupt MERGE_RR\"));\n \t\t}\n \t\tif (*(path++) != '\\t')\n \t\t\tdie(_(\"corrupt MERGE_RR\"));\n-\t\tbuf.buf[40] = '\\0';\n+\t\tbuf.buf[hexsz] = '\\0';\n \t\tid = new_rerere_id_hex(buf.buf);\n \t\tid->variant = variant;\n \t\tstring_list_insert(rr, path)->util = id;\n@@ -360,7 +361,7 @@ static void rerere_strbuf_putconflict(struct strbuf *buf, int ch, size_t size)\n }\n \n static int handle_conflict(struct strbuf *out, struct rerere_io *io,\n-\t\t\t   int marker_size, git_SHA_CTX *ctx)\n+\t\t\t   int marker_size, git_hash_ctx *ctx)\n {\n \tenum {\n \t\tRR_SIDE_1 = 0, RR_SIDE_2, RR_ORIGINAL\n@@ -398,10 +399,12 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,\n \t\t\tstrbuf_addbuf(out, &two);\n \t\t\trerere_strbuf_putconflict(out, '>', marker_size);\n \t\t\tif (ctx) {\n-\t\t\t\tgit_SHA1_Update(ctx, one.buf ? one.buf : \"\",\n-\t\t\t\t\t    one.len + 1);\n-\t\t\t\tgit_SHA1_Update(ctx, two.buf ? two.buf : \"\",\n-\t\t\t\t\t    two.len + 1);\n+\t\t\t\tthe_hash_algo->update_fn(ctx, one.buf ?\n+\t\t\t\t\t\t\t one.buf : \"\",\n+\t\t\t\t\t\t\t one.len + 1);\n+\t\t\t\tthe_hash_algo->update_fn(ctx, two.buf ?\n+\t\t\t\t\t\t\t two.buf : \"\",\n+\t\t\t\t\t\t\t two.len + 1);\n \t\t\t}\n \t\t\tbreak;\n \t\t} else if (hunk == RR_SIDE_1)\n@@ -430,18 +433,18 @@ static int handle_conflict(struct strbuf *out, struct rerere_io *io,\n  * Return 1 if conflict hunks are found, 0 if there are no conflict\n  * hunks and -1 if an error occured.\n  */\n-static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_size)\n+static int handle_path(unsigned char *hash, struct rerere_io *io, int marker_size)\n {\n-\tgit_SHA_CTX ctx;\n+\tgit_hash_ctx ctx;\n \tstruct strbuf buf = STRBUF_INIT, out = STRBUF_INIT;\n \tint has_conflicts = 0;\n-\tif (sha1)\n-\t\tgit_SHA1_Init(&ctx);\n+\tif (hash)\n+\t\tthe_hash_algo->init_fn(&ctx);\n \n \twhile (!io->getline(&buf, io)) {\n \t\tif (is_cmarker(buf.buf, '<', marker_size)) {\n \t\t\thas_conflicts = handle_conflict(&out, io, marker_size,\n-\t\t\t\t\t\t\tsha1 ? &ctx : NULL);\n+\t\t\t\t\t\t\thash ? &ctx : NULL);\n \t\t\tif (has_conflicts < 0)\n \t\t\t\tbreak;\n \t\t\trerere_io_putmem(out.buf, out.len, io);\n@@ -452,8 +455,8 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz\n \tstrbuf_release(&buf);\n \tstrbuf_release(&out);\n \n-\tif (sha1)\n-\t\tgit_SHA1_Final(sha1, &ctx);\n+\tif (hash)\n+\t\tthe_hash_algo->final_fn(hash, &ctx);\n \n \treturn has_conflicts;\n }\n@@ -462,7 +465,7 @@ static int handle_path(unsigned char *sha1, struct rerere_io *io, int marker_siz\n  * Scan the path for conflicts, do the \"handle_path()\" thing above, and\n  * return the number of conflict hunks found.\n  */\n-static int handle_file(const char *path, unsigned char *sha1, const char *output)\n+static int handle_file(const char *path, unsigned char *hash, const char *output)\n {\n \tint has_conflicts = 0;\n \tstruct rerere_io_file io;\n@@ -484,7 +487,7 @@ static int handle_file(const char *path, unsigned char *sha1, const char *output\n \t\t}\n \t}\n \n-\thas_conflicts = handle_path(sha1, (struct rerere_io *)&io, marker_size);\n+\thas_conflicts = handle_path(hash, (struct rerere_io *)&io, marker_size);\n \n \tfclose(io.input);\n \tif (io.io.wrerror)\n@@ -814,7 +817,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)\n \t */\n \tfor (i = 0; i < conflict.nr; i++) {\n \t\tstruct rerere_id *id;\n-\t\tunsigned char sha1[20];\n+\t\tunsigned char hash[GIT_MAX_RAWSZ];\n \t\tconst char *path = conflict.items[i].string;\n \t\tint ret;\n \n@@ -823,7 +826,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)\n \t\t * conflict ID.  No need to write anything out\n \t\t * yet.\n \t\t */\n-\t\tret = handle_file(path, sha1, NULL);\n+\t\tret = handle_file(path, hash, NULL);\n \t\tif (ret != 0 && string_list_has_string(rr, path)) {\n \t\t\tremove_variant(string_list_lookup(rr, path)->util);\n \t\t\tstring_list_remove(rr, path, 1);\n@@ -831,7 +834,7 @@ static int do_plain_rerere(struct string_list *rr, int fd)\n \t\tif (ret < 1)\n \t\t\tcontinue;\n \n-\t\tid = new_rerere_id(sha1);\n+\t\tid = new_rerere_id(hash);\n \t\tstring_list_insert(rr, path)->util = id;\n \n \t\t/* Ensure that the directory exists. */\n@@ -942,7 +945,7 @@ static int rerere_mem_getline(struct strbuf *sb, struct rerere_io *io_)\n \treturn 0;\n }\n \n-static int handle_cache(const char *path, unsigned char *sha1, const char *output)\n+static int handle_cache(const char *path, unsigned char *hash, const char *output)\n {\n \tmmfile_t mmfile[3] = {{NULL}};\n \tmmbuffer_t result = {NULL, 0};\n@@ -1001,7 +1004,7 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu\n \t * Grab the conflict ID and optionally write the original\n \t * contents with conflict markers out.\n \t */\n-\thas_conflicts = handle_path(sha1, (struct rerere_io *)&io, marker_size);\n+\thas_conflicts = handle_path(hash, (struct rerere_io *)&io, marker_size);\n \tstrbuf_release(&io.input);\n \tif (io.io.output)\n \t\tfclose(io.io.output);\n@@ -1012,7 +1015,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)\n {\n \tconst char *filename;\n \tstruct rerere_id *id;\n-\tunsigned char sha1[20];\n+\tunsigned char hash[GIT_MAX_RAWSZ];\n \tint ret;\n \tstruct string_list_item *item;\n \n@@ -1020,12 +1023,12 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)\n \t * Recreate the original conflict from the stages in the\n \t * index and compute the conflict ID\n \t */\n-\tret = handle_cache(path, sha1, NULL);\n+\tret = handle_cache(path, hash, NULL);\n \tif (ret < 1)\n \t\treturn error(_(\"could not parse conflict hunks in '%s'\"), path);\n \n \t/* Nuke the recorded resolution for the conflict */\n-\tid = new_rerere_id(sha1);\n+\tid = new_rerere_id(hash);\n \n \tfor (id->variant = 0;\n \t     id->variant < id->collection->status_nr;\n@@ -1037,7 +1040,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)\n \t\tif (!has_rerere_resolution(id))\n \t\t\tcontinue;\n \n-\t\thandle_cache(path, sha1, rerere_path(id, \"thisimage\"));\n+\t\thandle_cache(path, hash, rerere_path(id, \"thisimage\"));\n \t\tif (read_mmfile(&cur, rerere_path(id, \"thisimage\"))) {\n \t\t\tfree(cur.ptr);\n \t\t\terror(_(\"failed to update conflicted state in '%s'\"), path);\n@@ -1069,7 +1072,7 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)\n \t * conflict in the working tree, run us again to record\n \t * the postimage.\n \t */\n-\thandle_cache(path, sha1, rerere_path(id, \"preimage\"));\n+\thandle_cache(path, hash, rerere_path(id, \"preimage\"));\n \tfprintf_ln(stderr, _(\"Updated preimage for '%s'\"), path);\n \n \t/*\n"},{"id":"359876","messageId":"CAGZ79kYvW2PFdLfvd3W_t6rPs=oMBDxgMEgDRLtC4MHyo6MXVQ@mail.gmail.com","threadId":"49511","inReplyTo":"20181008215701.779099-3-sandals@crustytoothpaste.net","subject":"Re: [PATCH 02/14] builtin/repack: replace hard-coded constant","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-10-08T22:27:37Z","receivedAt":"2018-10-08T22:27:52Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  builtin/repack.c | 4 ++--\n>  1 file changed, 2 insertions(+), 2 deletions(-)\n>\n> diff --git a/builtin/repack.c b/builtin/repack.c\n> index c6a7943d5c..e77859062d 100644\n> --- a/builtin/repack.c\n> +++ b/builtin/repack.c\n> @@ -407,8 +407,8 @@ int cmd_repack(int argc, const char **argv, const char *prefix)\n>\n>         out = xfdopen(cmd.out, \"r\");\n>         while (strbuf_getline_lf(&line, out) != EOF) {\n> -               if (line.len != 40)\n> -                       die(\"repack: Expecting 40 character sha1 lines only from pack-objects.\");\n> +               if (line.len != the_hash_algo->hexsz)\n> +                       die(\"repack: Expecting full hex object ID lines only from pack-objects.\");\n\nThis is untranslated as it is plumbing?\nIf so, maybe\n\n    if (is_sha1(the_hash_algo)\n        die(\"repack: Expecting 40 character sh...\n    else\n        die(repack: Expecting full hex object ID in %s, of length %d\",\n            the_hash_algo->name,\n            the_hash_algo->hexsz);\n"},{"id":"359877","messageId":"CAGZ79kYeLiiU5tdO1n=cG3fPDWmezhd=oS=UiS=iZkxz+HfeFg@mail.gmail.com","threadId":"49511","inReplyTo":"20181008215701.779099-4-sandals@crustytoothpaste.net","subject":"Re: [PATCH 03/14] builtin/mktree: remove hard-coded constant","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-10-08T22:32:45Z","receivedAt":"2018-10-08T22:33:00Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> Instead of using a hard-coded constant for the size of a hex object ID,\n> switch to use the computed pointer from parse_oid_hex that points after\n> the parsed object ID.\n>\n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  builtin/mktree.c | 2 +-\n>  1 file changed, 1 insertion(+), 1 deletion(-)\n>\n> diff --git a/builtin/mktree.c b/builtin/mktree.c\n> index 2dc4ad6ba8..94e82b8504 100644\n> --- a/builtin/mktree.c\n> +++ b/builtin/mktree.c\n> @@ -98,7 +98,7 @@ static void mktree_line(char *buf, size_t len, int nul_term_line, int allow_miss\n>\n>         *ntr++ = 0; /* now at the beginning of SHA1 */\n>\n> -       path = ntr + 41;  /* at the beginning of name */\n> +       path = (char *)p + 1;  /* at the beginning of name */\n\n... and we need the cast to un-const p such that path takes it.\nMakes sense.\n"},{"id":"359878","messageId":"CAGZ79ka97gq5Vc_rp675=o0V+kJgZXhkTX3Da72QRCZwQWcM=g@mail.gmail.com","threadId":"49511","inReplyTo":"20181008215701.779099-6-sandals@crustytoothpaste.net","subject":"Re: [PATCH 05/14] pack-revindex: express constants in terms of the_hash_algo","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-10-08T22:44:36Z","receivedAt":"2018-10-08T22:44:51Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"> -       /* This knows the pack format -- the 20-byte trailer\n> +       /* This knows the pack format -- the hash trailer\n>          * follows immediately after the last object data.\n\nWhile at it, fix the comment style?\n\nWith or without the nit addressed, this patch (and patches\n1 and 4) are\n\n  Reviewed-by: Stefan Beller <sbeller@google.com>\n"},{"id":"359879","messageId":"CAGZ79kbirX6i+qkig6R1YOAsv=0BirhAVkar+AdBLyHgkrXYyg@mail.gmail.com","threadId":"49511","inReplyTo":"20181008215701.779099-7-sandals@crustytoothpaste.net","subject":"Re: [PATCH 06/14] packfile: express constants in terms of the_hash_algo","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-10-08T22:59:36Z","receivedAt":"2018-10-08T22:59:50Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> Replace uses of GIT_SHA1_RAWSZ with references to the_hash_algo to avoid\n> dependence on a particular hash length.\n\nUnlike the previous patches, this is dealing directly with packfiles,\nwhich (I would think) carry their own hash function selector?\n(i.e. packfiles up to version 4 are sha1 hardcoded and version\n5 and onwards will have a hash type field. Usually that hash type would\nmatch what is in the_repository, but you could obtain packfiles\nout of band, or the translation table that we plan to have might\nbe part of the packfile/idx file?)\n\n\n>\n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  packfile.c | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n>\n> diff --git a/packfile.c b/packfile.c\n> index 841b36182f..17f993b5bf 100644\n> --- a/packfile.c\n> +++ b/packfile.c\n> @@ -1121,13 +1121,14 @@ int unpack_object_header(struct packed_git *p,\n>  void mark_bad_packed_object(struct packed_git *p, const unsigned char *sha1)\n>  {\n>         unsigned i;\n> +       const unsigned hashsz = the_hash_algo->rawsz;\n>         for (i = 0; i < p->num_bad_objects; i++)\n> -               if (hasheq(sha1, p->bad_object_sha1 + GIT_SHA1_RAWSZ * i))\n> +               if (hasheq(sha1, p->bad_object_sha1 + hashsz * i))\n>                         return;\n>         p->bad_object_sha1 = xrealloc(p->bad_object_sha1,\n>                                       st_mult(GIT_MAX_RAWSZ,\n>                                               st_add(p->num_bad_objects, 1)));\n> -       hashcpy(p->bad_object_sha1 + GIT_SHA1_RAWSZ * p->num_bad_objects, sha1);\n> +       hashcpy(p->bad_object_sha1 + hashsz * p->num_bad_objects, sha1);\n>         p->num_bad_objects++;\n>  }\n>\n"},{"id":"359880","messageId":"CAPig+cS5VdYq1ZOrP9oPwpXZ3ZmSV3_QdQAHiz5fV1Tc1uEF9A@mail.gmail.com","threadId":"49511","inReplyTo":"CAGZ79kYvW2PFdLfvd3W_t6rPs=oMBDxgMEgDRLtC4MHyo6MXVQ@mail.gmail.com","subject":"Re: [PATCH 02/14] builtin/repack: replace hard-coded constant","fromName":"Eric Sunshine","fromEmail":"sunshine@sunshineco.com","sentAt":"2018-10-08T23:01:27Z","receivedAt":"2018-10-08T23:01:41Z","isPatch":true,"sender":{"key":"sunshine@sunshineco.com","avatar":"https://avatars.githubusercontent.com/u/163641?v=4"},"body":"On Mon, Oct 8, 2018 at 6:27 PM Stefan Beller <sbeller@google.com> wrote:\n> On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> > -               if (line.len != 40)\n> > -                       die(\"repack: Expecting 40 character sha1 lines only from pack-objects.\");\n> > +               if (line.len != the_hash_algo->hexsz)\n> > +                       die(\"repack: Expecting full hex object ID lines only from pack-objects.\");\n>\n> This is untranslated as it is plumbing? If so, maybe\n>\n>     if (is_sha1(the_hash_algo)\n>         die(\"repack: Expecting 40 character sh...\n>     else\n>         die(repack: Expecting full hex object ID in %s, of length %d\",\n>             the_hash_algo->name,\n>             the_hash_algo->hexsz);\n\nSpecial-casing for SHA-1 seems overkill for an error message. A script\nexpecting this particular error condition and this particular error\nmessage would be fragile indeed.\n"},{"id":"359883","messageId":"CAGZ79kbLqcvH9Zd5fH4NECvuES6FQ+jOFDcv713_5SXa-NvQ3g@mail.gmail.com","threadId":"49511","inReplyTo":"20181008215701.779099-14-sandals@crustytoothpaste.net","subject":"Re: [PATCH 13/14] submodule: make zero-oid comparison hash function agnostic","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-10-08T23:10:37Z","receivedAt":"2018-10-08T23:10:51Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> With SHA-256, the length of the all-zeros object ID is longer.  Add a\n> function to git-submodule.sh to check if a full hex object ID is the\n> all-zeros value, and use it to check the output we're parsing from git\n> diff-files or diff-index.\n>\n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n\nNice!\n"},{"id":"359884","messageId":"CAGZ79kZ+Kmo4QkatN7MufPy7UNT9_qb4om8J5oGB0D5aH+PtkQ@mail.gmail.com","threadId":"49511","inReplyTo":"20181008215701.779099-15-sandals@crustytoothpaste.net","subject":"Re: [PATCH 14/14] rerere: convert to use the_hash_algo","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-10-08T23:18:19Z","receivedAt":"2018-10-08T23:18:34Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> Since this data is stored in the .git directory, it makes sense for us\n> to use the same hash algorithm for it as for everything else.  Convert\n> the remaining uses of SHA-1 to use the_hash_algo.  Use GIT_MAX_RAWSZ for\n> allocations.  Rename various struct members, local variables, and a\n> function to be named \"hash\" instead of \"sha1\".\n>\n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  rerere.c | 81 +++++++++++++++++++++++++++++---------------------------\n>  1 file changed, 42 insertions(+), 39 deletions(-)\n\nI have reviewed all patches and had minor questions on some of them,\nall others look good to me.\n\nThanks,\nStefan\n"},{"id":"359954","messageId":"20181009222516.GR432229@genre.crustytoothpaste.net","threadId":"49511","inReplyTo":"CAGZ79kbirX6i+qkig6R1YOAsv=0BirhAVkar+AdBLyHgkrXYyg@mail.gmail.com","subject":"Re: [PATCH 06/14] packfile: express constants in terms of the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-09T22:25:16Z","receivedAt":"2018-10-09T22:25:25Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Oct 08, 2018 at 03:59:36PM -0700, Stefan Beller wrote:\n> On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> >\n> > Replace uses of GIT_SHA1_RAWSZ with references to the_hash_algo to avoid\n> > dependence on a particular hash length.\n> \n> Unlike the previous patches, this is dealing directly with packfiles,\n> which (I would think) carry their own hash function selector?\n> (i.e. packfiles up to version 4 are sha1 hardcoded and version\n> 5 and onwards will have a hash type field. Usually that hash type would\n> match what is in the_repository, but you could obtain packfiles\n> out of band, or the translation table that we plan to have might\n> be part of the packfile/idx file?)\n\nYeah, the transition plan doesn't specify a format for pack files, but\nwe may end up needing one.  We definitely have a specified format for\nindex files already, and that's where the translation table will be.\nAnything other than the pack index and the loose object index in the\n.git directory will have the same algorithm as the rest of the\nrepository, so technically we could use any pack format as long as it\nlives in the .git directory.\n\nThis code is mostly here on an interim basis to let us compile with a\nfully SHA-256 (no SHA-1) Git.  Once that piece is done, we can move on\nto a stage 4 Git, which can do either only SHA-256, or only SHA-1, where\nwe'll learn about various pack file formats and detecting the algorithm\nfrom them.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"359955","messageId":"20181009222616.GS432229@genre.crustytoothpaste.net","threadId":"49511","inReplyTo":"CAGZ79ka97gq5Vc_rp675=o0V+kJgZXhkTX3Da72QRCZwQWcM=g@mail.gmail.com","subject":"Re: [PATCH 05/14] pack-revindex: express constants in terms of the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-09T22:26:17Z","receivedAt":"2018-10-09T22:26:24Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Oct 08, 2018 at 03:44:36PM -0700, Stefan Beller wrote:\n> > -       /* This knows the pack format -- the 20-byte trailer\n> > +       /* This knows the pack format -- the hash trailer\n> >          * follows immediately after the last object data.\n> \n> While at it, fix the comment style?\n\nSure, I can do that.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"359956","messageId":"CAGZ79kbADWhuwk=7jzht5wZkESgT5ZqhhBOkGYGkC1HSSvExEA@mail.gmail.com","threadId":"49511","inReplyTo":"20181009222516.GR432229@genre.crustytoothpaste.net","subject":"Re: [PATCH 06/14] packfile: express constants in terms of the_hash_algo","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2018-10-09T22:34:17Z","receivedAt":"2018-10-09T22:34:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Tue, Oct 9, 2018 at 3:25 PM brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n>\n> On Mon, Oct 08, 2018 at 03:59:36PM -0700, Stefan Beller wrote:\n> > On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n> > <sandals@crustytoothpaste.net> wrote:\n> > >\n> > > Replace uses of GIT_SHA1_RAWSZ with references to the_hash_algo to avoid\n> > > dependence on a particular hash length.\n> >\n> > Unlike the previous patches, this is dealing directly with packfiles,\n> > which (I would think) carry their own hash function selector?\n> > (i.e. packfiles up to version 4 are sha1 hardcoded and version\n> > 5 and onwards will have a hash type field. Usually that hash type would\n> > match what is in the_repository, but you could obtain packfiles\n> > out of band, or the translation table that we plan to have might\n> > be part of the packfile/idx file?)\n>\n> Yeah, the transition plan doesn't specify a format for pack files, but\n> we may end up needing one.  We definitely have a specified format for\n> index files already, and that's where the translation table will be.\n> Anything other than the pack index and the loose object index in the\n> .git directory will have the same algorithm as the rest of the\n> repository, so technically we could use any pack format as long as it\n> lives in the .git directory.\n>\n> This code is mostly here on an interim basis to let us compile with a\n> fully SHA-256 (no SHA-1) Git.  Once that piece is done, we can move on\n> to a stage 4 Git, which can do either only SHA-256, or only SHA-1, where\n> we'll learn about various pack file formats and detecting the algorithm\n> from them.\n\nThis second paragraph really helps to put things into perspective, thanks!\nI assume this interim base of code only applies to this patch?\n(In that case maybe put it into the commit message?)\n"},{"id":"359958","messageId":"20181009225410.GT432229@genre.crustytoothpaste.net","threadId":"49511","inReplyTo":"CAGZ79kbADWhuwk=7jzht5wZkESgT5ZqhhBOkGYGkC1HSSvExEA@mail.gmail.com","subject":"Re: [PATCH 06/14] packfile: express constants in terms of the_hash_algo","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-09T22:54:10Z","receivedAt":"2018-10-09T22:54:18Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Tue, Oct 09, 2018 at 03:34:17PM -0700, Stefan Beller wrote:\n> On Tue, Oct 9, 2018 at 3:25 PM brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> > This code is mostly here on an interim basis to let us compile with a\n> > fully SHA-256 (no SHA-1) Git.  Once that piece is done, we can move on\n> > to a stage 4 Git, which can do either only SHA-256, or only SHA-1, where\n> > we'll learn about various pack file formats and detecting the algorithm\n> > from them.\n> \n> This second paragraph really helps to put things into perspective, thanks!\n> I assume this interim base of code only applies to this patch?\n> (In that case maybe put it into the commit message?)\n\nThat comment will apply to most of the changes to the packfile code,\nwhether in this series or in future series.  However, after your\nquestion, I was indeed going to put it into the commit message when I\nreroll.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"359959","messageId":"20181009230038.GU432229@genre.crustytoothpaste.net","threadId":"49511","inReplyTo":"CAPig+cS5VdYq1ZOrP9oPwpXZ3ZmSV3_QdQAHiz5fV1Tc1uEF9A@mail.gmail.com","subject":"Re: [PATCH 02/14] builtin/repack: replace hard-coded constant","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2018-10-09T23:00:38Z","receivedAt":"2018-10-09T23:00:47Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Mon, Oct 08, 2018 at 07:01:27PM -0400, Eric Sunshine wrote:\n> On Mon, Oct 8, 2018 at 6:27 PM Stefan Beller <sbeller@google.com> wrote:\n> > On Mon, Oct 8, 2018 at 2:57 PM brian m. carlson\n> > <sandals@crustytoothpaste.net> wrote:\n> > > -               if (line.len != 40)\n> > > -                       die(\"repack: Expecting 40 character sha1 lines only from pack-objects.\");\n> > > +               if (line.len != the_hash_algo->hexsz)\n> > > +                       die(\"repack: Expecting full hex object ID lines only from pack-objects.\");\n> >\n> > This is untranslated as it is plumbing? If so, maybe\n> >\n> >     if (is_sha1(the_hash_algo)\n> >         die(\"repack: Expecting 40 character sh...\n> >     else\n> >         die(repack: Expecting full hex object ID in %s, of length %d\",\n> >             the_hash_algo->name,\n> >             the_hash_algo->hexsz);\n> \n> Special-casing for SHA-1 seems overkill for an error message. A script\n> expecting this particular error condition and this particular error\n> message would be fragile indeed.\n\nYeah, I don't think a special case is needed here.  Moreover, since we\njust invoked pack-objects ourselves and are now reading the output of\nit, seeing this error message means that someone has broken Git in a\nsignificant way.  The end user should never see this message.\n-- \nbrian m. carlson: Houston, Texas, US\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"360302","messageId":"20181012131116.23733-1-szeder.dev@gmail.com","threadId":"49511","inReplyTo":"20181008215701.779099-15-sandals@crustytoothpaste.net","subject":"[PATCH] object_id.cocci: match only expressions of type 'struct object_id'","fromName":"SZEDER Gábor","fromEmail":"szeder.dev@gmail.com","sentAt":"2018-10-12T13:11:16Z","receivedAt":"2018-10-12T13:11:24Z","isPatch":true,"sender":{"key":"szeder.dev@gmail.com","avatar":"https://avatars.githubusercontent.com/u/116324?v=4"},"body":"Most of our semantic patches in 'contrib/coccinelle/object_id.cocci'\nturn calls of SHA1-specific functions into calls of their\ncorresponding object_id counterparts, e.g. sha1_to_hex() to\noid_to_hex().  These semantic patches look something like this:\n\n  @@\n  expression E1;\n  @@\n  - sha1_to_hex(E1.hash)\n  + oid_to_hex(&E1)\n\nand match the access to the 'hash' field in any data type, not only in\n'struct object_id', and, consquently, can produce wrong\ntransformations.\n\nCase in point is the recent hash function transition patch \"rerere:\nconvert to use the_hash_algo\" [1], which, among other things, renamed\n'struct rerere_dir's 'sha1' field to 'hash', and then 'make\ncoccicheck' started to suggest the following wrong transformations for\n'rerere.c' [2]:\n\n  -    return sha1_to_hex(id->collection->hash);\n  +    return oid_to_hex(id->collection);\n\nand\n\n  -    DIR *dir = opendir(git_path(\"rr-cache/%s\", sha1_to_hex(rr_dir->hash)));\n  +    DIR *dir = opendir(git_path(\"rr-cache/%s\", oid_to_hex(rr_dir)));\n\nAvoid such wrong transformations by tightening semantic patches in\n'object_id.cocci' to match only type of or pointers to 'struct\nobject_id'.\n\n[1] https://public-inbox.org/git/20181008215701.779099-15-sandals@crustytoothpaste.net/\n[2] https://travis-ci.org/git/git/jobs/440463476#L580\n\nSigned-off-by: SZEDER Gábor <szeder.dev@gmail.com>\n---\n\nI think this patch should come before that patch mentioned in the commit\nmessage, or perhaps even before the whole patch series.\n\n contrib/coccinelle/object_id.cocci | 117 ++++++++++++++++-------------\n 1 file changed, 63 insertions(+), 54 deletions(-)\n\ndiff --git a/contrib/coccinelle/object_id.cocci b/contrib/coccinelle/object_id.cocci\nindex d8bdb48712..6a7cf3e02d 100644\n--- a/contrib/coccinelle/object_id.cocci\n+++ b/contrib/coccinelle/object_id.cocci\n@@ -1,119 +1,127 @@\n @@\n-expression E1;\n+struct object_id OID;\n @@\n-- is_null_sha1(E1.hash)\n-+ is_null_oid(&E1)\n+- is_null_sha1(OID.hash)\n++ is_null_oid(&OID)\n \n @@\n-expression E1;\n+struct object_id *OIDPTR;\n @@\n-- is_null_sha1(E1->hash)\n-+ is_null_oid(E1)\n+- is_null_sha1(OIDPTR->hash)\n++ is_null_oid(OIDPTR)\n \n @@\n-expression E1;\n+struct object_id OID;\n @@\n-- sha1_to_hex(E1.hash)\n-+ oid_to_hex(&E1)\n+- sha1_to_hex(OID.hash)\n++ oid_to_hex(&OID)\n \n @@\n identifier f != oid_to_hex;\n-expression E1;\n+struct object_id *OIDPTR;\n @@\n   f(...) {<...\n-- sha1_to_hex(E1->hash)\n-+ oid_to_hex(E1)\n+- sha1_to_hex(OIDPTR->hash)\n++ oid_to_hex(OIDPTR)\n   ...>}\n \n @@\n-expression E1, E2;\n+expression E;\n+struct object_id OID;\n @@\n-- sha1_to_hex_r(E1, E2.hash)\n-+ oid_to_hex_r(E1, &E2)\n+- sha1_to_hex_r(E, OID.hash)\n++ oid_to_hex_r(E, &OID)\n \n @@\n identifier f != oid_to_hex_r;\n-expression E1, E2;\n+expression E;\n+struct object_id *OIDPTR;\n @@\n    f(...) {<...\n-- sha1_to_hex_r(E1, E2->hash)\n-+ oid_to_hex_r(E1, E2)\n+- sha1_to_hex_r(E, OIDPTR->hash)\n++ oid_to_hex_r(E, OIDPTR)\n   ...>}\n \n @@\n-expression E1;\n+struct object_id OID;\n @@\n-- hashclr(E1.hash)\n-+ oidclr(&E1)\n+- hashclr(OID.hash)\n++ oidclr(&OID)\n \n @@\n identifier f != oidclr;\n-expression E1;\n+struct object_id *OIDPTR;\n @@\n   f(...) {<...\n-- hashclr(E1->hash)\n-+ oidclr(E1)\n+- hashclr(OIDPTR->hash)\n++ oidclr(OIDPTR)\n   ...>}\n \n @@\n-expression E1, E2;\n+struct object_id OID1, OID2;\n @@\n-- hashcmp(E1.hash, E2.hash)\n-+ oidcmp(&E1, &E2)\n+- hashcmp(OID1.hash, OID2.hash)\n++ oidcmp(&OID1, &OID2)\n \n @@\n identifier f != oidcmp;\n-expression E1, E2;\n+struct object_id *OIDPTR1, OIDPTR2;\n @@\n   f(...) {<...\n-- hashcmp(E1->hash, E2->hash)\n-+ oidcmp(E1, E2)\n+- hashcmp(OIDPTR1->hash, OIDPTR2->hash)\n++ oidcmp(OIDPTR1, OIDPTR2)\n   ...>}\n \n @@\n-expression E1, E2;\n+struct object_id *OIDPTR;\n+struct object_id OID;\n @@\n-- hashcmp(E1->hash, E2.hash)\n-+ oidcmp(E1, &E2)\n+- hashcmp(OIDPTR->hash, OID.hash)\n++ oidcmp(OIDPTR, &OID)\n \n @@\n-expression E1, E2;\n+struct object_id *OIDPTR;\n+struct object_id OID;\n @@\n-- hashcmp(E1.hash, E2->hash)\n-+ oidcmp(&E1, E2)\n+- hashcmp(OID.hash, OIDPTR->hash)\n++ oidcmp(&OID, OIDPTR)\n \n @@\n-expression E1, E2;\n+struct object_id OID1, OID2;\n @@\n-- hashcpy(E1.hash, E2.hash)\n-+ oidcpy(&E1, &E2)\n+- hashcpy(OID1.hash, OID2.hash)\n++ oidcpy(&OID1, &OID2)\n \n @@\n identifier f != oidcpy;\n-expression E1, E2;\n+struct object_id *OIDPTR1;\n+struct object_id *OIDPTR2;\n @@\n   f(...) {<...\n-- hashcpy(E1->hash, E2->hash)\n-+ oidcpy(E1, E2)\n+- hashcpy(OIDPTR1->hash, OIDPTR2->hash)\n++ oidcpy(OIDPTR1, OIDPTR2)\n   ...>}\n \n @@\n-expression E1, E2;\n+struct object_id *OIDPTR;\n+struct object_id OID;\n @@\n-- hashcpy(E1->hash, E2.hash)\n-+ oidcpy(E1, &E2)\n+- hashcpy(OIDPTR->hash, OID.hash)\n++ oidcpy(OIDPTR, &OID)\n \n @@\n-expression E1, E2;\n+struct object_id *OIDPTR;\n+struct object_id OID;\n @@\n-- hashcpy(E1.hash, E2->hash)\n-+ oidcpy(&E1, E2)\n+- hashcpy(OID.hash, OIDPTR->hash)\n++ oidcpy(&OID, OIDPTR)\n \n @@\n-expression E1, E2;\n+struct object_id *OIDPTR1;\n+struct object_id *OIDPTR2;\n @@\n-- oidcmp(E1, E2) == 0\n-+ oideq(E1, E2)\n+- oidcmp(OIDPTR1, OIDPTR2) == 0\n++ oideq(OIDPTR1, OIDPTR2)\n \n @@\n identifier f != hasheq;\n@@ -125,10 +133,11 @@ expression E1, E2;\n   ...>}\n \n @@\n-expression E1, E2;\n+struct object_id *OIDPTR1;\n+struct object_id *OIDPTR2;\n @@\n-- oidcmp(E1, E2) != 0\n-+ !oideq(E1, E2)\n+- oidcmp(OIDPTR1, OIDPTR2) != 0\n++ !oideq(OIDPTR1, OIDPTR2)\n \n @@\n identifier f != hasheq;\n-- \n2.19.1.465.gaff195083f\n\n"},{"id":"360474","messageId":"xmqqh8ho6ipe.fsf@gitster-ct.c.googlers.com","threadId":"49511","inReplyTo":"20181012131116.23733-1-szeder.dev@gmail.com","subject":"Re: [PATCH] object_id.cocci: match only expressions of type 'struct object_id'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-10-15T02:34:53Z","receivedAt":"2018-10-15T02:34:58Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"SZEDER Gábor <szeder.dev@gmail.com> writes:\n\n> Most of our semantic patches in 'contrib/coccinelle/object_id.cocci'\n> turn calls of SHA1-specific functions into calls of their\n> corresponding object_id counterparts, e.g. sha1_to_hex() to\n> oid_to_hex().  These semantic patches look something like this:\n>\n>   @@\n>   expression E1;\n>   @@\n>   - sha1_to_hex(E1.hash)\n>   + oid_to_hex(&E1)\n>\n> and match the access to the 'hash' field in any data type, not only in\n> 'struct object_id', and, consquently, can produce wrong\n> transformations.\n\nThanks, will queue.\n\n"},{"id":"360481","messageId":"xmqqefcr6dne.fsf@gitster-ct.c.googlers.com","threadId":"49511","inReplyTo":"xmqqh8ho6ipe.fsf@gitster-ct.c.googlers.com","subject":"Re: [PATCH] object_id.cocci: match only expressions of type 'struct object_id'","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2018-10-15T04:24:05Z","receivedAt":"2018-10-15T04:24:10Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> SZEDER Gábor <szeder.dev@gmail.com> writes:\n>\n>> Most of our semantic patches in 'contrib/coccinelle/object_id.cocci'\n>> turn calls of SHA1-specific functions into calls of their\n>> corresponding object_id counterparts, e.g. sha1_to_hex() to\n>> oid_to_hex().  These semantic patches look something like this:\n>>\n>>   @@\n>>   expression E1;\n>>   @@\n>>   - sha1_to_hex(E1.hash)\n>>   + oid_to_hex(&E1)\n>>\n>> and match the access to the 'hash' field in any data type, not only in\n>> 'struct object_id', and, consquently, can produce wrong\n>> transformations.\n>\n> Thanks, will queue.\n\nI ended up taking this as part of Brian's \"the-hash-algo\" series.\n"}]}