{"thread":{"id":"44012","subject":"[PATCH v2 19/20] builtin/commit-tree: convert to struct object_id","startedAt":"2016-09-05T20:09:51Z","lastAt":"2016-09-07T23:05:16Z","messageCount":24,"participants":["brian m. carlson","Junio C Hamano"],"isPatch":true,"patchVersion":2,"patchTotal":20},"messages":[{"id":"301116","messageId":"20160905200811.697889-20-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 19/20] builtin/commit-tree: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:10Z","receivedAt":"2016-09-05T20:09:51Z","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/commit-tree.c | 20 ++++++++++----------\n 1 file changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/commit-tree.c b/builtin/commit-tree.c\nindex 8a674bc9..60501726 100644\n--- a/builtin/commit-tree.c\n+++ b/builtin/commit-tree.c\n@@ -40,8 +40,8 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n {\n \tint i, got_tree = 0;\n \tstruct commit_list *parents = NULL;\n-\tunsigned char tree_sha1[20];\n-\tunsigned char commit_sha1[20];\n+\tstruct object_id tree_oid;\n+\tstruct object_id commit_oid;\n \tstruct strbuf buffer = STRBUF_INIT;\n \n \tgit_config(commit_tree_config, NULL);\n@@ -52,13 +52,13 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \tfor (i = 1; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n \t\tif (!strcmp(arg, \"-p\")) {\n-\t\t\tunsigned char sha1[20];\n+\t\t\tstruct object_id oid;\n \t\t\tif (argc <= ++i)\n \t\t\t\tusage(commit_tree_usage);\n-\t\t\tif (get_sha1_commit(argv[i], sha1))\n+\t\t\tif (get_sha1_commit(argv[i], oid.hash))\n \t\t\t\tdie(\"Not a valid object name %s\", argv[i]);\n-\t\t\tassert_sha1_type(sha1, OBJ_COMMIT);\n-\t\t\tnew_parent(lookup_commit(sha1), &parents);\n+\t\t\tassert_sha1_type(oid.hash, OBJ_COMMIT);\n+\t\t\tnew_parent(lookup_commit(oid.hash), &parents);\n \t\t\tcontinue;\n \t\t}\n \n@@ -105,7 +105,7 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \t\t\tcontinue;\n \t\t}\n \n-\t\tif (get_sha1_tree(arg, tree_sha1))\n+\t\tif (get_sha1_tree(arg, tree_oid.hash))\n \t\t\tdie(\"Not a valid object name %s\", arg);\n \t\tif (got_tree)\n \t\t\tdie(\"Cannot give more than one trees\");\n@@ -117,13 +117,13 @@ int cmd_commit_tree(int argc, const char **argv, const char *prefix)\n \t\t\tdie_errno(\"git commit-tree: failed to read\");\n \t}\n \n-\tif (commit_tree(buffer.buf, buffer.len, tree_sha1, parents,\n-\t\t\tcommit_sha1, NULL, sign_commit)) {\n+\tif (commit_tree(buffer.buf, buffer.len, tree_oid.hash, parents,\n+\t\t\tcommit_oid.hash, NULL, sign_commit)) {\n \t\tstrbuf_release(&buffer);\n \t\treturn 1;\n \t}\n \n-\tprintf(\"%s\\n\", sha1_to_hex(commit_sha1));\n+\tprintf(\"%s\\n\", oid_to_hex(&commit_oid));\n \tstrbuf_release(&buffer);\n \treturn 0;\n }\n"},{"id":"301117","messageId":"20160905200811.697889-19-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 18/20] builtin/am: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:09Z","receivedAt":"2016-09-05T20:09:55Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert uses of unsigned char [20] to struct object_id.  Rename the\ngenerically-named \"ptr\" to \"old_oid\" and make it const.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/am.c | 140 +++++++++++++++++++++++++++++------------------------------\n 1 file changed, 70 insertions(+), 70 deletions(-)\n\ndiff --git a/builtin/am.c b/builtin/am.c\nindex 739b34dc..1b4829a1 100644\n--- a/builtin/am.c\n+++ b/builtin/am.c\n@@ -108,7 +108,7 @@ struct am_state {\n \tsize_t msg_len;\n \n \t/* when --rebasing, records the original commit the patch came from */\n-\tunsigned char orig_commit[GIT_SHA1_RAWSZ];\n+\tstruct object_id orig_commit;\n \n \t/* number of digits in patch filename */\n \tint prec;\n@@ -428,8 +428,8 @@ static void am_load(struct am_state *state)\n \tread_commit_msg(state);\n \n \tif (read_state_file(&sb, state, \"original-commit\", 1) < 0)\n-\t\thashclr(state->orig_commit);\n-\telse if (get_sha1_hex(sb.buf, state->orig_commit) < 0)\n+\t\toidclr(&state->orig_commit);\n+\telse if (get_oid_hex(sb.buf, &state->orig_commit) < 0)\n \t\tdie(_(\"could not parse %s\"), am_path(state, \"original-commit\"));\n \n \tread_state_file(&sb, state, \"threeway\", 1);\n@@ -555,14 +555,14 @@ static int copy_notes_for_rebase(const struct am_state *state)\n \tfp = xfopen(am_path(state, \"rewritten\"), \"r\");\n \n \twhile (!strbuf_getline_lf(&sb, fp)) {\n-\t\tunsigned char from_obj[GIT_SHA1_RAWSZ], to_obj[GIT_SHA1_RAWSZ];\n+\t\tstruct object_id from_obj, to_obj;\n \n \t\tif (sb.len != GIT_SHA1_HEXSZ * 2 + 1) {\n \t\t\tret = error(invalid_line, sb.buf);\n \t\t\tgoto finish;\n \t\t}\n \n-\t\tif (get_sha1_hex(sb.buf, from_obj)) {\n+\t\tif (get_oid_hex(sb.buf, &from_obj)) {\n \t\t\tret = error(invalid_line, sb.buf);\n \t\t\tgoto finish;\n \t\t}\n@@ -572,14 +572,14 @@ static int copy_notes_for_rebase(const struct am_state *state)\n \t\t\tgoto finish;\n \t\t}\n \n-\t\tif (get_sha1_hex(sb.buf + GIT_SHA1_HEXSZ + 1, to_obj)) {\n+\t\tif (get_oid_hex(sb.buf + GIT_SHA1_HEXSZ + 1, &to_obj)) {\n \t\t\tret = error(invalid_line, sb.buf);\n \t\t\tgoto finish;\n \t\t}\n \n-\t\tif (copy_note_for_rewrite(c, from_obj, to_obj))\n+\t\tif (copy_note_for_rewrite(c, from_obj.hash, to_obj.hash))\n \t\t\tret = error(_(\"Failed to copy notes from '%s' to '%s'\"),\n-\t\t\t\t\tsha1_to_hex(from_obj), sha1_to_hex(to_obj));\n+\t\t\t\t\toid_to_hex(&from_obj), oid_to_hex(&to_obj));\n \t}\n \n finish:\n@@ -985,7 +985,7 @@ static int split_mail(struct am_state *state, enum patch_format patch_format,\n static void am_setup(struct am_state *state, enum patch_format patch_format,\n \t\t\tconst char **paths, int keep_cr)\n {\n-\tunsigned char curr_head[GIT_SHA1_RAWSZ];\n+\tstruct object_id curr_head;\n \tconst char *str;\n \tstruct strbuf sb = STRBUF_INIT;\n \n@@ -1053,10 +1053,10 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,\n \telse\n \t\twrite_state_text(state, \"applying\", \"\");\n \n-\tif (!get_sha1(\"HEAD\", curr_head)) {\n-\t\twrite_state_text(state, \"abort-safety\", sha1_to_hex(curr_head));\n+\tif (!get_oid(\"HEAD\", &curr_head)) {\n+\t\twrite_state_text(state, \"abort-safety\", oid_to_hex(&curr_head));\n \t\tif (!state->rebasing)\n-\t\t\tupdate_ref(\"am\", \"ORIG_HEAD\", curr_head, NULL, 0,\n+\t\t\tupdate_ref_oid(\"am\", \"ORIG_HEAD\", &curr_head, NULL, 0,\n \t\t\t\t\tUPDATE_REFS_DIE_ON_ERR);\n \t} else {\n \t\twrite_state_text(state, \"abort-safety\", \"\");\n@@ -1081,7 +1081,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format,\n  */\n static void am_next(struct am_state *state)\n {\n-\tunsigned char head[GIT_SHA1_RAWSZ];\n+\tstruct object_id head;\n \n \tfree(state->author_name);\n \tstate->author_name = NULL;\n@@ -1099,11 +1099,11 @@ static void am_next(struct am_state *state)\n \tunlink(am_path(state, \"author-script\"));\n \tunlink(am_path(state, \"final-commit\"));\n \n-\thashclr(state->orig_commit);\n+\toidclr(&state->orig_commit);\n \tunlink(am_path(state, \"original-commit\"));\n \n-\tif (!get_sha1(\"HEAD\", head))\n-\t\twrite_state_text(state, \"abort-safety\", sha1_to_hex(head));\n+\tif (!get_oid(\"HEAD\", &head))\n+\t\twrite_state_text(state, \"abort-safety\", oid_to_hex(&head));\n \telse\n \t\twrite_state_text(state, \"abort-safety\", \"\");\n \n@@ -1145,17 +1145,17 @@ static void refresh_and_write_cache(void)\n  */\n static int index_has_changes(struct strbuf *sb)\n {\n-\tunsigned char head[GIT_SHA1_RAWSZ];\n+\tstruct object_id head;\n \tint i;\n \n-\tif (!get_sha1_tree(\"HEAD\", head)) {\n+\tif (!get_sha1_tree(\"HEAD\", head.hash)) {\n \t\tstruct diff_options opt;\n \n \t\tdiff_setup(&opt);\n \t\tDIFF_OPT_SET(&opt, EXIT_WITH_STATUS);\n \t\tif (!sb)\n \t\t\tDIFF_OPT_SET(&opt, QUICK);\n-\t\tdo_diff_cache(head, &opt);\n+\t\tdo_diff_cache(head.hash, &opt);\n \t\tdiffcore_std(&opt);\n \t\tfor (i = 0; sb && i < diff_queued_diff.nr; i++) {\n \t\t\tif (i)\n@@ -1362,7 +1362,7 @@ static int parse_mail(struct am_state *state, const char *mail)\n  * Sets commit_id to the commit hash where the mail was generated from.\n  * Returns 0 on success, -1 on failure.\n  */\n-static int get_mail_commit_sha1(unsigned char *commit_id, const char *mail)\n+static int get_mail_commit_oid(struct object_id *commit_id, const char *mail)\n {\n \tstruct strbuf sb = STRBUF_INIT;\n \tFILE *fp = xfopen(mail, \"r\");\n@@ -1374,7 +1374,7 @@ static int get_mail_commit_sha1(unsigned char *commit_id, const char *mail)\n \tif (!skip_prefix(sb.buf, \"From \", &x))\n \t\treturn -1;\n \n-\tif (get_sha1_hex(x, commit_id) < 0)\n+\tif (get_oid_hex(x, commit_id) < 0)\n \t\treturn -1;\n \n \tstrbuf_release(&sb);\n@@ -1464,12 +1464,12 @@ static void write_commit_patch(const struct am_state *state, struct commit *comm\n static void write_index_patch(const struct am_state *state)\n {\n \tstruct tree *tree;\n-\tunsigned char head[GIT_SHA1_RAWSZ];\n+\tstruct object_id head;\n \tstruct rev_info rev_info;\n \tFILE *fp;\n \n-\tif (!get_sha1_tree(\"HEAD\", head))\n-\t\ttree = lookup_tree(head);\n+\tif (!get_sha1_tree(\"HEAD\", head.hash))\n+\t\ttree = lookup_tree(head.hash);\n \telse\n \t\ttree = lookup_tree(EMPTY_TREE_SHA1_BIN);\n \n@@ -1499,19 +1499,19 @@ static void write_index_patch(const struct am_state *state)\n static int parse_mail_rebase(struct am_state *state, const char *mail)\n {\n \tstruct commit *commit;\n-\tunsigned char commit_sha1[GIT_SHA1_RAWSZ];\n+\tstruct object_id commit_oid;\n \n-\tif (get_mail_commit_sha1(commit_sha1, mail) < 0)\n+\tif (get_mail_commit_oid(&commit_oid, mail) < 0)\n \t\tdie(_(\"could not parse %s\"), mail);\n \n-\tcommit = lookup_commit_or_die(commit_sha1, mail);\n+\tcommit = lookup_commit_or_die(commit_oid.hash, mail);\n \n \tget_commit_info(state, commit);\n \n \twrite_commit_patch(state, commit);\n \n-\thashcpy(state->orig_commit, commit_sha1);\n-\twrite_state_text(state, \"original-commit\", sha1_to_hex(commit_sha1));\n+\toidcpy(&state->orig_commit, &commit_oid);\n+\twrite_state_text(state, \"original-commit\", oid_to_hex(&commit_oid));\n \n \treturn 0;\n }\n@@ -1665,9 +1665,8 @@ static int fall_back_threeway(const struct am_state *state, const char *index_pa\n  */\n static void do_commit(const struct am_state *state)\n {\n-\tunsigned char tree[GIT_SHA1_RAWSZ], parent[GIT_SHA1_RAWSZ],\n-\t\t      commit[GIT_SHA1_RAWSZ];\n-\tunsigned char *ptr;\n+\tstruct object_id tree, parent, commit;\n+\tconst struct object_id *old_oid;\n \tstruct commit_list *parents = NULL;\n \tconst char *reflog_msg, *author;\n \tstruct strbuf sb = STRBUF_INIT;\n@@ -1675,14 +1674,14 @@ static void do_commit(const struct am_state *state)\n \tif (run_hook_le(NULL, \"pre-applypatch\", NULL))\n \t\texit(1);\n \n-\tif (write_cache_as_tree(tree, 0, NULL))\n+\tif (write_cache_as_tree(tree.hash, 0, NULL))\n \t\tdie(_(\"git write-tree failed to write a tree\"));\n \n-\tif (!get_sha1_commit(\"HEAD\", parent)) {\n-\t\tptr = parent;\n-\t\tcommit_list_insert(lookup_commit(parent), &parents);\n+\tif (!get_sha1_commit(\"HEAD\", parent.hash)) {\n+\t\told_oid = &parent;\n+\t\tcommit_list_insert(lookup_commit(parent.hash), &parents);\n \t} else {\n-\t\tptr = NULL;\n+\t\told_oid = NULL;\n \t\tsay(state, stderr, _(\"applying to an empty history\"));\n \t}\n \n@@ -1694,7 +1693,7 @@ static void do_commit(const struct am_state *state)\n \t\tsetenv(\"GIT_COMMITTER_DATE\",\n \t\t\tstate->ignore_date ? \"\" : state->author_date, 1);\n \n-\tif (commit_tree(state->msg, state->msg_len, tree, parents, commit,\n+\tif (commit_tree(state->msg, state->msg_len, tree.hash, parents, commit.hash,\n \t\t\t\tauthor, state->sign_commit))\n \t\tdie(_(\"failed to write commit object\"));\n \n@@ -1705,14 +1704,15 @@ static void do_commit(const struct am_state *state)\n \tstrbuf_addf(&sb, \"%s: %.*s\", reflog_msg, linelen(state->msg),\n \t\t\tstate->msg);\n \n-\tupdate_ref(sb.buf, \"HEAD\", commit, ptr, 0, UPDATE_REFS_DIE_ON_ERR);\n+\tupdate_ref_oid(sb.buf, \"HEAD\", &commit, old_oid, 0,\n+\t\t\tUPDATE_REFS_DIE_ON_ERR);\n \n \tif (state->rebasing) {\n \t\tFILE *fp = xfopen(am_path(state, \"rewritten\"), \"a\");\n \n-\t\tassert(!is_null_sha1(state->orig_commit));\n-\t\tfprintf(fp, \"%s \", sha1_to_hex(state->orig_commit));\n-\t\tfprintf(fp, \"%s\\n\", sha1_to_hex(commit));\n+\t\tassert(!is_null_oid(&state->orig_commit));\n+\t\tfprintf(fp, \"%s \", oid_to_hex(&state->orig_commit));\n+\t\tfprintf(fp, \"%s\\n\", oid_to_hex(&commit));\n \t\tfclose(fp);\n \t}\n \n@@ -2033,30 +2033,30 @@ static int merge_tree(struct tree *tree)\n  * Clean the index without touching entries that are not modified between\n  * `head` and `remote`.\n  */\n-static int clean_index(const unsigned char *head, const unsigned char *remote)\n+static int clean_index(const struct object_id *head, const struct object_id *remote)\n {\n \tstruct tree *head_tree, *remote_tree, *index_tree;\n-\tunsigned char index[GIT_SHA1_RAWSZ];\n+\tstruct object_id index;\n \n-\thead_tree = parse_tree_indirect(head);\n+\thead_tree = parse_tree_indirect(head->hash);\n \tif (!head_tree)\n-\t\treturn error(_(\"Could not parse object '%s'.\"), sha1_to_hex(head));\n+\t\treturn error(_(\"Could not parse object '%s'.\"), oid_to_hex(head));\n \n-\tremote_tree = parse_tree_indirect(remote);\n+\tremote_tree = parse_tree_indirect(remote->hash);\n \tif (!remote_tree)\n-\t\treturn error(_(\"Could not parse object '%s'.\"), sha1_to_hex(remote));\n+\t\treturn error(_(\"Could not parse object '%s'.\"), oid_to_hex(remote));\n \n \tread_cache_unmerged();\n \n \tif (fast_forward_to(head_tree, head_tree, 1))\n \t\treturn -1;\n \n-\tif (write_cache_as_tree(index, 0, NULL))\n+\tif (write_cache_as_tree(index.hash, 0, NULL))\n \t\treturn -1;\n \n-\tindex_tree = parse_tree_indirect(index);\n+\tindex_tree = parse_tree_indirect(index.hash);\n \tif (!index_tree)\n-\t\treturn error(_(\"Could not parse object '%s'.\"), sha1_to_hex(index));\n+\t\treturn error(_(\"Could not parse object '%s'.\"), oid_to_hex(&index));\n \n \tif (fast_forward_to(index_tree, remote_tree, 0))\n \t\treturn -1;\n@@ -2084,14 +2084,14 @@ static void am_rerere_clear(void)\n  */\n static void am_skip(struct am_state *state)\n {\n-\tunsigned char head[GIT_SHA1_RAWSZ];\n+\tstruct object_id head;\n \n \tam_rerere_clear();\n \n-\tif (get_sha1(\"HEAD\", head))\n-\t\thashcpy(head, EMPTY_TREE_SHA1_BIN);\n+\tif (get_oid(\"HEAD\", &head))\n+\t\thashcpy(head.hash, EMPTY_TREE_SHA1_BIN);\n \n-\tif (clean_index(head, head))\n+\tif (clean_index(&head, &head))\n \t\tdie(_(\"failed to clean index\"));\n \n \tam_next(state);\n@@ -2109,21 +2109,21 @@ static void am_skip(struct am_state *state)\n static int safe_to_abort(const struct am_state *state)\n {\n \tstruct strbuf sb = STRBUF_INIT;\n-\tunsigned char abort_safety[GIT_SHA1_RAWSZ], head[GIT_SHA1_RAWSZ];\n+\tstruct object_id abort_safety, head;\n \n \tif (file_exists(am_path(state, \"dirtyindex\")))\n \t\treturn 0;\n \n \tif (read_state_file(&sb, state, \"abort-safety\", 1) > 0) {\n-\t\tif (get_sha1_hex(sb.buf, abort_safety))\n+\t\tif (get_oid_hex(sb.buf, &abort_safety))\n \t\t\tdie(_(\"could not parse %s\"), am_path(state, \"abort_safety\"));\n \t} else\n-\t\thashclr(abort_safety);\n+\t\toidclr(&abort_safety);\n \n-\tif (get_sha1(\"HEAD\", head))\n-\t\thashclr(head);\n+\tif (get_oid(\"HEAD\", &head))\n+\t\toidclr(&head);\n \n-\tif (!hashcmp(head, abort_safety))\n+\tif (!oidcmp(&head, &abort_safety))\n \t\treturn 1;\n \n \terror(_(\"You seem to have moved HEAD since the last 'am' failure.\\n\"\n@@ -2137,7 +2137,7 @@ static int safe_to_abort(const struct am_state *state)\n  */\n static void am_abort(struct am_state *state)\n {\n-\tunsigned char curr_head[GIT_SHA1_RAWSZ], orig_head[GIT_SHA1_RAWSZ];\n+\tstruct object_id curr_head, orig_head;\n \tint has_curr_head, has_orig_head;\n \tchar *curr_branch;\n \n@@ -2148,20 +2148,20 @@ static void am_abort(struct am_state *state)\n \n \tam_rerere_clear();\n \n-\tcurr_branch = resolve_refdup(\"HEAD\", 0, curr_head, NULL);\n-\thas_curr_head = !is_null_sha1(curr_head);\n+\tcurr_branch = resolve_refdup(\"HEAD\", 0, curr_head.hash, NULL);\n+\thas_curr_head = !is_null_oid(&curr_head);\n \tif (!has_curr_head)\n-\t\thashcpy(curr_head, EMPTY_TREE_SHA1_BIN);\n+\t\thashcpy(curr_head.hash, EMPTY_TREE_SHA1_BIN);\n \n-\thas_orig_head = !get_sha1(\"ORIG_HEAD\", orig_head);\n+\thas_orig_head = !get_oid(\"ORIG_HEAD\", &orig_head);\n \tif (!has_orig_head)\n-\t\thashcpy(orig_head, EMPTY_TREE_SHA1_BIN);\n+\t\thashcpy(orig_head.hash, EMPTY_TREE_SHA1_BIN);\n \n-\tclean_index(curr_head, orig_head);\n+\tclean_index(&curr_head, &orig_head);\n \n \tif (has_orig_head)\n-\t\tupdate_ref(\"am --abort\", \"HEAD\", orig_head,\n-\t\t\t\thas_curr_head ? curr_head : NULL, 0,\n+\t\tupdate_ref_oid(\"am --abort\", \"HEAD\", &orig_head,\n+\t\t\t\thas_curr_head ? &curr_head : NULL, 0,\n \t\t\t\tUPDATE_REFS_DIE_ON_ERR);\n \telse if (curr_branch)\n \t\tdelete_ref(curr_branch, NULL, REF_NODEREF);\n"},{"id":"301118","messageId":"20160905200811.697889-18-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 17/20] refs: add an update_ref_oid function.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:08Z","receivedAt":"2016-09-05T20:09:58Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Several places around the codebase want to pass update_ref data from\nstruct object_id, but update_ref may also be passed NULL pointers.\nInstead of checking and dereferencing in every caller, create an\nupdate_ref_oid which wraps update_ref and provides this functionality.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n refs.c | 8 ++++++++\n refs.h | 3 +++\n 2 files changed, 11 insertions(+)\n\ndiff --git a/refs.c b/refs.c\nindex b4e7cac7..f567a78e 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -858,6 +858,14 @@ int ref_transaction_verify(struct ref_transaction *transaction,\n \t\t\t\t      flags, NULL, err);\n }\n \n+int update_ref_oid(const char *msg, const char *refname,\n+\t       const struct object_id *new_oid, const struct object_id *old_oid,\n+\t       unsigned int flags, enum action_on_err onerr)\n+{\n+\treturn update_ref(msg, refname, new_oid ? new_oid->hash : NULL,\n+\t\told_oid ? old_oid->hash : NULL, flags, onerr);\n+}\n+\n int update_ref(const char *msg, const char *refname,\n \t       const unsigned char *new_sha1, const unsigned char *old_sha1,\n \t       unsigned int flags, enum action_on_err onerr)\ndiff --git a/refs.h b/refs.h\nindex 1b020437..7a77f3ef 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -477,6 +477,9 @@ void ref_transaction_free(struct ref_transaction *transaction);\n int update_ref(const char *msg, const char *refname,\n \t       const unsigned char *new_sha1, const unsigned char *old_sha1,\n \t       unsigned int flags, enum action_on_err onerr);\n+int update_ref_oid(const char *msg, const char *refname,\n+\t       const struct object_id *new_oid, const struct object_id *old_oid,\n+\t       unsigned int flags, enum action_on_err onerr);\n \n int parse_hide_refs_config(const char *var, const char *value, const char *);\n \n"},{"id":"301119","messageId":"20160905200811.697889-17-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 16/20] sha1_name: convert get_sha1_mb to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:07Z","receivedAt":"2016-09-05T20:09:59Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"All of the callers of this function use struct object_id, so rename it\nto get_oid_mb and make it take struct object_id instead of\nunsigned char *.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/checkout.c |  2 +-\n cache.h            |  2 +-\n sha1_name.c        | 18 +++++++++---------\n 3 files changed, 11 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 13169221..8013a1b8 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -973,7 +973,7 @@ static int parse_branchname_arg(int argc, const char **argv,\n \tif (!strcmp(arg, \"-\"))\n \t\targ = \"@{-1}\";\n \n-\tif (get_sha1_mb(arg, rev->hash)) {\n+\tif (get_oid_mb(arg, rev)) {\n \t\t/*\n \t\t * Either case (3) or (4), with <something> not being\n \t\t * a commit, or an attempt to use case (1) with an\ndiff --git a/cache.h b/cache.h\nindex a679484e..e40165d1 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1204,7 +1204,7 @@ extern char *sha1_to_hex(const unsigned char *sha1);\t/* static buffer result! */\n extern char *oid_to_hex(const struct object_id *oid);\t/* same static buffer as sha1_to_hex */\n \n extern int interpret_branch_name(const char *str, int len, struct strbuf *);\n-extern int get_sha1_mb(const char *str, unsigned char *sha1);\n+extern int get_oid_mb(const char *str, struct object_id *oid);\n \n extern int validate_headref(const char *ref);\n \ndiff --git a/sha1_name.c b/sha1_name.c\nindex e4404391..faf873cf 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -995,35 +995,35 @@ static int interpret_nth_prior_checkout(const char *name, int namelen,\n \treturn retval;\n }\n \n-int get_sha1_mb(const char *name, unsigned char *sha1)\n+int get_oid_mb(const char *name, struct object_id *oid)\n {\n \tstruct commit *one, *two;\n \tstruct commit_list *mbs;\n-\tunsigned char sha1_tmp[20];\n+\tstruct object_id oid_tmp;\n \tconst char *dots;\n \tint st;\n \n \tdots = strstr(name, \"...\");\n \tif (!dots)\n-\t\treturn get_sha1(name, sha1);\n+\t\treturn get_oid(name, oid);\n \tif (dots == name)\n-\t\tst = get_sha1(\"HEAD\", sha1_tmp);\n+\t\tst = get_oid(\"HEAD\", &oid_tmp);\n \telse {\n \t\tstruct strbuf sb;\n \t\tstrbuf_init(&sb, dots - name);\n \t\tstrbuf_add(&sb, name, dots - name);\n-\t\tst = get_sha1_committish(sb.buf, sha1_tmp);\n+\t\tst = get_sha1_committish(sb.buf, oid_tmp.hash);\n \t\tstrbuf_release(&sb);\n \t}\n \tif (st)\n \t\treturn st;\n-\tone = lookup_commit_reference_gently(sha1_tmp, 0);\n+\tone = lookup_commit_reference_gently(oid_tmp.hash, 0);\n \tif (!one)\n \t\treturn -1;\n \n-\tif (get_sha1_committish(dots[3] ? (dots + 3) : \"HEAD\", sha1_tmp))\n+\tif (get_sha1_committish(dots[3] ? (dots + 3) : \"HEAD\", oid_tmp.hash))\n \t\treturn -1;\n-\ttwo = lookup_commit_reference_gently(sha1_tmp, 0);\n+\ttwo = lookup_commit_reference_gently(oid_tmp.hash, 0);\n \tif (!two)\n \t\treturn -1;\n \tmbs = get_merge_bases(one, two);\n@@ -1031,7 +1031,7 @@ int get_sha1_mb(const char *name, unsigned char *sha1)\n \t\tst = -1;\n \telse {\n \t\tst = 0;\n-\t\thashcpy(sha1, mbs->item->object.oid.hash);\n+\t\toidcpy(oid, &mbs->item->object.oid);\n \t}\n \tfree_commit_list(mbs);\n \treturn st;\n"},{"id":"301120","messageId":"20160905200811.697889-16-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 15/20] builtin/update-index: convert file to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:06Z","receivedAt":"2016-09-05T20:10:03Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert all functions to use struct object_id, and replace instances of\nhardcoded 40, 41, and 42 with appropriate references to GIT_SHA1_HEXSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/update-index.c | 61 +++++++++++++++++++++++++-------------------------\n 1 file changed, 31 insertions(+), 30 deletions(-)\n\ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex a60a30a8..44fb2e4f 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -312,7 +312,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len\n  */\n static int process_directory(const char *path, int len, struct stat *st)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tint pos = cache_name_pos(path, len);\n \n \t/* Exact match: file or existing gitlink */\n@@ -321,7 +321,7 @@ static int process_directory(const char *path, int len, struct stat *st)\n \t\tif (S_ISGITLINK(ce->ce_mode)) {\n \n \t\t\t/* Do nothing to the index if there is no HEAD! */\n-\t\t\tif (resolve_gitlink_ref(path, \"HEAD\", sha1) < 0)\n+\t\t\tif (resolve_gitlink_ref(path, \"HEAD\", oid.hash) < 0)\n \t\t\t\treturn 0;\n \n \t\t\treturn add_one_path(ce, path, len, st);\n@@ -347,7 +347,7 @@ static int process_directory(const char *path, int len, struct stat *st)\n \t}\n \n \t/* No match - should we add it as a gitlink? */\n-\tif (!resolve_gitlink_ref(path, \"HEAD\", sha1))\n+\tif (!resolve_gitlink_ref(path, \"HEAD\", oid.hash))\n \t\treturn add_one_path(NULL, path, len, st);\n \n \t/* Error out. */\n@@ -390,7 +390,7 @@ static int process_path(const char *path)\n \treturn add_one_path(ce, path, len, &st);\n }\n \n-static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,\n+static int add_cacheinfo(unsigned int mode, const struct object_id *oid,\n \t\t\t const char *path, int stage)\n {\n \tint size, len, option;\n@@ -403,7 +403,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,\n \tsize = cache_entry_size(len);\n \tce = xcalloc(1, size);\n \n-\thashcpy(ce->oid.hash, sha1);\n+\toidcpy(&ce->oid, oid);\n \tmemcpy(ce->name, path, len);\n \tce->ce_flags = create_ce_flags(stage);\n \tce->ce_namelen = len;\n@@ -487,7 +487,7 @@ static void read_index_info(int nul_term_line)\n \twhile (getline_fn(&buf, stdin) != EOF) {\n \t\tchar *ptr, *tab;\n \t\tchar *path_name;\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tunsigned int mode;\n \t\tunsigned long ul;\n \t\tint stage;\n@@ -516,7 +516,7 @@ static void read_index_info(int nul_term_line)\n \t\tmode = ul;\n \n \t\ttab = strchr(ptr, '\\t');\n-\t\tif (!tab || tab - ptr < 41)\n+\t\tif (!tab || tab - ptr < GIT_SHA1_HEXSZ + 1)\n \t\t\tgoto bad_line;\n \n \t\tif (tab[-2] == ' ' && '0' <= tab[-1] && tab[-1] <= '3') {\n@@ -529,7 +529,8 @@ static void read_index_info(int nul_term_line)\n \t\t\tptr = tab + 1; /* point at the head of path */\n \t\t}\n \n-\t\tif (get_sha1_hex(tab - 40, sha1) || tab[-41] != ' ')\n+\t\tif (get_oid_hex(tab - GIT_SHA1_HEXSZ, &oid) ||\n+\t\t\ttab[-(GIT_SHA1_HEXSZ + 1)] != ' ')\n \t\t\tgoto bad_line;\n \n \t\tpath_name = ptr;\n@@ -557,8 +558,8 @@ static void read_index_info(int nul_term_line)\n \t\t\t * ptr[-1] points at tab,\n \t\t\t * ptr[-41] is at the beginning of sha1\n \t\t\t */\n-\t\t\tptr[-42] = ptr[-1] = 0;\n-\t\t\tif (add_cacheinfo(mode, sha1, path_name, stage))\n+\t\t\tptr[-(GIT_SHA1_HEXSZ + 2)] = ptr[-1] = 0;\n+\t\t\tif (add_cacheinfo(mode, &oid, path_name, stage))\n \t\t\t\tdie(\"git update-index: unable to update %s\",\n \t\t\t\t    path_name);\n \t\t}\n@@ -576,19 +577,19 @@ static const char * const update_index_usage[] = {\n \tNULL\n };\n \n-static unsigned char head_sha1[20];\n-static unsigned char merge_head_sha1[20];\n+static struct object_id head_oid;\n+static struct object_id merge_head_oid;\n \n static struct cache_entry *read_one_ent(const char *which,\n-\t\t\t\t\tunsigned char *ent, const char *path,\n+\t\t\t\t\tstruct object_id *ent, const char *path,\n \t\t\t\t\tint namelen, int stage)\n {\n \tunsigned mode;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tint size;\n \tstruct cache_entry *ce;\n \n-\tif (get_tree_entry(ent, path, sha1, &mode)) {\n+\tif (get_tree_entry(ent->hash, path, oid.hash, &mode)) {\n \t\tif (which)\n \t\t\terror(\"%s: not in %s branch.\", path, which);\n \t\treturn NULL;\n@@ -601,7 +602,7 @@ static struct cache_entry *read_one_ent(const char *which,\n \tsize = cache_entry_size(namelen);\n \tce = xcalloc(1, size);\n \n-\thashcpy(ce->oid.hash, sha1);\n+\toidcpy(&ce->oid, &oid);\n \tmemcpy(ce->name, path, namelen);\n \tce->ce_flags = create_ce_flags(stage);\n \tce->ce_namelen = namelen;\n@@ -651,8 +652,8 @@ static int unresolve_one(const char *path)\n \t * stuff HEAD version in stage #2,\n \t * stuff MERGE_HEAD version in stage #3.\n \t */\n-\tce_2 = read_one_ent(\"our\", head_sha1, path, namelen, 2);\n-\tce_3 = read_one_ent(\"their\", merge_head_sha1, path, namelen, 3);\n+\tce_2 = read_one_ent(\"our\", &head_oid, path, namelen, 2);\n+\tce_3 = read_one_ent(\"their\", &merge_head_oid, path, namelen, 3);\n \n \tif (!ce_2 || !ce_3) {\n \t\tret = -1;\n@@ -683,9 +684,9 @@ static int unresolve_one(const char *path)\n \n static void read_head_pointers(void)\n {\n-\tif (read_ref(\"HEAD\", head_sha1))\n+\tif (read_ref(\"HEAD\", head_oid.hash))\n \t\tdie(\"No HEAD -- no initial commit yet?\");\n-\tif (read_ref(\"MERGE_HEAD\", merge_head_sha1)) {\n+\tif (read_ref(\"MERGE_HEAD\", merge_head_oid.hash)) {\n \t\tfprintf(stderr, \"Not in the middle of a merge.\\n\");\n \t\texit(0);\n \t}\n@@ -725,7 +726,7 @@ static int do_reupdate(int ac, const char **av,\n \t\t       PATHSPEC_PREFER_CWD,\n \t\t       prefix, av + 1);\n \n-\tif (read_ref(\"HEAD\", head_sha1))\n+\tif (read_ref(\"HEAD\", head_oid.hash))\n \t\t/* If there is no HEAD, that means it is an initial\n \t\t * commit.  Update everything in the index.\n \t\t */\n@@ -740,7 +741,7 @@ static int do_reupdate(int ac, const char **av,\n \t\tif (ce_stage(ce) || !ce_path_match(ce, &pathspec, NULL))\n \t\t\tcontinue;\n \t\tif (has_head)\n-\t\t\told = read_one_ent(NULL, head_sha1,\n+\t\t\told = read_one_ent(NULL, &head_oid,\n \t\t\t\t\t   ce->name, ce_namelen(ce), 0);\n \t\tif (old && ce->ce_mode == old->ce_mode &&\n \t\t    !oidcmp(&ce->oid, &old->oid)) {\n@@ -807,7 +808,7 @@ static int resolve_undo_clear_callback(const struct option *opt,\n \n static int parse_new_style_cacheinfo(const char *arg,\n \t\t\t\t     unsigned int *mode,\n-\t\t\t\t     unsigned char sha1[],\n+\t\t\t\t     struct object_id *oid,\n \t\t\t\t     const char **path)\n {\n \tunsigned long ul;\n@@ -822,21 +823,21 @@ static int parse_new_style_cacheinfo(const char *arg,\n \t\treturn -1; /* not a new-style cacheinfo */\n \t*mode = ul;\n \tendp++;\n-\tif (get_sha1_hex(endp, sha1) || endp[40] != ',')\n+\tif (get_oid_hex(endp, oid) || endp[GIT_SHA1_HEXSZ] != ',')\n \t\treturn -1;\n-\t*path = endp + 41;\n+\t*path = endp + GIT_SHA1_HEXSZ + 1;\n \treturn 0;\n }\n \n static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,\n \t\t\t\tconst struct option *opt, int unset)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tunsigned int mode;\n \tconst char *path;\n \n-\tif (!parse_new_style_cacheinfo(ctx->argv[1], &mode, sha1, &path)) {\n-\t\tif (add_cacheinfo(mode, sha1, path, 0))\n+\tif (!parse_new_style_cacheinfo(ctx->argv[1], &mode, &oid, &path)) {\n+\t\tif (add_cacheinfo(mode, &oid, path, 0))\n \t\t\tdie(\"git update-index: --cacheinfo cannot add %s\", path);\n \t\tctx->argv++;\n \t\tctx->argc--;\n@@ -845,8 +846,8 @@ static int cacheinfo_callback(struct parse_opt_ctx_t *ctx,\n \tif (ctx->argc <= 3)\n \t\treturn error(\"option 'cacheinfo' expects <mode>,<sha1>,<path>\");\n \tif (strtoul_ui(*++ctx->argv, 8, &mode) ||\n-\t    get_sha1_hex(*++ctx->argv, sha1) ||\n-\t    add_cacheinfo(mode, sha1, *++ctx->argv, 0))\n+\t    get_oid_hex(*++ctx->argv, &oid) ||\n+\t    add_cacheinfo(mode, &oid, *++ctx->argv, 0))\n \t\tdie(\"git update-index: --cacheinfo cannot add %s\", *ctx->argv);\n \tctx->argc -= 3;\n \treturn 0;\n"},{"id":"301121","messageId":"20160905200811.697889-15-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 14/20] notes: convert init_notes to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:05Z","receivedAt":"2016-09-05T20:10:05Z","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 notes.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/notes.c b/notes.c\nindex df4660fe..2bab961a 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -993,7 +993,7 @@ const char *default_notes_ref(void)\n void init_notes(struct notes_tree *t, const char *notes_ref,\n \t\tcombine_notes_fn combine_notes, int flags)\n {\n-\tunsigned char sha1[20], object_sha1[20];\n+\tstruct object_id oid, object_oid;\n \tunsigned mode;\n \tstruct leaf_node root_tree;\n \n@@ -1017,16 +1017,16 @@ void init_notes(struct notes_tree *t, const char *notes_ref,\n \tt->dirty = 0;\n \n \tif (flags & NOTES_INIT_EMPTY || !notes_ref ||\n-\t    get_sha1_treeish(notes_ref, object_sha1))\n+\t    get_sha1_treeish(notes_ref, object_oid.hash))\n \t\treturn;\n-\tif (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_sha1))\n+\tif (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, object_oid.hash))\n \t\tdie(\"Cannot use notes ref %s\", notes_ref);\n-\tif (get_tree_entry(object_sha1, \"\", sha1, &mode))\n+\tif (get_tree_entry(object_oid.hash, \"\", oid.hash, &mode))\n \t\tdie(\"Failed to read notes tree referenced by %s (%s)\",\n-\t\t    notes_ref, sha1_to_hex(object_sha1));\n+\t\t    notes_ref, oid_to_hex(&object_oid));\n \n \thashclr(root_tree.key_sha1);\n-\thashcpy(root_tree.val_sha1, sha1);\n+\thashcpy(root_tree.val_sha1, oid.hash);\n \tload_subtree(t, &root_tree, t->root, 0);\n }\n \n"},{"id":"301122","messageId":"20160905200811.697889-14-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 13/20] builtin/rm: convert to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:04Z","receivedAt":"2016-09-05T20:10:08Z","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/rm.c | 18 +++++++++---------\n 1 file changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex 109969d5..3f3e24eb 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -107,7 +107,7 @@ static int check_submodules_use_gitfiles(void)\n \treturn errs;\n }\n \n-static int check_local_mod(unsigned char *head, int index_only)\n+static int check_local_mod(struct object_id *head, int index_only)\n {\n \t/*\n \t * Items in list are already sorted in the cache order,\n@@ -123,13 +123,13 @@ static int check_local_mod(unsigned char *head, int index_only)\n \tstruct string_list files_submodule = STRING_LIST_INIT_NODUP;\n \tstruct string_list files_local = STRING_LIST_INIT_NODUP;\n \n-\tno_head = is_null_sha1(head);\n+\tno_head = is_null_oid(head);\n \tfor (i = 0; i < list.nr; i++) {\n \t\tstruct stat st;\n \t\tint pos;\n \t\tconst struct cache_entry *ce;\n \t\tconst char *name = list.entry[i].name;\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tunsigned mode;\n \t\tint local_changes = 0;\n \t\tint staged_changes = 0;\n@@ -197,9 +197,9 @@ static int check_local_mod(unsigned char *head, int index_only)\n \t\t * way as changed from the HEAD.\n \t\t */\n \t\tif (no_head\n-\t\t     || get_tree_entry(head, name, sha1, &mode)\n+\t\t     || get_tree_entry(head->hash, name, oid.hash, &mode)\n \t\t     || ce->ce_mode != create_ce_mode(mode)\n-\t\t     || hashcmp(ce->oid.hash, sha1))\n+\t\t     || oidcmp(&ce->oid, &oid))\n \t\t\tstaged_changes = 1;\n \n \t\t/*\n@@ -351,10 +351,10 @@ int cmd_rm(int argc, const char **argv, const char *prefix)\n \t * report no changes unless forced.\n \t */\n \tif (!force) {\n-\t\tunsigned char sha1[20];\n-\t\tif (get_sha1(\"HEAD\", sha1))\n-\t\t\thashclr(sha1);\n-\t\tif (check_local_mod(sha1, index_only))\n+\t\tstruct object_id oid;\n+\t\tif (get_oid(\"HEAD\", &oid))\n+\t\t\toidclr(&oid);\n+\t\tif (check_local_mod(&oid, index_only))\n \t\t\texit(1);\n \t} else if (!index_only) {\n \t\tif (check_submodules_use_gitfiles())\n"},{"id":"301123","messageId":"20160905200811.697889-13-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 12/20] builtin/blame: convert file to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:03Z","receivedAt":"2016-09-05T20:10:11Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert this file to use struct object_id, and additionally convert some\nuses of the constant 40 to GIT_SHA1_HEXSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/blame.c | 28 ++++++++++++++--------------\n 1 file changed, 14 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 0e10e302..ccaf8be5 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -1941,7 +1941,7 @@ static void emit_other(struct scoreboard *sb, struct blame_entry *ent, int opt)\n \tcp = nth_line(sb, ent->lno);\n \tfor (cnt = 0; cnt < ent->num_lines; cnt++) {\n \t\tchar ch;\n-\t\tint length = (opt & OUTPUT_LONG_OBJECT_NAME) ? 40 : abbrev;\n+\t\tint length = (opt & OUTPUT_LONG_OBJECT_NAME) ? GIT_SHA1_HEXSZ : abbrev;\n \n \t\tif (suspect->commit->object.flags & UNINTERESTING) {\n \t\t\tif (blank_boundary)\n@@ -2232,12 +2232,12 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)\n \tint pos;\n \n \tfor (parents = work_tree->parents; parents; parents = parents->next) {\n-\t\tconst unsigned char *commit_sha1 = parents->item->object.oid.hash;\n-\t\tunsigned char blob_sha1[20];\n+\t\tconst struct object_id *commit_oid = &parents->item->object.oid;\n+\t\tstruct object_id blob_oid;\n \t\tunsigned mode;\n \n-\t\tif (!get_tree_entry(commit_sha1, path, blob_sha1, &mode) &&\n-\t\t    sha1_object_info(blob_sha1, NULL) == OBJ_BLOB)\n+\t\tif (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) &&\n+\t\t    sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)\n \t\t\treturn;\n \t}\n \n@@ -2251,13 +2251,13 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)\n \t\tdie(\"no such path '%s' in HEAD\", path);\n }\n \n-static struct commit_list **append_parent(struct commit_list **tail, const unsigned char *sha1)\n+static struct commit_list **append_parent(struct commit_list **tail, const struct object_id *oid)\n {\n \tstruct commit *parent;\n \n-\tparent = lookup_commit_reference(sha1);\n+\tparent = lookup_commit_reference(oid->hash);\n \tif (!parent)\n-\t\tdie(\"no such commit %s\", sha1_to_hex(sha1));\n+\t\tdie(\"no such commit %s\", oid_to_hex(oid));\n \treturn &commit_list_insert(parent, tail)->next;\n }\n \n@@ -2274,10 +2274,10 @@ static void append_merge_parents(struct commit_list **tail)\n \t}\n \n \twhile (!strbuf_getwholeline_fd(&line, merge_head, '\\n')) {\n-\t\tunsigned char sha1[20];\n-\t\tif (line.len < 40 || get_sha1_hex(line.buf, sha1))\n+\t\tstruct object_id oid;\n+\t\tif (line.len < GIT_SHA1_HEXSZ || get_oid_hex(line.buf, &oid))\n \t\t\tdie(\"unknown line in '%s': %s\", git_path_merge_head(), line.buf);\n-\t\ttail = append_parent(tail, sha1);\n+\t\ttail = append_parent(tail, &oid);\n \t}\n \tclose(merge_head);\n \tstrbuf_release(&line);\n@@ -2306,7 +2306,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \tstruct commit *commit;\n \tstruct origin *origin;\n \tstruct commit_list **parent_tail, *parent;\n-\tunsigned char head_sha1[20];\n+\tstruct object_id head_oid;\n \tstruct strbuf buf = STRBUF_INIT;\n \tconst char *ident;\n \ttime_t now;\n@@ -2322,10 +2322,10 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \tcommit->date = now;\n \tparent_tail = &commit->parents;\n \n-\tif (!resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, head_sha1, NULL))\n+\tif (!resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING, head_oid.hash, NULL))\n \t\tdie(\"no such ref: HEAD\");\n \n-\tparent_tail = append_parent(parent_tail, head_sha1);\n+\tparent_tail = append_parent(parent_tail, &head_oid);\n \tappend_merge_parents(parent_tail);\n \tverify_working_tree_path(commit, path);\n \n"},{"id":"301124","messageId":"20160905200811.697889-11-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 10/20] notes-merge: convert struct notes_merge_pair to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:01Z","receivedAt":"2016-09-05T20:10:13Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert each of this structure's members from an unsigned char array to\na struct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n notes-merge.c | 127 ++++++++++++++++++++++++++++++----------------------------\n 1 file changed, 65 insertions(+), 62 deletions(-)\n\ndiff --git a/notes-merge.c b/notes-merge.c\nindex 97fc42f6..cb36b43c 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -12,7 +12,7 @@\n #include \"notes-utils.h\"\n \n struct notes_merge_pair {\n-\tunsigned char obj[20], base[20], local[20], remote[20];\n+\tstruct object_id obj, base, local, remote;\n };\n \n void init_notes_merge_options(struct notes_merge_options *o)\n@@ -75,7 +75,7 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(\n \tint i = last_index < len ? last_index : len - 1;\n \tint prev_cmp = 0, cmp = -1;\n \twhile (i >= 0 && i < len) {\n-\t\tcmp = hashcmp(obj, list[i].obj);\n+\t\tcmp = hashcmp(obj, list[i].obj.hash);\n \t\tif (!cmp) /* obj belongs @ i */\n \t\t\tbreak;\n \t\telse if (cmp < 0 && prev_cmp <= 0) /* obj belongs < i */\n@@ -108,9 +108,10 @@ static struct notes_merge_pair *find_notes_merge_pair_pos(\n \treturn list + i;\n }\n \n-static unsigned char uninitialized[20] =\n+static struct object_id uninitialized = {\n \t\"\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\" \\\n-\t\"\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\";\n+\t\"\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\\xff\"\n+};\n \n static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,\n \t\t\t\t\t\t const unsigned char *base,\n@@ -149,25 +150,25 @@ static struct notes_merge_pair *diff_tree_remote(struct notes_merge_options *o,\n \t\tmp = find_notes_merge_pair_pos(changes, len, obj, 1, &occupied);\n \t\tif (occupied) {\n \t\t\t/* We've found an addition/deletion pair */\n-\t\t\tassert(!hashcmp(mp->obj, obj));\n+\t\t\tassert(!hashcmp(mp->obj.hash, obj));\n \t\t\tif (is_null_oid(&p->one->oid)) { /* addition */\n-\t\t\t\tassert(is_null_sha1(mp->remote));\n-\t\t\t\thashcpy(mp->remote, p->two->oid.hash);\n+\t\t\t\tassert(is_null_oid(&mp->remote));\n+\t\t\t\toidcpy(&mp->remote, &p->two->oid);\n \t\t\t} else if (is_null_oid(&p->two->oid)) { /* deletion */\n-\t\t\t\tassert(is_null_sha1(mp->base));\n-\t\t\t\thashcpy(mp->base, p->one->oid.hash);\n+\t\t\t\tassert(is_null_oid(&mp->base));\n+\t\t\t\toidcpy(&mp->base, &p->one->oid);\n \t\t\t} else\n \t\t\t\tassert(!\"Invalid existing change recorded\");\n \t\t} else {\n-\t\t\thashcpy(mp->obj, obj);\n-\t\t\thashcpy(mp->base, p->one->oid.hash);\n-\t\t\thashcpy(mp->local, uninitialized);\n-\t\t\thashcpy(mp->remote, p->two->oid.hash);\n+\t\t\thashcpy(mp->obj.hash, obj);\n+\t\t\toidcpy(&mp->base, &p->one->oid);\n+\t\t\toidcpy(&mp->local, &uninitialized);\n+\t\t\toidcpy(&mp->remote, &p->two->oid);\n \t\t\tlen++;\n \t\t}\n \t\ttrace_printf(\"\\t\\tStored remote change for %s: %.7s -> %.7s\\n\",\n-\t\t       sha1_to_hex(mp->obj), sha1_to_hex(mp->base),\n-\t\t       sha1_to_hex(mp->remote));\n+\t\t       oid_to_hex(&mp->obj), oid_to_hex(&mp->base),\n+\t\t       oid_to_hex(&mp->remote));\n \t}\n \tdiff_flush(&opt);\n \tclear_pathspec(&opt.pathspec);\n@@ -216,7 +217,7 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\tcontinue;\n \t\t}\n \n-\t\tassert(!hashcmp(mp->obj, obj));\n+\t\tassert(!hashcmp(mp->obj.hash, obj));\n \t\tif (is_null_oid(&p->two->oid)) { /* deletion */\n \t\t\t/*\n \t\t\t * Either this is a true deletion (1), or it is part\n@@ -227,8 +228,8 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\t * (3) mp->local is uninitialized; set it to null_sha1\n \t\t\t *     (will be overwritten by following addition)\n \t\t\t */\n-\t\t\tif (!hashcmp(mp->local, uninitialized))\n-\t\t\t\thashclr(mp->local);\n+\t\t\tif (!oidcmp(&mp->local, &uninitialized))\n+\t\t\t\toidclr(&mp->local);\n \t\t} else if (is_null_oid(&p->one->oid)) { /* addition */\n \t\t\t/*\n \t\t\t * Either this is a true addition (1), or it is part\n@@ -238,22 +239,22 @@ static void diff_tree_local(struct notes_merge_options *o,\n \t\t\t * (2) mp->local is uninitialized; set to p->two->sha1\n \t\t\t * (3) mp->local is null_sha1;     set to p->two->sha1\n \t\t\t */\n-\t\t\tassert(is_null_sha1(mp->local) ||\n-\t\t\t       !hashcmp(mp->local, uninitialized));\n-\t\t\thashcpy(mp->local, p->two->oid.hash);\n+\t\t\tassert(is_null_oid(&mp->local) ||\n+\t\t\t       !oidcmp(&mp->local, &uninitialized));\n+\t\t\toidcpy(&mp->local, &p->two->oid);\n \t\t} else { /* modification */\n \t\t\t/*\n \t\t\t * This is a true modification. p->one->sha1 shall\n \t\t\t * match mp->base, and mp->local shall be uninitialized.\n \t\t\t * Set mp->local to p->two->sha1.\n \t\t\t */\n-\t\t\tassert(!hashcmp(p->one->oid.hash, mp->base));\n-\t\t\tassert(!hashcmp(mp->local, uninitialized));\n-\t\t\thashcpy(mp->local, p->two->oid.hash);\n+\t\t\tassert(!oidcmp(&p->one->oid, &mp->base));\n+\t\t\tassert(!oidcmp(&mp->local, &uninitialized));\n+\t\t\toidcpy(&mp->local, &p->two->oid);\n \t\t}\n \t\ttrace_printf(\"\\t\\tStored local change for %s: %.7s -> %.7s\\n\",\n-\t\t       sha1_to_hex(mp->obj), sha1_to_hex(mp->base),\n-\t\t       sha1_to_hex(mp->local));\n+\t\t       oid_to_hex(&mp->obj), oid_to_hex(&mp->base),\n+\t\t       oid_to_hex(&mp->local));\n \t}\n \tdiff_flush(&opt);\n \tclear_pathspec(&opt.pathspec);\n@@ -343,11 +344,11 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,\n \tmmfile_t base, local, remote;\n \tint status;\n \n-\tread_mmblob(&base, p->base);\n-\tread_mmblob(&local, p->local);\n-\tread_mmblob(&remote, p->remote);\n+\tread_mmblob(&base, p->base.hash);\n+\tread_mmblob(&local, p->local.hash);\n+\tread_mmblob(&remote, p->remote.hash);\n \n-\tstatus = ll_merge(&result_buf, sha1_to_hex(p->obj), &base, NULL,\n+\tstatus = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,\n \t\t\t  &local, o->local_ref, &remote, o->remote_ref, NULL);\n \n \tfree(base.ptr);\n@@ -357,7 +358,7 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,\n \tif ((status < 0) || !result_buf.ptr)\n \t\tdie(\"Failed to execute internal merge\");\n \n-\twrite_buf_to_worktree(p->obj, result_buf.ptr, result_buf.size);\n+\twrite_buf_to_worktree(p->obj.hash, result_buf.ptr, result_buf.size);\n \tfree(result_buf.ptr);\n \n \treturn status;\n@@ -372,51 +373,52 @@ static int merge_one_change_manual(struct notes_merge_options *o,\n \n \ttrace_printf(\"\\t\\t\\tmerge_one_change_manual(obj = %.7s, base = %.7s, \"\n \t       \"local = %.7s, remote = %.7s)\\n\",\n-\t       sha1_to_hex(p->obj), sha1_to_hex(p->base),\n-\t       sha1_to_hex(p->local), sha1_to_hex(p->remote));\n+\t       oid_to_hex(&p->obj), oid_to_hex(&p->base),\n+\t       oid_to_hex(&p->local), oid_to_hex(&p->remote));\n \n \t/* add \"Conflicts:\" section to commit message first time through */\n \tif (!o->has_worktree)\n \t\tstrbuf_addstr(&(o->commit_msg), \"\\n\\nConflicts:\\n\");\n \n-\tstrbuf_addf(&(o->commit_msg), \"\\t%s\\n\", sha1_to_hex(p->obj));\n+\tstrbuf_addf(&(o->commit_msg), \"\\t%s\\n\", oid_to_hex(&p->obj));\n \n \tif (o->verbosity >= 2)\n-\t\tprintf(\"Auto-merging notes for %s\\n\", sha1_to_hex(p->obj));\n+\t\tprintf(\"Auto-merging notes for %s\\n\", oid_to_hex(&p->obj));\n \tcheck_notes_merge_worktree(o);\n-\tif (is_null_sha1(p->local)) {\n+\tif (is_null_oid(&p->local)) {\n \t\t/* D/F conflict, checkout p->remote */\n-\t\tassert(!is_null_sha1(p->remote));\n+\t\tassert(!is_null_oid(&p->remote));\n \t\tif (o->verbosity >= 1)\n \t\t\tprintf(\"CONFLICT (delete/modify): Notes for object %s \"\n \t\t\t\t\"deleted in %s and modified in %s. Version from %s \"\n \t\t\t\t\"left in tree.\\n\",\n-\t\t\t\tsha1_to_hex(p->obj), lref, rref, rref);\n-\t\twrite_note_to_worktree(p->obj, p->remote);\n-\t} else if (is_null_sha1(p->remote)) {\n+\t\t\t\toid_to_hex(&p->obj), lref, rref, rref);\n+\t\twrite_note_to_worktree(p->obj.hash, p->remote.hash);\n+\t} else if (is_null_oid(&p->remote)) {\n \t\t/* D/F conflict, checkout p->local */\n-\t\tassert(!is_null_sha1(p->local));\n+\t\tassert(!is_null_oid(&p->local));\n \t\tif (o->verbosity >= 1)\n \t\t\tprintf(\"CONFLICT (delete/modify): Notes for object %s \"\n \t\t\t\t\"deleted in %s and modified in %s. Version from %s \"\n \t\t\t\t\"left in tree.\\n\",\n-\t\t\t\tsha1_to_hex(p->obj), rref, lref, lref);\n-\t\twrite_note_to_worktree(p->obj, p->local);\n+\t\t\t\toid_to_hex(&p->obj), rref, lref, lref);\n+\t\twrite_note_to_worktree(p->obj.hash, p->local.hash);\n \t} else {\n \t\t/* \"regular\" conflict, checkout result of ll_merge() */\n \t\tconst char *reason = \"content\";\n-\t\tif (is_null_sha1(p->base))\n+\t\tif (is_null_oid(&p->base))\n \t\t\treason = \"add/add\";\n-\t\tassert(!is_null_sha1(p->local));\n-\t\tassert(!is_null_sha1(p->remote));\n+\t\tassert(!is_null_oid(&p->local));\n+\t\tassert(!is_null_oid(&p->remote));\n \t\tif (o->verbosity >= 1)\n \t\t\tprintf(\"CONFLICT (%s): Merge conflict in notes for \"\n-\t\t\t\t\"object %s\\n\", reason, sha1_to_hex(p->obj));\n+\t\t\t\t\"object %s\\n\", reason,\n+\t\t\t\toid_to_hex(&p->obj));\n \t\tll_merge_in_worktree(o, p);\n \t}\n \n \ttrace_printf(\"\\t\\t\\tremoving from partial merge result\\n\");\n-\tremove_note(t, p->obj);\n+\tremove_note(t, p->obj.hash);\n \n \treturn 1;\n }\n@@ -435,29 +437,29 @@ static int merge_one_change(struct notes_merge_options *o,\n \tcase NOTES_MERGE_RESOLVE_OURS:\n \t\tif (o->verbosity >= 2)\n \t\t\tprintf(\"Using local notes for %s\\n\",\n-\t\t\t\t\t\tsha1_to_hex(p->obj));\n+\t\t\t\t\t\toid_to_hex(&p->obj));\n \t\t/* nothing to do */\n \t\treturn 0;\n \tcase NOTES_MERGE_RESOLVE_THEIRS:\n \t\tif (o->verbosity >= 2)\n \t\t\tprintf(\"Using remote notes for %s\\n\",\n-\t\t\t\t\t\tsha1_to_hex(p->obj));\n-\t\tif (add_note(t, p->obj, p->remote, combine_notes_overwrite))\n+\t\t\t\t\t\toid_to_hex(&p->obj));\n+\t\tif (add_note(t, p->obj.hash, p->remote.hash, combine_notes_overwrite))\n \t\t\tdie(\"BUG: combine_notes_overwrite failed\");\n \t\treturn 0;\n \tcase NOTES_MERGE_RESOLVE_UNION:\n \t\tif (o->verbosity >= 2)\n \t\t\tprintf(\"Concatenating local and remote notes for %s\\n\",\n-\t\t\t\t\t\t\tsha1_to_hex(p->obj));\n-\t\tif (add_note(t, p->obj, p->remote, combine_notes_concatenate))\n+\t\t\t\t\t\t\toid_to_hex(&p->obj));\n+\t\tif (add_note(t, p->obj.hash, p->remote.hash, combine_notes_concatenate))\n \t\t\tdie(\"failed to concatenate notes \"\n \t\t\t    \"(combine_notes_concatenate)\");\n \t\treturn 0;\n \tcase NOTES_MERGE_RESOLVE_CAT_SORT_UNIQ:\n \t\tif (o->verbosity >= 2)\n \t\t\tprintf(\"Concatenating unique lines in local and remote \"\n-\t\t\t\t\"notes for %s\\n\", sha1_to_hex(p->obj));\n-\t\tif (add_note(t, p->obj, p->remote, combine_notes_cat_sort_uniq))\n+\t\t\t\t\"notes for %s\\n\", oid_to_hex(&p->obj));\n+\t\tif (add_note(t, p->obj.hash, p->remote.hash, combine_notes_cat_sort_uniq))\n \t\t\tdie(\"failed to concatenate notes \"\n \t\t\t    \"(combine_notes_cat_sort_uniq)\");\n \t\treturn 0;\n@@ -475,20 +477,21 @@ static int merge_changes(struct notes_merge_options *o,\n \tfor (i = 0; i < *num_changes; i++) {\n \t\tstruct notes_merge_pair *p = changes + i;\n \t\ttrace_printf(\"\\t\\t%.7s: %.7s -> %.7s/%.7s\\n\",\n-\t\t       sha1_to_hex(p->obj), sha1_to_hex(p->base),\n-\t\t       sha1_to_hex(p->local), sha1_to_hex(p->remote));\n+\t\t       oid_to_hex(&p->obj), oid_to_hex(&p->base),\n+\t\t       oid_to_hex(&p->local),\n+\t\t       oid_to_hex(&p->remote));\n \n-\t\tif (!hashcmp(p->base, p->remote)) {\n+\t\tif (!oidcmp(&p->base, &p->remote)) {\n \t\t\t/* no remote change; nothing to do */\n \t\t\ttrace_printf(\"\\t\\t\\tskipping (no remote change)\\n\");\n-\t\t} else if (!hashcmp(p->local, p->remote)) {\n+\t\t} else if (!oidcmp(&p->local, &p->remote)) {\n \t\t\t/* same change in local and remote; nothing to do */\n \t\t\ttrace_printf(\"\\t\\t\\tskipping (local == remote)\\n\");\n-\t\t} else if (!hashcmp(p->local, uninitialized) ||\n-\t\t\t   !hashcmp(p->local, p->base)) {\n+\t\t} else if (!oidcmp(&p->local, &uninitialized) ||\n+\t\t\t   !oidcmp(&p->local, &p->base)) {\n \t\t\t/* no local change; adopt remote change */\n \t\t\ttrace_printf(\"\\t\\t\\tno local change, adopted remote\\n\");\n-\t\t\tif (add_note(t, p->obj, p->remote,\n+\t\t\tif (add_note(t, p->obj.hash, p->remote.hash,\n \t\t\t\t     combine_notes_overwrite))\n \t\t\t\tdie(\"BUG: combine_notes_overwrite failed\");\n \t\t} else {\n"},{"id":"301125","messageId":"20160905200811.697889-12-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 11/20] Convert read_mmblob to take struct object_id.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:02Z","receivedAt":"2016-09-05T20:10:16Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Since all of its callers have been updated, convert read_mmblob to take\na pointer to struct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/apply.c    | 6 +++---\n builtin/checkout.c | 6 +++---\n merge-recursive.c  | 6 +++---\n notes-merge.c      | 6 +++---\n xdiff-interface.c  | 8 ++++----\n xdiff-interface.h  | 3 ++-\n 6 files changed, 18 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 76b16121..df2c95d3 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -3435,9 +3435,9 @@ static int three_way_merge(struct image *image,\n \tmmbuffer_t result = { NULL };\n \tint status;\n \n-\tread_mmblob(&base_file, base->hash);\n-\tread_mmblob(&our_file, ours->hash);\n-\tread_mmblob(&their_file, theirs->hash);\n+\tread_mmblob(&base_file, base);\n+\tread_mmblob(&our_file, ours);\n+\tread_mmblob(&their_file, theirs);\n \tstatus = ll_merge(&result, path,\n \t\t\t  &base_file, \"base\",\n \t\t\t  &our_file, \"ours\",\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex ec85af56..13169221 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -195,9 +195,9 @@ static int checkout_merged(int pos, struct checkout *state)\n \tif (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))\n \t\treturn error(_(\"path '%s' does not have necessary versions\"), path);\n \n-\tread_mmblob(&ancestor, threeway[0].hash);\n-\tread_mmblob(&ours, threeway[1].hash);\n-\tread_mmblob(&theirs, threeway[2].hash);\n+\tread_mmblob(&ancestor, &threeway[0]);\n+\tread_mmblob(&ours, &threeway[1]);\n+\tread_mmblob(&theirs, &threeway[2]);\n \n \t/*\n \t * NEEDSWORK: re-create conflicts from merges with\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex e3db594d..3750d253 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -910,9 +910,9 @@ static int merge_3way(struct merge_options *o,\n \t\tname2 = mkpathdup(\"%s\", branch2);\n \t}\n \n-\tread_mmblob(&orig, one->oid.hash);\n-\tread_mmblob(&src1, a->oid.hash);\n-\tread_mmblob(&src2, b->oid.hash);\n+\tread_mmblob(&orig, &one->oid);\n+\tread_mmblob(&src1, &a->oid);\n+\tread_mmblob(&src2, &b->oid);\n \n \tmerge_status = ll_merge(result_buf, a->path, &orig, base_name,\n \t\t\t\t&src1, name1, &src2, name2, &ll_opts);\ndiff --git a/notes-merge.c b/notes-merge.c\nindex cb36b43c..b3536284 100644\n--- a/notes-merge.c\n+++ b/notes-merge.c\n@@ -344,9 +344,9 @@ static int ll_merge_in_worktree(struct notes_merge_options *o,\n \tmmfile_t base, local, remote;\n \tint status;\n \n-\tread_mmblob(&base, p->base.hash);\n-\tread_mmblob(&local, p->local.hash);\n-\tread_mmblob(&remote, p->remote.hash);\n+\tread_mmblob(&base, &p->base);\n+\tread_mmblob(&local, &p->local);\n+\tread_mmblob(&remote, &p->remote);\n \n \tstatus = ll_merge(&result_buf, oid_to_hex(&p->obj), &base, NULL,\n \t\t\t  &local, o->local_ref, &remote, o->remote_ref, NULL);\ndiff --git a/xdiff-interface.c b/xdiff-interface.c\nindex f34ea762..3bfc69ca 100644\n--- a/xdiff-interface.c\n+++ b/xdiff-interface.c\n@@ -178,20 +178,20 @@ int read_mmfile(mmfile_t *ptr, const char *filename)\n \treturn 0;\n }\n \n-void read_mmblob(mmfile_t *ptr, const unsigned char *sha1)\n+void read_mmblob(mmfile_t *ptr, const struct object_id *oid)\n {\n \tunsigned long size;\n \tenum object_type type;\n \n-\tif (!hashcmp(sha1, null_sha1)) {\n+\tif (!oidcmp(oid, &null_oid)) {\n \t\tptr->ptr = xstrdup(\"\");\n \t\tptr->size = 0;\n \t\treturn;\n \t}\n \n-\tptr->ptr = read_sha1_file(sha1, &type, &size);\n+\tptr->ptr = read_sha1_file(oid->hash, &type, &size);\n \tif (!ptr->ptr || type != OBJ_BLOB)\n-\t\tdie(\"unable to read blob object %s\", sha1_to_hex(sha1));\n+\t\tdie(\"unable to read blob object %s\", oid_to_hex(oid));\n \tptr->size = size;\n }\n \ndiff --git a/xdiff-interface.h b/xdiff-interface.h\nindex fbb5a1c3..6f6ba909 100644\n--- a/xdiff-interface.h\n+++ b/xdiff-interface.h\n@@ -1,6 +1,7 @@\n #ifndef XDIFF_INTERFACE_H\n #define XDIFF_INTERFACE_H\n \n+#include \"cache.h\"\n #include \"xdiff/xdiff.h\"\n \n /*\n@@ -20,7 +21,7 @@ int parse_hunk_header(char *line, int len,\n \t\t      int *ob, int *on,\n \t\t      int *nb, int *nn);\n int read_mmfile(mmfile_t *ptr, const char *filename);\n-void read_mmblob(mmfile_t *ptr, const unsigned char *sha1);\n+void read_mmblob(mmfile_t *ptr, const struct object_id *oid);\n int buffer_is_binary(const char *ptr, unsigned long size);\n \n extern void xdiff_set_find_func(xdemitconf_t *xecfg, const char *line, int cflags);\n"},{"id":"301126","messageId":"20160905200811.697889-10-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 09/20] builtin/checkout: convert some static functions to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:00Z","receivedAt":"2016-09-05T20:10:18Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert all the static functions that are not callbacks to struct\nobject_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/checkout.c | 66 +++++++++++++++++++++++++++---------------------------\n 1 file changed, 33 insertions(+), 33 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex a9523ffa..ec85af56 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -175,9 +175,9 @@ static int checkout_merged(int pos, struct checkout *state)\n \tconst char *path = ce->name;\n \tmmfile_t ancestor, ours, theirs;\n \tint status;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tmmbuffer_t result_buf;\n-\tunsigned char threeway[3][20];\n+\tstruct object_id threeway[3];\n \tunsigned mode = 0;\n \n \tmemset(threeway, 0, sizeof(threeway));\n@@ -186,18 +186,18 @@ static int checkout_merged(int pos, struct checkout *state)\n \t\tstage = ce_stage(ce);\n \t\tif (!stage || strcmp(path, ce->name))\n \t\t\tbreak;\n-\t\thashcpy(threeway[stage - 1], ce->oid.hash);\n+\t\toidcpy(&threeway[stage - 1], &ce->oid);\n \t\tif (stage == 2)\n \t\t\tmode = create_ce_mode(ce->ce_mode);\n \t\tpos++;\n \t\tce = active_cache[pos];\n \t}\n-\tif (is_null_sha1(threeway[1]) || is_null_sha1(threeway[2]))\n+\tif (is_null_oid(&threeway[1]) || is_null_oid(&threeway[2]))\n \t\treturn error(_(\"path '%s' does not have necessary versions\"), path);\n \n-\tread_mmblob(&ancestor, threeway[0]);\n-\tread_mmblob(&ours, threeway[1]);\n-\tread_mmblob(&theirs, threeway[2]);\n+\tread_mmblob(&ancestor, threeway[0].hash);\n+\tread_mmblob(&ours, threeway[1].hash);\n+\tread_mmblob(&theirs, threeway[2].hash);\n \n \t/*\n \t * NEEDSWORK: re-create conflicts from merges with\n@@ -226,9 +226,9 @@ static int checkout_merged(int pos, struct checkout *state)\n \t * object database even when it may contain conflicts).\n \t */\n \tif (write_sha1_file(result_buf.ptr, result_buf.size,\n-\t\t\t    blob_type, sha1))\n+\t\t\t    blob_type, oid.hash))\n \t\tdie(_(\"Unable to add merge result for '%s'\"), path);\n-\tce = make_cache_entry(mode, sha1, path, 2, 0);\n+\tce = make_cache_entry(mode, oid.hash, path, 2, 0);\n \tif (!ce)\n \t\tdie(_(\"make_cache_entry failed for path '%s'\"), path);\n \tstatus = checkout_entry(ce, state, NULL);\n@@ -241,7 +241,7 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tint pos;\n \tstruct checkout state;\n \tstatic char *ps_matched;\n-\tunsigned char rev[20];\n+\tstruct object_id rev;\n \tstruct commit *head;\n \tint errs = 0;\n \tstruct lock_file *lock_file;\n@@ -374,8 +374,8 @@ static int checkout_paths(const struct checkout_opts *opts,\n \tif (write_locked_index(&the_index, lock_file, COMMIT_LOCK))\n \t\tdie(_(\"unable to write new index file\"));\n \n-\tread_ref_full(\"HEAD\", 0, rev, NULL);\n-\thead = lookup_commit_reference_gently(rev, 1);\n+\tread_ref_full(\"HEAD\", 0, rev.hash, NULL);\n+\thead = lookup_commit_reference_gently(rev.hash, 1);\n \n \terrs |= post_checkout_hook(head, head, 0);\n \treturn errs;\n@@ -808,11 +808,11 @@ static int switch_branches(const struct checkout_opts *opts,\n \tint ret = 0;\n \tstruct branch_info old;\n \tvoid *path_to_free;\n-\tunsigned char rev[20];\n+\tstruct object_id rev;\n \tint flag, writeout_error = 0;\n \tmemset(&old, 0, sizeof(old));\n-\told.path = path_to_free = resolve_refdup(\"HEAD\", 0, rev, &flag);\n-\told.commit = lookup_commit_reference_gently(rev, 1);\n+\told.path = path_to_free = resolve_refdup(\"HEAD\", 0, rev.hash, &flag);\n+\told.commit = lookup_commit_reference_gently(rev.hash, 1);\n \tif (!(flag & REF_ISSYMREF))\n \t\told.path = NULL;\n \n@@ -860,7 +860,7 @@ static int git_checkout_config(const char *var, const char *value, void *cb)\n struct tracking_name_data {\n \t/* const */ char *src_ref;\n \tchar *dst_ref;\n-\tunsigned char *dst_sha1;\n+\tstruct object_id *dst_oid;\n \tint unique;\n };\n \n@@ -871,7 +871,7 @@ static int check_tracking_name(struct remote *remote, void *cb_data)\n \tmemset(&query, 0, sizeof(struct refspec));\n \tquery.src = cb->src_ref;\n \tif (remote_find_tracking(remote, &query) ||\n-\t    get_sha1(query.dst, cb->dst_sha1)) {\n+\t    get_oid(query.dst, cb->dst_oid)) {\n \t\tfree(query.dst);\n \t\treturn 0;\n \t}\n@@ -884,13 +884,13 @@ static int check_tracking_name(struct remote *remote, void *cb_data)\n \treturn 0;\n }\n \n-static const char *unique_tracking_name(const char *name, unsigned char *sha1)\n+static const char *unique_tracking_name(const char *name, struct object_id *oid)\n {\n \tstruct tracking_name_data cb_data = { NULL, NULL, NULL, 1 };\n \tchar src_ref[PATH_MAX];\n \tsnprintf(src_ref, PATH_MAX, \"refs/heads/%s\", name);\n \tcb_data.src_ref = src_ref;\n-\tcb_data.dst_sha1 = sha1;\n+\tcb_data.dst_oid = oid;\n \tfor_each_remote(check_tracking_name, &cb_data);\n \tif (cb_data.unique)\n \t\treturn cb_data.dst_ref;\n@@ -902,12 +902,12 @@ static int parse_branchname_arg(int argc, const char **argv,\n \t\t\t\tint dwim_new_local_branch_ok,\n \t\t\t\tstruct branch_info *new,\n \t\t\t\tstruct checkout_opts *opts,\n-\t\t\t\tunsigned char rev[20])\n+\t\t\t\tstruct object_id *rev)\n {\n \tstruct tree **source_tree = &opts->source_tree;\n \tconst char **new_branch = &opts->new_branch;\n \tint argcount = 0;\n-\tunsigned char branch_rev[20];\n+\tstruct object_id branch_rev;\n \tconst char *arg;\n \tint dash_dash_pos;\n \tint has_dash_dash = 0;\n@@ -973,7 +973,7 @@ static int parse_branchname_arg(int argc, const char **argv,\n \tif (!strcmp(arg, \"-\"))\n \t\targ = \"@{-1}\";\n \n-\tif (get_sha1_mb(arg, rev)) {\n+\tif (get_sha1_mb(arg, rev->hash)) {\n \t\t/*\n \t\t * Either case (3) or (4), with <something> not being\n \t\t * a commit, or an attempt to use case (1) with an\n@@ -1022,15 +1022,15 @@ static int parse_branchname_arg(int argc, const char **argv,\n \tsetup_branch_path(new);\n \n \tif (!check_refname_format(new->path, 0) &&\n-\t    !read_ref(new->path, branch_rev))\n-\t\thashcpy(rev, branch_rev);\n+\t    !read_ref(new->path, branch_rev.hash))\n+\t\toidcpy(rev, &branch_rev);\n \telse\n \t\tnew->path = NULL; /* not an existing branch */\n \n-\tnew->commit = lookup_commit_reference_gently(rev, 1);\n+\tnew->commit = lookup_commit_reference_gently(rev->hash, 1);\n \tif (!new->commit) {\n \t\t/* not a commit */\n-\t\t*source_tree = parse_tree_indirect(rev);\n+\t\t*source_tree = parse_tree_indirect(rev->hash);\n \t} else {\n \t\tparse_commit_or_die(new->commit);\n \t\t*source_tree = new->commit->tree;\n@@ -1108,9 +1108,9 @@ static int checkout_branch(struct checkout_opts *opts,\n \n \tif (new->path && !opts->force_detach && !opts->new_branch &&\n \t    !opts->ignore_other_worktrees) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tint flag;\n-\t\tchar *head_ref = resolve_refdup(\"HEAD\", 0, sha1, &flag);\n+\t\tchar *head_ref = resolve_refdup(\"HEAD\", 0, oid.hash, &flag);\n \t\tif (head_ref &&\n \t\t    (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))\n \t\t\tdie_if_checked_out(new->path, 1);\n@@ -1118,11 +1118,11 @@ static int checkout_branch(struct checkout_opts *opts,\n \t}\n \n \tif (!new->commit && opts->new_branch) {\n-\t\tunsigned char rev[20];\n+\t\tstruct object_id rev;\n \t\tint flag;\n \n-\t\tif (!read_ref_full(\"HEAD\", 0, rev, &flag) &&\n-\t\t    (flag & REF_ISSYMREF) && is_null_sha1(rev))\n+\t\tif (!read_ref_full(\"HEAD\", 0, rev.hash, &flag) &&\n+\t\t    (flag & REF_ISSYMREF) && is_null_oid(&rev))\n \t\t\treturn switch_unborn_to_new_branch(opts);\n \t}\n \treturn switch_branches(opts, new);\n@@ -1232,14 +1232,14 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)\n \t * remote branches, erroring out for invalid or ambiguous cases.\n \t */\n \tif (argc) {\n-\t\tunsigned char rev[20];\n+\t\tstruct object_id rev;\n \t\tint dwim_ok =\n \t\t\t!opts.patch_mode &&\n \t\t\tdwim_new_local_branch &&\n \t\t\topts.track == BRANCH_TRACK_UNSPECIFIED &&\n \t\t\t!opts.new_branch;\n \t\tint n = parse_branchname_arg(argc, argv, dwim_ok,\n-\t\t\t\t\t     &new, &opts, rev);\n+\t\t\t\t\t     &new, &opts, &rev);\n \t\targv += n;\n \t\targc -= n;\n \t}\n"},{"id":"301127","messageId":"20160905200811.697889-9-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 08/20] streaming: make stream_blob_to_fd take struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:59Z","receivedAt":"2016-09-05T20:10:20Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Since all of its callers have been updated, modify stream_blob_to_fd to\ntake a struct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/cat-file.c | 6 +++---\n builtin/fsck.c     | 2 +-\n builtin/log.c      | 4 ++--\n entry.c            | 2 +-\n streaming.c        | 4 ++--\n streaming.h        | 2 +-\n 6 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 7b2e0537..49b8fa8e 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -83,7 +83,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t}\n \n \t\tif (type == OBJ_BLOB)\n-\t\t\treturn stream_blob_to_fd(1, oid.hash, NULL, 0);\n+\t\t\treturn stream_blob_to_fd(1, &oid, NULL, 0);\n \t\tbuf = read_sha1_file(oid.hash, &type, &size);\n \t\tif (!buf)\n \t\t\tdie(\"Cannot read object %s\", obj_name);\n@@ -105,7 +105,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t\t\toidcpy(&blob_oid, &oid);\n \n \t\t\tif (sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)\n-\t\t\t\treturn stream_blob_to_fd(1, blob_oid.hash, NULL, 0);\n+\t\t\t\treturn stream_blob_to_fd(1, &blob_oid, NULL, 0);\n \t\t\t/*\n \t\t\t * we attempted to dereference a tag to a blob\n \t\t\t * and failed; there may be new dereference\n@@ -240,7 +240,7 @@ static void print_object_or_die(struct batch_options *opt, struct expand_data *d\n \tif (data->type == OBJ_BLOB) {\n \t\tif (opt->buffer_output)\n \t\t\tfflush(stdout);\n-\t\tif (stream_blob_to_fd(1, oid->hash, NULL, 0) < 0)\n+\t\tif (stream_blob_to_fd(1, oid, NULL, 0) < 0)\n \t\t\tdie(\"unable to stream %s to stdout\", oid_to_hex(oid));\n \t}\n \telse {\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex f604adff..055dfdcf 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -268,7 +268,7 @@ static void check_unreachable_object(struct object *obj)\n \t\t\tif (!(f = fopen(filename, \"w\")))\n \t\t\t\tdie_errno(\"Could not open '%s'\", filename);\n \t\t\tif (obj->type == OBJ_BLOB) {\n-\t\t\t\tif (stream_blob_to_fd(fileno(f), obj->oid.hash, NULL, 1))\n+\t\t\t\tif (stream_blob_to_fd(fileno(f), &obj->oid, NULL, 1))\n \t\t\t\t\tdie_errno(\"Could not write '%s'\", filename);\n \t\t\t} else\n \t\t\t\tfprintf(f, \"%s\\n\", describe_object(obj));\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 48b9db51..0b427b67 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -474,13 +474,13 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c\n \tfflush(rev->diffopt.file);\n \tif (!DIFF_OPT_TOUCHED(&rev->diffopt, ALLOW_TEXTCONV) ||\n \t    !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))\n-\t\treturn stream_blob_to_fd(1, oid->hash, NULL, 0);\n+\t\treturn stream_blob_to_fd(1, oid, NULL, 0);\n \n \tif (get_sha1_with_context(obj_name, 0, oidc.hash, &obj_context))\n \t\tdie(_(\"Not a valid object name %s\"), obj_name);\n \tif (!obj_context.path[0] ||\n \t    !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size))\n-\t\treturn stream_blob_to_fd(1, oid->hash, NULL, 0);\n+\t\treturn stream_blob_to_fd(1, oid, NULL, 0);\n \n \tif (!buf)\n \t\tdie(_(\"git show %s: bad file\"), obj_name);\ndiff --git a/entry.c b/entry.c\nindex ce80d292..c6eea240 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -127,7 +127,7 @@ static int streaming_write_entry(const struct cache_entry *ce, char *path,\n \tif (fd < 0)\n \t\treturn -1;\n \n-\tresult |= stream_blob_to_fd(fd, ce->oid.hash, filter, 1);\n+\tresult |= stream_blob_to_fd(fd, &ce->oid, filter, 1);\n \t*fstat_done = fstat_output(fd, state, statbuf);\n \tresult |= close(fd);\n \ndiff --git a/streaming.c b/streaming.c\nindex 811fcc24..3c48f049 100644\n--- a/streaming.c\n+++ b/streaming.c\n@@ -497,7 +497,7 @@ static open_method_decl(incore)\n  * Users of streaming interface\n  ****************************************************************/\n \n-int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *filter,\n+int stream_blob_to_fd(int fd, const struct object_id *oid, struct stream_filter *filter,\n \t\t      int can_seek)\n {\n \tstruct git_istream *st;\n@@ -506,7 +506,7 @@ int stream_blob_to_fd(int fd, unsigned const char *sha1, struct stream_filter *f\n \tssize_t kept = 0;\n \tint result = -1;\n \n-\tst = open_istream(sha1, &type, &sz, filter);\n+\tst = open_istream(oid->hash, &type, &sz, filter);\n \tif (!st) {\n \t\tif (filter)\n \t\t\tfree_stream_filter(filter);\ndiff --git a/streaming.h b/streaming.h\nindex 1d05c2a4..73c1d156 100644\n--- a/streaming.h\n+++ b/streaming.h\n@@ -12,6 +12,6 @@ extern struct git_istream *open_istream(const unsigned char *, enum object_type\n extern int close_istream(struct git_istream *);\n extern ssize_t read_istream(struct git_istream *, void *, size_t);\n \n-extern int stream_blob_to_fd(int fd, const unsigned char *, struct stream_filter *, int can_seek);\n+extern int stream_blob_to_fd(int fd, const struct object_id *, struct stream_filter *, int can_seek);\n \n #endif /* STREAMING_H */\n"},{"id":"301128","messageId":"20160905200811.697889-21-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 20/20] builtin/reset: convert to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:08:11Z","receivedAt":"2016-09-05T20:10:23Z","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/reset.c | 52 ++++++++++++++++++++++++++--------------------------\n 1 file changed, 26 insertions(+), 26 deletions(-)\n\ndiff --git a/builtin/reset.c b/builtin/reset.c\nindex 9020ec66..5aa86079 100644\n--- a/builtin/reset.c\n+++ b/builtin/reset.c\n@@ -39,7 +39,7 @@ static inline int is_merge(void)\n \treturn !access(git_path_merge_head(), F_OK);\n }\n \n-static int reset_index(const unsigned char *sha1, int reset_type, int quiet)\n+static int reset_index(const struct object_id *oid, int reset_type, int quiet)\n {\n \tint nr = 1;\n \tstruct tree_desc desc[2];\n@@ -69,22 +69,22 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet)\n \tread_cache_unmerged();\n \n \tif (reset_type == KEEP) {\n-\t\tunsigned char head_sha1[20];\n-\t\tif (get_sha1(\"HEAD\", head_sha1))\n+\t\tstruct object_id head_oid;\n+\t\tif (get_oid(\"HEAD\", &head_oid))\n \t\t\treturn error(_(\"You do not have a valid HEAD.\"));\n-\t\tif (!fill_tree_descriptor(desc, head_sha1))\n+\t\tif (!fill_tree_descriptor(desc, head_oid.hash))\n \t\t\treturn error(_(\"Failed to find tree of HEAD.\"));\n \t\tnr++;\n \t\topts.fn = twoway_merge;\n \t}\n \n-\tif (!fill_tree_descriptor(desc + nr - 1, sha1))\n-\t\treturn error(_(\"Failed to find tree of %s.\"), sha1_to_hex(sha1));\n+\tif (!fill_tree_descriptor(desc + nr - 1, oid->hash))\n+\t\treturn error(_(\"Failed to find tree of %s.\"), oid_to_hex(oid));\n \tif (unpack_trees(nr, desc, &opts))\n \t\treturn -1;\n \n \tif (reset_type == MIXED || reset_type == HARD) {\n-\t\ttree = parse_tree_indirect(sha1);\n+\t\ttree = parse_tree_indirect(oid->hash);\n \t\tprime_cache_tree(&the_index, tree);\n \t}\n \n@@ -143,7 +143,7 @@ static void update_index_from_diff(struct diff_queue_struct *q,\n }\n \n static int read_from_tree(const struct pathspec *pathspec,\n-\t\t\t  unsigned char *tree_sha1,\n+\t\t\t  struct object_id *tree_oid,\n \t\t\t  int intent_to_add)\n {\n \tstruct diff_options opt;\n@@ -154,7 +154,7 @@ static int read_from_tree(const struct pathspec *pathspec,\n \topt.format_callback = update_index_from_diff;\n \topt.format_callback_data = &intent_to_add;\n \n-\tif (do_diff_cache(tree_sha1, &opt))\n+\tif (do_diff_cache(tree_oid->hash, &opt))\n \t\treturn 1;\n \tdiffcore_std(&opt);\n \tdiff_flush(&opt);\n@@ -191,7 +191,7 @@ static void parse_args(struct pathspec *pathspec,\n \t\t       const char **rev_ret)\n {\n \tconst char *rev = \"HEAD\";\n-\tunsigned char unused[20];\n+\tstruct object_id unused;\n \t/*\n \t * Possible arguments are:\n \t *\n@@ -216,8 +216,8 @@ static void parse_args(struct pathspec *pathspec,\n \t\t * has to be unambiguous. If there is a single argument, it\n \t\t * can not be a tree\n \t\t */\n-\t\telse if ((!argv[1] && !get_sha1_committish(argv[0], unused)) ||\n-\t\t\t (argv[1] && !get_sha1_treeish(argv[0], unused))) {\n+\t\telse if ((!argv[1] && !get_sha1_committish(argv[0], unused.hash)) ||\n+\t\t\t (argv[1] && !get_sha1_treeish(argv[0], unused.hash))) {\n \t\t\t/*\n \t\t\t * Ok, argv[0] looks like a commit/tree; it should not\n \t\t\t * be a filename.\n@@ -241,24 +241,24 @@ static void parse_args(struct pathspec *pathspec,\n \t\t       prefix, argv);\n }\n \n-static int reset_refs(const char *rev, const unsigned char *sha1)\n+static int reset_refs(const char *rev, const struct object_id *oid)\n {\n \tint update_ref_status;\n \tstruct strbuf msg = STRBUF_INIT;\n-\tunsigned char *orig = NULL, sha1_orig[20],\n-\t\t*old_orig = NULL, sha1_old_orig[20];\n+\tstruct object_id *orig = NULL, oid_orig,\n+\t\t*old_orig = NULL, oid_old_orig;\n \n-\tif (!get_sha1(\"ORIG_HEAD\", sha1_old_orig))\n-\t\told_orig = sha1_old_orig;\n-\tif (!get_sha1(\"HEAD\", sha1_orig)) {\n-\t\torig = sha1_orig;\n+\tif (!get_oid(\"ORIG_HEAD\", &oid_old_orig))\n+\t\told_orig = &oid_old_orig;\n+\tif (!get_oid(\"HEAD\", &oid_orig)) {\n+\t\torig = &oid_orig;\n \t\tset_reflog_message(&msg, \"updating ORIG_HEAD\", NULL);\n-\t\tupdate_ref(msg.buf, \"ORIG_HEAD\", orig, old_orig, 0,\n+\t\tupdate_ref_oid(msg.buf, \"ORIG_HEAD\", orig, old_orig, 0,\n \t\t\t   UPDATE_REFS_MSG_ON_ERR);\n \t} else if (old_orig)\n-\t\tdelete_ref(\"ORIG_HEAD\", old_orig, 0);\n+\t\tdelete_ref(\"ORIG_HEAD\", old_orig->hash, 0);\n \tset_reflog_message(&msg, \"updating HEAD\", rev);\n-\tupdate_ref_status = update_ref(msg.buf, \"HEAD\", sha1, orig, 0,\n+\tupdate_ref_status = update_ref_oid(msg.buf, \"HEAD\", oid, orig, 0,\n \t\t\t\t       UPDATE_REFS_MSG_ON_ERR);\n \tstrbuf_release(&msg);\n \treturn update_ref_status;\n@@ -357,15 +357,15 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \t\thold_locked_index(lock, 1);\n \t\tif (reset_type == MIXED) {\n \t\t\tint flags = quiet ? REFRESH_QUIET : REFRESH_IN_PORCELAIN;\n-\t\t\tif (read_from_tree(&pathspec, oid.hash, intent_to_add))\n+\t\t\tif (read_from_tree(&pathspec, &oid, intent_to_add))\n \t\t\t\treturn 1;\n \t\t\tif (get_git_work_tree())\n \t\t\t\trefresh_index(&the_index, flags, NULL, NULL,\n \t\t\t\t\t      _(\"Unstaged changes after reset:\"));\n \t\t} else {\n-\t\t\tint err = reset_index(oid.hash, reset_type, quiet);\n+\t\t\tint err = reset_index(&oid, reset_type, quiet);\n \t\t\tif (reset_type == KEEP && !err)\n-\t\t\t\terr = reset_index(oid.hash, MIXED, quiet);\n+\t\t\t\terr = reset_index(&oid, MIXED, quiet);\n \t\t\tif (err)\n \t\t\t\tdie(_(\"Could not reset index file to revision '%s'.\"), rev);\n \t\t}\n@@ -377,7 +377,7 @@ int cmd_reset(int argc, const char **argv, const char *prefix)\n \tif (!pathspec.nr && !unborn) {\n \t\t/* Any resets without paths update HEAD to the head being\n \t\t * switched to, saving the previous head in ORIG_HEAD before. */\n-\t\tupdate_ref_status = reset_refs(rev, oid.hash);\n+\t\tupdate_ref_status = reset_refs(rev, &oid);\n \n \t\tif (reset_type == HARD && !update_ref_status && !quiet)\n \t\t\tprint_new_head_line(lookup_commit_reference(oid.hash));\n"},{"id":"301129","messageId":"20160905200811.697889-8-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 07/20] builtin: convert textconv_object to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:58Z","receivedAt":"2016-09-05T20:10:27Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Since all of its callers have been updated, make textconv_object take a\nstruct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin.h          |  2 +-\n builtin/blame.c    | 12 ++++++------\n builtin/cat-file.c |  2 +-\n builtin/log.c      |  2 +-\n 4 files changed, 9 insertions(+), 9 deletions(-)\n\ndiff --git a/builtin.h b/builtin.h\nindex 6b95006a..b9122bc5 100644\n--- a/builtin.h\n+++ b/builtin.h\n@@ -25,7 +25,7 @@ struct fmt_merge_msg_opts {\n extern int fmt_merge_msg(struct strbuf *in, struct strbuf *out,\n \t\t\t struct fmt_merge_msg_opts *);\n \n-extern int textconv_object(const char *path, unsigned mode, const unsigned char *sha1, int sha1_valid, char **buf, unsigned long *buf_size);\n+extern int textconv_object(const char *path, unsigned mode, const struct object_id *oid, int oid_valid, char **buf, unsigned long *buf_size);\n \n extern int is_builtin(const char *s);\n \ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 9c09d464..0e10e302 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -154,8 +154,8 @@ static int diff_hunks(mmfile_t *file_a, mmfile_t *file_b,\n  */\n int textconv_object(const char *path,\n \t\t    unsigned mode,\n-\t\t    const unsigned char *sha1,\n-\t\t    int sha1_valid,\n+\t\t    const struct object_id *oid,\n+\t\t    int oid_valid,\n \t\t    char **buf,\n \t\t    unsigned long *buf_size)\n {\n@@ -163,7 +163,7 @@ int textconv_object(const char *path,\n \tstruct userdiff_driver *textconv;\n \n \tdf = alloc_filespec(path);\n-\tfill_filespec(df, sha1, sha1_valid, mode);\n+\tfill_filespec(df, oid->hash, oid_valid, mode);\n \ttextconv = get_textconv(df);\n \tif (!textconv) {\n \t\tfree_filespec(df);\n@@ -188,7 +188,7 @@ static void fill_origin_blob(struct diff_options *opt,\n \n \t\tnum_read_blob++;\n \t\tif (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&\n-\t\t    textconv_object(o->path, o->mode, o->blob_oid.hash, 1, &file->ptr, &file_size))\n+\t\t    textconv_object(o->path, o->mode, &o->blob_oid, 1, &file->ptr, &file_size))\n \t\t\t;\n \t\telse\n \t\t\tfile->ptr = read_sha1_file(o->blob_oid.hash, &type,\n@@ -2366,7 +2366,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \t\tswitch (st.st_mode & S_IFMT) {\n \t\tcase S_IFREG:\n \t\t\tif (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&\n-\t\t\t    textconv_object(read_from, mode, null_sha1, 0, &buf_ptr, &buf_len))\n+\t\t\t    textconv_object(read_from, mode, &null_oid, 0, &buf_ptr, &buf_len))\n \t\t\t\tstrbuf_attach(&buf, buf_ptr, buf_len, buf_len + 1);\n \t\t\telse if (strbuf_read_file(&buf, read_from, st.st_size) != st.st_size)\n \t\t\t\tdie_errno(\"cannot open or read '%s'\", read_from);\n@@ -2793,7 +2793,7 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\t\tdie(\"no such path %s in %s\", path, final_commit_name);\n \n \t\tif (DIFF_OPT_TST(&sb.revs->diffopt, ALLOW_TEXTCONV) &&\n-\t\t    textconv_object(path, o->mode, o->blob_oid.hash, 1, (char **) &sb.final_buf,\n+\t\t    textconv_object(path, o->mode, &o->blob_oid, 1, (char **) &sb.final_buf,\n \t\t\t\t    &sb.final_buf_size))\n \t\t\t;\n \t\telse\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 8b773787..7b2e0537 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -66,7 +66,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t\tdie(\"git cat-file --textconv %s: <object> must be <sha1:path>\",\n \t\t\t    obj_name);\n \n-\t\tif (textconv_object(obj_context.path, obj_context.mode, oid.hash, 1, &buf, &size))\n+\t\tif (textconv_object(obj_context.path, obj_context.mode, &oid, 1, &buf, &size))\n \t\t\tbreak;\n \n \tcase 'p':\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 226212c9..48b9db51 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -479,7 +479,7 @@ static int show_blob_object(const struct object_id *oid, struct rev_info *rev, c\n \tif (get_sha1_with_context(obj_name, 0, oidc.hash, &obj_context))\n \t\tdie(_(\"Not a valid object name %s\"), obj_name);\n \tif (!obj_context.path[0] ||\n-\t    !textconv_object(obj_context.path, obj_context.mode, oidc.hash, 1, &buf, &size))\n+\t    !textconv_object(obj_context.path, obj_context.mode, &oidc, 1, &buf, &size))\n \t\treturn stream_blob_to_fd(1, oid->hash, NULL, 0);\n \n \tif (!buf)\n"},{"id":"301130","messageId":"20160905200811.697889-6-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 05/20] builtin/cat-file: convert struct expand_data to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:56Z","receivedAt":"2016-09-05T20:10:30Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert struct cache_entry to use struct object_id by applying the\nfollowing semantic patch and the object_id transforms from contrib,\nplus the actual change to the struct:\n\n@@\nstruct expand_data E1;\n@@\n- E1.sha1\n+ E1.oid.hash\n\n@@\nstruct expand_data *E1;\n@@\n- E1->sha1\n+ E1->oid.hash\n\n@@\nstruct expand_data E1;\n@@\n- E1.delta_base_sha1\n+ E1.delta_base_oid.hash\n\n@@\nstruct expand_data *E1;\n@@\n- E1->delta_base_sha1\n+ E1->delta_base_oid.hash\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/cat-file.c | 22 ++++++++++++----------\n 1 file changed, 12 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 2dfe6265..16b0b8c9 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -128,12 +128,12 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n }\n \n struct expand_data {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tenum object_type type;\n \tunsigned long size;\n \toff_t disk_size;\n \tconst char *rest;\n-\tunsigned char delta_base_sha1[20];\n+\tstruct object_id delta_base_oid;\n \n \t/*\n \t * If mark_query is true, we do not expand anything, but rather\n@@ -176,7 +176,7 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,\n \n \tif (is_atom(\"objectname\", atom, len)) {\n \t\tif (!data->mark_query)\n-\t\t\tstrbuf_addstr(sb, sha1_to_hex(data->sha1));\n+\t\t\tstrbuf_addstr(sb, oid_to_hex(&data->oid));\n \t} else if (is_atom(\"objecttype\", atom, len)) {\n \t\tif (data->mark_query)\n \t\t\tdata->info.typep = &data->type;\n@@ -199,9 +199,10 @@ static void expand_atom(struct strbuf *sb, const char *atom, int len,\n \t\t\tstrbuf_addstr(sb, data->rest);\n \t} else if (is_atom(\"deltabase\", atom, len)) {\n \t\tif (data->mark_query)\n-\t\t\tdata->info.delta_base_sha1 = data->delta_base_sha1;\n+\t\t\tdata->info.delta_base_sha1 = data->delta_base_oid.hash;\n \t\telse\n-\t\t\tstrbuf_addstr(sb, sha1_to_hex(data->delta_base_sha1));\n+\t\t\tstrbuf_addstr(sb,\n+\t\t\t\t      oid_to_hex(&data->delta_base_oid));\n \t} else\n \t\tdie(\"unknown format element: %.*s\", len, atom);\n }\n@@ -232,7 +233,7 @@ static void batch_write(struct batch_options *opt, const void *data, int len)\n \n static void print_object_or_die(struct batch_options *opt, struct expand_data *data)\n {\n-\tconst unsigned char *sha1 = data->sha1;\n+\tconst unsigned char *sha1 = data->oid.hash;\n \n \tassert(data->info.typep);\n \n@@ -266,8 +267,9 @@ static void batch_object_write(const char *obj_name, struct batch_options *opt,\n \tstruct strbuf buf = STRBUF_INIT;\n \n \tif (!data->skip_object_info &&\n-\t    sha1_object_info_extended(data->sha1, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {\n-\t\tprintf(\"%s missing\\n\", obj_name ? obj_name : sha1_to_hex(data->sha1));\n+\t    sha1_object_info_extended(data->oid.hash, &data->info, LOOKUP_REPLACE_OBJECT) < 0) {\n+\t\tprintf(\"%s missing\\n\",\n+\t\t       obj_name ? obj_name : oid_to_hex(&data->oid));\n \t\tfflush(stdout);\n \t\treturn;\n \t}\n@@ -290,7 +292,7 @@ static void batch_one_object(const char *obj_name, struct batch_options *opt,\n \tint flags = opt->follow_symlinks ? GET_SHA1_FOLLOW_SYMLINKS : 0;\n \tenum follow_symlinks_result result;\n \n-\tresult = get_sha1_with_context(obj_name, flags, data->sha1, &ctx);\n+\tresult = get_sha1_with_context(obj_name, flags, data->oid.hash, &ctx);\n \tif (result != FOUND) {\n \t\tswitch (result) {\n \t\tcase MISSING_OBJECT:\n@@ -336,7 +338,7 @@ struct object_cb_data {\n static void batch_object_cb(const unsigned char sha1[20], void *vdata)\n {\n \tstruct object_cb_data *data = vdata;\n-\thashcpy(data->expand->sha1, sha1);\n+\thashcpy(data->expand->oid.hash, sha1);\n \tbatch_object_write(NULL, data->opt, data->expand);\n }\n \n"},{"id":"301131","messageId":"20160905200811.697889-7-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 06/20] builtin/cat-file: convert some static functions to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:57Z","receivedAt":"2016-09-05T20:10:35Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert all of the static functions that are not callbacks to use struct\nobject_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/cat-file.c | 50 +++++++++++++++++++++++++-------------------------\n 1 file changed, 25 insertions(+), 25 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 16b0b8c9..8b773787 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -23,7 +23,7 @@ struct batch_options {\n static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t\tint unknown_type)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tenum object_type type;\n \tchar *buf;\n \tunsigned long size;\n@@ -35,14 +35,14 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \tif (unknown_type)\n \t\tflags |= LOOKUP_UNKNOWN_OBJECT;\n \n-\tif (get_sha1_with_context(obj_name, 0, sha1, &obj_context))\n+\tif (get_sha1_with_context(obj_name, 0, oid.hash, &obj_context))\n \t\tdie(\"Not a valid object name %s\", obj_name);\n \n \tbuf = NULL;\n \tswitch (opt) {\n \tcase 't':\n \t\toi.typename = &sb;\n-\t\tif (sha1_object_info_extended(sha1, &oi, flags) < 0)\n+\t\tif (sha1_object_info_extended(oid.hash, &oi, flags) < 0)\n \t\t\tdie(\"git cat-file: could not get object info\");\n \t\tif (sb.len) {\n \t\t\tprintf(\"%s\\n\", sb.buf);\n@@ -53,24 +53,24 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \n \tcase 's':\n \t\toi.sizep = &size;\n-\t\tif (sha1_object_info_extended(sha1, &oi, flags) < 0)\n+\t\tif (sha1_object_info_extended(oid.hash, &oi, flags) < 0)\n \t\t\tdie(\"git cat-file: could not get object info\");\n \t\tprintf(\"%lu\\n\", size);\n \t\treturn 0;\n \n \tcase 'e':\n-\t\treturn !has_sha1_file(sha1);\n+\t\treturn !has_object_file(&oid);\n \n \tcase 'c':\n \t\tif (!obj_context.path[0])\n \t\t\tdie(\"git cat-file --textconv %s: <object> must be <sha1:path>\",\n \t\t\t    obj_name);\n \n-\t\tif (textconv_object(obj_context.path, obj_context.mode, sha1, 1, &buf, &size))\n+\t\tif (textconv_object(obj_context.path, obj_context.mode, oid.hash, 1, &buf, &size))\n \t\t\tbreak;\n \n \tcase 'p':\n-\t\ttype = sha1_object_info(sha1, NULL);\n+\t\ttype = sha1_object_info(oid.hash, NULL);\n \t\tif (type < 0)\n \t\t\tdie(\"Not a valid object name %s\", obj_name);\n \n@@ -83,8 +83,8 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t}\n \n \t\tif (type == OBJ_BLOB)\n-\t\t\treturn stream_blob_to_fd(1, sha1, NULL, 0);\n-\t\tbuf = read_sha1_file(sha1, &type, &size);\n+\t\t\treturn stream_blob_to_fd(1, oid.hash, NULL, 0);\n+\t\tbuf = read_sha1_file(oid.hash, &type, &size);\n \t\tif (!buf)\n \t\t\tdie(\"Cannot read object %s\", obj_name);\n \n@@ -93,19 +93,19 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \n \tcase 0:\n \t\tif (type_from_string(exp_type) == OBJ_BLOB) {\n-\t\t\tunsigned char blob_sha1[20];\n-\t\t\tif (sha1_object_info(sha1, NULL) == OBJ_TAG) {\n-\t\t\t\tchar *buffer = read_sha1_file(sha1, &type, &size);\n+\t\t\tstruct object_id blob_oid;\n+\t\t\tif (sha1_object_info(oid.hash, NULL) == OBJ_TAG) {\n+\t\t\t\tchar *buffer = read_sha1_file(oid.hash, &type, &size);\n \t\t\t\tconst char *target;\n \t\t\t\tif (!skip_prefix(buffer, \"object \", &target) ||\n-\t\t\t\t    get_sha1_hex(target, blob_sha1))\n-\t\t\t\t\tdie(\"%s not a valid tag\", sha1_to_hex(sha1));\n+\t\t\t\t    get_oid_hex(target, &blob_oid))\n+\t\t\t\t\tdie(\"%s not a valid tag\", oid_to_hex(&oid));\n \t\t\t\tfree(buffer);\n \t\t\t} else\n-\t\t\t\thashcpy(blob_sha1, sha1);\n+\t\t\t\toidcpy(&blob_oid, &oid);\n \n-\t\t\tif (sha1_object_info(blob_sha1, NULL) == OBJ_BLOB)\n-\t\t\t\treturn stream_blob_to_fd(1, blob_sha1, NULL, 0);\n+\t\t\tif (sha1_object_info(blob_oid.hash, NULL) == OBJ_BLOB)\n+\t\t\t\treturn stream_blob_to_fd(1, blob_oid.hash, NULL, 0);\n \t\t\t/*\n \t\t\t * we attempted to dereference a tag to a blob\n \t\t\t * and failed; there may be new dereference\n@@ -113,7 +113,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,\n \t\t\t * fall-back to the usual case.\n \t\t\t */\n \t\t}\n-\t\tbuf = read_object_with_reference(sha1, exp_type, &size, NULL);\n+\t\tbuf = read_object_with_reference(oid.hash, exp_type, &size, NULL);\n \t\tbreak;\n \n \tdefault:\n@@ -233,28 +233,28 @@ static void batch_write(struct batch_options *opt, const void *data, int len)\n \n static void print_object_or_die(struct batch_options *opt, struct expand_data *data)\n {\n-\tconst unsigned char *sha1 = data->oid.hash;\n+\tconst struct object_id *oid = &data->oid;\n \n \tassert(data->info.typep);\n \n \tif (data->type == OBJ_BLOB) {\n \t\tif (opt->buffer_output)\n \t\t\tfflush(stdout);\n-\t\tif (stream_blob_to_fd(1, sha1, NULL, 0) < 0)\n-\t\t\tdie(\"unable to stream %s to stdout\", sha1_to_hex(sha1));\n+\t\tif (stream_blob_to_fd(1, oid->hash, NULL, 0) < 0)\n+\t\t\tdie(\"unable to stream %s to stdout\", oid_to_hex(oid));\n \t}\n \telse {\n \t\tenum object_type type;\n \t\tunsigned long size;\n \t\tvoid *contents;\n \n-\t\tcontents = read_sha1_file(sha1, &type, &size);\n+\t\tcontents = read_sha1_file(oid->hash, &type, &size);\n \t\tif (!contents)\n-\t\t\tdie(\"object %s disappeared\", sha1_to_hex(sha1));\n+\t\t\tdie(\"object %s disappeared\", oid_to_hex(oid));\n \t\tif (type != data->type)\n-\t\t\tdie(\"object %s changed type!?\", sha1_to_hex(sha1));\n+\t\t\tdie(\"object %s changed type!?\", oid_to_hex(oid));\n \t\tif (data->info.sizep && size != data->size)\n-\t\t\tdie(\"object %s changed size!?\", sha1_to_hex(sha1));\n+\t\t\tdie(\"object %s changed size!?\", oid_to_hex(oid));\n \n \t\tbatch_write(opt, contents, size);\n \t\tfree(contents);\n"},{"id":"301132","messageId":"20160905200811.697889-5-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 04/20] builtin/log: convert some static functions to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:55Z","receivedAt":"2016-09-05T20:10:38Z","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/log.c | 44 ++++++++++++++++++++++----------------------\n 1 file changed, 22 insertions(+), 22 deletions(-)\n\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 92dc34dc..226212c9 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -464,9 +464,9 @@ static void show_tagger(char *buf, int len, struct rev_info *rev)\n \tstrbuf_release(&out);\n }\n \n-static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, const char *obj_name)\n+static int show_blob_object(const struct object_id *oid, struct rev_info *rev, const char *obj_name)\n {\n-\tunsigned char sha1c[20];\n+\tstruct object_id oidc;\n \tstruct object_context obj_context;\n \tchar *buf;\n \tunsigned long size;\n@@ -474,13 +474,13 @@ static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, con\n \tfflush(rev->diffopt.file);\n \tif (!DIFF_OPT_TOUCHED(&rev->diffopt, ALLOW_TEXTCONV) ||\n \t    !DIFF_OPT_TST(&rev->diffopt, ALLOW_TEXTCONV))\n-\t\treturn stream_blob_to_fd(1, sha1, NULL, 0);\n+\t\treturn stream_blob_to_fd(1, oid->hash, NULL, 0);\n \n-\tif (get_sha1_with_context(obj_name, 0, sha1c, &obj_context))\n+\tif (get_sha1_with_context(obj_name, 0, oidc.hash, &obj_context))\n \t\tdie(_(\"Not a valid object name %s\"), obj_name);\n \tif (!obj_context.path[0] ||\n-\t    !textconv_object(obj_context.path, obj_context.mode, sha1c, 1, &buf, &size))\n-\t\treturn stream_blob_to_fd(1, sha1, NULL, 0);\n+\t    !textconv_object(obj_context.path, obj_context.mode, oidc.hash, 1, &buf, &size))\n+\t\treturn stream_blob_to_fd(1, oid->hash, NULL, 0);\n \n \tif (!buf)\n \t\tdie(_(\"git show %s: bad file\"), obj_name);\n@@ -489,15 +489,15 @@ static int show_blob_object(const unsigned char *sha1, struct rev_info *rev, con\n \treturn 0;\n }\n \n-static int show_tag_object(const unsigned char *sha1, struct rev_info *rev)\n+static int show_tag_object(const struct object_id *oid, struct rev_info *rev)\n {\n \tunsigned long size;\n \tenum object_type type;\n-\tchar *buf = read_sha1_file(sha1, &type, &size);\n+\tchar *buf = read_sha1_file(oid->hash, &type, &size);\n \tint offset = 0;\n \n \tif (!buf)\n-\t\treturn error(_(\"Could not read object %s\"), sha1_to_hex(sha1));\n+\t\treturn error(_(\"Could not read object %s\"), oid_to_hex(oid));\n \n \tassert(type == OBJ_TAG);\n \twhile (offset < size && buf[offset] != '\\n') {\n@@ -574,7 +574,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)\n \t\tconst char *name = objects[i].name;\n \t\tswitch (o->type) {\n \t\tcase OBJ_BLOB:\n-\t\t\tret = show_blob_object(o->oid.hash, &rev, name);\n+\t\t\tret = show_blob_object(&o->oid, &rev, name);\n \t\t\tbreak;\n \t\tcase OBJ_TAG: {\n \t\t\tstruct tag *t = (struct tag *)o;\n@@ -585,7 +585,7 @@ int cmd_show(int argc, const char **argv, const char *prefix)\n \t\t\t\t\tdiff_get_color_opt(&rev.diffopt, DIFF_COMMIT),\n \t\t\t\t\tt->tag,\n \t\t\t\t\tdiff_get_color_opt(&rev.diffopt, DIFF_RESET));\n-\t\t\tret = show_tag_object(o->oid.hash, &rev);\n+\t\t\tret = show_tag_object(&o->oid, &rev);\n \t\t\trev.shown_one = 1;\n \t\t\tif (ret)\n \t\t\t\tbreak;\n@@ -1248,11 +1248,11 @@ static struct commit *get_base_commit(const char *base_commit,\n \t\tif (upstream) {\n \t\t\tstruct commit_list *base_list;\n \t\t\tstruct commit *commit;\n-\t\t\tunsigned char sha1[20];\n+\t\t\tstruct object_id oid;\n \n-\t\t\tif (get_sha1(upstream, sha1))\n+\t\t\tif (get_oid(upstream, &oid))\n \t\t\t\tdie(_(\"Failed to resolve '%s' as a valid ref.\"), upstream);\n-\t\t\tcommit = lookup_commit_or_die(sha1, \"upstream base\");\n+\t\t\tcommit = lookup_commit_or_die(oid.hash, \"upstream base\");\n \t\t\tbase_list = get_merge_bases_many(commit, total, list);\n \t\t\t/* There should be one and only one merge base. */\n \t\t\tif (!base_list || base_list->next)\n@@ -1339,15 +1339,15 @@ static void prepare_bases(struct base_tree_info *bases,\n \t * and stuff them in bases structure.\n \t */\n \twhile ((commit = get_revision(&revs)) != NULL) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tstruct object_id *patch_id;\n \t\tif (commit->util)\n \t\t\tcontinue;\n-\t\tif (commit_patch_id(commit, &diffopt, sha1, 0))\n+\t\tif (commit_patch_id(commit, &diffopt, oid.hash, 0))\n \t\t\tdie(_(\"cannot get patch id\"));\n \t\tALLOC_GROW(bases->patch_id, bases->nr_patch_id + 1, bases->alloc_patch_id);\n \t\tpatch_id = bases->patch_id + bases->nr_patch_id;\n-\t\thashcpy(patch_id->hash, sha1);\n+\t\toidcpy(patch_id, &oid);\n \t\tbases->nr_patch_id++;\n \t}\n }\n@@ -1628,10 +1628,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \t\t\tcheck_head = 1;\n \n \t\tif (check_head) {\n-\t\t\tunsigned char sha1[20];\n+\t\t\tstruct object_id oid;\n \t\t\tconst char *ref, *v;\n \t\t\tref = resolve_ref_unsafe(\"HEAD\", RESOLVE_REF_READING,\n-\t\t\t\t\t\t sha1, NULL);\n+\t\t\t\t\t\t oid.hash, NULL);\n \t\t\tif (ref && skip_prefix(ref, \"refs/heads/\", &v))\n \t\t\t\tbranch_name = xstrdup(v);\n \t\t\telse\n@@ -1802,9 +1802,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)\n \n static int add_pending_commit(const char *arg, struct rev_info *revs, int flags)\n {\n-\tunsigned char sha1[20];\n-\tif (get_sha1(arg, sha1) == 0) {\n-\t\tstruct commit *commit = lookup_commit_reference(sha1);\n+\tstruct object_id oid;\n+\tif (get_oid(arg, &oid) == 0) {\n+\t\tstruct commit *commit = lookup_commit_reference(oid.hash);\n \t\tif (commit) {\n \t\t\tcommit->object.flags |= flags;\n \t\t\tadd_pending_object(revs, &commit->object, arg);\n"},{"id":"301133","messageId":"20160905200811.697889-4-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 03/20] builtin/blame: convert struct origin to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:54Z","receivedAt":"2016-09-05T20:11:03Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert struct origin to use struct object_id by applying the\nfollowing semantic patch and the object_id transforms from contrib,\nplus the actual change to the struct:\n\n@@\nstruct origin E1;\n@@\n- E1.blob_sha1\n+ E1.blob_oid.hash\n\n@@\nstruct origin *E1;\n@@\n- E1->blob_sha1\n+ E1->blob_oid.hash\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/blame.c | 40 ++++++++++++++++++++--------------------\n 1 file changed, 20 insertions(+), 20 deletions(-)\n\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex 5eb3725d..9c09d464 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -120,7 +120,7 @@ struct origin {\n \t */\n \tstruct blame_entry *suspects;\n \tmmfile_t file;\n-\tunsigned char blob_sha1[20];\n+\tstruct object_id blob_oid;\n \tunsigned mode;\n \t/* guilty gets set when shipping any suspects to the final\n \t * blame list instead of other commits\n@@ -188,15 +188,16 @@ static void fill_origin_blob(struct diff_options *opt,\n \n \t\tnum_read_blob++;\n \t\tif (DIFF_OPT_TST(opt, ALLOW_TEXTCONV) &&\n-\t\t    textconv_object(o->path, o->mode, o->blob_sha1, 1, &file->ptr, &file_size))\n+\t\t    textconv_object(o->path, o->mode, o->blob_oid.hash, 1, &file->ptr, &file_size))\n \t\t\t;\n \t\telse\n-\t\t\tfile->ptr = read_sha1_file(o->blob_sha1, &type, &file_size);\n+\t\t\tfile->ptr = read_sha1_file(o->blob_oid.hash, &type,\n+\t\t\t\t\t\t   &file_size);\n \t\tfile->size = file_size;\n \n \t\tif (!file->ptr)\n \t\t\tdie(\"Cannot read blob %s for path %s\",\n-\t\t\t    sha1_to_hex(o->blob_sha1),\n+\t\t\t    oid_to_hex(&o->blob_oid),\n \t\t\t    o->path);\n \t\to->file = *file;\n \t}\n@@ -508,17 +509,17 @@ static struct origin *get_origin(struct scoreboard *sb,\n  */\n static int fill_blob_sha1_and_mode(struct origin *origin)\n {\n-\tif (!is_null_sha1(origin->blob_sha1))\n+\tif (!is_null_oid(&origin->blob_oid))\n \t\treturn 0;\n \tif (get_tree_entry(origin->commit->object.oid.hash,\n \t\t\t   origin->path,\n-\t\t\t   origin->blob_sha1, &origin->mode))\n+\t\t\t   origin->blob_oid.hash, &origin->mode))\n \t\tgoto error_out;\n-\tif (sha1_object_info(origin->blob_sha1, NULL) != OBJ_BLOB)\n+\tif (sha1_object_info(origin->blob_oid.hash, NULL) != OBJ_BLOB)\n \t\tgoto error_out;\n \treturn 0;\n  error_out:\n-\thashclr(origin->blob_sha1);\n+\toidclr(&origin->blob_oid);\n \torigin->mode = S_IFINVALID;\n \treturn -1;\n }\n@@ -572,7 +573,7 @@ static struct origin *find_origin(struct scoreboard *sb,\n \tif (!diff_queued_diff.nr) {\n \t\t/* The path is the same as parent */\n \t\tporigin = get_origin(sb, parent, origin->path);\n-\t\thashcpy(porigin->blob_sha1, origin->blob_sha1);\n+\t\toidcpy(&porigin->blob_oid, &origin->blob_oid);\n \t\tporigin->mode = origin->mode;\n \t} else {\n \t\t/*\n@@ -598,7 +599,7 @@ static struct origin *find_origin(struct scoreboard *sb,\n \t\t\t    p->status);\n \t\tcase 'M':\n \t\t\tporigin = get_origin(sb, parent, origin->path);\n-\t\t\thashcpy(porigin->blob_sha1, p->one->oid.hash);\n+\t\t\toidcpy(&porigin->blob_oid, &p->one->oid);\n \t\t\tporigin->mode = p->one->mode;\n \t\t\tbreak;\n \t\tcase 'A':\n@@ -644,7 +645,7 @@ static struct origin *find_rename(struct scoreboard *sb,\n \t\tif ((p->status == 'R' || p->status == 'C') &&\n \t\t    !strcmp(p->two->path, origin->path)) {\n \t\t\tporigin = get_origin(sb, parent, p->one->path);\n-\t\t\thashcpy(porigin->blob_sha1, p->one->oid.hash);\n+\t\t\toidcpy(&porigin->blob_oid, &p->one->oid);\n \t\t\tporigin->mode = p->one->mode;\n \t\t\tbreak;\n \t\t}\n@@ -1308,7 +1309,7 @@ static void find_copy_in_parent(struct scoreboard *sb,\n \t\t\t\tcontinue;\n \n \t\t\tnorigin = get_origin(sb, parent, p->one->path);\n-\t\t\thashcpy(norigin->blob_sha1, p->one->oid.hash);\n+\t\t\toidcpy(&norigin->blob_oid, &p->one->oid);\n \t\t\tnorigin->mode = p->one->mode;\n \t\t\tfill_origin_blob(&sb->revs->diffopt, norigin, &file_p);\n \t\t\tif (!file_p.ptr)\n@@ -1458,15 +1459,14 @@ static void pass_blame(struct scoreboard *sb, struct origin *origin, int opt)\n \t\t\tporigin = find(sb, p, origin);\n \t\t\tif (!porigin)\n \t\t\t\tcontinue;\n-\t\t\tif (!hashcmp(porigin->blob_sha1, origin->blob_sha1)) {\n+\t\t\tif (!oidcmp(&porigin->blob_oid, &origin->blob_oid)) {\n \t\t\t\tpass_whole_blame(sb, origin, porigin);\n \t\t\t\torigin_decref(porigin);\n \t\t\t\tgoto finish;\n \t\t\t}\n \t\t\tfor (j = same = 0; j < i; j++)\n \t\t\t\tif (sg_origin[j] &&\n-\t\t\t\t    !hashcmp(sg_origin[j]->blob_sha1,\n-\t\t\t\t\t     porigin->blob_sha1)) {\n+\t\t\t\t    !oidcmp(&sg_origin[j]->blob_oid, &porigin->blob_oid)) {\n \t\t\t\t\tsame = 1;\n \t\t\t\t\tbreak;\n \t\t\t\t}\n@@ -2388,7 +2388,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \tconvert_to_git(path, buf.buf, buf.len, &buf, 0);\n \torigin->file.ptr = buf.buf;\n \torigin->file.size = buf.len;\n-\tpretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_sha1);\n+\tpretend_sha1_file(buf.buf, buf.len, OBJ_BLOB, origin->blob_oid.hash);\n \n \t/*\n \t * Read the current index, replace the path entry with\n@@ -2410,7 +2410,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \t}\n \tsize = cache_entry_size(len);\n \tce = xcalloc(1, size);\n-\thashcpy(ce->oid.hash, origin->blob_sha1);\n+\toidcpy(&ce->oid, &origin->blob_oid);\n \tmemcpy(ce->name, path, len);\n \tce->ce_flags = create_ce_flags(0);\n \tce->ce_namelen = len;\n@@ -2793,16 +2793,16 @@ int cmd_blame(int argc, const char **argv, const char *prefix)\n \t\t\tdie(\"no such path %s in %s\", path, final_commit_name);\n \n \t\tif (DIFF_OPT_TST(&sb.revs->diffopt, ALLOW_TEXTCONV) &&\n-\t\t    textconv_object(path, o->mode, o->blob_sha1, 1, (char **) &sb.final_buf,\n+\t\t    textconv_object(path, o->mode, o->blob_oid.hash, 1, (char **) &sb.final_buf,\n \t\t\t\t    &sb.final_buf_size))\n \t\t\t;\n \t\telse\n-\t\t\tsb.final_buf = read_sha1_file(o->blob_sha1, &type,\n+\t\t\tsb.final_buf = read_sha1_file(o->blob_oid.hash, &type,\n \t\t\t\t\t\t      &sb.final_buf_size);\n \n \t\tif (!sb.final_buf)\n \t\t\tdie(\"Cannot read blob %s for path %s\",\n-\t\t\t    sha1_to_hex(o->blob_sha1),\n+\t\t\t    oid_to_hex(&o->blob_oid),\n \t\t\t    path);\n \t}\n \tnum_read_blob++;\n"},{"id":"301134","messageId":"20160905200811.697889-2-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 01/20] cache: convert struct cache_entry to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:52Z","receivedAt":"2016-09-05T20:11:06Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert struct cache_entry to use struct object_id by applying the\nfollowing semantic patch and the object_id transforms from contrib, plus\nthe actual change to the struct:\n\n@@\nstruct cache_entry E1;\n@@\n- E1.sha1\n+ E1.oid.hash\n\n@@\nstruct cache_entry *E1;\n@@\n- E1->sha1\n+ E1->oid.hash\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/apply.c                  | 10 +++++-----\n builtin/blame.c                  |  2 +-\n builtin/checkout.c               |  6 +++---\n builtin/fsck.c                   |  2 +-\n builtin/grep.c                   |  3 ++-\n builtin/ls-files.c               |  2 +-\n builtin/merge-index.c            |  2 +-\n builtin/read-tree.c              |  2 +-\n builtin/rm.c                     |  2 +-\n builtin/submodule--helper.c      |  5 +++--\n builtin/update-index.c           | 10 +++++-----\n cache-tree.c                     |  4 ++--\n cache.h                          |  2 +-\n diff-lib.c                       | 31 ++++++++++++++++++-------------\n diff.c                           |  2 +-\n dir.c                            |  7 ++++---\n entry.c                          |  9 +++++----\n merge-recursive.c                |  2 +-\n read-cache.c                     | 24 ++++++++++++------------\n rerere.c                         |  3 ++-\n resolve-undo.c                   |  2 +-\n revision.c                       |  2 +-\n sha1_name.c                      |  2 +-\n t/helper/test-dump-split-index.c |  2 +-\n tree.c                           |  2 +-\n unpack-trees.c                   |  8 ++++----\n 26 files changed, 79 insertions(+), 69 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex 1a488f9e..ba0e75bf 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -3220,7 +3220,7 @@ static int read_file_or_gitlink(const struct cache_entry *ce, struct strbuf *buf\n {\n \tif (!ce)\n \t\treturn 0;\n-\treturn read_blob_object(buf, ce->sha1, ce->ce_mode);\n+\treturn read_blob_object(buf, ce->oid.hash, ce->ce_mode);\n }\n \n static struct patch *in_fn_table(struct apply_state *state, const char *name)\n@@ -3959,7 +3959,7 @@ static int get_current_sha1(const char *path, unsigned char *sha1)\n \tpos = cache_name_pos(path, strlen(path));\n \tif (pos < 0)\n \t\treturn -1;\n-\thashcpy(sha1, active_cache[pos]->sha1);\n+\thashcpy(sha1, active_cache[pos]->oid.hash);\n \treturn 0;\n }\n \n@@ -4211,7 +4211,7 @@ static void add_index_file(struct apply_state *state,\n \t\tconst char *s;\n \n \t\tif (!skip_prefix(buf, \"Subproject commit \", &s) ||\n-\t\t    get_sha1_hex(s, ce->sha1))\n+\t\t    get_sha1_hex(s, ce->oid.hash))\n \t\t\tdie(_(\"corrupt patch for submodule %s\"), path);\n \t} else {\n \t\tif (!state->cached) {\n@@ -4220,7 +4220,7 @@ static void add_index_file(struct apply_state *state,\n \t\t\t\t\t  path);\n \t\t\tfill_stat_cache_info(ce, &st);\n \t\t}\n-\t\tif (write_sha1_file(buf, size, blob_type, ce->sha1) < 0)\n+\t\tif (write_sha1_file(buf, size, blob_type, ce->oid.hash) < 0)\n \t\t\tdie(_(\"unable to create backing store for newly created file %s\"), path);\n \t}\n \tif (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)\n@@ -4335,7 +4335,7 @@ static void add_conflicted_stages_file(struct apply_state *state,\n \t\tce->ce_mode = create_ce_mode(mode);\n \t\tce->ce_flags = create_ce_flags(stage);\n \t\tce->ce_namelen = namelen;\n-\t\thashcpy(ce->sha1, patch->threeway_stage[stage - 1].hash);\n+\t\toidcpy(&ce->oid, &patch->threeway_stage[stage - 1]);\n \t\tif (add_cache_entry(ce, ADD_CACHE_OK_TO_ADD) < 0)\n \t\t\tdie(_(\"unable to add cache entry for %s\"), patch->new_name);\n \t}\ndiff --git a/builtin/blame.c b/builtin/blame.c\nindex a5bbf91e..5eb3725d 100644\n--- a/builtin/blame.c\n+++ b/builtin/blame.c\n@@ -2410,7 +2410,7 @@ static struct commit *fake_working_tree_commit(struct diff_options *opt,\n \t}\n \tsize = cache_entry_size(len);\n \tce = xcalloc(1, size);\n-\thashcpy(ce->sha1, origin->blob_sha1);\n+\thashcpy(ce->oid.hash, origin->blob_sha1);\n \tmemcpy(ce->name, path, len);\n \tce->ce_flags = create_ce_flags(0);\n \tce->ce_namelen = len;\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 8672d072..a9523ffa 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -76,7 +76,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,\n \n \tlen = base->len + strlen(pathname);\n \tce = xcalloc(1, cache_entry_size(len));\n-\thashcpy(ce->sha1, sha1);\n+\thashcpy(ce->oid.hash, sha1);\n \tmemcpy(ce->name, base->buf, base->len);\n \tmemcpy(ce->name + base->len, pathname, len - base->len);\n \tce->ce_flags = create_ce_flags(0) | CE_UPDATE;\n@@ -92,7 +92,7 @@ static int update_some(const unsigned char *sha1, struct strbuf *base,\n \tif (pos >= 0) {\n \t\tstruct cache_entry *old = active_cache[pos];\n \t\tif (ce->ce_mode == old->ce_mode &&\n-\t\t    !hashcmp(ce->sha1, old->sha1)) {\n+\t\t    !oidcmp(&ce->oid, &old->oid)) {\n \t\t\told->ce_flags |= CE_UPDATE;\n \t\t\tfree(ce);\n \t\t\treturn 0;\n@@ -186,7 +186,7 @@ static int checkout_merged(int pos, struct checkout *state)\n \t\tstage = ce_stage(ce);\n \t\tif (!stage || strcmp(path, ce->name))\n \t\t\tbreak;\n-\t\thashcpy(threeway[stage - 1], ce->sha1);\n+\t\thashcpy(threeway[stage - 1], ce->oid.hash);\n \t\tif (stage == 2)\n \t\t\tmode = create_ce_mode(ce->ce_mode);\n \t\tpos++;\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 2de272ea..f604adff 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -722,7 +722,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)\n \t\t\tmode = active_cache[i]->ce_mode;\n \t\t\tif (S_ISGITLINK(mode))\n \t\t\t\tcontinue;\n-\t\t\tblob = lookup_blob(active_cache[i]->sha1);\n+\t\t\tblob = lookup_blob(active_cache[i]->oid.hash);\n \t\t\tif (!blob)\n \t\t\t\tcontinue;\n \t\t\tobj = &blob->object;\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex ae738312..8887b6ad 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -398,7 +398,8 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec, int\n \t\tif (cached || (ce->ce_flags & CE_VALID) || ce_skip_worktree(ce)) {\n \t\t\tif (ce_stage(ce) || ce_intent_to_add(ce))\n \t\t\t\tcontinue;\n-\t\t\thit |= grep_sha1(opt, ce->sha1, ce->name, 0, ce->name);\n+\t\t\thit |= grep_sha1(opt, ce->oid.hash, ce->name, 0,\n+\t\t\t\t\t ce->name);\n \t\t}\n \t\telse\n \t\t\thit |= grep_file(opt, ce->name);\ndiff --git a/builtin/ls-files.c b/builtin/ls-files.c\nindex 00ea91aa..197f153f 100644\n--- a/builtin/ls-files.c\n+++ b/builtin/ls-files.c\n@@ -187,7 +187,7 @@ static void show_ce_entry(const char *tag, const struct cache_entry *ce)\n \t\tprintf(\"%s%06o %s %d\\t\",\n \t\t       tag,\n \t\t       ce->ce_mode,\n-\t\t       find_unique_abbrev(ce->sha1,abbrev),\n+\t\t       find_unique_abbrev(ce->oid.hash,abbrev),\n \t\t       ce_stage(ce));\n \t}\n \twrite_eolinfo(ce, ce->name);\ndiff --git a/builtin/merge-index.c b/builtin/merge-index.c\nindex 1c3427c3..ce356b1d 100644\n--- a/builtin/merge-index.c\n+++ b/builtin/merge-index.c\n@@ -22,7 +22,7 @@ static int merge_entry(int pos, const char *path)\n \t\tif (strcmp(ce->name, path))\n \t\t\tbreak;\n \t\tfound++;\n-\t\tsha1_to_hex_r(hexbuf[stage], ce->sha1);\n+\t\tsha1_to_hex_r(hexbuf[stage], ce->oid.hash);\n \t\txsnprintf(ownbuf[stage], sizeof(ownbuf[stage]), \"%o\", ce->ce_mode);\n \t\targuments[stage] = hexbuf[stage];\n \t\targuments[stage + 4] = ownbuf[stage];\ndiff --git a/builtin/read-tree.c b/builtin/read-tree.c\nindex 8c693e75..9bd1fd75 100644\n--- a/builtin/read-tree.c\n+++ b/builtin/read-tree.c\n@@ -78,7 +78,7 @@ static void debug_stage(const char *label, const struct cache_entry *ce,\n \telse\n \t\tprintf(\"%06o #%d %s %.8s\\n\",\n \t\t       ce->ce_mode, ce_stage(ce), ce->name,\n-\t\t       sha1_to_hex(ce->sha1));\n+\t\t       oid_to_hex(&ce->oid));\n }\n \n static int debug_merge(const struct cache_entry * const *stages,\ndiff --git a/builtin/rm.c b/builtin/rm.c\nindex b2fee3e9..109969d5 100644\n--- a/builtin/rm.c\n+++ b/builtin/rm.c\n@@ -199,7 +199,7 @@ static int check_local_mod(unsigned char *head, int index_only)\n \t\tif (no_head\n \t\t     || get_tree_entry(head, name, sha1, &mode)\n \t\t     || ce->ce_mode != create_ce_mode(mode)\n-\t\t     || hashcmp(ce->sha1, sha1))\n+\t\t     || hashcmp(ce->oid.hash, sha1))\n \t\t\tstaged_changes = 1;\n \n \t\t/*\ndiff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c\nindex e79790f0..566cfdd7 100644\n--- a/builtin/submodule--helper.c\n+++ b/builtin/submodule--helper.c\n@@ -296,7 +296,8 @@ static int module_list(int argc, const char **argv, const char *prefix)\n \t\tif (ce_stage(ce))\n \t\t\tprintf(\"%06o %s U\\t\", ce->ce_mode, sha1_to_hex(null_sha1));\n \t\telse\n-\t\t\tprintf(\"%06o %s %d\\t\", ce->ce_mode, sha1_to_hex(ce->sha1), ce_stage(ce));\n+\t\t\tprintf(\"%06o %s %d\\t\", ce->ce_mode,\n+\t\t\t       oid_to_hex(&ce->oid), ce_stage(ce));\n \n \t\tutf8_fprintf(stdout, \"%s\\n\", ce->name);\n \t}\n@@ -683,7 +684,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,\n \n \tstrbuf_reset(&sb);\n \tstrbuf_addf(&sb, \"%06o %s %d %d\\t%s\\n\", ce->ce_mode,\n-\t\t\tsha1_to_hex(ce->sha1), ce_stage(ce),\n+\t\t\toid_to_hex(&ce->oid), ce_stage(ce),\n \t\t\tneeds_cloning, ce->name);\n \tstring_list_append(&suc->projectlines, sb.buf);\n \ndiff --git a/builtin/update-index.c b/builtin/update-index.c\nindex ba04b197..a60a30a8 100644\n--- a/builtin/update-index.c\n+++ b/builtin/update-index.c\n@@ -275,7 +275,7 @@ static int add_one_path(const struct cache_entry *old, const char *path, int len\n \tfill_stat_cache_info(ce, st);\n \tce->ce_mode = ce_mode_from_stat(old, st->st_mode);\n \n-\tif (index_path(ce->sha1, path, st,\n+\tif (index_path(ce->oid.hash, path, st,\n \t\t       info_only ? 0 : HASH_WRITE_OBJECT)) {\n \t\tfree(ce);\n \t\treturn -1;\n@@ -403,7 +403,7 @@ static int add_cacheinfo(unsigned int mode, const unsigned char *sha1,\n \tsize = cache_entry_size(len);\n \tce = xcalloc(1, size);\n \n-\thashcpy(ce->sha1, sha1);\n+\thashcpy(ce->oid.hash, sha1);\n \tmemcpy(ce->name, path, len);\n \tce->ce_flags = create_ce_flags(stage);\n \tce->ce_namelen = len;\n@@ -601,7 +601,7 @@ static struct cache_entry *read_one_ent(const char *which,\n \tsize = cache_entry_size(namelen);\n \tce = xcalloc(1, size);\n \n-\thashcpy(ce->sha1, sha1);\n+\thashcpy(ce->oid.hash, sha1);\n \tmemcpy(ce->name, path, namelen);\n \tce->ce_flags = create_ce_flags(stage);\n \tce->ce_namelen = namelen;\n@@ -658,7 +658,7 @@ static int unresolve_one(const char *path)\n \t\tret = -1;\n \t\tgoto free_return;\n \t}\n-\tif (!hashcmp(ce_2->sha1, ce_3->sha1) &&\n+\tif (!oidcmp(&ce_2->oid, &ce_3->oid) &&\n \t    ce_2->ce_mode == ce_3->ce_mode) {\n \t\tfprintf(stderr, \"%s: identical in both, skipping.\\n\",\n \t\t\tpath);\n@@ -743,7 +743,7 @@ static int do_reupdate(int ac, const char **av,\n \t\t\told = read_one_ent(NULL, head_sha1,\n \t\t\t\t\t   ce->name, ce_namelen(ce), 0);\n \t\tif (old && ce->ce_mode == old->ce_mode &&\n-\t\t    !hashcmp(ce->sha1, old->sha1)) {\n+\t\t    !oidcmp(&ce->oid, &old->oid)) {\n \t\t\tfree(old);\n \t\t\tcontinue; /* unchanged */\n \t\t}\ndiff --git a/cache-tree.c b/cache-tree.c\nindex f28b1f45..345ea359 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -168,7 +168,7 @@ static int verify_cache(struct cache_entry **cache,\n \t\t\t\tbreak;\n \t\t\t}\n \t\t\tfprintf(stderr, \"%s: unmerged (%s)\\n\",\n-\t\t\t\tce->name, sha1_to_hex(ce->sha1));\n+\t\t\t\tce->name, oid_to_hex(&ce->oid));\n \t\t}\n \t}\n \tif (funny)\n@@ -349,7 +349,7 @@ static int update_one(struct cache_tree *it,\n \t\t\t}\n \t\t}\n \t\telse {\n-\t\t\tsha1 = ce->sha1;\n+\t\t\tsha1 = ce->oid.hash;\n \t\t\tmode = ce->ce_mode;\n \t\t\tentlen = pathlen - baselen;\n \t\t\ti++;\ndiff --git a/cache.h b/cache.h\nindex b780a91a..a679484e 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -173,7 +173,7 @@ struct cache_entry {\n \tunsigned int ce_flags;\n \tunsigned int ce_namelen;\n \tunsigned int index;\t/* for link extension */\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tchar name[FLEX_ARRAY]; /* more */\n };\n \ndiff --git a/diff-lib.c b/diff-lib.c\nindex bc49c708..3007c852 100644\n--- a/diff-lib.c\n+++ b/diff-lib.c\n@@ -155,7 +155,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \t\t\t\tif (2 <= stage) {\n \t\t\t\t\tint mode = nce->ce_mode;\n \t\t\t\t\tnum_compare_stages++;\n-\t\t\t\t\thashcpy(dpath->parent[stage-2].oid.hash, nce->sha1);\n+\t\t\t\t\toidcpy(&dpath->parent[stage - 2].oid,\n+\t\t\t\t\t       &nce->oid);\n \t\t\t\t\tdpath->parent[stage-2].mode = ce_mode_from_stat(nce, mode);\n \t\t\t\t\tdpath->parent[stage-2].status =\n \t\t\t\t\t\tDIFF_STATUS_MODIFIED;\n@@ -209,7 +210,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \t\t\t\t\tcontinue;\n \t\t\t\t}\n \t\t\t\tdiff_addremove(&revs->diffopt, '-', ce->ce_mode,\n-\t\t\t\t\t       ce->sha1, !is_null_sha1(ce->sha1),\n+\t\t\t\t\t       ce->oid.hash,\n+\t\t\t\t\t       !is_null_oid(&ce->oid),\n \t\t\t\t\t       ce->name, 0);\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -225,8 +227,8 @@ int run_diff_files(struct rev_info *revs, unsigned int option)\n \t\t\t\tcontinue;\n \t\t}\n \t\toldmode = ce->ce_mode;\n-\t\told_sha1 = ce->sha1;\n-\t\tnew_sha1 = changed ? null_sha1 : ce->sha1;\n+\t\told_sha1 = ce->oid.hash;\n+\t\tnew_sha1 = changed ? null_sha1 : ce->oid.hash;\n \t\tdiff_change(&revs->diffopt, oldmode, newmode,\n \t\t\t    old_sha1, new_sha1,\n \t\t\t    !is_null_sha1(old_sha1),\n@@ -261,7 +263,7 @@ static int get_stat_data(const struct cache_entry *ce,\n \t\t\t int cached, int match_missing,\n \t\t\t unsigned *dirty_submodule, struct diff_options *diffopt)\n {\n-\tconst unsigned char *sha1 = ce->sha1;\n+\tconst unsigned char *sha1 = ce->oid.hash;\n \tunsigned int mode = ce->ce_mode;\n \n \tif (!cached && !ce_uptodate(ce)) {\n@@ -324,12 +326,13 @@ static int show_modified(struct rev_info *revs,\n \t\t\t  &dirty_submodule, &revs->diffopt) < 0) {\n \t\tif (report_missing)\n \t\t\tdiff_index_show_file(revs, \"-\", old,\n-\t\t\t\t\t     old->sha1, 1, old->ce_mode, 0);\n+\t\t\t\t\t     old->oid.hash, 1, old->ce_mode,\n+\t\t\t\t\t     0);\n \t\treturn -1;\n \t}\n \n \tif (revs->combine_merges && !cached &&\n-\t    (hashcmp(sha1, old->sha1) || hashcmp(old->sha1, new->sha1))) {\n+\t    (hashcmp(sha1, old->oid.hash) || oidcmp(&old->oid, &new->oid))) {\n \t\tstruct combine_diff_path *p;\n \t\tint pathlen = ce_namelen(new);\n \n@@ -343,22 +346,22 @@ static int show_modified(struct rev_info *revs,\n \t\tmemset(p->parent, 0, 2 * sizeof(struct combine_diff_parent));\n \t\tp->parent[0].status = DIFF_STATUS_MODIFIED;\n \t\tp->parent[0].mode = new->ce_mode;\n-\t\thashcpy(p->parent[0].oid.hash, new->sha1);\n+\t\toidcpy(&p->parent[0].oid, &new->oid);\n \t\tp->parent[1].status = DIFF_STATUS_MODIFIED;\n \t\tp->parent[1].mode = old->ce_mode;\n-\t\thashcpy(p->parent[1].oid.hash, old->sha1);\n+\t\toidcpy(&p->parent[1].oid, &old->oid);\n \t\tshow_combined_diff(p, 2, revs->dense_combined_merges, revs);\n \t\tfree(p);\n \t\treturn 0;\n \t}\n \n \toldmode = old->ce_mode;\n-\tif (mode == oldmode && !hashcmp(sha1, old->sha1) && !dirty_submodule &&\n+\tif (mode == oldmode && !hashcmp(sha1, old->oid.hash) && !dirty_submodule &&\n \t    !DIFF_OPT_TST(&revs->diffopt, FIND_COPIES_HARDER))\n \t\treturn 0;\n \n \tdiff_change(&revs->diffopt, oldmode, mode,\n-\t\t    old->sha1, sha1, 1, !is_null_sha1(sha1),\n+\t\t    old->oid.hash, sha1, 1, !is_null_sha1(sha1),\n \t\t    old->name, 0, dirty_submodule);\n \treturn 0;\n }\n@@ -392,7 +395,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,\n \t\tstruct diff_filepair *pair;\n \t\tpair = diff_unmerge(&revs->diffopt, idx->name);\n \t\tif (tree)\n-\t\t\tfill_filespec(pair->one, tree->sha1, 1, tree->ce_mode);\n+\t\t\tfill_filespec(pair->one, tree->oid.hash, 1,\n+\t\t\t\t      tree->ce_mode);\n \t\treturn;\n \t}\n \n@@ -408,7 +412,8 @@ static void do_oneway_diff(struct unpack_trees_options *o,\n \t * Something removed from the tree?\n \t */\n \tif (!idx) {\n-\t\tdiff_index_show_file(revs, \"-\", tree, tree->sha1, 1, tree->ce_mode, 0);\n+\t\tdiff_index_show_file(revs, \"-\", tree, tree->oid.hash, 1,\n+\t\t\t\t     tree->ce_mode, 0);\n \t\treturn;\n \t}\n \ndiff --git a/diff.c b/diff.c\nindex 534c12e2..bba80665 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -2700,7 +2700,7 @@ static int reuse_worktree_file(const char *name, const unsigned char *sha1, int\n \t * This is not the sha1 we are looking for, or\n \t * unreusable because it is not a regular file.\n \t */\n-\tif (hashcmp(sha1, ce->sha1) || !S_ISREG(ce->ce_mode))\n+\tif (hashcmp(sha1, ce->oid.hash) || !S_ISREG(ce->ce_mode))\n \t\treturn 0;\n \n \t/*\ndiff --git a/dir.c b/dir.c\nindex 0ea235f3..9e09bcbd 100644\n--- a/dir.c\n+++ b/dir.c\n@@ -525,7 +525,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size,\n \t\treturn NULL;\n \tif (!ce_skip_worktree(active_cache[pos]))\n \t\treturn NULL;\n-\tdata = read_sha1_file(active_cache[pos]->sha1, &type, &sz);\n+\tdata = read_sha1_file(active_cache[pos]->oid.hash, &type, &sz);\n \tif (!data || type != OBJ_BLOB) {\n \t\tfree(data);\n \t\treturn NULL;\n@@ -533,7 +533,7 @@ static void *read_skip_worktree_file_from_index(const char *path, size_t *size,\n \t*size = xsize_t(sz);\n \tif (sha1_stat) {\n \t\tmemset(&sha1_stat->stat, 0, sizeof(sha1_stat->stat));\n-\t\thashcpy(sha1_stat->sha1, active_cache[pos]->sha1);\n+\t\thashcpy(sha1_stat->sha1, active_cache[pos]->oid.hash);\n \t}\n \treturn data;\n }\n@@ -713,7 +713,8 @@ static int add_excludes(const char *fname, const char *base, int baselen,\n \t\t\t\t !ce_stage(active_cache[pos]) &&\n \t\t\t\t ce_uptodate(active_cache[pos]) &&\n \t\t\t\t !would_convert_to_git(fname))\n-\t\t\t\thashcpy(sha1_stat->sha1, active_cache[pos]->sha1);\n+\t\t\t\thashcpy(sha1_stat->sha1,\n+\t\t\t\t\tactive_cache[pos]->oid.hash);\n \t\t\telse\n \t\t\t\thash_sha1_file(buf, size, \"blob\", sha1_stat->sha1);\n \t\t\tfill_stat_data(&sha1_stat->stat, &st);\ndiff --git a/entry.c b/entry.c\nindex 519e0422..ce80d292 100644\n--- a/entry.c\n+++ b/entry.c\n@@ -82,7 +82,7 @@ static int create_file(const char *path, unsigned int mode)\n static void *read_blob_entry(const struct cache_entry *ce, unsigned long *size)\n {\n \tenum object_type type;\n-\tvoid *new = read_sha1_file(ce->sha1, &type, size);\n+\tvoid *new = read_sha1_file(ce->oid.hash, &type, size);\n \n \tif (new) {\n \t\tif (type == OBJ_BLOB)\n@@ -127,7 +127,7 @@ static int streaming_write_entry(const struct cache_entry *ce, char *path,\n \tif (fd < 0)\n \t\treturn -1;\n \n-\tresult |= stream_blob_to_fd(fd, ce->sha1, filter, 1);\n+\tresult |= stream_blob_to_fd(fd, ce->oid.hash, filter, 1);\n \t*fstat_done = fstat_output(fd, state, statbuf);\n \tresult |= close(fd);\n \n@@ -148,7 +148,8 @@ static int write_entry(struct cache_entry *ce,\n \tstruct stat st;\n \n \tif (ce_mode_s_ifmt == S_IFREG) {\n-\t\tstruct stream_filter *filter = get_stream_filter(ce->name, ce->sha1);\n+\t\tstruct stream_filter *filter = get_stream_filter(ce->name,\n+\t\t\t\t\t\t\t\t ce->oid.hash);\n \t\tif (filter &&\n \t\t    !streaming_write_entry(ce, path, filter,\n \t\t\t\t\t   state, to_tempfile,\n@@ -162,7 +163,7 @@ static int write_entry(struct cache_entry *ce,\n \t\tnew = read_blob_entry(ce, &size);\n \t\tif (!new)\n \t\t\treturn error(\"unable to read sha1 file of %s (%s)\",\n-\t\t\t\tpath, sha1_to_hex(ce->sha1));\n+\t\t\t\tpath, oid_to_hex(&ce->oid));\n \n \t\tif (ce_mode_s_ifmt == S_IFLNK && has_symlinks && !to_tempfile) {\n \t\t\tret = symlink(new, path);\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex e3491268..e3db594d 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -382,7 +382,7 @@ static struct string_list *get_unmerged(void)\n \t\t}\n \t\te = item->util;\n \t\te->stages[ce_stage(ce)].mode = ce->ce_mode;\n-\t\thashcpy(e->stages[ce_stage(ce)].oid.hash, ce->sha1);\n+\t\toidcpy(&e->stages[ce_stage(ce)].oid, &ce->oid);\n \t}\n \n \treturn unmerged;\ndiff --git a/read-cache.c b/read-cache.c\nindex 491e52d1..31eddec5 100644\n--- a/read-cache.c\n+++ b/read-cache.c\n@@ -161,7 +161,7 @@ static int ce_compare_data(const struct cache_entry *ce, struct stat *st)\n \tif (fd >= 0) {\n \t\tunsigned char sha1[20];\n \t\tif (!index_fd(sha1, fd, st, OBJ_BLOB, ce->name, 0))\n-\t\t\tmatch = hashcmp(sha1, ce->sha1);\n+\t\t\tmatch = hashcmp(sha1, ce->oid.hash);\n \t\t/* index_fd() closed the file descriptor already */\n \t}\n \treturn match;\n@@ -178,7 +178,7 @@ static int ce_compare_link(const struct cache_entry *ce, size_t expected_size)\n \tif (strbuf_readlink(&sb, ce->name, expected_size))\n \t\treturn -1;\n \n-\tbuffer = read_sha1_file(ce->sha1, &type, &size);\n+\tbuffer = read_sha1_file(ce->oid.hash, &type, &size);\n \tif (buffer) {\n \t\tif (size == sb.len)\n \t\t\tmatch = memcmp(buffer, sb.buf, size);\n@@ -202,7 +202,7 @@ static int ce_compare_gitlink(const struct cache_entry *ce)\n \t */\n \tif (resolve_gitlink_ref(ce->name, \"HEAD\", sha1) < 0)\n \t\treturn 0;\n-\treturn hashcmp(sha1, ce->sha1);\n+\treturn hashcmp(sha1, ce->oid.hash);\n }\n \n static int ce_modified_check_fs(const struct cache_entry *ce, struct stat *st)\n@@ -262,7 +262,7 @@ static int ce_match_stat_basic(const struct cache_entry *ce, struct stat *st)\n \n \t/* Racily smudged entry? */\n \tif (!ce->ce_stat_data.sd_size) {\n-\t\tif (!is_empty_blob_sha1(ce->sha1))\n+\t\tif (!is_empty_blob_sha1(ce->oid.hash))\n \t\t\tchanged |= DATA_CHANGED;\n \t}\n \n@@ -624,7 +624,7 @@ void set_object_name_for_intent_to_add_entry(struct cache_entry *ce)\n \tunsigned char sha1[20];\n \tif (write_sha1_file(\"\", 0, blob_type, sha1))\n \t\tdie(\"cannot create an empty blob in the object database\");\n-\thashcpy(ce->sha1, sha1);\n+\thashcpy(ce->oid.hash, sha1);\n }\n \n int add_to_index(struct index_state *istate, const char *path, struct stat *st, int flags, int force_mode)\n@@ -691,7 +691,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,\n \t\treturn 0;\n \t}\n \tif (!intent_only) {\n-\t\tif (index_path(ce->sha1, path, st, HASH_WRITE_OBJECT)) {\n+\t\tif (index_path(ce->oid.hash, path, st, HASH_WRITE_OBJECT)) {\n \t\t\tfree(ce);\n \t\t\treturn error(\"unable to index file %s\", path);\n \t\t}\n@@ -705,7 +705,7 @@ int add_to_index(struct index_state *istate, const char *path, struct stat *st,\n \t/* It was suspected to be racily clean, but it turns out to be Ok */\n \twas_same = (alias &&\n \t\t    !ce_stage(alias) &&\n-\t\t    !hashcmp(alias->sha1, ce->sha1) &&\n+\t\t    !oidcmp(&alias->oid, &ce->oid) &&\n \t\t    ce->ce_mode == alias->ce_mode);\n \n \tif (pretend)\n@@ -744,7 +744,7 @@ struct cache_entry *make_cache_entry(unsigned int mode,\n \tsize = cache_entry_size(len);\n \tce = xcalloc(1, size);\n \n-\thashcpy(ce->sha1, sha1);\n+\thashcpy(ce->oid.hash, sha1);\n \tmemcpy(ce->name, path, len);\n \tce->ce_flags = create_ce_flags(stage);\n \tce->ce_namelen = len;\n@@ -1424,7 +1424,7 @@ static struct cache_entry *cache_entry_from_ondisk(struct ondisk_cache_entry *on\n \tce->ce_flags = flags & ~CE_NAMEMASK;\n \tce->ce_namelen = len;\n \tce->index = 0;\n-\thashcpy(ce->sha1, ondisk->sha1);\n+\thashcpy(ce->oid.hash, ondisk->sha1);\n \tmemcpy(ce->name, name, len);\n \tce->name[len] = '\\0';\n \treturn ce;\n@@ -1849,7 +1849,7 @@ static char *copy_cache_entry_to_ondisk(struct ondisk_cache_entry *ondisk,\n \tondisk->uid  = htonl(ce->ce_stat_data.sd_uid);\n \tondisk->gid  = htonl(ce->ce_stat_data.sd_gid);\n \tondisk->size = htonl(ce->ce_stat_data.sd_size);\n-\thashcpy(ondisk->sha1, ce->sha1);\n+\thashcpy(ondisk->sha1, ce->oid.hash);\n \n \tflags = ce->ce_flags & ~CE_NAMEMASK;\n \tflags |= (ce_namelen(ce) >= CE_NAMEMASK ? CE_NAMEMASK : ce_namelen(ce));\n@@ -2038,7 +2038,7 @@ static int do_write_index(struct index_state *istate, int newfd,\n \t\t\tcontinue;\n \t\tif (!ce_uptodate(ce) && is_racy_timestamp(istate, ce))\n \t\t\tce_smudge_racily_clean_entry(ce);\n-\t\tif (is_null_sha1(ce->sha1)) {\n+\t\tif (is_null_oid(&ce->oid)) {\n \t\t\tstatic const char msg[] = \"cache entry has null sha1: %s\";\n \t\t\tstatic int allow = -1;\n \n@@ -2285,7 +2285,7 @@ void *read_blob_data_from_index(struct index_state *istate, const char *path, un\n \t}\n \tif (pos < 0)\n \t\treturn NULL;\n-\tdata = read_sha1_file(istate->cache[pos]->sha1, &type, &sz);\n+\tdata = read_sha1_file(istate->cache[pos]->oid.hash, &type, &sz);\n \tif (!data || type != OBJ_BLOB) {\n \t\tfree(data);\n \t\treturn NULL;\ndiff --git a/rerere.c b/rerere.c\nindex aaadec17..5d083ca5 100644\n--- a/rerere.c\n+++ b/rerere.c\n@@ -980,7 +980,8 @@ static int handle_cache(const char *path, unsigned char *sha1, const char *outpu\n \t\t\tbreak;\n \t\ti = ce_stage(ce) - 1;\n \t\tif (!mmfile[i].ptr) {\n-\t\t\tmmfile[i].ptr = read_sha1_file(ce->sha1, &type, &size);\n+\t\t\tmmfile[i].ptr = read_sha1_file(ce->oid.hash, &type,\n+\t\t\t\t\t\t       &size);\n \t\t\tmmfile[i].size = size;\n \t\t}\n \t}\ndiff --git a/resolve-undo.c b/resolve-undo.c\nindex 468a2eb9..b40f3173 100644\n--- a/resolve-undo.c\n+++ b/resolve-undo.c\n@@ -24,7 +24,7 @@ void record_resolve_undo(struct index_state *istate, struct cache_entry *ce)\n \tif (!lost->util)\n \t\tlost->util = xcalloc(1, sizeof(*ui));\n \tui = lost->util;\n-\thashcpy(ui->sha1[stage - 1], ce->sha1);\n+\thashcpy(ui->sha1[stage - 1], ce->oid.hash);\n \tui->mode[stage - 1] = ce->ce_mode;\n }\n \ndiff --git a/revision.c b/revision.c\nindex 8a29cb03..969b3d14 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1275,7 +1275,7 @@ void add_index_objects_to_pending(struct rev_info *revs, unsigned flags)\n \t\tif (S_ISGITLINK(ce->ce_mode))\n \t\t\tcontinue;\n \n-\t\tblob = lookup_blob(ce->sha1);\n+\t\tblob = lookup_blob(ce->oid.hash);\n \t\tif (!blob)\n \t\t\tdie(\"unable to add index blob to traversal\");\n \t\tadd_pending_object_with_path(revs, &blob->object, \"\",\ndiff --git a/sha1_name.c b/sha1_name.c\nindex ca7ddd6f..e4404391 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1435,7 +1435,7 @@ static int get_sha1_with_context_1(const char *name,\n \t\t\t    memcmp(ce->name, cp, namelen))\n \t\t\t\tbreak;\n \t\t\tif (ce_stage(ce) == stage) {\n-\t\t\t\thashcpy(sha1, ce->sha1);\n+\t\t\t\thashcpy(sha1, ce->oid.hash);\n \t\t\t\toc->mode = ce->ce_mode;\n \t\t\t\tfree(new_path);\n \t\t\t\treturn 0;\ndiff --git a/t/helper/test-dump-split-index.c b/t/helper/test-dump-split-index.c\nindex d1689248..e44430b6 100644\n--- a/t/helper/test-dump-split-index.c\n+++ b/t/helper/test-dump-split-index.c\n@@ -23,7 +23,7 @@ int cmd_main(int ac, const char **av)\n \tfor (i = 0; i < the_index.cache_nr; i++) {\n \t\tstruct cache_entry *ce = the_index.cache[i];\n \t\tprintf(\"%06o %s %d\\t%s\\n\", ce->ce_mode,\n-\t\t       sha1_to_hex(ce->sha1), ce_stage(ce), ce->name);\n+\t\t       oid_to_hex(&ce->oid), ce_stage(ce), ce->name);\n \t}\n \tprintf(\"replacements:\");\n \tif (si->replace_bitmap)\ndiff --git a/tree.c b/tree.c\nindex 0089e52d..2b5a5a86 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -26,7 +26,7 @@ static int read_one_entry_opt(const unsigned char *sha1, const char *base, int b\n \tce->ce_namelen = baselen + len;\n \tmemcpy(ce->name, base, baselen);\n \tmemcpy(ce->name + baselen, pathname, len+1);\n-\thashcpy(ce->sha1, sha1);\n+\thashcpy(ce->oid.hash, sha1);\n \treturn add_cache_entry(ce, opt);\n }\n \ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 11c37fbc..9238308f 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -625,7 +625,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con\n \tce->ce_mode = create_ce_mode(n->mode);\n \tce->ce_flags = create_ce_flags(stage);\n \tce->ce_namelen = len;\n-\thashcpy(ce->sha1, n->oid->hash);\n+\toidcpy(&ce->oid, n->oid);\n \tmake_traverse_path(ce->name, info, n);\n \n \treturn ce;\n@@ -1287,7 +1287,7 @@ static int same(const struct cache_entry *a, const struct cache_entry *b)\n \tif ((a->ce_flags | b->ce_flags) & CE_CONFLICTED)\n \t\treturn 0;\n \treturn a->ce_mode == b->ce_mode &&\n-\t       !hashcmp(a->sha1, b->sha1);\n+\t       !oidcmp(&a->oid, &b->oid);\n }\n \n \n@@ -1393,7 +1393,7 @@ static int verify_clean_subdirectory(const struct cache_entry *ce,\n \t\t/* If we are not going to update the submodule, then\n \t\t * we don't care.\n \t\t */\n-\t\tif (!hashcmp(sha1, ce->sha1))\n+\t\tif (!hashcmp(sha1, ce->oid.hash))\n \t\t\treturn 0;\n \t\treturn verify_clean_submodule(ce, error_type, o);\n \t}\n@@ -1665,7 +1665,7 @@ static void show_stage_entry(FILE *o,\n \t\tfprintf(o, \"%s%06o %s %d\\t%s\\n\",\n \t\t\tlabel,\n \t\t\tce->ce_mode,\n-\t\t\tsha1_to_hex(ce->sha1),\n+\t\t\toid_to_hex(&ce->oid),\n \t\t\tce_stage(ce),\n \t\t\tce->name);\n }\n"},{"id":"301135","messageId":"20160905200811.697889-1-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":null,"subject":"[PATCH v2 00/20] object_id part 5","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:51Z","receivedAt":"2016-09-05T20:11:08Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"\nThis is the fifth in a series of series to convert from unsigned char [20] to\nstruct object_id.\n\nThis series converts many of the files in the builtin directory to use struct\nobject_id.  This gets us almost to the point where we can convert get_tree_entry\nto use struct object_id, but not quite.  That function is used indirectly by\nget_sha1, meaning that get_oid would have to completely replace it in order for\nget_tree_entry to be converted.\n\nHowever, this series tackles one of two major sources of object ID values: the\ncommand line (the other, of course, being the refs code).  Converting several of\nthe builtin commands to use struct object_id as much as possible makes it easier\nto convert other functions down the line.\n\nChanges from v1:\n* More clearly state that the Coccinelle-using patches also have a manual struct\n  update.\n* Convert the uninitialized constant in notes-merge.c.\n* Convert one additional use of update_ref into update_ref_oid.\n\nbrian m. carlson (20):\n  cache: convert struct cache_entry to use struct object_id\n  builtin/apply: convert static functions to struct object_id\n  builtin/blame: convert struct origin to use struct object_id\n  builtin/log: convert some static functions to use struct object_id\n  builtin/cat-file: convert struct expand_data to use struct object_id\n  builtin/cat-file: convert some static functions to struct object_id\n  builtin: convert textconv_object to use struct object_id\n  streaming: make stream_blob_to_fd take struct object_id\n  builtin/checkout: convert some static functions to struct object_id\n  notes-merge: convert struct notes_merge_pair to struct object_id\n  Convert read_mmblob to take struct object_id.\n  builtin/blame: convert file to use struct object_id\n  builtin/rm: convert to use struct object_id\n  notes: convert init_notes to use struct object_id\n  builtin/update-index: convert file to struct object_id\n  sha1_name: convert get_sha1_mb to struct object_id\n  refs: add an update_ref_oid function.\n  builtin/am: convert to struct object_id\n  builtin/commit-tree: convert to struct object_id\n  builtin/reset: convert to use struct object_id\n\n builtin.h                        |   2 +-\n builtin/am.c                     | 140 +++++++++++++++++++--------------------\n builtin/apply.c                  |  94 +++++++++++++-------------\n builtin/blame.c                  |  76 ++++++++++-----------\n builtin/cat-file.c               |  70 ++++++++++----------\n builtin/checkout.c               |  70 ++++++++++----------\n builtin/commit-tree.c            |  20 +++---\n builtin/fsck.c                   |   4 +-\n builtin/grep.c                   |   3 +-\n builtin/log.c                    |  44 ++++++------\n builtin/ls-files.c               |   2 +-\n builtin/merge-index.c            |   2 +-\n builtin/read-tree.c              |   2 +-\n builtin/reset.c                  |  52 +++++++--------\n builtin/rm.c                     |  18 ++---\n builtin/submodule--helper.c      |   5 +-\n builtin/update-index.c           |  67 ++++++++++---------\n cache-tree.c                     |   4 +-\n cache.h                          |   4 +-\n diff-lib.c                       |  31 +++++----\n diff.c                           |   2 +-\n dir.c                            |   7 +-\n entry.c                          |   9 +--\n merge-recursive.c                |   8 +--\n notes-merge.c                    | 127 ++++++++++++++++++-----------------\n notes.c                          |  12 ++--\n read-cache.c                     |  24 +++----\n refs.c                           |   8 +++\n refs.h                           |   3 +\n rerere.c                         |   3 +-\n resolve-undo.c                   |   2 +-\n revision.c                       |   2 +-\n sha1_name.c                      |  20 +++---\n streaming.c                      |   4 +-\n streaming.h                      |   2 +-\n t/helper/test-dump-split-index.c |   2 +-\n tree.c                           |   2 +-\n unpack-trees.c                   |   8 +--\n xdiff-interface.c                |   8 +--\n xdiff-interface.h                |   3 +-\n 40 files changed, 497 insertions(+), 469 deletions(-)\n\n"},{"id":"301136","messageId":"20160905200811.697889-3-sandals@crustytoothpaste.net","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 02/20] builtin/apply: convert static functions to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-05T20:07:53Z","receivedAt":"2016-09-05T20:11:09Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"There were several static functions using unsigned char arrays for SHA-1\nvalues.  Convert them to use struct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/apply.c | 96 ++++++++++++++++++++++++++++-----------------------------\n 1 file changed, 48 insertions(+), 48 deletions(-)\n\ndiff --git a/builtin/apply.c b/builtin/apply.c\nindex ba0e75bf..76b16121 100644\n--- a/builtin/apply.c\n+++ b/builtin/apply.c\n@@ -3101,16 +3101,16 @@ static int apply_binary(struct apply_state *state,\n \t\t\tstruct patch *patch)\n {\n \tconst char *name = patch->old_name ? patch->old_name : patch->new_name;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\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 */\n-\tif (strlen(patch->old_sha1_prefix) != 40 ||\n-\t    strlen(patch->new_sha1_prefix) != 40 ||\n-\t    get_sha1_hex(patch->old_sha1_prefix, sha1) ||\n-\t    get_sha1_hex(patch->new_sha1_prefix, sha1))\n+\tif (strlen(patch->old_sha1_prefix) != GIT_SHA1_HEXSZ ||\n+\t    strlen(patch->new_sha1_prefix) != GIT_SHA1_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 \t\t\t     \"without full index line\", name);\n \n@@ -3119,12 +3119,12 @@ static int apply_binary(struct apply_state *state,\n \t\t * See if the old one matches what the patch\n \t\t * applies to.\n \t\t */\n-\t\thash_sha1_file(img->buf, img->len, blob_type, sha1);\n-\t\tif (strcmp(sha1_to_hex(sha1), patch->old_sha1_prefix))\n+\t\thash_sha1_file(img->buf, img->len, blob_type, oid.hash);\n+\t\tif (strcmp(oid_to_hex(&oid), patch->old_sha1_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-\t\t\t\t     name, sha1_to_hex(sha1));\n+\t\t\t\t     name, oid_to_hex(&oid));\n \t}\n \telse {\n \t\t/* Otherwise, the old one must be empty. */\n@@ -3133,19 +3133,19 @@ 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_sha1_hex(patch->new_sha1_prefix, sha1);\n-\tif (is_null_sha1(sha1)) {\n+\tget_oid_hex(patch->new_sha1_prefix, &oid);\n+\tif (is_null_oid(&oid)) {\n \t\tclear_image(img);\n \t\treturn 0; /* deletion patch */\n \t}\n \n-\tif (has_sha1_file(sha1)) {\n+\tif (has_sha1_file(oid.hash)) {\n \t\t/* We already have the postimage */\n \t\tenum object_type type;\n \t\tunsigned long size;\n \t\tchar *result;\n \n-\t\tresult = read_sha1_file(sha1, &type, &size);\n+\t\tresult = read_sha1_file(oid.hash, &type, &size);\n \t\tif (!result)\n \t\t\treturn error(\"the necessary postimage %s for \"\n \t\t\t\t     \"'%s' cannot be read\",\n@@ -3164,10 +3164,10 @@ static int apply_binary(struct apply_state *state,\n \t\t\t\t     name);\n \n \t\t/* verify that the result matches */\n-\t\thash_sha1_file(img->buf, img->len, blob_type, sha1);\n-\t\tif (strcmp(sha1_to_hex(sha1), patch->new_sha1_prefix))\n+\t\thash_sha1_file(img->buf, img->len, blob_type, oid.hash);\n+\t\tif (strcmp(oid_to_hex(&oid), patch->new_sha1_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, sha1_to_hex(sha1));\n+\t\t\t\tname, patch->new_sha1_prefix, oid_to_hex(&oid));\n \t}\n \n \treturn 0;\n@@ -3197,17 +3197,17 @@ static int apply_fragments(struct apply_state *state, struct image *img, struct\n \treturn 0;\n }\n \n-static int read_blob_object(struct strbuf *buf, const unsigned char *sha1, unsigned mode)\n+static int read_blob_object(struct strbuf *buf, const struct object_id *oid, unsigned mode)\n {\n \tif (S_ISGITLINK(mode)) {\n \t\tstrbuf_grow(buf, 100);\n-\t\tstrbuf_addf(buf, \"Subproject commit %s\\n\", sha1_to_hex(sha1));\n+\t\tstrbuf_addf(buf, \"Subproject commit %s\\n\", oid_to_hex(oid));\n \t} else {\n \t\tenum object_type type;\n \t\tunsigned long sz;\n \t\tchar *result;\n \n-\t\tresult = read_sha1_file(sha1, &type, &sz);\n+\t\tresult = read_sha1_file(oid->hash, &type, &sz);\n \t\tif (!result)\n \t\t\treturn -1;\n \t\t/* XXX read_sha1_file NUL-terminates */\n@@ -3220,7 +3220,7 @@ static int read_file_or_gitlink(const struct cache_entry *ce, struct strbuf *buf\n {\n \tif (!ce)\n \t\treturn 0;\n-\treturn read_blob_object(buf, ce->oid.hash, ce->ce_mode);\n+\treturn read_blob_object(buf, &ce->oid, ce->ce_mode);\n }\n \n static struct patch *in_fn_table(struct apply_state *state, const char *name)\n@@ -3427,17 +3427,17 @@ static int load_preimage(struct apply_state *state,\n \n static int three_way_merge(struct image *image,\n \t\t\t   char *path,\n-\t\t\t   const unsigned char *base,\n-\t\t\t   const unsigned char *ours,\n-\t\t\t   const unsigned char *theirs)\n+\t\t\t   const struct object_id *base,\n+\t\t\t   const struct object_id *ours,\n+\t\t\t   const struct object_id *theirs)\n {\n \tmmfile_t base_file, our_file, their_file;\n \tmmbuffer_t result = { NULL };\n \tint status;\n \n-\tread_mmblob(&base_file, base);\n-\tread_mmblob(&our_file, ours);\n-\tread_mmblob(&their_file, theirs);\n+\tread_mmblob(&base_file, base->hash);\n+\tread_mmblob(&our_file, ours->hash);\n+\tread_mmblob(&their_file, theirs->hash);\n \tstatus = ll_merge(&result, path,\n \t\t\t  &base_file, \"base\",\n \t\t\t  &our_file, \"ours\",\n@@ -3506,7 +3506,7 @@ static int try_threeway(struct apply_state *state,\n \t\t\tstruct stat *st,\n \t\t\tconst struct cache_entry *ce)\n {\n-\tunsigned char pre_sha1[20], post_sha1[20], our_sha1[20];\n+\tstruct object_id pre_oid, post_oid, our_oid;\n \tstruct strbuf buf = STRBUF_INIT;\n \tsize_t len;\n \tint status;\n@@ -3520,9 +3520,9 @@ static int try_threeway(struct apply_state *state,\n \n \t/* Preimage the patch was prepared for */\n \tif (patch->is_new)\n-\t\twrite_sha1_file(\"\", 0, blob_type, pre_sha1);\n-\telse if (get_sha1(patch->old_sha1_prefix, pre_sha1) ||\n-\t\t read_blob_object(&buf, pre_sha1, patch->old_mode))\n+\t\twrite_sha1_file(\"\", 0, blob_type, pre_oid.hash);\n+\telse if (get_sha1(patch->old_sha1_prefix, pre_oid.hash) ||\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 \tfprintf(stderr, \"Falling back to three-way merge...\\n\");\n@@ -3535,7 +3535,7 @@ static int try_threeway(struct apply_state *state,\n \t\treturn -1;\n \t}\n \t/* post_sha1[] is theirs */\n-\twrite_sha1_file(tmp_image.buf, tmp_image.len, blob_type, post_sha1);\n+\twrite_sha1_file(tmp_image.buf, tmp_image.len, blob_type, post_oid.hash);\n \tclear_image(&tmp_image);\n \n \t/* our_sha1[] is ours */\n@@ -3548,12 +3548,12 @@ static int try_threeway(struct apply_state *state,\n \t\t\treturn error(\"cannot read the current contents of '%s'\",\n \t\t\t\t     patch->old_name);\n \t}\n-\twrite_sha1_file(tmp_image.buf, tmp_image.len, blob_type, our_sha1);\n+\twrite_sha1_file(tmp_image.buf, tmp_image.len, blob_type, our_oid.hash);\n \tclear_image(&tmp_image);\n \n \t/* in-core three-way merge between post and our using pre as base */\n \tstatus = three_way_merge(image, patch->new_name,\n-\t\t\t\t pre_sha1, our_sha1, post_sha1);\n+\t\t\t\t &pre_oid, &our_oid, &post_oid);\n \tif (status < 0) {\n \t\tfprintf(stderr, \"Failed to fall back on three-way merge...\\n\");\n \t\treturn status;\n@@ -3564,9 +3564,9 @@ static int try_threeway(struct apply_state *state,\n \t\tif (patch->is_new)\n \t\t\toidclr(&patch->threeway_stage[0]);\n \t\telse\n-\t\t\thashcpy(patch->threeway_stage[0].hash, pre_sha1);\n-\t\thashcpy(patch->threeway_stage[1].hash, our_sha1);\n-\t\thashcpy(patch->threeway_stage[2].hash, post_sha1);\n+\t\t\toidcpy(&patch->threeway_stage[0], &pre_oid);\n+\t\toidcpy(&patch->threeway_stage[1], &our_oid);\n+\t\toidcpy(&patch->threeway_stage[2], &post_oid);\n \t\tfprintf(stderr, \"Applied patch to '%s' with conflicts.\\n\", patch->new_name);\n \t} else {\n \t\tfprintf(stderr, \"Applied patch to '%s' cleanly.\\n\", patch->new_name);\n@@ -3949,8 +3949,8 @@ static int check_patch_list(struct apply_state *state, struct patch *patch)\n \treturn err;\n }\n \n-/* This function tries to read the sha1 from the current index */\n-static int get_current_sha1(const char *path, unsigned char *sha1)\n+/* This function tries to read the object ID from the current index */\n+static int get_current_oid(const char *path, struct object_id *oid)\n {\n \tint pos;\n \n@@ -3959,11 +3959,11 @@ static int get_current_sha1(const char *path, unsigned char *sha1)\n \tpos = cache_name_pos(path, strlen(path));\n \tif (pos < 0)\n \t\treturn -1;\n-\thashcpy(sha1, active_cache[pos]->oid.hash);\n+\toidcpy(oid, &active_cache[pos]->oid);\n \treturn 0;\n }\n \n-static int preimage_sha1_in_gitlink_patch(struct patch *p, unsigned char sha1[20])\n+static int preimage_oid_in_gitlink_patch(struct patch *p, struct object_id *oid)\n {\n \t/*\n \t * A usable gitlink patch has only one fragment (hunk) that looks like:\n@@ -3987,14 +3987,14 @@ static int preimage_sha1_in_gitlink_patch(struct patch *p, unsigned char sha1[20\n \t    (preimage = memchr(hunk->patch, '\\n', hunk->size)) != NULL &&\n \t    starts_with(++preimage, heading) &&\n \t    /* does it record full SHA-1? */\n-\t    !get_sha1_hex(preimage + sizeof(heading) - 1, sha1) &&\n-\t    preimage[sizeof(heading) + 40 - 1] == '\\n' &&\n+\t    !get_oid_hex(preimage + sizeof(heading) - 1, oid) &&\n+\t    preimage[sizeof(heading) + GIT_SHA1_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 \n \t/* we may have full object name on the index line */\n-\treturn get_sha1_hex(p->old_sha1_prefix, sha1);\n+\treturn get_oid_hex(p->old_sha1_prefix, oid);\n }\n \n /* Build an index that contains the just the files needed for a 3way merge */\n@@ -4008,7 +4008,7 @@ static void build_fake_ancestor(struct patch *list, const char *filename)\n \t * worth showing the new sha1 prefix, but until then...\n \t */\n \tfor (patch = list; patch; patch = patch->next) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tstruct cache_entry *ce;\n \t\tconst char *name;\n \n@@ -4017,23 +4017,23 @@ static void build_fake_ancestor(struct patch *list, const char *filename)\n \t\t\tcontinue;\n \n \t\tif (S_ISGITLINK(patch->old_mode)) {\n-\t\t\tif (!preimage_sha1_in_gitlink_patch(patch, sha1))\n+\t\t\tif (!preimage_oid_in_gitlink_patch(patch, &oid))\n \t\t\t\t; /* ok, the textual part looks sane */\n \t\t\telse\n \t\t\t\tdie(\"sha1 information is lacking or useless for submodule %s\",\n \t\t\t\t    name);\n-\t\t} else if (!get_sha1_blob(patch->old_sha1_prefix, sha1)) {\n+\t\t} else if (!get_sha1_blob(patch->old_sha1_prefix, oid.hash)) {\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-\t\t\tif (get_current_sha1(patch->old_name, sha1))\n+\t\t\tif (get_current_oid(patch->old_name, &oid))\n \t\t\t\tdie(\"mode change for %s, which is not \"\n \t\t\t\t    \"in current HEAD\", name);\n \t\t} else\n \t\t\tdie(\"sha1 information is lacking or useless \"\n \t\t\t    \"(%s).\", name);\n \n-\t\tce = make_cache_entry(patch->old_mode, sha1, name, 0, 0);\n+\t\tce = make_cache_entry(patch->old_mode, oid.hash, name, 0, 0);\n \t\tif (!ce)\n \t\t\tdie(_(\"make_cache_entry failed for path '%s'\"), name);\n \t\tif (add_index_entry(&result, ce, ADD_CACHE_OK_TO_ADD))\n@@ -4211,7 +4211,7 @@ static void add_index_file(struct apply_state *state,\n \t\tconst char *s;\n \n \t\tif (!skip_prefix(buf, \"Subproject commit \", &s) ||\n-\t\t    get_sha1_hex(s, ce->oid.hash))\n+\t\t    get_oid_hex(s, &ce->oid))\n \t\t\tdie(_(\"corrupt patch for submodule %s\"), path);\n \t} else {\n \t\tif (!state->cached) {\n"},{"id":"301324","messageId":"xmqq60q7lbae.fsf@gitster.mtv.corp.google.com","threadId":"44012","inReplyTo":"20160905200811.697889-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 00/20] object_id part 5","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-09-07T20:12:09Z","receivedAt":"2016-09-07T20:13:39Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> This is the fifth in a series of series to convert from unsigned char [20] to\n> struct object_id.\n>\n> This series converts many of the files in the builtin directory to use struct\n> object_id.  This gets us almost to the point where we can convert get_tree_entry\n> to use struct object_id, but not quite.  That function is used indirectly by\n> get_sha1, meaning that get_oid would have to completely replace it in order for\n> get_tree_entry to be converted.\n>\n> However, this series tackles one of two major sources of object ID values: the\n> command line (the other, of course, being the refs code).  Converting several of\n> the builtin commands to use struct object_id as much as possible makes it easier\n> to convert other functions down the line.\n\nIt is a bit unfortunate that this conflicts somewhat in builtin/cat-file.c\nand heavily with builtin/apply.c with other topics in flight.\n\nLet me see how bad the conflict resolution is and report back later.\n\nThanks.\n"},{"id":"301334","messageId":"20160907222207.6fdorwi4q4p72gro@vauxhall.crustytoothpaste.net","threadId":"44012","inReplyTo":"xmqq60q7lbae.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH v2 00/20] object_id part 5","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-09-07T22:22:07Z","receivedAt":"2016-09-07T22:22:19Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Wed, Sep 07, 2016 at 01:12:09PM -0700, Junio C Hamano wrote:\n> It is a bit unfortunate that this conflicts somewhat in builtin/cat-file.c\n> and heavily with builtin/apply.c with other topics in flight.\n> \n> Let me see how bad the conflict resolution is and report back later.\n\nIf it ends up being problematic, feel free to drop the appropriate\npatches and I'll fix them up and send them in in the next set.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"301339","messageId":"xmqqwpinjopn.fsf@gitster.mtv.corp.google.com","threadId":"44012","inReplyTo":"20160907222207.6fdorwi4q4p72gro@vauxhall.crustytoothpaste.net","subject":"Re: [PATCH v2 00/20] object_id part 5","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-09-07T23:05:08Z","receivedAt":"2016-09-07T23:05:16Z","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 Wed, Sep 07, 2016 at 01:12:09PM -0700, Junio C Hamano wrote:\n>> It is a bit unfortunate that this conflicts somewhat in builtin/cat-file.c\n>> and heavily with builtin/apply.c with other topics in flight.\n>> \n>> Let me see how bad the conflict resolution is and report back later.\n>\n> If it ends up being problematic, feel free to drop the appropriate\n> patches and I'll fix them up and send them in in the next set.\n\nLet's see how well I do first ;-) There was another one in\nwt-status.c that was touched by the \"status --porcelain=v2\" series,\nbut I haven't finished today's merges yet.\n"}]}