{"thread":{"id":"44802","subject":"[PATCH 00/17] object_id part 6","startedAt":"2017-01-01T19:19:41Z","lastAt":"2017-01-03T01:32:25Z","messageCount":27,"participants":["brian m. carlson","Michael Haggerty","Jeff King"],"isPatch":true,"patchVersion":1,"patchTotal":17},"messages":[{"id":"308583","messageId":"20170101191847.564741-1-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":null,"subject":"[PATCH 00/17] object_id part 6","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:30Z","receivedAt":"2017-01-01T19:19:41Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"This is another series in the continuing conversion to struct object_id.\n\nThis series converts more of the builtin directory and some of the\nrefs code to use struct object_id. Additionally, it implements an\nnth_packed_object_oid function which provides a struct object_id\nversion of the nth_packed_object function.\n\nThere is a small known conflict with next, but it can easily be fixed up.\n\nbrian m. carlson (17):\n  builtin/commit: convert to struct object_id\n  builtin/diff-tree: convert to struct object_id\n  builtin/describe: convert to struct object_id\n  builtin/fast-export: convert to struct object_id\n  builtin/fmt-merge-message: convert to struct object_id\n  builtin/grep: convert to struct object_id\n  builtin/branch: convert to struct object_id\n  builtin/clone: convert to struct object_id\n  builtin/merge: convert to struct object_id\n  Convert remaining callers of resolve_refdup to object_id\n  builtin/replace: convert to struct object_id\n  reflog-walk: convert struct reflog_info to struct object_id\n  refs: convert each_reflog_ent_fn to struct object_id\n  sha1_file: introduce an nth_packed_object_oid function\n  Convert object iteration callbacks to struct object_id\n  builtin/merge-base: convert to struct object_id\n  wt-status: convert to struct object_id\n\n builtin/branch.c        |  26 ++++-----\n builtin/cat-file.c      |   8 +--\n builtin/clone.c         |  10 ++--\n builtin/commit.c        |  46 ++++++++--------\n builtin/count-objects.c |   4 +-\n builtin/describe.c      |  50 +++++++++---------\n builtin/diff-tree.c     |  38 +++++++-------\n builtin/fast-export.c   |  58 ++++++++++-----------\n builtin/fmt-merge-msg.c |  70 ++++++++++++-------------\n builtin/fsck.c          |  26 ++++-----\n builtin/grep.c          |  24 ++++-----\n builtin/merge-base.c    |  30 +++++------\n builtin/merge.c         | 136 ++++++++++++++++++++++++------------------------\n builtin/notes.c         |  18 +++----\n builtin/pack-objects.c  |   6 +--\n builtin/prune-packed.c  |   4 +-\n builtin/prune.c         |   8 +--\n builtin/receive-pack.c  |   4 +-\n builtin/reflog.c        |   2 +-\n builtin/replace.c       | 112 +++++++++++++++++++--------------------\n cache.h                 |   5 +-\n reachable.c             |  30 +++++------\n ref-filter.c            |   4 +-\n reflog-walk.c           |  26 ++++-----\n refs.c                  |  24 ++++-----\n refs.h                  |   2 +-\n refs/files-backend.c    |  24 ++++-----\n revision.c              |  12 ++---\n sha1_file.c             |  22 +++++---\n sha1_name.c             |   2 +-\n transport.c             |   4 +-\n wt-status.c             |  52 +++++++++---------\n 32 files changed, 448 insertions(+), 439 deletions(-)\n\n-- \n2.11.0\n\n"},{"id":"308584","messageId":"20170101191847.564741-4-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 03/17] builtin/describe: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:33Z","receivedAt":"2017-01-01T19:19:45Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert the functions in this file and struct commit_name  to struct\nobject_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/describe.c | 50 +++++++++++++++++++++++++-------------------------\n 1 file changed, 25 insertions(+), 25 deletions(-)\n\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex 01490a157..738e68f95 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -39,11 +39,11 @@ static const char *diff_index_args[] = {\n \n struct commit_name {\n \tstruct hashmap_entry entry;\n-\tunsigned char peeled[20];\n+\tstruct object_id peeled;\n \tstruct tag *tag;\n \tunsigned prio:2; /* annotated tag = 2, tag = 1, head = 0 */\n \tunsigned name_checked:1;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tchar *path;\n };\n \n@@ -54,17 +54,17 @@ static const char *prio_names[] = {\n static int commit_name_cmp(const struct commit_name *cn1,\n \t\tconst struct commit_name *cn2, const void *peeled)\n {\n-\treturn hashcmp(cn1->peeled, peeled ? peeled : cn2->peeled);\n+\treturn oidcmp(&cn1->peeled, peeled ? peeled : &cn2->peeled);\n }\n \n-static inline struct commit_name *find_commit_name(const unsigned char *peeled)\n+static inline struct commit_name *find_commit_name(const struct object_id *peeled)\n {\n-\treturn hashmap_get_from_hash(&names, sha1hash(peeled), peeled);\n+\treturn hashmap_get_from_hash(&names, sha1hash(peeled->hash), peeled->hash);\n }\n \n static int replace_name(struct commit_name *e,\n \t\t\t       int prio,\n-\t\t\t       const unsigned char *sha1,\n+\t\t\t       const struct object_id *oid,\n \t\t\t       struct tag **tag)\n {\n \tif (!e || e->prio < prio)\n@@ -77,13 +77,13 @@ static int replace_name(struct commit_name *e,\n \t\tstruct tag *t;\n \n \t\tif (!e->tag) {\n-\t\t\tt = lookup_tag(e->sha1);\n+\t\t\tt = lookup_tag(e->oid.hash);\n \t\t\tif (!t || parse_tag(t))\n \t\t\t\treturn 1;\n \t\t\te->tag = t;\n \t\t}\n \n-\t\tt = lookup_tag(sha1);\n+\t\tt = lookup_tag(oid->hash);\n \t\tif (!t || parse_tag(t))\n \t\t\treturn 0;\n \t\t*tag = t;\n@@ -96,24 +96,24 @@ static int replace_name(struct commit_name *e,\n }\n \n static void add_to_known_names(const char *path,\n-\t\t\t       const unsigned char *peeled,\n+\t\t\t       const struct object_id *peeled,\n \t\t\t       int prio,\n-\t\t\t       const unsigned char *sha1)\n+\t\t\t       const struct object_id *oid)\n {\n \tstruct commit_name *e = find_commit_name(peeled);\n \tstruct tag *tag = NULL;\n-\tif (replace_name(e, prio, sha1, &tag)) {\n+\tif (replace_name(e, prio, oid, &tag)) {\n \t\tif (!e) {\n \t\t\te = xmalloc(sizeof(struct commit_name));\n-\t\t\thashcpy(e->peeled, peeled);\n-\t\t\thashmap_entry_init(e, sha1hash(peeled));\n+\t\t\toidcpy(&e->peeled, peeled);\n+\t\t\thashmap_entry_init(e, sha1hash(peeled->hash));\n \t\t\thashmap_add(&names, e);\n \t\t\te->path = NULL;\n \t\t}\n \t\te->tag = tag;\n \t\te->prio = prio;\n \t\te->name_checked = 0;\n-\t\thashcpy(e->sha1, sha1);\n+\t\toidcpy(&e->oid, oid);\n \t\tfree(e->path);\n \t\te->path = xstrdup(path);\n \t}\n@@ -154,7 +154,7 @@ static int get_name(const char *path, const struct object_id *oid, int flag, voi\n \telse\n \t\tprio = 0;\n \n-\tadd_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash);\n+\tadd_to_known_names(all ? path + 5 : path + 10, &peeled, prio, oid);\n \treturn 0;\n }\n \n@@ -212,7 +212,7 @@ static unsigned long finish_depth_computation(\n static void display_name(struct commit_name *n)\n {\n \tif (n->prio == 2 && !n->tag) {\n-\t\tn->tag = lookup_tag(n->sha1);\n+\t\tn->tag = lookup_tag(n->oid.hash);\n \t\tif (!n->tag || parse_tag(n->tag))\n \t\t\tdie(_(\"annotated tag %s not available\"), n->path);\n \t}\n@@ -230,14 +230,14 @@ static void display_name(struct commit_name *n)\n \t\tprintf(\"%s\", n->path);\n }\n \n-static void show_suffix(int depth, const unsigned char *sha1)\n+static void show_suffix(int depth, const struct object_id *oid)\n {\n-\tprintf(\"-%d-g%s\", depth, find_unique_abbrev(sha1, abbrev));\n+\tprintf(\"-%d-g%s\", depth, find_unique_abbrev(oid->hash, abbrev));\n }\n \n static void describe(const char *arg, int last_one)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstruct commit *cmit, *gave_up_on = NULL;\n \tstruct commit_list *list;\n \tstruct commit_name *n;\n@@ -246,20 +246,20 @@ static void describe(const char *arg, int last_one)\n \tunsigned long seen_commits = 0;\n \tunsigned int unannotated_cnt = 0;\n \n-\tif (get_sha1(arg, sha1))\n+\tif (get_oid(arg, &oid))\n \t\tdie(_(\"Not a valid object name %s\"), arg);\n-\tcmit = lookup_commit_reference(sha1);\n+\tcmit = lookup_commit_reference(oid.hash);\n \tif (!cmit)\n \t\tdie(_(\"%s is not a valid '%s' object\"), arg, commit_type);\n \n-\tn = find_commit_name(cmit->object.oid.hash);\n+\tn = find_commit_name(&cmit->object.oid);\n \tif (n && (tags || all || n->prio == 2)) {\n \t\t/*\n \t\t * Exact match to an existing ref.\n \t\t */\n \t\tdisplay_name(n);\n \t\tif (longformat)\n-\t\t\tshow_suffix(0, n->tag ? n->tag->tagged->oid.hash : sha1);\n+\t\t\tshow_suffix(0, n->tag ? &n->tag->tagged->oid : &oid);\n \t\tif (dirty)\n \t\t\tprintf(\"%s\", dirty);\n \t\tprintf(\"\\n\");\n@@ -276,7 +276,7 @@ static void describe(const char *arg, int last_one)\n \t\tstruct commit *c;\n \t\tstruct commit_name *n = hashmap_iter_first(&names, &iter);\n \t\tfor (; n; n = hashmap_iter_next(&iter)) {\n-\t\t\tc = lookup_commit_reference_gently(n->peeled, 1);\n+\t\t\tc = lookup_commit_reference_gently(n->peeled.hash, 1);\n \t\t\tif (c)\n \t\t\t\tc->util = n;\n \t\t}\n@@ -380,7 +380,7 @@ static void describe(const char *arg, int last_one)\n \n \tdisplay_name(all_matches[0].name);\n \tif (abbrev)\n-\t\tshow_suffix(all_matches[0].depth, cmit->object.oid.hash);\n+\t\tshow_suffix(all_matches[0].depth, &cmit->object.oid);\n \tif (dirty)\n \t\tprintf(\"%s\", dirty);\n \tprintf(\"\\n\");\n-- \n2.11.0\n\n"},{"id":"308585","messageId":"20170101191847.564741-8-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 07/17] builtin/branch: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:37Z","receivedAt":"2017-01-01T19:19:48Z","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/branch.c | 26 +++++++++++++-------------\n 1 file changed, 13 insertions(+), 13 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 9d30f55b0..faf472ff8 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -32,7 +32,7 @@ static const char * const builtin_branch_usage[] = {\n };\n \n static const char *head;\n-static unsigned char head_sha1[20];\n+static struct object_id head_oid;\n \n static int branch_use_color = -1;\n static char branch_colors[][COLOR_MAXLEN] = {\n@@ -117,13 +117,13 @@ static int branch_merged(int kind, const char *name,\n \tif (kind == FILTER_REFS_BRANCHES) {\n \t\tstruct branch *branch = branch_get(name);\n \t\tconst char *upstream = branch_get_upstream(branch, NULL);\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \n \t\tif (upstream &&\n \t\t    (reference_name = reference_name_to_free =\n \t\t     resolve_refdup(upstream, RESOLVE_REF_READING,\n-\t\t\t\t    sha1, NULL)) != NULL)\n-\t\t\treference_rev = lookup_commit_reference(sha1);\n+\t\t\t\t    oid.hash, NULL)) != NULL)\n+\t\t\treference_rev = lookup_commit_reference(oid.hash);\n \t}\n \tif (!reference_rev)\n \t\treference_rev = head_rev;\n@@ -153,10 +153,10 @@ static int branch_merged(int kind, const char *name,\n }\n \n static int check_branch_commit(const char *branchname, const char *refname,\n-\t\t\t       const unsigned char *sha1, struct commit *head_rev,\n+\t\t\t       const struct object_id *oid, struct commit *head_rev,\n \t\t\t       int kinds, int force)\n {\n-\tstruct commit *rev = lookup_commit_reference(sha1);\n+\tstruct commit *rev = lookup_commit_reference(oid->hash);\n \tif (!rev) {\n \t\terror(_(\"Couldn't look up commit object for '%s'\"), refname);\n \t\treturn -1;\n@@ -183,7 +183,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\t\t   int quiet)\n {\n \tstruct commit *head_rev = NULL;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tchar *name = NULL;\n \tconst char *fmt;\n \tint i;\n@@ -207,7 +207,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t}\n \n \tif (!force) {\n-\t\thead_rev = lookup_commit_reference(head_sha1);\n+\t\thead_rev = lookup_commit_reference(head_oid.hash);\n \t\tif (!head_rev)\n \t\t\tdie(_(\"Couldn't look up commit object for HEAD\"));\n \t}\n@@ -235,7 +235,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\t\t\t\tRESOLVE_REF_READING\n \t\t\t\t\t| RESOLVE_REF_NO_RECURSE\n \t\t\t\t\t| RESOLVE_REF_ALLOW_BAD_NAME,\n-\t\t\t\t\tsha1, &flags);\n+\t\t\t\t\toid.hash, &flags);\n \t\tif (!target) {\n \t\t\terror(remote_branch\n \t\t\t      ? _(\"remote-tracking branch '%s' not found.\")\n@@ -245,13 +245,13 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\t}\n \n \t\tif (!(flags & (REF_ISSYMREF|REF_ISBROKEN)) &&\n-\t\t    check_branch_commit(bname.buf, name, sha1, head_rev, kinds,\n+\t\t    check_branch_commit(bname.buf, name, &oid, head_rev, kinds,\n \t\t\t\t\tforce)) {\n \t\t\tret = 1;\n \t\t\tgoto next;\n \t\t}\n \n-\t\tif (delete_ref(name, is_null_sha1(sha1) ? NULL : sha1,\n+\t\tif (delete_ref(name, is_null_oid(&oid) ? NULL : oid.hash,\n \t\t\t       REF_NODEREF)) {\n \t\t\terror(remote_branch\n \t\t\t      ? _(\"Error deleting remote-tracking branch '%s'\")\n@@ -267,7 +267,7 @@ static int delete_branches(int argc, const char **argv, int force, int kinds,\n \t\t\t       bname.buf,\n \t\t\t       (flags & REF_ISBROKEN) ? \"broken\"\n \t\t\t       : (flags & REF_ISSYMREF) ? target\n-\t\t\t       : find_unique_abbrev(sha1, DEFAULT_ABBREV));\n+\t\t\t       : find_unique_abbrev(oid.hash, DEFAULT_ABBREV));\n \t\t}\n \t\tdelete_branch_config(bname.buf);\n \n@@ -693,7 +693,7 @@ int cmd_branch(int argc, const char **argv, const char *prefix)\n \n \ttrack = git_branch_track;\n \n-\thead = resolve_refdup(\"HEAD\", 0, head_sha1, NULL);\n+\thead = resolve_refdup(\"HEAD\", 0, head_oid.hash, NULL);\n \tif (!head)\n \t\tdie(_(\"Failed to resolve HEAD as a valid ref.\"));\n \tif (!strcmp(head, \"HEAD\"))\n-- \n2.11.0\n\n"},{"id":"308586","messageId":"20170101191847.564741-10-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 09/17] builtin/merge: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:39Z","receivedAt":"2017-01-01T19:19:54Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Additionally convert several uses of the constant 40 into\nGIT_SHA1_HEXSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/merge.c | 136 ++++++++++++++++++++++++++++----------------------------\n 1 file changed, 68 insertions(+), 68 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex 0070bf255..30bb05ec4 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -240,7 +240,7 @@ static void drop_save(void)\n \tunlink(git_path_merge_mode());\n }\n \n-static int save_state(unsigned char *stash)\n+static int save_state(struct object_id *stash)\n {\n \tint len;\n \tstruct child_process cp = CHILD_PROCESS_INIT;\n@@ -261,7 +261,7 @@ static int save_state(unsigned char *stash)\n \telse if (!len)\t\t/* no changes */\n \t\treturn -1;\n \tstrbuf_setlen(&buffer, buffer.len-1);\n-\tif (get_sha1(buffer.buf, stash))\n+\tif (get_oid(buffer.buf, stash))\n \t\tdie(_(\"not a valid object: %s\"), buffer.buf);\n \treturn 0;\n }\n@@ -301,18 +301,18 @@ static void reset_hard(unsigned const char *sha1, int verbose)\n \t\tdie(_(\"read-tree failed\"));\n }\n \n-static void restore_state(const unsigned char *head,\n-\t\t\t  const unsigned char *stash)\n+static void restore_state(const struct object_id *head,\n+\t\t\t  const struct object_id *stash)\n {\n \tstruct strbuf sb = STRBUF_INIT;\n \tconst char *args[] = { \"stash\", \"apply\", NULL, NULL };\n \n-\tif (is_null_sha1(stash))\n+\tif (is_null_oid(stash))\n \t\treturn;\n \n-\treset_hard(head, 1);\n+\treset_hard(head->hash, 1);\n \n-\targs[2] = sha1_to_hex(stash);\n+\targs[2] = oid_to_hex(stash);\n \n \t/*\n \t * It is OK to ignore error here, for example when there was\n@@ -372,10 +372,10 @@ static void squash_message(struct commit *commit, struct commit_list *remotehead\n \n static void finish(struct commit *head_commit,\n \t\t   struct commit_list *remoteheads,\n-\t\t   const unsigned char *new_head, const char *msg)\n+\t\t   const struct object_id *new_head, const char *msg)\n {\n \tstruct strbuf reflog_message = STRBUF_INIT;\n-\tconst unsigned char *head = head_commit->object.oid.hash;\n+\tconst struct object_id *head = &head_commit->object.oid;\n \n \tif (!msg)\n \t\tstrbuf_addstr(&reflog_message, getenv(\"GIT_REFLOG_ACTION\"));\n@@ -393,7 +393,7 @@ static void finish(struct commit *head_commit,\n \t\telse {\n \t\t\tconst char *argv_gc_auto[] = { \"gc\", \"--auto\", NULL };\n \t\t\tupdate_ref(reflog_message.buf, \"HEAD\",\n-\t\t\t\tnew_head, head, 0,\n+\t\t\t\tnew_head->hash, head->hash, 0,\n \t\t\t\tUPDATE_REFS_DIE_ON_ERR);\n \t\t\t/*\n \t\t\t * We ignore errors in 'gc --auto', since the\n@@ -412,7 +412,7 @@ static void finish(struct commit *head_commit,\n \t\t\tDIFF_FORMAT_SUMMARY | DIFF_FORMAT_DIFFSTAT;\n \t\topts.detect_rename = DIFF_DETECT_RENAME;\n \t\tdiff_setup_done(&opts);\n-\t\tdiff_tree_sha1(head, new_head, \"\", &opts);\n+\t\tdiff_tree_sha1(head->hash, new_head->hash, \"\", &opts);\n \t\tdiffcore_std(&opts);\n \t\tdiff_flush(&opts);\n \t}\n@@ -427,7 +427,7 @@ static void finish(struct commit *head_commit,\n static void merge_name(const char *remote, struct strbuf *msg)\n {\n \tstruct commit *remote_head;\n-\tunsigned char branch_head[20];\n+\tstruct object_id branch_head;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct strbuf bname = STRBUF_INIT;\n \tconst char *ptr;\n@@ -437,25 +437,25 @@ static void merge_name(const char *remote, struct strbuf *msg)\n \tstrbuf_branchname(&bname, remote);\n \tremote = bname.buf;\n \n-\tmemset(branch_head, 0, sizeof(branch_head));\n+\tmemset(&branch_head, 0, sizeof(branch_head));\n \tremote_head = get_merge_parent(remote);\n \tif (!remote_head)\n \t\tdie(_(\"'%s' does not point to a commit\"), remote);\n \n-\tif (dwim_ref(remote, strlen(remote), branch_head, &found_ref) > 0) {\n+\tif (dwim_ref(remote, strlen(remote), branch_head.hash, &found_ref) > 0) {\n \t\tif (starts_with(found_ref, \"refs/heads/\")) {\n \t\t\tstrbuf_addf(msg, \"%s\\t\\tbranch '%s' of .\\n\",\n-\t\t\t\t    sha1_to_hex(branch_head), remote);\n+\t\t\t\t    oid_to_hex(&branch_head), remote);\n \t\t\tgoto cleanup;\n \t\t}\n \t\tif (starts_with(found_ref, \"refs/tags/\")) {\n \t\t\tstrbuf_addf(msg, \"%s\\t\\ttag '%s' of .\\n\",\n-\t\t\t\t    sha1_to_hex(branch_head), remote);\n+\t\t\t\t    oid_to_hex(&branch_head), remote);\n \t\t\tgoto cleanup;\n \t\t}\n \t\tif (starts_with(found_ref, \"refs/remotes/\")) {\n \t\t\tstrbuf_addf(msg, \"%s\\t\\tremote-tracking branch '%s' of .\\n\",\n-\t\t\t\t    sha1_to_hex(branch_head), remote);\n+\t\t\t\t    oid_to_hex(&branch_head), remote);\n \t\t\tgoto cleanup;\n \t\t}\n \t}\n@@ -586,8 +586,8 @@ static int git_merge_config(const char *k, const char *v, void *cb)\n \treturn git_diff_ui_config(k, v, cb);\n }\n \n-static int read_tree_trivial(unsigned char *common, unsigned char *head,\n-\t\t\t     unsigned char *one)\n+static int read_tree_trivial(struct object_id *common, struct object_id *head,\n+\t\t\t     struct object_id *one)\n {\n \tint i, nr_trees = 0;\n \tstruct tree *trees[MAX_UNPACK_TREES];\n@@ -602,13 +602,13 @@ static int read_tree_trivial(unsigned char *common, unsigned char *head,\n \topts.verbose_update = 1;\n \topts.trivial_merges_only = 1;\n \topts.merge = 1;\n-\ttrees[nr_trees] = parse_tree_indirect(common);\n+\ttrees[nr_trees] = parse_tree_indirect(common->hash);\n \tif (!trees[nr_trees++])\n \t\treturn -1;\n-\ttrees[nr_trees] = parse_tree_indirect(head);\n+\ttrees[nr_trees] = parse_tree_indirect(head->hash);\n \tif (!trees[nr_trees++])\n \t\treturn -1;\n-\ttrees[nr_trees] = parse_tree_indirect(one);\n+\ttrees[nr_trees] = parse_tree_indirect(one->hash);\n \tif (!trees[nr_trees++])\n \t\treturn -1;\n \topts.fn = threeway_merge;\n@@ -622,9 +622,9 @@ static int read_tree_trivial(unsigned char *common, unsigned char *head,\n \treturn 0;\n }\n \n-static void write_tree_trivial(unsigned char *sha1)\n+static void write_tree_trivial(struct object_id *oid)\n {\n-\tif (write_cache_as_tree(sha1, 0, NULL))\n+\tif (write_cache_as_tree(oid->hash, 0, NULL))\n \t\tdie(_(\"git write-tree failed to write a tree\"));\n }\n \n@@ -777,7 +777,7 @@ static void prepare_to_commit(struct commit_list *remoteheads)\n \n static int merge_trivial(struct commit *head, struct commit_list *remoteheads)\n {\n-\tunsigned char result_tree[20], result_commit[20];\n+\tstruct object_id result_tree, result_commit;\n \tstruct commit_list *parents, **pptr = &parents;\n \tstatic struct lock_file lock;\n \n@@ -788,15 +788,15 @@ static int merge_trivial(struct commit *head, struct commit_list *remoteheads)\n \t\treturn error(_(\"Unable to write index.\"));\n \trollback_lock_file(&lock);\n \n-\twrite_tree_trivial(result_tree);\n+\twrite_tree_trivial(&result_tree);\n \tprintf(_(\"Wonderful.\\n\"));\n \tpptr = commit_list_append(head, pptr);\n \tpptr = commit_list_append(remoteheads->item, pptr);\n \tprepare_to_commit(remoteheads);\n-\tif (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,\n-\t\t\tresult_commit, NULL, sign_commit))\n+\tif (commit_tree(merge_msg.buf, merge_msg.len, result_tree.hash, parents,\n+\t\t\tresult_commit.hash, NULL, sign_commit))\n \t\tdie(_(\"failed to write commit object\"));\n-\tfinish(head, remoteheads, result_commit, \"In-index merge\");\n+\tfinish(head, remoteheads, &result_commit, \"In-index merge\");\n \tdrop_save();\n \treturn 0;\n }\n@@ -805,12 +805,12 @@ static int finish_automerge(struct commit *head,\n \t\t\t    int head_subsumed,\n \t\t\t    struct commit_list *common,\n \t\t\t    struct commit_list *remoteheads,\n-\t\t\t    unsigned char *result_tree,\n+\t\t\t    struct object_id *result_tree,\n \t\t\t    const char *wt_strategy)\n {\n \tstruct commit_list *parents = NULL;\n \tstruct strbuf buf = STRBUF_INIT;\n-\tunsigned char result_commit[20];\n+\tstruct object_id result_commit;\n \n \tfree_commit_list(common);\n \tparents = remoteheads;\n@@ -818,11 +818,11 @@ static int finish_automerge(struct commit *head,\n \t\tcommit_list_insert(head, &parents);\n \tstrbuf_addch(&merge_msg, '\\n');\n \tprepare_to_commit(remoteheads);\n-\tif (commit_tree(merge_msg.buf, merge_msg.len, result_tree, parents,\n-\t\t\tresult_commit, NULL, sign_commit))\n+\tif (commit_tree(merge_msg.buf, merge_msg.len, result_tree->hash, parents,\n+\t\t\tresult_commit.hash, NULL, sign_commit))\n \t\tdie(_(\"failed to write commit object\"));\n \tstrbuf_addf(&buf, \"Merge made by the '%s' strategy.\", wt_strategy);\n-\tfinish(head, remoteheads, result_commit, buf.buf);\n+\tfinish(head, remoteheads, &result_commit, buf.buf);\n \tstrbuf_release(&buf);\n \tdrop_save();\n \treturn 0;\n@@ -850,18 +850,18 @@ static int suggest_conflicts(void)\n }\n \n static struct commit *is_old_style_invocation(int argc, const char **argv,\n-\t\t\t\t\t      const unsigned char *head)\n+\t\t\t\t\t      const struct object_id *head)\n {\n \tstruct commit *second_token = NULL;\n \tif (argc > 2) {\n-\t\tunsigned char second_sha1[20];\n+\t\tstruct object_id second_oid;\n \n-\t\tif (get_sha1(argv[1], second_sha1))\n+\t\tif (get_oid(argv[1], &second_oid))\n \t\t\treturn NULL;\n-\t\tsecond_token = lookup_commit_reference_gently(second_sha1, 0);\n+\t\tsecond_token = lookup_commit_reference_gently(second_oid.hash, 0);\n \t\tif (!second_token)\n \t\t\tdie(_(\"'%s' is not a commit\"), argv[1]);\n-\t\tif (hashcmp(second_token->object.oid.hash, head))\n+\t\tif (oidcmp(&second_token->object.oid, head))\n \t\t\treturn NULL;\n \t}\n \treturn second_token;\n@@ -1034,7 +1034,7 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge\n \t\tdie_errno(_(\"could not close '%s'\"), filename);\n \n \tfor (pos = 0; pos < merge_names->len; pos = npos) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tchar *ptr;\n \t\tstruct commit *commit;\n \n@@ -1044,16 +1044,16 @@ static void handle_fetch_head(struct commit_list **remotes, struct strbuf *merge\n \t\telse\n \t\t\tnpos = merge_names->len;\n \n-\t\tif (npos - pos < 40 + 2 ||\n-\t\t    get_sha1_hex(merge_names->buf + pos, sha1))\n+\t\tif (npos - pos < GIT_SHA1_HEXSZ + 2 ||\n+\t\t    get_oid_hex(merge_names->buf + pos, &oid))\n \t\t\tcommit = NULL; /* bad */\n-\t\telse if (memcmp(merge_names->buf + pos + 40, \"\\t\\t\", 2))\n+\t\telse if (memcmp(merge_names->buf + pos + GIT_SHA1_HEXSZ, \"\\t\\t\", 2))\n \t\t\tcontinue; /* not-for-merge */\n \t\telse {\n-\t\t\tchar saved = merge_names->buf[pos + 40];\n-\t\t\tmerge_names->buf[pos + 40] = '\\0';\n+\t\t\tchar saved = merge_names->buf[pos + GIT_SHA1_HEXSZ];\n+\t\t\tmerge_names->buf[pos + GIT_SHA1_HEXSZ] = '\\0';\n \t\t\tcommit = get_merge_parent(merge_names->buf + pos);\n-\t\t\tmerge_names->buf[pos + 40] = saved;\n+\t\t\tmerge_names->buf[pos + GIT_SHA1_HEXSZ] = saved;\n \t\t}\n \t\tif (!commit) {\n \t\t\tif (ptr)\n@@ -1113,9 +1113,9 @@ static struct commit_list *collect_parents(struct commit *head_commit,\n \n int cmd_merge(int argc, const char **argv, const char *prefix)\n {\n-\tunsigned char result_tree[20];\n-\tunsigned char stash[20];\n-\tunsigned char head_sha1[20];\n+\tstruct object_id result_tree;\n+\tstruct object_id stash;\n+\tstruct object_id head_oid;\n \tstruct commit *head_commit;\n \tstruct strbuf buf = STRBUF_INIT;\n \tconst char *head_arg;\n@@ -1133,13 +1133,13 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t * Check if we are _not_ on a detached HEAD, i.e. if there is a\n \t * current branch.\n \t */\n-\tbranch = branch_to_free = resolve_refdup(\"HEAD\", 0, head_sha1, NULL);\n+\tbranch = branch_to_free = resolve_refdup(\"HEAD\", 0, head_oid.hash, NULL);\n \tif (branch && starts_with(branch, \"refs/heads/\"))\n \t\tbranch += 11;\n-\tif (!branch || is_null_sha1(head_sha1))\n+\tif (!branch || is_null_oid(&head_oid))\n \t\thead_commit = NULL;\n \telse\n-\t\thead_commit = lookup_commit_or_die(head_sha1, \"HEAD\");\n+\t\thead_commit = lookup_commit_or_die(head_oid.hash, \"HEAD\");\n \n \tinit_diff_ui_defaults();\n \tgit_config(git_merge_config, NULL);\n@@ -1217,7 +1217,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t * to forbid \"git merge\" into a branch yet to be born.\n \t\t * We do the same for \"git pull\".\n \t\t */\n-\t\tunsigned char *remote_head_sha1;\n+\t\tstruct object_id *remote_head_oid;\n \t\tif (squash)\n \t\t\tdie(_(\"Squash commit into empty head not supported yet\"));\n \t\tif (fast_forward == FF_NO)\n@@ -1229,9 +1229,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\tdie(_(\"%s - not something we can merge\"), argv[0]);\n \t\tif (remoteheads->next)\n \t\t\tdie(_(\"Can merge only exactly one commit into empty head\"));\n-\t\tremote_head_sha1 = remoteheads->item->object.oid.hash;\n-\t\tread_empty(remote_head_sha1, 0);\n-\t\tupdate_ref(\"initial pull\", \"HEAD\", remote_head_sha1,\n+\t\tremote_head_oid = &remoteheads->item->object.oid;\n+\t\tread_empty(remote_head_oid->hash, 0);\n+\t\tupdate_ref(\"initial pull\", \"HEAD\", remote_head_oid->hash,\n \t\t\t   NULL, 0, UPDATE_REFS_DIE_ON_ERR);\n \t\tgoto done;\n \t}\n@@ -1245,7 +1245,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t * additional safety measure to check for it.\n \t */\n \tif (!have_message &&\n-\t    is_old_style_invocation(argc, argv, head_commit->object.oid.hash)) {\n+\t    is_old_style_invocation(argc, argv, &head_commit->object.oid)) {\n \t\twarning(\"old-style 'git merge <msg> HEAD <commit>' is deprecated.\");\n \t\tstrbuf_addstr(&merge_msg, argv[0]);\n \t\thead_arg = argv[1];\n@@ -1397,7 +1397,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\tgoto done;\n \t\t}\n \n-\t\tfinish(head_commit, remoteheads, commit->object.oid.hash, msg.buf);\n+\t\tfinish(head_commit, remoteheads, &commit->object.oid, msg.buf);\n \t\tdrop_save();\n \t\tgoto done;\n \t} else if (!remoteheads->next && common->next)\n@@ -1416,9 +1416,9 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t\t/* See if it is really trivial. */\n \t\t\tgit_committer_info(IDENT_STRICT);\n \t\t\tprintf(_(\"Trying really trivial in-index merge...\\n\"));\n-\t\t\tif (!read_tree_trivial(common->item->object.oid.hash,\n-\t\t\t\t\t       head_commit->object.oid.hash,\n-\t\t\t\t\t       remoteheads->item->object.oid.hash)) {\n+\t\t\tif (!read_tree_trivial(&common->item->object.oid,\n+\t\t\t\t\t       &head_commit->object.oid,\n+\t\t\t\t\t       &remoteheads->item->object.oid)) {\n \t\t\t\tret = merge_trivial(head_commit, remoteheads);\n \t\t\t\tgoto done;\n \t\t\t}\n@@ -1470,14 +1470,14 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t    /*\n \t     * Stash away the local changes so that we can try more than one.\n \t     */\n-\t    save_state(stash))\n-\t\thashclr(stash);\n+\t    save_state(&stash))\n+\t\toidclr(&stash);\n \n \tfor (i = 0; i < use_strategies_nr; i++) {\n \t\tint ret;\n \t\tif (i) {\n \t\t\tprintf(_(\"Rewinding the tree to pristine...\\n\"));\n-\t\t\trestore_state(head_commit->object.oid.hash, stash);\n+\t\t\trestore_state(&head_commit->object.oid, &stash);\n \t\t}\n \t\tif (use_strategies_nr != 1)\n \t\t\tprintf(_(\"Trying merge strategy %s...\\n\"),\n@@ -1522,7 +1522,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t}\n \n \t\t/* Automerge succeeded. */\n-\t\twrite_tree_trivial(result_tree);\n+\t\twrite_tree_trivial(&result_tree);\n \t\tautomerge_was_ok = 1;\n \t\tbreak;\n \t}\n@@ -1534,7 +1534,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \tif (automerge_was_ok) {\n \t\tret = finish_automerge(head_commit, head_subsumed,\n \t\t\t\t       common, remoteheads,\n-\t\t\t\t       result_tree, wt_strategy);\n+\t\t\t\t       &result_tree, wt_strategy);\n \t\tgoto done;\n \t}\n \n@@ -1543,7 +1543,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t * it up.\n \t */\n \tif (!best_strategy) {\n-\t\trestore_state(head_commit->object.oid.hash, stash);\n+\t\trestore_state(&head_commit->object.oid, &stash);\n \t\tif (use_strategies_nr > 1)\n \t\t\tfprintf(stderr,\n \t\t\t\t_(\"No merge strategy handled the merge.\\n\"));\n@@ -1556,7 +1556,7 @@ int cmd_merge(int argc, const char **argv, const char *prefix)\n \t\t; /* We already have its result in the working tree. */\n \telse {\n \t\tprintf(_(\"Rewinding the tree to pristine...\\n\"));\n-\t\trestore_state(head_commit->object.oid.hash, stash);\n+\t\trestore_state(&head_commit->object.oid, &stash);\n \t\tprintf(_(\"Using the %s to prepare resolving by hand.\\n\"),\n \t\t\tbest_strategy);\n \t\ttry_merge_strategy(best_strategy, common, remoteheads,\n-- \n2.11.0\n\n"},{"id":"308587","messageId":"20170101191847.564741-12-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 11/17] builtin/replace: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:41Z","receivedAt":"2017-01-01T19:19:58Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert various uses of unsigned char [20] to struct object_id.  Rename\nreplace_object_sha1 to rename_object_oid.  Finally, specify a constant\nin terms of GIT_SHA1_HEXSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/replace.c | 112 +++++++++++++++++++++++++++---------------------------\n 1 file changed, 56 insertions(+), 56 deletions(-)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex b58c714cb..f7716a547 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -88,78 +88,78 @@ static int list_replace_refs(const char *pattern, const char *format)\n }\n \n typedef int (*each_replace_name_fn)(const char *name, const char *ref,\n-\t\t\t\t    const unsigned char *sha1);\n+\t\t\t\t    const struct object_id *oid);\n \n static int for_each_replace_name(const char **argv, each_replace_name_fn fn)\n {\n \tconst char **p, *full_hex;\n \tchar ref[PATH_MAX];\n \tint had_error = 0;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \n \tfor (p = argv; *p; p++) {\n-\t\tif (get_sha1(*p, sha1)) {\n+\t\tif (get_oid(*p, &oid)) {\n \t\t\terror(\"Failed to resolve '%s' as a valid ref.\", *p);\n \t\t\thad_error = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tfull_hex = sha1_to_hex(sha1);\n+\t\tfull_hex = oid_to_hex(&oid);\n \t\tsnprintf(ref, sizeof(ref), \"%s%s\", git_replace_ref_base, full_hex);\n \t\t/* read_ref() may reuse the buffer */\n \t\tfull_hex = ref + strlen(git_replace_ref_base);\n-\t\tif (read_ref(ref, sha1)) {\n+\t\tif (read_ref(ref, oid.hash)) {\n \t\t\terror(\"replace ref '%s' not found.\", full_hex);\n \t\t\thad_error = 1;\n \t\t\tcontinue;\n \t\t}\n-\t\tif (fn(full_hex, ref, sha1))\n+\t\tif (fn(full_hex, ref, &oid))\n \t\t\thad_error = 1;\n \t}\n \treturn had_error;\n }\n \n static int delete_replace_ref(const char *name, const char *ref,\n-\t\t\t      const unsigned char *sha1)\n+\t\t\t      const struct object_id *oid)\n {\n-\tif (delete_ref(ref, sha1, 0))\n+\tif (delete_ref(ref, oid->hash, 0))\n \t\treturn 1;\n \tprintf(\"Deleted replace ref '%s'\\n\", name);\n \treturn 0;\n }\n \n-static void check_ref_valid(unsigned char object[20],\n-\t\t\t    unsigned char prev[20],\n+static void check_ref_valid(struct object_id *object,\n+\t\t\t    struct object_id *prev,\n \t\t\t    char *ref,\n \t\t\t    int ref_size,\n \t\t\t    int force)\n {\n \tif (snprintf(ref, ref_size,\n \t\t     \"%s%s\", git_replace_ref_base,\n-\t\t     sha1_to_hex(object)) > ref_size - 1)\n+\t\t     oid_to_hex(object)) > ref_size - 1)\n \t\tdie(\"replace ref name too long: %.*s...\", 50, ref);\n \tif (check_refname_format(ref, 0))\n \t\tdie(\"'%s' is not a valid ref name.\", ref);\n \n-\tif (read_ref(ref, prev))\n-\t\thashclr(prev);\n+\tif (read_ref(ref, prev->hash))\n+\t\toidclr(prev);\n \telse if (!force)\n \t\tdie(\"replace ref '%s' already exists\", ref);\n }\n \n-static int replace_object_sha1(const char *object_ref,\n-\t\t\t       unsigned char object[20],\n+static int replace_object_oid(const char *object_ref,\n+\t\t\t       struct object_id *object,\n \t\t\t       const char *replace_ref,\n-\t\t\t       unsigned char repl[20],\n+\t\t\t       struct object_id *repl,\n \t\t\t       int force)\n {\n-\tunsigned char prev[20];\n+\tstruct object_id prev;\n \tenum object_type obj_type, repl_type;\n \tchar ref[PATH_MAX];\n \tstruct ref_transaction *transaction;\n \tstruct strbuf err = STRBUF_INIT;\n \n-\tobj_type = sha1_object_info(object, NULL);\n-\trepl_type = sha1_object_info(repl, NULL);\n+\tobj_type = sha1_object_info(object->hash, NULL);\n+\trepl_type = sha1_object_info(repl->hash, NULL);\n \tif (!force && obj_type != repl_type)\n \t\tdie(\"Objects must be of the same type.\\n\"\n \t\t    \"'%s' points to a replaced object of type '%s'\\n\"\n@@ -167,11 +167,11 @@ static int replace_object_sha1(const char *object_ref,\n \t\t    object_ref, typename(obj_type),\n \t\t    replace_ref, typename(repl_type));\n \n-\tcheck_ref_valid(object, prev, ref, sizeof(ref), force);\n+\tcheck_ref_valid(object, &prev, ref, sizeof(ref), force);\n \n \ttransaction = ref_transaction_begin(&err);\n \tif (!transaction ||\n-\t    ref_transaction_update(transaction, ref, repl, prev,\n+\t    ref_transaction_update(transaction, ref, repl->hash, prev.hash,\n \t\t\t\t   0, NULL, &err) ||\n \t    ref_transaction_commit(transaction, &err))\n \t\tdie(\"%s\", err.buf);\n@@ -182,14 +182,14 @@ static int replace_object_sha1(const char *object_ref,\n \n static int replace_object(const char *object_ref, const char *replace_ref, int force)\n {\n-\tunsigned char object[20], repl[20];\n+\tstruct object_id object, repl;\n \n-\tif (get_sha1(object_ref, object))\n+\tif (get_oid(object_ref, &object))\n \t\tdie(\"Failed to resolve '%s' as a valid ref.\", object_ref);\n-\tif (get_sha1(replace_ref, repl))\n+\tif (get_oid(replace_ref, &repl))\n \t\tdie(\"Failed to resolve '%s' as a valid ref.\", replace_ref);\n \n-\treturn replace_object_sha1(object_ref, object, replace_ref, repl, force);\n+\treturn replace_object_oid(object_ref, &object, replace_ref, &repl, force);\n }\n \n /*\n@@ -197,7 +197,7 @@ static int replace_object(const char *object_ref, const char *replace_ref, int f\n  * If \"raw\" is true, then the object's raw contents are printed according to\n  * \"type\". Otherwise, we pretty-print the contents for human editing.\n  */\n-static void export_object(const unsigned char *sha1, enum object_type type,\n+static void export_object(const struct object_id *oid, enum object_type type,\n \t\t\t  int raw, const char *filename)\n {\n \tstruct child_process cmd = CHILD_PROCESS_INIT;\n@@ -213,7 +213,7 @@ static void export_object(const unsigned char *sha1, enum object_type type,\n \t\targv_array_push(&cmd.args, typename(type));\n \telse\n \t\targv_array_push(&cmd.args, \"-p\");\n-\targv_array_push(&cmd.args, sha1_to_hex(sha1));\n+\targv_array_push(&cmd.args, oid_to_hex(oid));\n \tcmd.git_cmd = 1;\n \tcmd.out = fd;\n \n@@ -226,7 +226,7 @@ static void export_object(const unsigned char *sha1, enum object_type type,\n  * interpreting it as \"type\", and writing the result to the object database.\n  * The sha1 of the written object is returned via sha1.\n  */\n-static void import_object(unsigned char *sha1, enum object_type type,\n+static void import_object(struct object_id *oid, enum object_type type,\n \t\t\t  int raw, const char *filename)\n {\n \tint fd;\n@@ -254,7 +254,7 @@ static void import_object(unsigned char *sha1, enum object_type type,\n \n \t\tif (finish_command(&cmd))\n \t\t\tdie(\"mktree reported failure\");\n-\t\tif (get_sha1_hex(result.buf, sha1) < 0)\n+\t\tif (get_oid_hex(result.buf, oid) < 0)\n \t\t\tdie(\"mktree did not return an object name\");\n \n \t\tstrbuf_release(&result);\n@@ -264,7 +264,7 @@ static void import_object(unsigned char *sha1, enum object_type type,\n \n \t\tif (fstat(fd, &st) < 0)\n \t\t\tdie_errno(\"unable to fstat %s\", filename);\n-\t\tif (index_fd(sha1, fd, &st, type, NULL, flags) < 0)\n+\t\tif (index_fd(oid->hash, fd, &st, type, NULL, flags) < 0)\n \t\t\tdie(\"unable to write object to database\");\n \t\t/* index_fd close()s fd for us */\n \t}\n@@ -279,29 +279,29 @@ static int edit_and_replace(const char *object_ref, int force, int raw)\n {\n \tchar *tmpfile = git_pathdup(\"REPLACE_EDITOBJ\");\n \tenum object_type type;\n-\tunsigned char old[20], new[20], prev[20];\n+\tstruct object_id old, new, prev;\n \tchar ref[PATH_MAX];\n \n-\tif (get_sha1(object_ref, old) < 0)\n+\tif (get_oid(object_ref, &old) < 0)\n \t\tdie(\"Not a valid object name: '%s'\", object_ref);\n \n-\ttype = sha1_object_info(old, NULL);\n+\ttype = sha1_object_info(old.hash, NULL);\n \tif (type < 0)\n-\t\tdie(\"unable to get object type for %s\", sha1_to_hex(old));\n+\t\tdie(\"unable to get object type for %s\", oid_to_hex(&old));\n \n-\tcheck_ref_valid(old, prev, ref, sizeof(ref), force);\n+\tcheck_ref_valid(&old, &prev, ref, sizeof(ref), force);\n \n-\texport_object(old, type, raw, tmpfile);\n+\texport_object(&old, type, raw, tmpfile);\n \tif (launch_editor(tmpfile, NULL, NULL) < 0)\n \t\tdie(\"editing object file failed\");\n-\timport_object(new, type, raw, tmpfile);\n+\timport_object(&new, type, raw, tmpfile);\n \n \tfree(tmpfile);\n \n-\tif (!hashcmp(old, new))\n-\t\treturn error(\"new object is the same as the old one: '%s'\", sha1_to_hex(old));\n+\tif (!oidcmp(&old, &new))\n+\t\treturn error(\"new object is the same as the old one: '%s'\", oid_to_hex(&old));\n \n-\treturn replace_object_sha1(object_ref, old, \"replacement\", new, force);\n+\treturn replace_object_oid(object_ref, &old, \"replacement\", &new, force);\n }\n \n static void replace_parents(struct strbuf *buf, int argc, const char **argv)\n@@ -312,7 +312,7 @@ static void replace_parents(struct strbuf *buf, int argc, const char **argv)\n \n \t/* find existing parents */\n \tparent_start = buf->buf;\n-\tparent_start += 46; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n+\tparent_start += GIT_SHA1_HEXSZ + 6; /* \"tree \" + \"hex sha1\" + \"\\n\" */\n \tparent_end = parent_start;\n \n \twhile (starts_with(parent_end, \"parent \"))\n@@ -320,11 +320,11 @@ static void replace_parents(struct strbuf *buf, int argc, const char **argv)\n \n \t/* prepare new parents */\n \tfor (i = 0; i < argc; i++) {\n-\t\tunsigned char sha1[20];\n-\t\tif (get_sha1(argv[i], sha1) < 0)\n+\t\tstruct object_id oid;\n+\t\tif (get_oid(argv[i], &oid) < 0)\n \t\t\tdie(_(\"Not a valid object name: '%s'\"), argv[i]);\n-\t\tlookup_commit_or_die(sha1, argv[i]);\n-\t\tstrbuf_addf(&new_parents, \"parent %s\\n\", sha1_to_hex(sha1));\n+\t\tlookup_commit_or_die(oid.hash, argv[i]);\n+\t\tstrbuf_addf(&new_parents, \"parent %s\\n\", oid_to_hex(&oid));\n \t}\n \n \t/* replace existing parents with new ones */\n@@ -345,12 +345,12 @@ static void check_one_mergetag(struct commit *commit,\n {\n \tstruct check_mergetag_data *mergetag_data = (struct check_mergetag_data *)data;\n \tconst char *ref = mergetag_data->argv[0];\n-\tunsigned char tag_sha1[20];\n+\tstruct object_id tag_oid;\n \tstruct tag *tag;\n \tint i;\n \n-\thash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_sha1);\n-\ttag = lookup_tag(tag_sha1);\n+\thash_sha1_file(extra->value, extra->len, typename(OBJ_TAG), tag_oid.hash);\n+\ttag = lookup_tag(tag_oid.hash);\n \tif (!tag)\n \t\tdie(_(\"bad mergetag in commit '%s'\"), ref);\n \tif (parse_tag_buffer(tag, extra->value, extra->len))\n@@ -366,7 +366,7 @@ static void check_one_mergetag(struct commit *commit,\n \t}\n \n \tdie(_(\"original commit '%s' contains mergetag '%s' that is discarded; \"\n-\t      \"use --edit instead of --graft\"), ref, sha1_to_hex(tag_sha1));\n+\t      \"use --edit instead of --graft\"), ref, oid_to_hex(&tag_oid));\n }\n \n static void check_mergetags(struct commit *commit, int argc, const char **argv)\n@@ -380,16 +380,16 @@ static void check_mergetags(struct commit *commit, int argc, const char **argv)\n \n static int create_graft(int argc, const char **argv, int force)\n {\n-\tunsigned char old[20], new[20];\n+\tstruct object_id old, new;\n \tconst char *old_ref = argv[0];\n \tstruct commit *commit;\n \tstruct strbuf buf = STRBUF_INIT;\n \tconst char *buffer;\n \tunsigned long size;\n \n-\tif (get_sha1(old_ref, old) < 0)\n+\tif (get_oid(old_ref, &old) < 0)\n \t\tdie(_(\"Not a valid object name: '%s'\"), old_ref);\n-\tcommit = lookup_commit_or_die(old, old_ref);\n+\tcommit = lookup_commit_or_die(old.hash, old_ref);\n \n \tbuffer = get_commit_buffer(commit, &size);\n \tstrbuf_add(&buf, buffer, size);\n@@ -404,15 +404,15 @@ static int create_graft(int argc, const char **argv, int force)\n \n \tcheck_mergetags(commit, argc, argv);\n \n-\tif (write_sha1_file(buf.buf, buf.len, commit_type, new))\n+\tif (write_sha1_file(buf.buf, buf.len, commit_type, new.hash))\n \t\tdie(_(\"could not write replacement commit for: '%s'\"), old_ref);\n \n \tstrbuf_release(&buf);\n \n-\tif (!hashcmp(old, new))\n-\t\treturn error(\"new commit is the same as the old one: '%s'\", sha1_to_hex(old));\n+\tif (!oidcmp(&old, &new))\n+\t\treturn error(\"new commit is the same as the old one: '%s'\", oid_to_hex(&old));\n \n-\treturn replace_object_sha1(old_ref, old, \"replacement\", new, force);\n+\treturn replace_object_oid(old_ref, &old, \"replacement\", &new, force);\n }\n \n int cmd_replace(int argc, const char **argv, const char *prefix)\n-- \n2.11.0\n\n"},{"id":"308588","messageId":"20170101191847.564741-17-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 16/17] builtin/merge-base: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:46Z","receivedAt":"2017-01-01T19:20:02Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert the remaining uses of unsigned char [20] to struct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/merge-base.c | 28 ++++++++++++++--------------\n 1 file changed, 14 insertions(+), 14 deletions(-)\n\ndiff --git a/builtin/merge-base.c b/builtin/merge-base.c\nindex db95bc29c..cfe2a796f 100644\n--- a/builtin/merge-base.c\n+++ b/builtin/merge-base.c\n@@ -36,12 +36,12 @@ static const char * const merge_base_usage[] = {\n \n static struct commit *get_commit_reference(const char *arg)\n {\n-\tunsigned char revkey[20];\n+\tstruct object_id revkey;\n \tstruct commit *r;\n \n-\tif (get_sha1(arg, revkey))\n+\tif (get_oid(arg, &revkey))\n \t\tdie(\"Not a valid object name %s\", arg);\n-\tr = lookup_commit_reference(revkey);\n+\tr = lookup_commit_reference(revkey.hash);\n \tif (!r)\n \t\tdie(\"Not a valid commit name %s\", arg);\n \n@@ -113,14 +113,14 @@ struct rev_collect {\n \tunsigned int initial : 1;\n };\n \n-static void add_one_commit(unsigned char *sha1, struct rev_collect *revs)\n+static void add_one_commit(struct object_id *oid, struct rev_collect *revs)\n {\n \tstruct commit *commit;\n \n-\tif (is_null_sha1(sha1))\n+\tif (is_null_oid(oid))\n \t\treturn;\n \n-\tcommit = lookup_commit(sha1);\n+\tcommit = lookup_commit(oid->hash);\n \tif (!commit ||\n \t    (commit->object.flags & TMP_MARK) ||\n \t    parse_commit(commit))\n@@ -139,15 +139,15 @@ static int collect_one_reflog_ent(struct object_id *ooid, struct object_id *noid\n \n \tif (revs->initial) {\n \t\trevs->initial = 0;\n-\t\tadd_one_commit(ooid->hash, revs);\n+\t\tadd_one_commit(ooid, revs);\n \t}\n-\tadd_one_commit(noid->hash, revs);\n+\tadd_one_commit(noid, revs);\n \treturn 0;\n }\n \n static int handle_fork_point(int argc, const char **argv)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tchar *refname;\n \tconst char *commitname;\n \tstruct rev_collect revs;\n@@ -155,7 +155,7 @@ static int handle_fork_point(int argc, const char **argv)\n \tstruct commit_list *bases;\n \tint i, ret = 0;\n \n-\tswitch (dwim_ref(argv[0], strlen(argv[0]), sha1, &refname)) {\n+\tswitch (dwim_ref(argv[0], strlen(argv[0]), oid.hash, &refname)) {\n \tcase 0:\n \t\tdie(\"No such ref: '%s'\", argv[0]);\n \tcase 1:\n@@ -165,16 +165,16 @@ static int handle_fork_point(int argc, const char **argv)\n \t}\n \n \tcommitname = (argc == 2) ? argv[1] : \"HEAD\";\n-\tif (get_sha1(commitname, sha1))\n+\tif (get_oid(commitname, &oid))\n \t\tdie(\"Not a valid object name: '%s'\", commitname);\n \n-\tderived = lookup_commit_reference(sha1);\n+\tderived = lookup_commit_reference(oid.hash);\n \tmemset(&revs, 0, sizeof(revs));\n \trevs.initial = 1;\n \tfor_each_reflog_ent(refname, collect_one_reflog_ent, &revs);\n \n-\tif (!revs.nr && !get_sha1(refname, sha1))\n-\t\tadd_one_commit(sha1, &revs);\n+\tif (!revs.nr && !get_oid(refname, &oid))\n+\t\tadd_one_commit(&oid, &revs);\n \n \tfor (i = 0; i < revs.nr; i++)\n \t\trevs.commit[i]->object.flags &= ~TMP_MARK;\n-- \n2.11.0\n\n"},{"id":"308589","messageId":"20170101191847.564741-16-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 15/17] Convert object iteration callbacks to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:45Z","receivedAt":"2017-01-01T19:20:05Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert each_loose_object_fn and each_packed_object_fn to take a pointer\nto struct object_id.  Update the various callbacks.  Convert several\n40-based constants to use GIT_SHA1_HEXSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/cat-file.c      |  8 ++++----\n builtin/count-objects.c |  4 ++--\n builtin/fsck.c          | 10 +++++-----\n builtin/pack-objects.c  |  6 +++---\n builtin/prune-packed.c  |  4 ++--\n builtin/prune.c         |  8 ++++----\n cache.h                 |  4 ++--\n reachable.c             | 30 +++++++++++++++---------------\n sha1_file.c             | 12 ++++++------\n 9 files changed, 43 insertions(+), 43 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 30383e9eb..8b85cb8cf 100644\n--- a/builtin/cat-file.c\n+++ b/builtin/cat-file.c\n@@ -409,20 +409,20 @@ static int batch_object_cb(const unsigned char sha1[20], void *vdata)\n \treturn 0;\n }\n \n-static int batch_loose_object(const unsigned char *sha1,\n+static int batch_loose_object(const struct object_id *oid,\n \t\t\t      const char *path,\n \t\t\t      void *data)\n {\n-\tsha1_array_append(data, sha1);\n+\tsha1_array_append(data, oid->hash);\n \treturn 0;\n }\n \n-static int batch_packed_object(const unsigned char *sha1,\n+static int batch_packed_object(const struct object_id *oid,\n \t\t\t       struct packed_git *pack,\n \t\t\t       uint32_t pos,\n \t\t\t       void *data)\n {\n-\tsha1_array_append(data, sha1);\n+\tsha1_array_append(data, oid->hash);\n \treturn 0;\n }\n \ndiff --git a/builtin/count-objects.c b/builtin/count-objects.c\nindex a04b4f2ef..acb05940f 100644\n--- a/builtin/count-objects.c\n+++ b/builtin/count-objects.c\n@@ -53,7 +53,7 @@ static void loose_garbage(const char *path)\n \t\treport_garbage(PACKDIR_FILE_GARBAGE, path);\n }\n \n-static int count_loose(const unsigned char *sha1, const char *path, void *data)\n+static int count_loose(const struct object_id *oid, const char *path, void *data)\n {\n \tstruct stat st;\n \n@@ -62,7 +62,7 @@ static int count_loose(const unsigned char *sha1, const char *path, void *data)\n \telse {\n \t\tloose_size += on_disk_bytes(st);\n \t\tloose++;\n-\t\tif (verbose && has_sha1_pack(sha1))\n+\t\tif (verbose && has_sha1_pack(oid->hash))\n \t\t\tpacked_loose++;\n \t}\n \treturn 0;\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 8d6e98399..90da0928a 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -362,13 +362,13 @@ static int fsck_obj(struct object *obj)\n \treturn 0;\n }\n \n-static int fsck_sha1(const unsigned char *sha1)\n+static int fsck_oid(const struct object_id *oid)\n {\n-\tstruct object *obj = parse_object(sha1);\n+\tstruct object *obj = parse_object(oid->hash);\n \tif (!obj) {\n \t\terrors_found |= ERROR_OBJECT;\n \t\treturn error(\"%s: object corrupt or missing\",\n-\t\t\t     sha1_to_hex(sha1));\n+\t\t\t     oid_to_hex(oid));\n \t}\n \tobj->flags |= HAS_OBJ;\n \treturn fsck_obj(obj);\n@@ -488,9 +488,9 @@ static void get_default_heads(void)\n \t}\n }\n \n-static int fsck_loose(const unsigned char *sha1, const char *path, void *data)\n+static int fsck_loose(const struct object_id *oid, const char *path, void *data)\n {\n-\tif (fsck_sha1(sha1))\n+\tif (fsck_oid(oid))\n \t\terrors_found |= ERROR_OBJECT;\n \treturn 0;\n }\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 0fd52bd6b..ef5b8e66d 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2546,17 +2546,17 @@ static void add_objects_in_unpacked_packs(struct rev_info *revs)\n \tfree(in_pack.array);\n }\n \n-static int add_loose_object(const unsigned char *sha1, const char *path,\n+static int add_loose_object(const struct object_id *oid, const char *path,\n \t\t\t    void *data)\n {\n-\tenum object_type type = sha1_object_info(sha1, NULL);\n+\tenum object_type type = sha1_object_info(oid->hash, NULL);\n \n \tif (type < 0) {\n \t\twarning(\"loose object at %s could not be examined\", path);\n \t\treturn 0;\n \t}\n \n-\tadd_object_entry(sha1, type, \"\", 0);\n+\tadd_object_entry(oid->hash, type, \"\", 0);\n \treturn 0;\n }\n \ndiff --git a/builtin/prune-packed.c b/builtin/prune-packed.c\nindex 7cf900ea0..c026299e7 100644\n--- a/builtin/prune-packed.c\n+++ b/builtin/prune-packed.c\n@@ -19,12 +19,12 @@ static int prune_subdir(int nr, const char *path, void *data)\n \treturn 0;\n }\n \n-static int prune_object(const unsigned char *sha1, const char *path,\n+static int prune_object(const struct object_id *oid, const char *path,\n \t\t\t void *data)\n {\n \tint *opts = data;\n \n-\tif (!has_sha1_pack(sha1))\n+\tif (!has_sha1_pack(oid->hash))\n \t\treturn 0;\n \n \tif (*opts & PRUNE_PACKED_DRY_RUN)\ndiff --git a/builtin/prune.c b/builtin/prune.c\nindex 8f4f05228..42633e0c6 100644\n--- a/builtin/prune.c\n+++ b/builtin/prune.c\n@@ -30,7 +30,7 @@ static int prune_tmp_file(const char *fullpath)\n \treturn 0;\n }\n \n-static int prune_object(const unsigned char *sha1, const char *fullpath,\n+static int prune_object(const struct object_id *oid, const char *fullpath,\n \t\t\tvoid *data)\n {\n \tstruct stat st;\n@@ -39,7 +39,7 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,\n \t * Do we know about this object?\n \t * It must have been reachable\n \t */\n-\tif (lookup_object(sha1))\n+\tif (lookup_object(oid->hash))\n \t\treturn 0;\n \n \tif (lstat(fullpath, &st)) {\n@@ -50,8 +50,8 @@ static int prune_object(const unsigned char *sha1, const char *fullpath,\n \tif (st.st_mtime > expire)\n \t\treturn 0;\n \tif (show_only || verbose) {\n-\t\tenum object_type type = sha1_object_info(sha1, NULL);\n-\t\tprintf(\"%s %s\\n\", sha1_to_hex(sha1),\n+\t\tenum object_type type = sha1_object_info(oid->hash, NULL);\n+\t\tprintf(\"%s %s\\n\", oid_to_hex(oid),\n \t\t       (type > 0) ? typename(type) : \"unknown\");\n \t}\n \tif (!show_only)\ndiff --git a/cache.h b/cache.h\nindex b1ed1c7ae..8c01a8ea2 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1582,7 +1582,7 @@ extern int unpack_object_header(struct packed_git *, struct pack_window **, off_\n  * scratch buffer, but restored to its original contents before\n  * the function returns.\n  */\n-typedef int each_loose_object_fn(const unsigned char *sha1,\n+typedef int each_loose_object_fn(const struct object_id *oid,\n \t\t\t\t const char *path,\n \t\t\t\t void *data);\n typedef int each_loose_cruft_fn(const char *basename,\n@@ -1608,7 +1608,7 @@ int for_each_loose_file_in_objdir_buf(struct strbuf *path,\n  * LOCAL_ONLY flag is set).\n  */\n #define FOR_EACH_OBJECT_LOCAL_ONLY 0x1\n-typedef int each_packed_object_fn(const unsigned char *sha1,\n+typedef int each_packed_object_fn(const struct object_id *oid,\n \t\t\t\t  struct packed_git *pack,\n \t\t\t\t  uint32_t pos,\n \t\t\t\t  void *data);\ndiff --git a/reachable.c b/reachable.c\nindex d0199cace..a8a979bd4 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -58,7 +58,7 @@ struct recent_data {\n \tunsigned long timestamp;\n };\n \n-static void add_recent_object(const unsigned char *sha1,\n+static void add_recent_object(const struct object_id *oid,\n \t\t\t      unsigned long mtime,\n \t\t\t      struct recent_data *data)\n {\n@@ -75,37 +75,37 @@ static void add_recent_object(const unsigned char *sha1,\n \t * later processing, and the revision machinery expects\n \t * commits and tags to have been parsed.\n \t */\n-\ttype = sha1_object_info(sha1, NULL);\n+\ttype = sha1_object_info(oid->hash, NULL);\n \tif (type < 0)\n-\t\tdie(\"unable to get object info for %s\", sha1_to_hex(sha1));\n+\t\tdie(\"unable to get object info for %s\", oid_to_hex(oid));\n \n \tswitch (type) {\n \tcase OBJ_TAG:\n \tcase OBJ_COMMIT:\n-\t\tobj = parse_object_or_die(sha1, NULL);\n+\t\tobj = parse_object_or_die(oid->hash, NULL);\n \t\tbreak;\n \tcase OBJ_TREE:\n-\t\tobj = (struct object *)lookup_tree(sha1);\n+\t\tobj = (struct object *)lookup_tree(oid->hash);\n \t\tbreak;\n \tcase OBJ_BLOB:\n-\t\tobj = (struct object *)lookup_blob(sha1);\n+\t\tobj = (struct object *)lookup_blob(oid->hash);\n \t\tbreak;\n \tdefault:\n \t\tdie(\"unknown object type for %s: %s\",\n-\t\t    sha1_to_hex(sha1), typename(type));\n+\t\t    oid_to_hex(oid), typename(type));\n \t}\n \n \tif (!obj)\n-\t\tdie(\"unable to lookup %s\", sha1_to_hex(sha1));\n+\t\tdie(\"unable to lookup %s\", oid_to_hex(oid));\n \n \tadd_pending_object(data->revs, obj, \"\");\n }\n \n-static int add_recent_loose(const unsigned char *sha1,\n+static int add_recent_loose(const struct object_id *oid,\n \t\t\t    const char *path, void *data)\n {\n \tstruct stat st;\n-\tstruct object *obj = lookup_object(sha1);\n+\tstruct object *obj = lookup_object(oid->hash);\n \n \tif (obj && obj->flags & SEEN)\n \t\treturn 0;\n@@ -119,22 +119,22 @@ static int add_recent_loose(const unsigned char *sha1,\n \t\t */\n \t\tif (errno == ENOENT)\n \t\t\treturn 0;\n-\t\treturn error_errno(\"unable to stat %s\", sha1_to_hex(sha1));\n+\t\treturn error_errno(\"unable to stat %s\", oid_to_hex(oid));\n \t}\n \n-\tadd_recent_object(sha1, st.st_mtime, data);\n+\tadd_recent_object(oid, st.st_mtime, data);\n \treturn 0;\n }\n \n-static int add_recent_packed(const unsigned char *sha1,\n+static int add_recent_packed(const struct object_id *oid,\n \t\t\t     struct packed_git *p, uint32_t pos,\n \t\t\t     void *data)\n {\n-\tstruct object *obj = lookup_object(sha1);\n+\tstruct object *obj = lookup_object(oid->hash);\n \n \tif (obj && obj->flags & SEEN)\n \t\treturn 0;\n-\tadd_recent_object(sha1, p->mtime, data);\n+\tadd_recent_object(oid, p->mtime, data);\n \treturn 0;\n }\n \ndiff --git a/sha1_file.c b/sha1_file.c\nindex d27d1521b..8db91b387 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -3660,15 +3660,15 @@ static int for_each_file_in_obj_subdir(int subdir_nr,\n \t\tstrbuf_setlen(path, baselen);\n \t\tstrbuf_addf(path, \"/%s\", de->d_name);\n \n-\t\tif (strlen(de->d_name) == 38)  {\n-\t\t\tchar hex[41];\n-\t\t\tunsigned char sha1[20];\n+\t\tif (strlen(de->d_name) == GIT_SHA1_HEXSZ - 2)  {\n+\t\t\tchar hex[GIT_SHA1_HEXSZ+1];\n+\t\t\tstruct object_id oid;\n \n \t\t\tsnprintf(hex, sizeof(hex), \"%02x%s\",\n \t\t\t\t subdir_nr, de->d_name);\n-\t\t\tif (!get_sha1_hex(hex, sha1)) {\n+\t\t\tif (!get_oid_hex(hex, &oid)) {\n \t\t\t\tif (obj_cb) {\n-\t\t\t\t\tr = obj_cb(sha1, path->buf, data);\n+\t\t\t\t\tr = obj_cb(&oid, path->buf, data);\n \t\t\t\t\tif (r)\n \t\t\t\t\t\tbreak;\n \t\t\t\t}\n@@ -3780,7 +3780,7 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c\n \t\t\treturn error(\"unable to get sha1 of object %u in %s\",\n \t\t\t\t     i, p->pack_name);\n \n-\t\tr = cb(oid->hash, p, i, data);\n+\t\tr = cb(oid, p, i, data);\n \t\tif (r)\n \t\t\tbreak;\n \t}\n-- \n2.11.0\n\n"},{"id":"308590","messageId":"20170101191847.564741-9-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 08/17] builtin/clone: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:38Z","receivedAt":"2017-01-01T19:20:06Z","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/clone.c | 10 +++++-----\n 1 file changed, 5 insertions(+), 5 deletions(-)\n\ndiff --git a/builtin/clone.c b/builtin/clone.c\nindex 5ef81927a..e0916e5f3 100644\n--- a/builtin/clone.c\n+++ b/builtin/clone.c\n@@ -681,7 +681,7 @@ static void update_head(const struct ref *our, const struct ref *remote,\n \n static int checkout(int submodule_progress)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tchar *head;\n \tstruct lock_file *lock_file;\n \tstruct unpack_trees_options opts;\n@@ -692,7 +692,7 @@ static int checkout(int submodule_progress)\n \tif (option_no_checkout)\n \t\treturn 0;\n \n-\thead = resolve_refdup(\"HEAD\", RESOLVE_REF_READING, sha1, NULL);\n+\thead = resolve_refdup(\"HEAD\", RESOLVE_REF_READING, oid.hash, NULL);\n \tif (!head) {\n \t\twarning(_(\"remote HEAD refers to nonexistent ref, \"\n \t\t\t  \"unable to checkout.\\n\"));\n@@ -700,7 +700,7 @@ static int checkout(int submodule_progress)\n \t}\n \tif (!strcmp(head, \"HEAD\")) {\n \t\tif (advice_detached_head)\n-\t\t\tdetach_advice(sha1_to_hex(sha1));\n+\t\t\tdetach_advice(oid_to_hex(&oid));\n \t} else {\n \t\tif (!starts_with(head, \"refs/heads/\"))\n \t\t\tdie(_(\"HEAD not found below refs/heads!\"));\n@@ -721,7 +721,7 @@ static int checkout(int submodule_progress)\n \topts.src_index = &the_index;\n \topts.dst_index = &the_index;\n \n-\ttree = parse_tree_indirect(sha1);\n+\ttree = parse_tree_indirect(oid.hash);\n \tparse_tree(tree);\n \tinit_tree_desc(&t, tree->buffer, tree->size);\n \tif (unpack_trees(1, &t, &opts) < 0)\n@@ -731,7 +731,7 @@ static int checkout(int submodule_progress)\n \t\tdie(_(\"unable to write new index file\"));\n \n \terr |= run_hook_le(NULL, \"post-checkout\", sha1_to_hex(null_sha1),\n-\t\t\t   sha1_to_hex(sha1), \"1\", NULL);\n+\t\t\t   oid_to_hex(&oid), \"1\", NULL);\n \n \tif (!err && option_recursive) {\n \t\tstruct argv_array args = ARGV_ARRAY_INIT;\n-- \n2.11.0\n\n"},{"id":"308591","messageId":"20170101191847.564741-15-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 14/17] sha1_file: introduce an nth_packed_object_oid function","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:44Z","receivedAt":"2017-01-01T19:20:08Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"There are places in the code where we would like to provide a struct\nobject_id *, yet read the hash directly from the pack.  Provide an\nnth_packed_object_oid function that mirrors the nth_packed_object_sha1\nfunction.\n\nThe required cast is questionable, but should be safe on all known\nplatforms.  The alternative of allocating an object as an intermediate\nwould be too inefficient and cause memory leaks.  If necessary, an\nintermediate union could be used; this practice is allowed by GCC and\nexplicitly sanctioned by C11.  However, such a change will likely not be\nnecessary, and can be made if and when it is.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h     |  1 +\n sha1_file.c | 12 +++++++++---\n 2 files changed, 10 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex a50a61a19..b1ed1c7ae 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1540,6 +1540,7 @@ extern void check_pack_index_ptr(const struct packed_git *p, const void *ptr);\n  * error.\n  */\n extern const unsigned char *nth_packed_object_sha1(struct packed_git *, uint32_t n);\n+extern const struct object_id *nth_packed_object_oid(struct packed_git *, uint32_t n);\n \n /*\n  * Return the offset of the nth object within the specified packfile.\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 117307185..d27d1521b 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2608,6 +2608,12 @@ const unsigned char *nth_packed_object_sha1(struct packed_git *p,\n \t}\n }\n \n+const struct object_id *nth_packed_object_oid(struct packed_git *p,\n+\t\t\t\t\t      uint32_t n)\n+{\n+\treturn (const struct object_id *)nth_packed_object_sha1(p, n);\n+}\n+\n void check_pack_index_ptr(const struct packed_git *p, const void *vptr)\n {\n \tconst unsigned char *ptr = vptr;\n@@ -3768,13 +3774,13 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c\n \tint r = 0;\n \n \tfor (i = 0; i < p->num_objects; i++) {\n-\t\tconst unsigned char *sha1 = nth_packed_object_sha1(p, i);\n+\t\tconst struct object_id *oid = nth_packed_object_oid(p, i);\n \n-\t\tif (!sha1)\n+\t\tif (!oid)\n \t\t\treturn error(\"unable to get sha1 of object %u in %s\",\n \t\t\t\t     i, p->pack_name);\n \n-\t\tr = cb(sha1, p, i, data);\n+\t\tr = cb(oid->hash, p, i, data);\n \t\tif (r)\n \t\t\tbreak;\n \t}\n-- \n2.11.0\n\n"},{"id":"308592","messageId":"20170101191847.564741-14-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 13/17] refs: convert each_reflog_ent_fn to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:43Z","receivedAt":"2017-01-01T19:20:09Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Make each_reflog_ent_fn take two struct object_id pointers instead of\ntwo pointers to unsigned char.  Convert the various callbacks to use\nstruct object_id as well.  Also, rename fsck_handle_reflog_sha1 to\nfsck_handle_reflog_oid.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/fsck.c       | 16 ++++++++--------\n builtin/merge-base.c |  6 +++---\n builtin/reflog.c     |  2 +-\n reflog-walk.c        |  6 +++---\n refs.c               | 24 ++++++++++++------------\n refs.h               |  2 +-\n refs/files-backend.c | 24 ++++++++++++------------\n revision.c           | 12 ++++++------\n sha1_name.c          |  2 +-\n wt-status.c          |  6 +++---\n 10 files changed, 50 insertions(+), 50 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex f01b81eeb..8d6e98399 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -393,13 +393,13 @@ static int fsck_obj_buffer(const unsigned char *sha1, enum object_type type,\n \n static int default_refs;\n \n-static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1,\n+static void fsck_handle_reflog_oid(const char *refname, struct object_id *oid,\n \tunsigned long timestamp)\n {\n \tstruct object *obj;\n \n-\tif (!is_null_sha1(sha1)) {\n-\t\tobj = lookup_object(sha1);\n+\tif (!is_null_oid(oid)) {\n+\t\tobj = lookup_object(oid->hash);\n \t\tif (obj) {\n \t\t\tif (timestamp && name_objects)\n \t\t\t\tadd_decoration(fsck_walk_options.object_names,\n@@ -408,13 +408,13 @@ static void fsck_handle_reflog_sha1(const char *refname, unsigned char *sha1,\n \t\t\tobj->used = 1;\n \t\t\tmark_object_reachable(obj);\n \t\t} else {\n-\t\t\terror(\"%s: invalid reflog entry %s\", refname, sha1_to_hex(sha1));\n+\t\t\terror(\"%s: invalid reflog entry %s\", refname, oid_to_hex(oid));\n \t\t\terrors_found |= ERROR_REACHABLE;\n \t\t}\n \t}\n }\n \n-static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n+static int fsck_handle_reflog_ent(struct object_id *ooid, struct object_id *noid,\n \t\tconst char *email, unsigned long timestamp, int tz,\n \t\tconst char *message, void *cb_data)\n {\n@@ -422,10 +422,10 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n \n \tif (verbose)\n \t\tfprintf(stderr, \"Checking reflog %s->%s\\n\",\n-\t\t\tsha1_to_hex(osha1), sha1_to_hex(nsha1));\n+\t\t\toid_to_hex(ooid), oid_to_hex(noid));\n \n-\tfsck_handle_reflog_sha1(refname, osha1, 0);\n-\tfsck_handle_reflog_sha1(refname, nsha1, timestamp);\n+\tfsck_handle_reflog_oid(refname, ooid, 0);\n+\tfsck_handle_reflog_oid(refname, noid, timestamp);\n \treturn 0;\n }\n \ndiff --git a/builtin/merge-base.c b/builtin/merge-base.c\nindex b572a37c2..db95bc29c 100644\n--- a/builtin/merge-base.c\n+++ b/builtin/merge-base.c\n@@ -131,7 +131,7 @@ static void add_one_commit(unsigned char *sha1, struct rev_collect *revs)\n \tcommit->object.flags |= TMP_MARK;\n }\n \n-static int collect_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n+static int collect_one_reflog_ent(struct object_id *ooid, struct object_id *noid,\n \t\t\t\t  const char *ident, unsigned long timestamp,\n \t\t\t\t  int tz, const char *message, void *cbdata)\n {\n@@ -139,9 +139,9 @@ static int collect_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n \n \tif (revs->initial) {\n \t\trevs->initial = 0;\n-\t\tadd_one_commit(osha1, revs);\n+\t\tadd_one_commit(ooid->hash, revs);\n \t}\n-\tadd_one_commit(nsha1, revs);\n+\tadd_one_commit(noid->hash, revs);\n \treturn 0;\n }\n \ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 7a7136e53..747277577 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -615,7 +615,7 @@ static int cmd_reflog_expire(int argc, const char **argv, const char *prefix)\n \treturn status;\n }\n \n-static int count_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n+static int count_reflog_ent(struct object_id *ooid, struct object_id *noid,\n \t\tconst char *email, unsigned long timestamp, int tz,\n \t\tconst char *message, void *cb_data)\n {\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex fe5be4147..99679f582 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -19,7 +19,7 @@ struct complete_reflogs {\n \tint nr, alloc;\n };\n \n-static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,\n+static int read_one_reflog(struct object_id *ooid, struct object_id *noid,\n \t\tconst char *email, unsigned long timestamp, int tz,\n \t\tconst char *message, void *cb_data)\n {\n@@ -28,8 +28,8 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,\n \n \tALLOC_GROW(array->items, array->nr + 1, array->alloc);\n \titem = array->items + array->nr;\n-\thashcpy(item->ooid.hash, osha1);\n-\thashcpy(item->noid.hash, nsha1);\n+\toidcpy(&item->ooid, ooid);\n+\toidcpy(&item->noid, noid);\n \titem->email = xstrdup(email);\n \titem->timestamp = timestamp;\n \titem->tz = tz;\ndiff --git a/refs.c b/refs.c\nindex 9bd0bc177..4bc924790 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -669,7 +669,7 @@ struct read_ref_at_cb {\n \tint *cutoff_cnt;\n };\n \n-static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,\n+static int read_ref_at_ent(struct object_id *ooid, struct object_id *noid,\n \t\tconst char *email, unsigned long timestamp, int tz,\n \t\tconst char *message, void *cb_data)\n {\n@@ -693,30 +693,30 @@ static int read_ref_at_ent(unsigned char *osha1, unsigned char *nsha1,\n \t\t * hold the values for the previous record.\n \t\t */\n \t\tif (!is_null_sha1(cb->osha1)) {\n-\t\t\thashcpy(cb->sha1, nsha1);\n-\t\t\tif (hashcmp(cb->osha1, nsha1))\n+\t\t\thashcpy(cb->sha1, noid->hash);\n+\t\t\tif (hashcmp(cb->osha1, noid->hash))\n \t\t\t\twarning(\"Log for ref %s has gap after %s.\",\n \t\t\t\t\tcb->refname, show_date(cb->date, cb->tz, DATE_MODE(RFC2822)));\n \t\t}\n \t\telse if (cb->date == cb->at_time)\n-\t\t\thashcpy(cb->sha1, nsha1);\n-\t\telse if (hashcmp(nsha1, cb->sha1))\n+\t\t\thashcpy(cb->sha1, noid->hash);\n+\t\telse if (hashcmp(noid->hash, cb->sha1))\n \t\t\twarning(\"Log for ref %s unexpectedly ended on %s.\",\n \t\t\t\tcb->refname, show_date(cb->date, cb->tz,\n \t\t\t\t\t\t       DATE_MODE(RFC2822)));\n-\t\thashcpy(cb->osha1, osha1);\n-\t\thashcpy(cb->nsha1, nsha1);\n+\t\thashcpy(cb->osha1, ooid->hash);\n+\t\thashcpy(cb->nsha1, noid->hash);\n \t\tcb->found_it = 1;\n \t\treturn 1;\n \t}\n-\thashcpy(cb->osha1, osha1);\n-\thashcpy(cb->nsha1, nsha1);\n+\thashcpy(cb->osha1, ooid->hash);\n+\thashcpy(cb->nsha1, noid->hash);\n \tif (cb->cnt > 0)\n \t\tcb->cnt--;\n \treturn 0;\n }\n \n-static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,\n+static int read_ref_at_ent_oldest(struct object_id *ooid, struct object_id *noid,\n \t\t\t\t  const char *email, unsigned long timestamp,\n \t\t\t\t  int tz, const char *message, void *cb_data)\n {\n@@ -730,9 +730,9 @@ static int read_ref_at_ent_oldest(unsigned char *osha1, unsigned char *nsha1,\n \t\t*cb->cutoff_tz = tz;\n \tif (cb->cutoff_cnt)\n \t\t*cb->cutoff_cnt = cb->reccnt;\n-\thashcpy(cb->sha1, osha1);\n+\thashcpy(cb->sha1, ooid->hash);\n \tif (is_null_sha1(cb->sha1))\n-\t\thashcpy(cb->sha1, nsha1);\n+\t\thashcpy(cb->sha1, noid->hash);\n \t/* We just want the first entry */\n \treturn 1;\n }\ndiff --git a/refs.h b/refs.h\nindex 694784391..ce35c4019 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -290,7 +290,7 @@ int delete_reflog(const char *refname);\n \n /* iterate over reflog entries */\n typedef int each_reflog_ent_fn(\n-\t\tunsigned char *old_sha1, unsigned char *new_sha1,\n+\t\tstruct object_id *old_oid, struct object_id *new_oid,\n \t\tconst char *committer, unsigned long timestamp,\n \t\tint tz, const char *msg, void *cb_data);\n \ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex f9023939d..3da3141ee 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -3113,15 +3113,15 @@ static int files_delete_reflog(struct ref_store *ref_store,\n \n static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)\n {\n-\tunsigned char osha1[20], nsha1[20];\n+\tstruct object_id ooid, noid;\n \tchar *email_end, *message;\n \tunsigned long timestamp;\n \tint tz;\n \n \t/* old SP new SP name <email> SP time TAB msg LF */\n \tif (sb->len < 83 || sb->buf[sb->len - 1] != '\\n' ||\n-\t    get_sha1_hex(sb->buf, osha1) || sb->buf[40] != ' ' ||\n-\t    get_sha1_hex(sb->buf + 41, nsha1) || sb->buf[81] != ' ' ||\n+\t    get_oid_hex(sb->buf, &ooid) || sb->buf[40] != ' ' ||\n+\t    get_oid_hex(sb->buf + 41, &noid) || sb->buf[81] != ' ' ||\n \t    !(email_end = strchr(sb->buf + 82, '>')) ||\n \t    email_end[1] != ' ' ||\n \t    !(timestamp = strtoul(email_end + 2, &message, 10)) ||\n@@ -3136,7 +3136,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c\n \t\tmessage += 6;\n \telse\n \t\tmessage += 7;\n-\treturn fn(osha1, nsha1, sb->buf + 82, timestamp, tz, message, cb_data);\n+\treturn fn(&ooid, &noid, sb->buf + 82, timestamp, tz, message, cb_data);\n }\n \n static char *find_beginning_of_line(char *bob, char *scan)\n@@ -3936,10 +3936,10 @@ struct expire_reflog_cb {\n \treflog_expiry_should_prune_fn *should_prune_fn;\n \tvoid *policy_cb;\n \tFILE *newlog;\n-\tunsigned char last_kept_sha1[20];\n+\tstruct object_id last_kept_oid;\n };\n \n-static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n+static int expire_reflog_ent(struct object_id *ooid, struct object_id *noid,\n \t\t\t     const char *email, unsigned long timestamp, int tz,\n \t\t\t     const char *message, void *cb_data)\n {\n@@ -3947,9 +3947,9 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n \tstruct expire_reflog_policy_cb *policy_cb = cb->policy_cb;\n \n \tif (cb->flags & EXPIRE_REFLOGS_REWRITE)\n-\t\tosha1 = cb->last_kept_sha1;\n+\t\tooid = &cb->last_kept_oid;\n \n-\tif ((*cb->should_prune_fn)(osha1, nsha1, email, timestamp, tz,\n+\tif ((*cb->should_prune_fn)(ooid->hash, noid->hash, email, timestamp, tz,\n \t\t\t\t   message, policy_cb)) {\n \t\tif (!cb->newlog)\n \t\t\tprintf(\"would prune %s\", message);\n@@ -3958,9 +3958,9 @@ static int expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n \t} else {\n \t\tif (cb->newlog) {\n \t\t\tfprintf(cb->newlog, \"%s %s %s %lu %+05d\\t%s\",\n-\t\t\t\tsha1_to_hex(osha1), sha1_to_hex(nsha1),\n+\t\t\t\toid_to_hex(ooid), oid_to_hex(noid),\n \t\t\t\temail, timestamp, tz, message);\n-\t\t\thashcpy(cb->last_kept_sha1, nsha1);\n+\t\t\toidcpy(&cb->last_kept_oid, noid);\n \t\t}\n \t\tif (cb->flags & EXPIRE_REFLOGS_VERBOSE)\n \t\t\tprintf(\"keep %s\", message);\n@@ -4047,14 +4047,14 @@ static int files_reflog_expire(struct ref_store *ref_store,\n \t\t */\n \t\tint update = (flags & EXPIRE_REFLOGS_UPDATE_REF) &&\n \t\t\t!(type & REF_ISSYMREF) &&\n-\t\t\t!is_null_sha1(cb.last_kept_sha1);\n+\t\t\t!is_null_oid(&cb.last_kept_oid);\n \n \t\tif (close_lock_file(&reflog_lock)) {\n \t\t\tstatus |= error(\"couldn't write %s: %s\", log_file,\n \t\t\t\t\tstrerror(errno));\n \t\t} else if (update &&\n \t\t\t   (write_in_full(get_lock_file_fd(lock->lk),\n-\t\t\t\tsha1_to_hex(cb.last_kept_sha1), 40) != 40 ||\n+\t\t\t\toid_to_hex(&cb.last_kept_oid), 40) != 40 ||\n \t\t\t    write_str_in_full(get_lock_file_fd(lock->lk), \"\\n\") != 1 ||\n \t\t\t    close_ref(lock) < 0)) {\n \t\t\tstatus |= error(\"couldn't write %s\",\ndiff --git a/revision.c b/revision.c\nindex b37dbec37..d9fe73318 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1196,11 +1196,11 @@ static void handle_refs(const char *submodule, struct rev_info *revs, unsigned f\n \tfor_each(submodule, handle_one_ref, &cb);\n }\n \n-static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)\n+static void handle_one_reflog_commit(struct object_id *oid, void *cb_data)\n {\n \tstruct all_refs_cb *cb = cb_data;\n-\tif (!is_null_sha1(sha1)) {\n-\t\tstruct object *o = parse_object(sha1);\n+\tif (!is_null_oid(oid)) {\n+\t\tstruct object *o = parse_object(oid->hash);\n \t\tif (o) {\n \t\t\to->flags |= cb->all_flags;\n \t\t\t/* ??? CMDLINEFLAGS ??? */\n@@ -1214,12 +1214,12 @@ static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)\n \t}\n }\n \n-static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n+static int handle_one_reflog_ent(struct object_id *ooid, struct object_id *noid,\n \t\tconst char *email, unsigned long timestamp, int tz,\n \t\tconst char *message, void *cb_data)\n {\n-\thandle_one_reflog_commit(osha1, cb_data);\n-\thandle_one_reflog_commit(nsha1, cb_data);\n+\thandle_one_reflog_commit(ooid, cb_data);\n+\thandle_one_reflog_commit(noid, cb_data);\n \treturn 0;\n }\n \ndiff --git a/sha1_name.c b/sha1_name.c\nindex 73a915ff1..744e9f884 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1051,7 +1051,7 @@ struct grab_nth_branch_switch_cbdata {\n \tstruct strbuf buf;\n };\n \n-static int grab_nth_branch_switch(unsigned char *osha1, unsigned char *nsha1,\n+static int grab_nth_branch_switch(struct object_id *ooid, struct object_id *noid,\n \t\t\t\t  const char *email, unsigned long timestamp, int tz,\n \t\t\t\t  const char *message, void *cb_data)\n {\ndiff --git a/wt-status.c b/wt-status.c\nindex f0d750880..08a4d0bd3 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1367,7 +1367,7 @@ struct grab_1st_switch_cbdata {\n \tunsigned char nsha1[20];\n };\n \n-static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,\n+static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,\n \t\t\t   const char *email, unsigned long timestamp, int tz,\n \t\t\t   const char *message, void *cb_data)\n {\n@@ -1381,13 +1381,13 @@ static int grab_1st_switch(unsigned char *osha1, unsigned char *nsha1,\n \t\treturn 0;\n \ttarget += strlen(\" to \");\n \tstrbuf_reset(&cb->buf);\n-\thashcpy(cb->nsha1, nsha1);\n+\thashcpy(cb->nsha1, noid->hash);\n \tend = strchrnul(target, '\\n');\n \tstrbuf_add(&cb->buf, target, end - target);\n \tif (!strcmp(cb->buf.buf, \"HEAD\")) {\n \t\t/* HEAD is relative. Resolve it to the right reflog entry. */\n \t\tstrbuf_reset(&cb->buf);\n-\t\tstrbuf_add_unique_abbrev(&cb->buf, nsha1, DEFAULT_ABBREV);\n+\t\tstrbuf_add_unique_abbrev(&cb->buf, noid->hash, DEFAULT_ABBREV);\n \t}\n \treturn 1;\n }\n-- \n2.11.0\n\n"},{"id":"308593","messageId":"20170101191847.564741-11-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 10/17] Convert remaining callers of resolve_refdup to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:40Z","receivedAt":"2017-01-01T19:20:13Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"There are a few leaf functions in various files that call\nresolve_refdup.  Convert these functions to use struct object_id\ninternally to prepare for transitioning resolve_refdup itself.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/notes.c        | 18 +++++++++---------\n builtin/receive-pack.c |  4 ++--\n ref-filter.c           |  4 ++--\n reflog-walk.c          | 12 ++++++------\n transport.c            |  4 ++--\n wt-status.c            |  4 ++--\n 6 files changed, 23 insertions(+), 23 deletions(-)\n\ndiff --git a/builtin/notes.c b/builtin/notes.c\nindex 5248a9bad..8c569a49a 100644\n--- a/builtin/notes.c\n+++ b/builtin/notes.c\n@@ -693,7 +693,7 @@ static int merge_abort(struct notes_merge_options *o)\n static int merge_commit(struct notes_merge_options *o)\n {\n \tstruct strbuf msg = STRBUF_INIT;\n-\tunsigned char sha1[20], parent_sha1[20];\n+\tstruct object_id oid, parent_oid;\n \tstruct notes_tree *t;\n \tstruct commit *partial;\n \tstruct pretty_print_context pretty_ctx;\n@@ -705,27 +705,27 @@ static int merge_commit(struct notes_merge_options *o)\n \t * and target notes ref from .git/NOTES_MERGE_REF.\n \t */\n \n-\tif (get_sha1(\"NOTES_MERGE_PARTIAL\", sha1))\n+\tif (get_oid(\"NOTES_MERGE_PARTIAL\", &oid))\n \t\tdie(_(\"failed to read ref NOTES_MERGE_PARTIAL\"));\n-\telse if (!(partial = lookup_commit_reference(sha1)))\n+\telse if (!(partial = lookup_commit_reference(oid.hash)))\n \t\tdie(_(\"could not find commit from NOTES_MERGE_PARTIAL.\"));\n \telse if (parse_commit(partial))\n \t\tdie(_(\"could not parse commit from NOTES_MERGE_PARTIAL.\"));\n \n \tif (partial->parents)\n-\t\thashcpy(parent_sha1, partial->parents->item->object.oid.hash);\n+\t\toidcpy(&parent_oid, &partial->parents->item->object.oid);\n \telse\n-\t\thashclr(parent_sha1);\n+\t\toidclr(&parent_oid);\n \n \tt = xcalloc(1, sizeof(struct notes_tree));\n \tinit_notes(t, \"NOTES_MERGE_PARTIAL\", combine_notes_overwrite, 0);\n \n \to->local_ref = local_ref_to_free =\n-\t\tresolve_refdup(\"NOTES_MERGE_REF\", 0, sha1, NULL);\n+\t\tresolve_refdup(\"NOTES_MERGE_REF\", 0, oid.hash, NULL);\n \tif (!o->local_ref)\n \t\tdie(_(\"failed to resolve NOTES_MERGE_REF\"));\n \n-\tif (notes_merge_commit(o, t, partial, sha1))\n+\tif (notes_merge_commit(o, t, partial, oid.hash))\n \t\tdie(_(\"failed to finalize notes merge\"));\n \n \t/* Reuse existing commit message in reflog message */\n@@ -733,8 +733,8 @@ static int merge_commit(struct notes_merge_options *o)\n \tformat_commit_message(partial, \"%s\", &msg, &pretty_ctx);\n \tstrbuf_trim(&msg);\n \tstrbuf_insert(&msg, 0, \"notes: \", 7);\n-\tupdate_ref(msg.buf, o->local_ref, sha1,\n-\t\t   is_null_sha1(parent_sha1) ? NULL : parent_sha1,\n+\tupdate_ref(msg.buf, o->local_ref, oid.hash,\n+\t\t   is_null_oid(&parent_oid) ? NULL : parent_oid.hash,\n \t\t   0, UPDATE_REFS_DIE_ON_ERR);\n \n \tfree_notes(t);\ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex 6b97cbdbe..b24644242 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -1414,7 +1414,7 @@ static void execute_commands(struct command *commands,\n {\n \tstruct check_connected_options opt = CHECK_CONNECTED_INIT;\n \tstruct command *cmd;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstruct iterate_data data;\n \tstruct async muxer;\n \tint err_fd = 0;\n@@ -1471,7 +1471,7 @@ static void execute_commands(struct command *commands,\n \tcheck_aliased_updates(commands);\n \n \tfree(head_name_to_free);\n-\thead_name = head_name_to_free = resolve_refdup(\"HEAD\", 0, sha1, NULL);\n+\thead_name = head_name_to_free = resolve_refdup(\"HEAD\", 0, oid.hash, NULL);\n \n \tif (use_atomic)\n \t\texecute_commands_atomic(commands, si);\ndiff --git a/ref-filter.c b/ref-filter.c\nindex 1a978405e..a759bf67d 100644\n--- a/ref-filter.c\n+++ b/ref-filter.c\n@@ -961,9 +961,9 @@ static void populate_value(struct ref_array_item *ref)\n \tref->value = xcalloc(used_atom_cnt, sizeof(struct atom_value));\n \n \tif (need_symref && (ref->flag & REF_ISSYMREF) && !ref->symref) {\n-\t\tunsigned char unused1[20];\n+\t\tstruct object_id unused1;\n \t\tref->symref = resolve_refdup(ref->refname, RESOLVE_REF_READING,\n-\t\t\t\t\t     unused1, NULL);\n+\t\t\t\t\t     unused1.hash, NULL);\n \t\tif (!ref->symref)\n \t\t\tref->symref = \"\";\n \t}\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex a246af276..f98748e2a 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -45,11 +45,11 @@ static struct complete_reflogs *read_complete_reflog(const char *ref)\n \treflogs->ref = xstrdup(ref);\n \tfor_each_reflog_ent(ref, read_one_reflog, reflogs);\n \tif (reflogs->nr == 0) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tconst char *name;\n \t\tvoid *name_to_free;\n \t\tname = name_to_free = resolve_refdup(ref, RESOLVE_REF_READING,\n-\t\t\t\t\t\t     sha1, NULL);\n+\t\t\t\t\t\t     oid.hash, NULL);\n \t\tif (name) {\n \t\t\tfor_each_reflog_ent(name, read_one_reflog, reflogs);\n \t\t\tfree(name_to_free);\n@@ -172,18 +172,18 @@ int add_reflog_for_walk(struct reflog_walk_info *info,\n \t\treflogs = item->util;\n \telse {\n \t\tif (*branch == '\\0') {\n-\t\t\tunsigned char sha1[20];\n+\t\t\tstruct object_id oid;\n \t\t\tfree(branch);\n-\t\t\tbranch = resolve_refdup(\"HEAD\", 0, sha1, NULL);\n+\t\t\tbranch = resolve_refdup(\"HEAD\", 0, oid.hash, NULL);\n \t\t\tif (!branch)\n \t\t\t\tdie (\"No current branch\");\n \n \t\t}\n \t\treflogs = read_complete_reflog(branch);\n \t\tif (!reflogs || reflogs->nr == 0) {\n-\t\t\tunsigned char sha1[20];\n+\t\t\tstruct object_id oid;\n \t\t\tchar *b;\n-\t\t\tif (dwim_log(branch, strlen(branch), sha1, &b) == 1) {\n+\t\t\tif (dwim_log(branch, strlen(branch), oid.hash, &b) == 1) {\n \t\t\t\tif (reflogs) {\n \t\t\t\t\tfree(reflogs->ref);\n \t\t\t\t\tfree(reflogs);\ndiff --git a/transport.c b/transport.c\nindex 04e5d6623..be217609f 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -467,11 +467,11 @@ void transport_print_push_status(const char *dest, struct ref *refs,\n {\n \tstruct ref *ref;\n \tint n = 0;\n-\tunsigned char head_sha1[20];\n+\tstruct object_id head_oid;\n \tchar *head;\n \tint summary_width = transport_summary_width(refs);\n \n-\thead = resolve_refdup(\"HEAD\", RESOLVE_REF_READING, head_sha1, NULL);\n+\thead = resolve_refdup(\"HEAD\", RESOLVE_REF_READING, head_oid.hash, NULL);\n \n \tif (verbose) {\n \t\tfor (ref = refs; ref; ref = ref->next)\ndiff --git a/wt-status.c b/wt-status.c\nindex a715e7190..f0d750880 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -121,7 +121,7 @@ static void status_printf_more(struct wt_status *s, const char *color,\n \n void wt_status_prepare(struct wt_status *s)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \n \tmemset(s, 0, sizeof(*s));\n \tmemcpy(s->color_palette, default_wt_status_colors,\n@@ -129,7 +129,7 @@ void wt_status_prepare(struct wt_status *s)\n \ts->show_untracked_files = SHOW_NORMAL_UNTRACKED_FILES;\n \ts->use_color = -1;\n \ts->relative_paths = 1;\n-\ts->branch = resolve_refdup(\"HEAD\", 0, sha1, NULL);\n+\ts->branch = resolve_refdup(\"HEAD\", 0, oid.hash, NULL);\n \ts->reference = \"HEAD\";\n \ts->fp = stdout;\n \ts->index_file = get_index_file();\n-- \n2.11.0\n\n"},{"id":"308594","messageId":"20170101191847.564741-13-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 12/17] reflog-walk: convert struct reflog_info to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:42Z","receivedAt":"2017-01-01T19:20:14Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert struct reflog_info to use struct object_id by changing the\nstructure definition and applying the following semantic patch:\n\n@@\nstruct reflog_info E1;\n@@\n- E1.osha1\n+ E1.ooid.hash\n\n@@\nstruct reflog_info *E1;\n@@\n- E1->osha1\n+ E1->ooid.hash\n\n@@\nstruct reflog_info E1;\n@@\n- E1.nsha1\n+ E1.noid.hash\n\n@@\nstruct reflog_info *E1;\n@@\n- E1->nsha1\n+ E1->noid.hash\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n reflog-walk.c | 12 ++++++------\n 1 file changed, 6 insertions(+), 6 deletions(-)\n\ndiff --git a/reflog-walk.c b/reflog-walk.c\nindex f98748e2a..fe5be4147 100644\n--- a/reflog-walk.c\n+++ b/reflog-walk.c\n@@ -10,7 +10,7 @@ struct complete_reflogs {\n \tchar *ref;\n \tconst char *short_ref;\n \tstruct reflog_info {\n-\t\tunsigned char osha1[20], nsha1[20];\n+\t\tstruct object_id ooid, noid;\n \t\tchar *email;\n \t\tunsigned long timestamp;\n \t\tint tz;\n@@ -28,8 +28,8 @@ static int read_one_reflog(unsigned char *osha1, unsigned char *nsha1,\n \n \tALLOC_GROW(array->items, array->nr + 1, array->alloc);\n \titem = array->items + array->nr;\n-\thashcpy(item->osha1, osha1);\n-\thashcpy(item->nsha1, nsha1);\n+\thashcpy(item->ooid.hash, osha1);\n+\thashcpy(item->noid.hash, nsha1);\n \titem->email = xstrdup(email);\n \titem->timestamp = timestamp;\n \titem->tz = tz;\n@@ -238,13 +238,13 @@ void fake_reflog_parent(struct reflog_walk_info *info, struct commit *commit)\n \tdo {\n \t\treflog = &commit_reflog->reflogs->items[commit_reflog->recno];\n \t\tcommit_reflog->recno--;\n-\t\tlogobj = parse_object(reflog->osha1);\n+\t\tlogobj = parse_object(reflog->ooid.hash);\n \t} while (commit_reflog->recno && (logobj && logobj->type != OBJ_COMMIT));\n \n-\tif (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->osha1)) {\n+\tif (!logobj && commit_reflog->recno >= 0 && is_null_sha1(reflog->ooid.hash)) {\n \t\t/* a root commit, but there are still more entries to show */\n \t\treflog = &commit_reflog->reflogs->items[commit_reflog->recno];\n-\t\tlogobj = parse_object(reflog->nsha1);\n+\t\tlogobj = parse_object(reflog->noid.hash);\n \t}\n \n \tif (!logobj || logobj->type != OBJ_COMMIT) {\n-- \n2.11.0\n\n"},{"id":"308595","messageId":"20170101191847.564741-18-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 17/17] wt-status: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:47Z","receivedAt":"2017-01-01T19:20:17Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert the remaining uses of unsigned char [20] to struct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n wt-status.c | 44 ++++++++++++++++++++++----------------------\n 1 file changed, 22 insertions(+), 22 deletions(-)\n\ndiff --git a/wt-status.c b/wt-status.c\nindex 08a4d0bd3..e07a46d21 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1115,16 +1115,16 @@ static void abbrev_sha1_in_line(struct strbuf *line)\n \n \tsplit = strbuf_split_max(line, ' ', 3);\n \tif (split[0] && split[1]) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \n \t\t/*\n \t\t * strbuf_split_max left a space. Trim it and re-add\n \t\t * it after abbreviation.\n \t\t */\n \t\tstrbuf_trim(split[1]);\n-\t\tif (!get_sha1(split[1]->buf, sha1)) {\n+\t\tif (!get_oid(split[1]->buf, &oid)) {\n \t\t\tstrbuf_reset(split[1]);\n-\t\t\tstrbuf_add_unique_abbrev(split[1], sha1,\n+\t\t\tstrbuf_add_unique_abbrev(split[1], oid.hash,\n \t\t\t\t\t\t DEFAULT_ABBREV);\n \t\t\tstrbuf_addch(split[1], ' ');\n \t\t\tstrbuf_reset(line);\n@@ -1334,7 +1334,7 @@ static void show_bisect_in_progress(struct wt_status *s,\n static char *get_branch(const struct worktree *wt, const char *path)\n {\n \tstruct strbuf sb = STRBUF_INIT;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tconst char *branch_name;\n \n \tif (strbuf_read_file(&sb, worktree_git_path(wt, \"%s\", path), 0) <= 0)\n@@ -1348,9 +1348,9 @@ static char *get_branch(const struct worktree *wt, const char *path)\n \t\tstrbuf_remove(&sb, 0, branch_name - sb.buf);\n \telse if (starts_with(sb.buf, \"refs/\"))\n \t\t;\n-\telse if (!get_sha1_hex(sb.buf, sha1)) {\n+\telse if (!get_oid_hex(sb.buf, &oid)) {\n \t\tstrbuf_reset(&sb);\n-\t\tstrbuf_add_unique_abbrev(&sb, sha1, DEFAULT_ABBREV);\n+\t\tstrbuf_add_unique_abbrev(&sb, oid.hash, DEFAULT_ABBREV);\n \t} else if (!strcmp(sb.buf, \"detached HEAD\")) /* rebase */\n \t\tgoto got_nothing;\n \telse\t\t\t/* bisect */\n@@ -1364,7 +1364,7 @@ static char *get_branch(const struct worktree *wt, const char *path)\n \n struct grab_1st_switch_cbdata {\n \tstruct strbuf buf;\n-\tunsigned char nsha1[20];\n+\tstruct object_id noid;\n };\n \n static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,\n@@ -1381,7 +1381,7 @@ static int grab_1st_switch(struct object_id *ooid, struct object_id *noid,\n \t\treturn 0;\n \ttarget += strlen(\" to \");\n \tstrbuf_reset(&cb->buf);\n-\thashcpy(cb->nsha1, noid->hash);\n+\toidcpy(&cb->noid, noid);\n \tend = strchrnul(target, '\\n');\n \tstrbuf_add(&cb->buf, target, end - target);\n \tif (!strcmp(cb->buf.buf, \"HEAD\")) {\n@@ -1396,7 +1396,7 @@ static void wt_status_get_detached_from(struct wt_status_state *state)\n {\n \tstruct grab_1st_switch_cbdata cb;\n \tstruct commit *commit;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tchar *ref = NULL;\n \n \tstrbuf_init(&cb.buf, 0);\n@@ -1405,22 +1405,22 @@ static void wt_status_get_detached_from(struct wt_status_state *state)\n \t\treturn;\n \t}\n \n-\tif (dwim_ref(cb.buf.buf, cb.buf.len, sha1, &ref) == 1 &&\n+\tif (dwim_ref(cb.buf.buf, cb.buf.len, oid.hash, &ref) == 1 &&\n \t    /* sha1 is a commit? match without further lookup */\n-\t    (!hashcmp(cb.nsha1, sha1) ||\n+\t    (!oidcmp(&cb.noid, &oid) ||\n \t     /* perhaps sha1 is a tag, try to dereference to a commit */\n-\t     ((commit = lookup_commit_reference_gently(sha1, 1)) != NULL &&\n-\t      !hashcmp(cb.nsha1, commit->object.oid.hash)))) {\n+\t     ((commit = lookup_commit_reference_gently(oid.hash, 1)) != NULL &&\n+\t      !oidcmp(&cb.noid, &commit->object.oid)))) {\n \t\tconst char *from = ref;\n \t\tif (!skip_prefix(from, \"refs/tags/\", &from))\n \t\t\tskip_prefix(from, \"refs/remotes/\", &from);\n \t\tstate->detached_from = xstrdup(from);\n \t} else\n \t\tstate->detached_from =\n-\t\t\txstrdup(find_unique_abbrev(cb.nsha1, DEFAULT_ABBREV));\n-\thashcpy(state->detached_sha1, cb.nsha1);\n-\tstate->detached_at = !get_sha1(\"HEAD\", sha1) &&\n-\t\t\t     !hashcmp(sha1, state->detached_sha1);\n+\t\t\txstrdup(find_unique_abbrev(cb.noid.hash, DEFAULT_ABBREV));\n+\thashcpy(state->detached_sha1, cb.noid.hash);\n+\tstate->detached_at = !get_oid(\"HEAD\", &oid) &&\n+\t\t\t     !hashcmp(oid.hash, state->detached_sha1);\n \n \tfree(ref);\n \tstrbuf_release(&cb.buf);\n@@ -1470,22 +1470,22 @@ void wt_status_get_state(struct wt_status_state *state,\n \t\t\t int get_detached_from)\n {\n \tstruct stat st;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \n \tif (!stat(git_path_merge_head(), &st)) {\n \t\tstate->merge_in_progress = 1;\n \t} else if (wt_status_check_rebase(NULL, state)) {\n \t\t;\t\t/* all set */\n \t} else if (!stat(git_path_cherry_pick_head(), &st) &&\n-\t\t\t!get_sha1(\"CHERRY_PICK_HEAD\", sha1)) {\n+\t\t\t!get_oid(\"CHERRY_PICK_HEAD\", &oid)) {\n \t\tstate->cherry_pick_in_progress = 1;\n-\t\thashcpy(state->cherry_pick_head_sha1, sha1);\n+\t\thashcpy(state->cherry_pick_head_sha1, oid.hash);\n \t}\n \twt_status_check_bisect(NULL, state);\n \tif (!stat(git_path_revert_head(), &st) &&\n-\t    !get_sha1(\"REVERT_HEAD\", sha1)) {\n+\t    !get_oid(\"REVERT_HEAD\", &oid)) {\n \t\tstate->revert_in_progress = 1;\n-\t\thashcpy(state->revert_head_sha1, sha1);\n+\t\thashcpy(state->revert_head_sha1, oid.hash);\n \t}\n \n \tif (get_detached_from)\n-- \n2.11.0\n\n"},{"id":"308596","messageId":"20170101191847.564741-7-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 06/17] builtin/grep: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:36Z","receivedAt":"2017-01-01T19:20:18Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert several functions to use struct object_id, and rename them so\nthat they no longer refer to SHA-1.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/grep.c | 24 ++++++++++++------------\n 1 file changed, 12 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 8887b6add..6fc9f2dc9 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -281,17 +281,17 @@ static int grep_cmd_config(const char *var, const char *value, void *cb)\n \treturn st;\n }\n \n-static void *lock_and_read_sha1_file(const unsigned char *sha1, enum object_type *type, unsigned long *size)\n+static void *lock_and_read_oid_file(const struct object_id *oid, enum object_type *type, unsigned long *size)\n {\n \tvoid *data;\n \n \tgrep_read_lock();\n-\tdata = read_sha1_file(sha1, type, size);\n+\tdata = read_sha1_file(oid->hash, type, size);\n \tgrep_read_unlock();\n \treturn data;\n }\n \n-static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,\n+static int grep_oid(struct grep_opt *opt, const struct object_id *oid,\n \t\t     const char *filename, int tree_name_len,\n \t\t     const char *path)\n {\n@@ -306,7 +306,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,\n \n #ifndef NO_PTHREADS\n \tif (num_threads) {\n-\t\tadd_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1);\n+\t\tadd_work(opt, GREP_SOURCE_SHA1, pathbuf.buf, path, oid);\n \t\tstrbuf_release(&pathbuf);\n \t\treturn 0;\n \t} else\n@@ -315,7 +315,7 @@ static int grep_sha1(struct grep_opt *opt, const unsigned char *sha1,\n \t\tstruct grep_source gs;\n \t\tint hit;\n \n-\t\tgrep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, sha1);\n+\t\tgrep_source_init(&gs, GREP_SOURCE_SHA1, pathbuf.buf, path, oid);\n \t\tstrbuf_release(&pathbuf);\n \t\thit = grep_source(opt, &gs);\n \n@@ -398,7 +398,7 @@ 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->oid.hash, ce->name, 0,\n+\t\t\thit |= grep_oid(opt, &ce->oid, ce->name, 0,\n \t\t\t\t\t ce->name);\n \t\t}\n \t\telse\n@@ -439,7 +439,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\tstrbuf_add(base, entry.path, te_len);\n \n \t\tif (S_ISREG(entry.mode)) {\n-\t\t\thit |= grep_sha1(opt, entry.oid->hash, base->buf, tn_len,\n+\t\t\thit |= grep_oid(opt, entry.oid, base->buf, tn_len,\n \t\t\t\t\t check_attr ? base->buf + tn_len : NULL);\n \t\t}\n \t\telse if (S_ISDIR(entry.mode)) {\n@@ -448,7 +448,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\t\tvoid *data;\n \t\t\tunsigned long size;\n \n-\t\t\tdata = lock_and_read_sha1_file(entry.oid->hash, &type, &size);\n+\t\t\tdata = lock_and_read_oid_file(entry.oid, &type, &size);\n \t\t\tif (!data)\n \t\t\t\tdie(_(\"unable to read tree (%s)\"),\n \t\t\t\t    oid_to_hex(entry.oid));\n@@ -471,7 +471,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\t       struct object *obj, const char *name, const char *path)\n {\n \tif (obj->type == OBJ_BLOB)\n-\t\treturn grep_sha1(opt, obj->oid.hash, name, 0, path);\n+\t\treturn grep_oid(opt, &obj->oid, name, 0, path);\n \tif (obj->type == OBJ_COMMIT || obj->type == OBJ_TREE) {\n \t\tstruct tree_desc tree;\n \t\tvoid *data;\n@@ -820,11 +820,11 @@ int cmd_grep(int argc, const char **argv, const char *prefix)\n \t/* Check revs and then paths */\n \tfor (i = 0; i < argc; i++) {\n \t\tconst char *arg = argv[i];\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tstruct object_context oc;\n \t\t/* Is it a rev? */\n-\t\tif (!get_sha1_with_context(arg, 0, sha1, &oc)) {\n-\t\t\tstruct object *object = parse_object_or_die(sha1, arg);\n+\t\tif (!get_sha1_with_context(arg, 0, oid.hash, &oc)) {\n+\t\t\tstruct object *object = parse_object_or_die(oid.hash, arg);\n \t\t\tif (!seen_dashdash)\n \t\t\t\tverify_non_filename(prefix, arg);\n \t\t\tadd_object_array_with_path(object, arg, &list, oc.mode, oc.path);\n-- \n2.11.0\n\n"},{"id":"308597","messageId":"20170101191847.564741-3-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 02/17] builtin/diff-tree: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:32Z","receivedAt":"2017-01-01T19:20:24Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert most leaf functions to struct object_id.  Rewrite several\nhardcoded numbers in terms of GIT_SHA1_HEXSZ, using an intermediate\nvariable where that makes sense.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/diff-tree.c | 38 ++++++++++++++++++++------------------\n 1 file changed, 20 insertions(+), 18 deletions(-)\n\ndiff --git a/builtin/diff-tree.c b/builtin/diff-tree.c\nindex 806dd7a88..516860e4f 100644\n--- a/builtin/diff-tree.c\n+++ b/builtin/diff-tree.c\n@@ -7,9 +7,9 @@\n \n static struct rev_info log_tree_opt;\n \n-static int diff_tree_commit_sha1(const unsigned char *sha1)\n+static int diff_tree_commit_sha1(const struct object_id *oid)\n {\n-\tstruct commit *commit = lookup_commit_reference(sha1);\n+\tstruct commit *commit = lookup_commit_reference(oid->hash);\n \tif (!commit)\n \t\treturn -1;\n \treturn log_tree_commit(&log_tree_opt, commit);\n@@ -18,22 +18,22 @@ static int diff_tree_commit_sha1(const unsigned char *sha1)\n /* Diff one or more commits. */\n static int stdin_diff_commit(struct commit *commit, char *line, int len)\n {\n-\tunsigned char sha1[20];\n-\tif (isspace(line[40]) && !get_sha1_hex(line+41, sha1)) {\n+\tstruct object_id oid;\n+\tif (isspace(line[GIT_SHA1_HEXSZ]) && !get_oid_hex(line+GIT_SHA1_HEXSZ+1, &oid)) {\n \t\t/* Graft the fake parents locally to the commit */\n-\t\tint pos = 41;\n+\t\tint pos = GIT_SHA1_HEXSZ + 1;\n \t\tstruct commit_list **pptr;\n \n \t\t/* Free the real parent list */\n \t\tfree_commit_list(commit->parents);\n \t\tcommit->parents = NULL;\n \t\tpptr = &(commit->parents);\n-\t\twhile (line[pos] && !get_sha1_hex(line + pos, sha1)) {\n-\t\t\tstruct commit *parent = lookup_commit(sha1);\n+\t\twhile (line[pos] && !get_oid_hex(line + pos, &oid)) {\n+\t\t\tstruct commit *parent = lookup_commit(oid.hash);\n \t\t\tif (parent) {\n \t\t\t\tpptr = &commit_list_insert(parent, pptr)->next;\n \t\t\t}\n-\t\t\tpos += 41;\n+\t\t\tpos += GIT_SHA1_HEXSZ + 1;\n \t\t}\n \t}\n \treturn log_tree_commit(&log_tree_opt, commit);\n@@ -42,11 +42,13 @@ static int stdin_diff_commit(struct commit *commit, char *line, int len)\n /* Diff two trees. */\n static int stdin_diff_trees(struct tree *tree1, char *line, int len)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstruct tree *tree2;\n-\tif (len != 82 || !isspace(line[40]) || get_sha1_hex(line + 41, sha1))\n+\tconst int chunksz = GIT_SHA1_HEXSZ + 1;\n+\tif (len != 2 * chunksz || !isspace(line[chunksz-1]) ||\n+\t\tget_sha1_hex(line + chunksz, oid.hash))\n \t\treturn error(\"Need exactly two trees, separated by a space\");\n-\ttree2 = lookup_tree(sha1);\n+\ttree2 = lookup_tree(oid.hash);\n \tif (!tree2 || parse_tree(tree2))\n \t\treturn -1;\n \tprintf(\"%s %s\\n\", oid_to_hex(&tree1->object.oid),\n@@ -60,15 +62,15 @@ static int stdin_diff_trees(struct tree *tree1, char *line, int len)\n static int diff_tree_stdin(char *line)\n {\n \tint len = strlen(line);\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstruct object *obj;\n \n \tif (!len || line[len-1] != '\\n')\n \t\treturn -1;\n \tline[len-1] = 0;\n-\tif (get_sha1_hex(line, sha1))\n+\tif (get_oid_hex(line, &oid))\n \t\treturn -1;\n-\tobj = parse_object(sha1);\n+\tobj = parse_object(oid.hash);\n \tif (!obj)\n \t\treturn -1;\n \tif (obj->type == OBJ_COMMIT)\n@@ -76,7 +78,7 @@ static int diff_tree_stdin(char *line)\n \tif (obj->type == OBJ_TREE)\n \t\treturn stdin_diff_trees((struct tree *)obj, line, len);\n \terror(\"Object %s is a %s, not a commit or tree\",\n-\t      sha1_to_hex(sha1), typename(obj->type));\n+\t      oid_to_hex(&oid), typename(obj->type));\n \treturn -1;\n }\n \n@@ -141,7 +143,7 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \t\tbreak;\n \tcase 1:\n \t\ttree1 = opt->pending.objects[0].item;\n-\t\tdiff_tree_commit_sha1(tree1->oid.hash);\n+\t\tdiff_tree_commit_sha1(&tree1->oid);\n \t\tbreak;\n \tcase 2:\n \t\ttree1 = opt->pending.objects[0].item;\n@@ -166,9 +168,9 @@ int cmd_diff_tree(int argc, const char **argv, const char *prefix)\n \t\t\topt->diffopt.setup |= (DIFF_SETUP_USE_SIZE_CACHE |\n \t\t\t\t\t       DIFF_SETUP_USE_CACHE);\n \t\twhile (fgets(line, sizeof(line), stdin)) {\n-\t\t\tunsigned char sha1[20];\n+\t\t\tstruct object_id oid;\n \n-\t\t\tif (get_sha1_hex(line, sha1)) {\n+\t\t\tif (get_oid_hex(line, &oid)) {\n \t\t\t\tfputs(line, stdout);\n \t\t\t\tfflush(stdout);\n \t\t\t}\n-- \n2.11.0\n\n"},{"id":"308598","messageId":"20170101191847.564741-6-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 05/17] builtin/fmt-merge-message: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:35Z","receivedAt":"2017-01-01T19:20:27Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert most of the code to use struct object_id, including struct\norigin_data and struct merge_parents.  Convert several instances of\nhardcoded numbers into references to GIT_SHA1_HEXSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/fmt-merge-msg.c | 70 ++++++++++++++++++++++++-------------------------\n 1 file changed, 35 insertions(+), 35 deletions(-)\n\ndiff --git a/builtin/fmt-merge-msg.c b/builtin/fmt-merge-msg.c\nindex efab62fd8..6faa3c0d2 100644\n--- a/builtin/fmt-merge-msg.c\n+++ b/builtin/fmt-merge-msg.c\n@@ -41,7 +41,7 @@ struct src_data {\n };\n \n struct origin_data {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tunsigned is_local_branch:1;\n };\n \n@@ -59,8 +59,8 @@ static struct string_list origins = STRING_LIST_INIT_DUP;\n struct merge_parents {\n \tint alloc, nr;\n \tstruct merge_parent {\n-\t\tunsigned char given[20];\n-\t\tunsigned char commit[20];\n+\t\tstruct object_id given;\n+\t\tstruct object_id commit;\n \t\tunsigned char used;\n \t} *item;\n };\n@@ -70,14 +70,14 @@ struct merge_parents {\n  * hundreds of heads at a time anyway.\n  */\n static struct merge_parent *find_merge_parent(struct merge_parents *table,\n-\t\t\t\t\t      unsigned char *given,\n-\t\t\t\t\t      unsigned char *commit)\n+\t\t\t\t\t      struct object_id *given,\n+\t\t\t\t\t      struct object_id *commit)\n {\n \tint i;\n \tfor (i = 0; i < table->nr; i++) {\n-\t\tif (given && hashcmp(table->item[i].given, given))\n+\t\tif (given && oidcmp(&table->item[i].given, given))\n \t\t\tcontinue;\n-\t\tif (commit && hashcmp(table->item[i].commit, commit))\n+\t\tif (commit && oidcmp(&table->item[i].commit, commit))\n \t\t\tcontinue;\n \t\treturn &table->item[i];\n \t}\n@@ -85,14 +85,14 @@ static struct merge_parent *find_merge_parent(struct merge_parents *table,\n }\n \n static void add_merge_parent(struct merge_parents *table,\n-\t\t\t     unsigned char *given,\n-\t\t\t     unsigned char *commit)\n+\t\t\t     struct object_id *given,\n+\t\t\t     struct object_id *commit)\n {\n \tif (table->nr && find_merge_parent(table, given, commit))\n \t\treturn;\n \tALLOC_GROW(table->item, table->nr + 1, table->alloc);\n-\thashcpy(table->item[table->nr].given, given);\n-\thashcpy(table->item[table->nr].commit, commit);\n+\toidcpy(&table->item[table->nr].given, given);\n+\toidcpy(&table->item[table->nr].commit, commit);\n \ttable->item[table->nr].used = 0;\n \ttable->nr++;\n }\n@@ -106,30 +106,30 @@ static int handle_line(char *line, struct merge_parents *merge_parents)\n \tstruct src_data *src_data;\n \tstruct string_list_item *item;\n \tint pulling_head = 0;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \n-\tif (len < 43 || line[40] != '\\t')\n+\tif (len < GIT_SHA1_HEXSZ + 3 || line[GIT_SHA1_HEXSZ] != '\\t')\n \t\treturn 1;\n \n-\tif (starts_with(line + 41, \"not-for-merge\"))\n+\tif (starts_with(line + GIT_SHA1_HEXSZ + 1, \"not-for-merge\"))\n \t\treturn 0;\n \n-\tif (line[41] != '\\t')\n+\tif (line[GIT_SHA1_HEXSZ + 1] != '\\t')\n \t\treturn 2;\n \n-\ti = get_sha1_hex(line, sha1);\n+\ti = get_oid_hex(line, &oid);\n \tif (i)\n \t\treturn 3;\n \n-\tif (!find_merge_parent(merge_parents, sha1, NULL))\n+\tif (!find_merge_parent(merge_parents, &oid, NULL))\n \t\treturn 0; /* subsumed by other parents */\n \n \torigin_data = xcalloc(1, sizeof(struct origin_data));\n-\thashcpy(origin_data->sha1, sha1);\n+\toidcpy(&origin_data->oid, &oid);\n \n \tif (line[len - 1] == '\\n')\n \t\tline[len - 1] = 0;\n-\tline += 42;\n+\tline += GIT_SHA1_HEXSZ + 2;\n \n \t/*\n \t * At this point, line points at the beginning of comment e.g.\n@@ -338,10 +338,10 @@ static void shortlog(const char *name,\n \tstruct string_list committers = STRING_LIST_INIT_DUP;\n \tint flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;\n \tstruct strbuf sb = STRBUF_INIT;\n-\tconst unsigned char *sha1 = origin_data->sha1;\n+\tconst struct object_id *oid = &origin_data->oid;\n \tint limit = opts->shortlog_len;\n \n-\tbranch = deref_tag(parse_object(sha1), sha1_to_hex(sha1), 40);\n+\tbranch = deref_tag(parse_object(oid->hash), oid_to_hex(oid), GIT_SHA1_HEXSZ);\n \tif (!branch || branch->type != OBJ_COMMIT)\n \t\treturn;\n \n@@ -531,7 +531,7 @@ static void fmt_merge_msg_sigs(struct strbuf *out)\n }\n \n static void find_merge_parents(struct merge_parents *result,\n-\t\t\t       struct strbuf *in, unsigned char *head)\n+\t\t\t       struct strbuf *in, struct object_id *head)\n {\n \tstruct commit_list *parents;\n \tstruct commit *head_commit;\n@@ -542,31 +542,31 @@ static void find_merge_parents(struct merge_parents *result,\n \t\tint len;\n \t\tchar *p = in->buf + pos;\n \t\tchar *newline = strchr(p, '\\n');\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tstruct commit *parent;\n \t\tstruct object *obj;\n \n \t\tlen = newline ? newline - p : strlen(p);\n \t\tpos += len + !!newline;\n \n-\t\tif (len < 43 ||\n-\t\t    get_sha1_hex(p, sha1) ||\n-\t\t    p[40] != '\\t' ||\n-\t\t    p[41] != '\\t')\n+\t\tif (len < GIT_SHA1_HEXSZ + 3 ||\n+\t\t    get_oid_hex(p, &oid) ||\n+\t\t    p[GIT_SHA1_HEXSZ] != '\\t' ||\n+\t\t    p[GIT_SHA1_HEXSZ + 1] != '\\t')\n \t\t\tcontinue; /* skip not-for-merge */\n \t\t/*\n \t\t * Do not use get_merge_parent() here; we do not have\n \t\t * \"name\" here and we do not want to contaminate its\n \t\t * util field yet.\n \t\t */\n-\t\tobj = parse_object(sha1);\n+\t\tobj = parse_object(oid.hash);\n \t\tparent = (struct commit *)peel_to_type(NULL, 0, obj, OBJ_COMMIT);\n \t\tif (!parent)\n \t\t\tcontinue;\n \t\tcommit_list_insert(parent, &parents);\n-\t\tadd_merge_parent(result, obj->oid.hash, parent->object.oid.hash);\n+\t\tadd_merge_parent(result, &obj->oid, &parent->object.oid);\n \t}\n-\thead_commit = lookup_commit(head);\n+\thead_commit = lookup_commit(head->hash);\n \tif (head_commit)\n \t\tcommit_list_insert(head_commit, &parents);\n \tparents = reduce_heads(parents);\n@@ -574,7 +574,7 @@ static void find_merge_parents(struct merge_parents *result,\n \twhile (parents) {\n \t\tstruct commit *cmit = pop_commit(&parents);\n \t\tfor (i = 0; i < result->nr; i++)\n-\t\t\tif (!hashcmp(result->item[i].commit, cmit->object.oid.hash))\n+\t\t\tif (!oidcmp(&result->item[i].commit, &cmit->object.oid))\n \t\t\t\tresult->item[i].used = 1;\n \t}\n \n@@ -592,7 +592,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,\n \t\t  struct fmt_merge_msg_opts *opts)\n {\n \tint i = 0, pos = 0;\n-\tunsigned char head_sha1[20];\n+\tstruct object_id head_oid;\n \tconst char *current_branch;\n \tvoid *current_branch_to_free;\n \tstruct merge_parents merge_parents;\n@@ -601,13 +601,13 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,\n \n \t/* get current branch */\n \tcurrent_branch = current_branch_to_free =\n-\t\tresolve_refdup(\"HEAD\", RESOLVE_REF_READING, head_sha1, NULL);\n+\t\tresolve_refdup(\"HEAD\", RESOLVE_REF_READING, head_oid.hash, NULL);\n \tif (!current_branch)\n \t\tdie(\"No current branch\");\n \tif (starts_with(current_branch, \"refs/heads/\"))\n \t\tcurrent_branch += 11;\n \n-\tfind_merge_parents(&merge_parents, in, head_sha1);\n+\tfind_merge_parents(&merge_parents, in, &head_oid);\n \n \t/* get a line */\n \twhile (pos < in->len) {\n@@ -633,7 +633,7 @@ int fmt_merge_msg(struct strbuf *in, struct strbuf *out,\n \t\tstruct commit *head;\n \t\tstruct rev_info rev;\n \n-\t\thead = lookup_commit_or_die(head_sha1, \"HEAD\");\n+\t\thead = lookup_commit_or_die(head_oid.hash, \"HEAD\");\n \t\tinit_revisions(&rev, NULL);\n \t\trev.commit_format = CMIT_FMT_ONELINE;\n \t\trev.ignore_merges = 1;\n-- \n2.11.0\n\n"},{"id":"308599","messageId":"20170101191847.564741-5-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 04/17] builtin/fast-export: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:34Z","receivedAt":"2017-01-01T19:20:29Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"In addition to converting to struct object_id, write some hardcoded\nbuffer sizes in terms of GIT_SHA1_RAWSZ.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/fast-export.c | 58 +++++++++++++++++++++++++--------------------------\n 1 file changed, 29 insertions(+), 29 deletions(-)\n\ndiff --git a/builtin/fast-export.c b/builtin/fast-export.c\nindex 1e815b557..e0220630d 100644\n--- a/builtin/fast-export.c\n+++ b/builtin/fast-export.c\n@@ -212,7 +212,7 @@ static char *anonymize_blob(unsigned long *size)\n \treturn strbuf_detach(&out, NULL);\n }\n \n-static void export_blob(const unsigned char *sha1)\n+static void export_blob(const struct object_id *oid)\n {\n \tunsigned long size;\n \tenum object_type type;\n@@ -223,34 +223,34 @@ static void export_blob(const unsigned char *sha1)\n \tif (no_data)\n \t\treturn;\n \n-\tif (is_null_sha1(sha1))\n+\tif (is_null_oid(oid))\n \t\treturn;\n \n-\tobject = lookup_object(sha1);\n+\tobject = lookup_object(oid->hash);\n \tif (object && object->flags & SHOWN)\n \t\treturn;\n \n \tif (anonymize) {\n \t\tbuf = anonymize_blob(&size);\n-\t\tobject = (struct object *)lookup_blob(sha1);\n+\t\tobject = (struct object *)lookup_blob(oid->hash);\n \t\teaten = 0;\n \t} else {\n-\t\tbuf = read_sha1_file(sha1, &type, &size);\n+\t\tbuf = read_sha1_file(oid->hash, &type, &size);\n \t\tif (!buf)\n-\t\t\tdie (\"Could not read blob %s\", sha1_to_hex(sha1));\n-\t\tif (check_sha1_signature(sha1, buf, size, typename(type)) < 0)\n-\t\t\tdie(\"sha1 mismatch in blob %s\", sha1_to_hex(sha1));\n-\t\tobject = parse_object_buffer(sha1, type, size, buf, &eaten);\n+\t\t\tdie (\"Could not read blob %s\", oid_to_hex(oid));\n+\t\tif (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)\n+\t\t\tdie(\"sha1 mismatch in blob %s\", oid_to_hex(oid));\n+\t\tobject = parse_object_buffer(oid->hash, type, size, buf, &eaten);\n \t}\n \n \tif (!object)\n-\t\tdie(\"Could not read blob %s\", sha1_to_hex(sha1));\n+\t\tdie(\"Could not read blob %s\", oid_to_hex(oid));\n \n \tmark_next_object(object);\n \n \tprintf(\"blob\\nmark :%\"PRIu32\"\\ndata %lu\\n\", last_idnum, size);\n \tif (size && fwrite(buf, size, 1, stdout) != 1)\n-\t\tdie_errno (\"Could not write blob '%s'\", sha1_to_hex(sha1));\n+\t\tdie_errno (\"Could not write blob '%s'\", oid_to_hex(oid));\n \tprintf(\"\\n\");\n \n \tshow_progress();\n@@ -323,19 +323,19 @@ static void print_path(const char *path)\n \t}\n }\n \n-static void *generate_fake_sha1(const void *old, size_t *len)\n+static void *generate_fake_oid(const void *old, size_t *len)\n {\n \tstatic uint32_t counter = 1; /* avoid null sha1 */\n-\tunsigned char *out = xcalloc(20, 1);\n-\tput_be32(out + 16, counter++);\n+\tunsigned char *out = xcalloc(GIT_SHA1_RAWSZ, 1);\n+\tput_be32(out + GIT_SHA1_RAWSZ - 4, counter++);\n \treturn out;\n }\n \n-static const unsigned char *anonymize_sha1(const unsigned char *sha1)\n+static const unsigned char *anonymize_sha1(const struct object_id *oid)\n {\n \tstatic struct hashmap sha1s;\n-\tsize_t len = 20;\n-\treturn anonymize_mem(&sha1s, generate_fake_sha1, sha1, &len);\n+\tsize_t len = GIT_SHA1_RAWSZ;\n+\treturn anonymize_mem(&sha1s, generate_fake_oid, oid, &len);\n }\n \n static void show_filemodify(struct diff_queue_struct *q,\n@@ -383,7 +383,7 @@ static void show_filemodify(struct diff_queue_struct *q,\n \t\t\tif (no_data || S_ISGITLINK(spec->mode))\n \t\t\t\tprintf(\"M %06o %s \", spec->mode,\n \t\t\t\t       sha1_to_hex(anonymize ?\n-\t\t\t\t\t\t   anonymize_sha1(spec->oid.hash) :\n+\t\t\t\t\t\t   anonymize_sha1(&spec->oid) :\n \t\t\t\t\t\t   spec->oid.hash));\n \t\t\telse {\n \t\t\t\tstruct object *object = lookup_object(spec->oid.hash);\n@@ -572,7 +572,7 @@ static void handle_commit(struct commit *commit, struct rev_info *rev)\n \t/* Export the referenced blobs, and remember the marks. */\n \tfor (i = 0; i < diff_queued_diff.nr; i++)\n \t\tif (!S_ISGITLINK(diff_queued_diff.queue[i]->two->mode))\n-\t\t\texport_blob(diff_queued_diff.queue[i]->two->oid.hash);\n+\t\t\texport_blob(&diff_queued_diff.queue[i]->two->oid);\n \n \trefname = commit->util;\n \tif (anonymize) {\n@@ -797,14 +797,14 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)\n \n \tfor (i = 0; i < info->nr; i++) {\n \t\tstruct rev_cmdline_entry *e = info->rev + i;\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tstruct commit *commit;\n \t\tchar *full_name;\n \n \t\tif (e->flags & UNINTERESTING)\n \t\t\tcontinue;\n \n-\t\tif (dwim_ref(e->name, strlen(e->name), sha1, &full_name) != 1)\n+\t\tif (dwim_ref(e->name, strlen(e->name), oid.hash, &full_name) != 1)\n \t\t\tcontinue;\n \n \t\tif (refspecs) {\n@@ -828,7 +828,7 @@ static void get_tags_and_duplicates(struct rev_cmdline_info *info)\n \t\tcase OBJ_COMMIT:\n \t\t\tbreak;\n \t\tcase OBJ_BLOB:\n-\t\t\texport_blob(commit->object.oid.hash);\n+\t\t\texport_blob(&commit->object.oid);\n \t\t\tcontinue;\n \t\tdefault: /* OBJ_TAG (nested tags) is already handled */\n \t\t\twarning(\"Tag points to object of unexpected type %s, skipping.\",\n@@ -912,7 +912,7 @@ static void import_marks(char *input_file)\n \twhile (fgets(line, sizeof(line), f)) {\n \t\tuint32_t mark;\n \t\tchar *line_end, *mark_end;\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tstruct object *object;\n \t\tstruct commit *commit;\n \t\tenum object_type type;\n@@ -924,28 +924,28 @@ static void import_marks(char *input_file)\n \n \t\tmark = strtoumax(line + 1, &mark_end, 10);\n \t\tif (!mark || mark_end == line + 1\n-\t\t\t|| *mark_end != ' ' || get_sha1_hex(mark_end + 1, sha1))\n+\t\t\t|| *mark_end != ' ' || get_oid_hex(mark_end + 1, &oid))\n \t\t\tdie(\"corrupt mark line: %s\", line);\n \n \t\tif (last_idnum < mark)\n \t\t\tlast_idnum = mark;\n \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(\"object not found: %s\", sha1_to_hex(sha1));\n+\t\t\tdie(\"object not found: %s\", oid_to_hex(&oid));\n \n \t\tif (type != OBJ_COMMIT)\n \t\t\t/* only commits */\n \t\t\tcontinue;\n \n-\t\tcommit = lookup_commit(sha1);\n+\t\tcommit = lookup_commit(oid.hash);\n \t\tif (!commit)\n-\t\t\tdie(\"not a commit? can't happen: %s\", sha1_to_hex(sha1));\n+\t\t\tdie(\"not a commit? can't happen: %s\", oid_to_hex(&oid));\n \n \t\tobject = &commit->object;\n \n \t\tif (object->flags & SHOWN)\n-\t\t\terror(\"Object %s already has a mark\", sha1_to_hex(sha1));\n+\t\t\terror(\"Object %s already has a mark\", oid_to_hex(&oid));\n \n \t\tmark_object(object, mark);\n \n-- \n2.11.0\n\n"},{"id":"308600","messageId":"20170101191847.564741-2-sandals@crustytoothpaste.net","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"[PATCH 01/17] builtin/commit: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-01-01T19:18:31Z","receivedAt":"2017-01-01T19:20:30Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert most leaf functions to use struct object_id.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/commit.c | 46 +++++++++++++++++++++++-----------------------\n 1 file changed, 23 insertions(+), 23 deletions(-)\n\ndiff --git a/builtin/commit.c b/builtin/commit.c\nindex 711f96cc4..6597d01f7 100644\n--- a/builtin/commit.c\n+++ b/builtin/commit.c\n@@ -496,7 +496,7 @@ static const char *prepare_index(int argc, const char **argv, const char *prefix\n static int run_status(FILE *fp, const char *index_file, const char *prefix, int nowarn,\n \t\t      struct wt_status *s)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \n \tif (s->relative_paths)\n \t\ts->prefix = prefix;\n@@ -509,9 +509,9 @@ static int run_status(FILE *fp, const char *index_file, const char *prefix, int\n \ts->index_file = index_file;\n \ts->fp = fp;\n \ts->nowarn = nowarn;\n-\ts->is_initial = get_sha1(s->reference, sha1) ? 1 : 0;\n+\ts->is_initial = get_sha1(s->reference, oid.hash) ? 1 : 0;\n \tif (!s->is_initial)\n-\t\thashcpy(s->sha1_commit, sha1);\n+\t\thashcpy(s->sha1_commit, oid.hash);\n \ts->status_format = status_format;\n \ts->ignore_submodule_arg = ignore_submodule_arg;\n \n@@ -885,7 +885,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\tcommitable = run_status(s->fp, index_file, prefix, 1, s);\n \t\ts->use_color = saved_color_setting;\n \t} else {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tconst char *parent = \"HEAD\";\n \n \t\tif (!active_nr && read_cache() < 0)\n@@ -894,7 +894,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix,\n \t\tif (amend)\n \t\t\tparent = \"HEAD^1\";\n \n-\t\tif (get_sha1(parent, sha1)) {\n+\t\tif (get_sha1(parent, oid.hash)) {\n \t\t\tint i, ita_nr = 0;\n \n \t\t\tfor (i = 0; i < active_nr; i++)\n@@ -1332,7 +1332,7 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n {\n \tstatic struct wt_status s;\n \tint fd;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstatic struct option builtin_status_options[] = {\n \t\tOPT__VERBOSE(&verbose, N_(\"be verbose\")),\n \t\tOPT_SET_INT('s', \"short\", &status_format,\n@@ -1382,9 +1382,9 @@ int cmd_status(int argc, const char **argv, const char *prefix)\n \n \tfd = hold_locked_index(&index_lock, 0);\n \n-\ts.is_initial = get_sha1(s.reference, sha1) ? 1 : 0;\n+\ts.is_initial = get_sha1(s.reference, oid.hash) ? 1 : 0;\n \tif (!s.is_initial)\n-\t\thashcpy(s.sha1_commit, sha1);\n+\t\thashcpy(s.sha1_commit, oid.hash);\n \n \ts.ignore_submodule_arg = ignore_submodule_arg;\n \ts.status_format = status_format;\n@@ -1418,19 +1418,19 @@ static const char *implicit_ident_advice(void)\n \n }\n \n-static void print_summary(const char *prefix, const unsigned char *sha1,\n+static void print_summary(const char *prefix, const struct object_id *oid,\n \t\t\t  int initial_commit)\n {\n \tstruct rev_info rev;\n \tstruct commit *commit;\n \tstruct strbuf format = STRBUF_INIT;\n-\tunsigned char junk_sha1[20];\n+\tstruct object_id junk_oid;\n \tconst char *head;\n \tstruct pretty_print_context pctx = {0};\n \tstruct strbuf author_ident = STRBUF_INIT;\n \tstruct strbuf committer_ident = STRBUF_INIT;\n \n-\tcommit = lookup_commit(sha1);\n+\tcommit = lookup_commit(oid->hash);\n \tif (!commit)\n \t\tdie(_(\"couldn't look up newly created commit\"));\n \tif (parse_commit(commit))\n@@ -1477,7 +1477,7 @@ static void print_summary(const char *prefix, const unsigned char *sha1,\n \trev.diffopt.break_opt = 0;\n \tdiff_setup_done(&rev.diffopt);\n \n-\thead = resolve_ref_unsafe(\"HEAD\", 0, junk_sha1, NULL);\n+\thead = resolve_ref_unsafe(\"HEAD\", 0, junk_oid.hash, NULL);\n \tif (!strcmp(head, \"HEAD\"))\n \t\thead = _(\"detached HEAD\");\n \telse\n@@ -1522,8 +1522,8 @@ static int git_commit_config(const char *k, const char *v, void *cb)\n \treturn git_status_config(k, v, s);\n }\n \n-static int run_rewrite_hook(const unsigned char *oldsha1,\n-\t\t\t    const unsigned char *newsha1)\n+static int run_rewrite_hook(const struct object_id *oldoid,\n+\t\t\t    const struct object_id *newoid)\n {\n \t/* oldsha1 SP newsha1 LF NUL */\n \tstatic char buf[2*40 + 3];\n@@ -1547,7 +1547,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1,\n \tif (code)\n \t\treturn code;\n \tn = snprintf(buf, sizeof(buf), \"%s %s\\n\",\n-\t\t     sha1_to_hex(oldsha1), sha1_to_hex(newsha1));\n+\t\t     oid_to_hex(oldoid), oid_to_hex(newoid));\n \tsigchain_push(SIGPIPE, SIG_IGN);\n \twrite_in_full(proc.in, buf, n);\n \tclose(proc.in);\n@@ -1639,7 +1639,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \tstruct strbuf author_ident = STRBUF_INIT;\n \tconst char *index_file, *reflog_msg;\n \tchar *nl;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tstruct commit_list *parents = NULL;\n \tstruct stat statbuf;\n \tstruct commit *current_head = NULL;\n@@ -1654,10 +1654,10 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \tstatus_format = STATUS_FORMAT_NONE; /* Ignore status.short */\n \ts.colopts = 0;\n \n-\tif (get_sha1(\"HEAD\", sha1))\n+\tif (get_sha1(\"HEAD\", oid.hash))\n \t\tcurrent_head = NULL;\n \telse {\n-\t\tcurrent_head = lookup_commit_or_die(sha1, \"HEAD\");\n+\t\tcurrent_head = lookup_commit_or_die(oid.hash, \"HEAD\");\n \t\tif (parse_commit(current_head))\n \t\t\tdie(_(\"could not parse HEAD commit\"));\n \t}\n@@ -1762,7 +1762,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (commit_tree_extended(sb.buf, sb.len, active_cache_tree->sha1,\n-\t\t\t parents, sha1, author_ident.buf, sign_commit, extra)) {\n+\t\t\t parents, oid.hash, author_ident.buf, sign_commit, extra)) {\n \t\trollback_index_files();\n \t\tdie(_(\"failed to write commit object\"));\n \t}\n@@ -1779,7 +1779,7 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \n \ttransaction = ref_transaction_begin(&err);\n \tif (!transaction ||\n-\t    ref_transaction_update(transaction, \"HEAD\", sha1,\n+\t    ref_transaction_update(transaction, \"HEAD\", oid.hash,\n \t\t\t\t   current_head\n \t\t\t\t   ? current_head->object.oid.hash : null_sha1,\n \t\t\t\t   0, sb.buf, &err) ||\n@@ -1808,13 +1808,13 @@ int cmd_commit(int argc, const char **argv, const char *prefix)\n \t\tcfg = init_copy_notes_for_rewrite(\"amend\");\n \t\tif (cfg) {\n \t\t\t/* we are amending, so current_head is not NULL */\n-\t\t\tcopy_note_for_rewrite(cfg, current_head->object.oid.hash, sha1);\n+\t\t\tcopy_note_for_rewrite(cfg, current_head->object.oid.hash, oid.hash);\n \t\t\tfinish_copy_notes_for_rewrite(cfg, \"Notes added by 'git commit --amend'\");\n \t\t}\n-\t\trun_rewrite_hook(current_head->object.oid.hash, sha1);\n+\t\trun_rewrite_hook(&current_head->object.oid, &oid);\n \t}\n \tif (!quiet)\n-\t\tprint_summary(prefix, sha1, !current_head);\n+\t\tprint_summary(prefix, &oid, !current_head);\n \n \tstrbuf_release(&err);\n \treturn 0;\n-- \n2.11.0\n\n"},{"id":"308624","messageId":"f6b59780-a76c-1e13-f983-c0cc767cc2b8@alum.mit.edu","threadId":"44802","inReplyTo":"20170101191847.564741-10-sandals@crustytoothpaste.net","subject":"Re: [PATCH 09/17] builtin/merge: convert to struct object_id","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-01-02T14:34:22Z","receivedAt":"2017-01-02T14:34:37Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/01/2017 08:18 PM, brian m. carlson wrote:\n> Additionally convert several uses of the constant 40 into\n> GIT_SHA1_HEXSZ.\n> \n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  builtin/merge.c | 136 ++++++++++++++++++++++++++++----------------------------\n>  1 file changed, 68 insertions(+), 68 deletions(-)\n> \n> [...]\n> @@ -437,25 +437,25 @@ static void merge_name(const char *remote, struct strbuf *msg)\n>  \tstrbuf_branchname(&bname, remote);\n>  \tremote = bname.buf;\n>  \n> -\tmemset(branch_head, 0, sizeof(branch_head));\n> +\tmemset(&branch_head, 0, sizeof(branch_head));\n\nI think this could be\n\n        oidclr(&branch_head);\n\n>  \tremote_head = get_merge_parent(remote);\n>  \tif (!remote_head)\n>  \t\tdie(_(\"'%s' does not point to a commit\"), remote);\n> [...]\n> @@ -1113,9 +1113,9 @@ static struct commit_list *collect_parents(struct commit *head_commit,\n>  \n>  int cmd_merge(int argc, const char **argv, const char *prefix)\n>  {\n> -\tunsigned char result_tree[20];\n> -\tunsigned char stash[20];\n> -\tunsigned char head_sha1[20];\n> +\tstruct object_id result_tree;\n> +\tstruct object_id stash;\n> +\tstruct object_id head_oid;\n\nThese could comfortably be declared on a single line now.\n\n>  \tstruct commit *head_commit;\n>  \tstruct strbuf buf = STRBUF_INIT;\n>  \tconst char *head_arg;\n> [...]\n\nMichael\n\n"},{"id":"308627","messageId":"49fcccfa-df28-c01b-0e51-1451ecf8e784@alum.mit.edu","threadId":"44802","inReplyTo":"20170101191847.564741-14-sandals@crustytoothpaste.net","subject":"Re: [PATCH 13/17] refs: convert each_reflog_ent_fn to struct object_id","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-01-02T15:07:16Z","receivedAt":"2017-01-02T15:07:34Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/01/2017 08:18 PM, brian m. carlson wrote:\n> Make each_reflog_ent_fn take two struct object_id pointers instead of\n> two pointers to unsigned char.  Convert the various callbacks to use\n> struct object_id as well.  Also, rename fsck_handle_reflog_sha1 to\n> fsck_handle_reflog_oid.\n> \n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  builtin/fsck.c       | 16 ++++++++--------\n>  builtin/merge-base.c |  6 +++---\n>  builtin/reflog.c     |  2 +-\n>  reflog-walk.c        |  6 +++---\n>  refs.c               | 24 ++++++++++++------------\n>  refs.h               |  2 +-\n>  refs/files-backend.c | 24 ++++++++++++------------\n>  revision.c           | 12 ++++++------\n>  sha1_name.c          |  2 +-\n>  wt-status.c          |  6 +++---\n>  10 files changed, 50 insertions(+), 50 deletions(-)\n> \n> [...]\n> diff --git a/refs/files-backend.c b/refs/files-backend.c\n> index f9023939d..3da3141ee 100644\n> --- a/refs/files-backend.c\n> +++ b/refs/files-backend.c\n> @@ -3113,15 +3113,15 @@ static int files_delete_reflog(struct ref_store *ref_store,\n>  \n>  static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *cb_data)\n>  {\n> -\tunsigned char osha1[20], nsha1[20];\n> +\tstruct object_id ooid, noid;\n>  \tchar *email_end, *message;\n>  \tunsigned long timestamp;\n>  \tint tz;\n>  \n>  \t/* old SP new SP name <email> SP time TAB msg LF */\n>  \tif (sb->len < 83 || sb->buf[sb->len - 1] != '\\n' ||\n> -\t    get_sha1_hex(sb->buf, osha1) || sb->buf[40] != ' ' ||\n> -\t    get_sha1_hex(sb->buf + 41, nsha1) || sb->buf[81] != ' ' ||\n> +\t    get_oid_hex(sb->buf, &ooid) || sb->buf[40] != ' ' ||\n> +\t    get_oid_hex(sb->buf + 41, &noid) || sb->buf[81] != ' ' ||\n\nSome magic numbers above could be converted to use constants.\n\n>  \t    !(email_end = strchr(sb->buf + 82, '>')) ||\n>  \t    email_end[1] != ' ' ||\n>  \t    !(timestamp = strtoul(email_end + 2, &message, 10)) ||\n> @@ -3136,7 +3136,7 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c\n>  \t\tmessage += 6;\n>  \telse\n>  \t\tmessage += 7;\n> -\treturn fn(osha1, nsha1, sb->buf + 82, timestamp, tz, message, cb_data);\n> +\treturn fn(&ooid, &noid, sb->buf + 82, timestamp, tz, message, cb_data);\n\nHere, too.\n\n>  }\n>  \n>  static char *find_beginning_of_line(char *bob, char *scan)\n> [...]\n> @@ -4047,14 +4047,14 @@ static int files_reflog_expire(struct ref_store *ref_store,\n>  \t\t */\n>  \t\tint update = (flags & EXPIRE_REFLOGS_UPDATE_REF) &&\n>  \t\t\t!(type & REF_ISSYMREF) &&\n> -\t\t\t!is_null_sha1(cb.last_kept_sha1);\n> +\t\t\t!is_null_oid(&cb.last_kept_oid);\n>  \n>  \t\tif (close_lock_file(&reflog_lock)) {\n>  \t\t\tstatus |= error(\"couldn't write %s: %s\", log_file,\n>  \t\t\t\t\tstrerror(errno));\n>  \t\t} else if (update &&\n>  \t\t\t   (write_in_full(get_lock_file_fd(lock->lk),\n> -\t\t\t\tsha1_to_hex(cb.last_kept_sha1), 40) != 40 ||\n> +\t\t\t\toid_to_hex(&cb.last_kept_oid), 40) != 40 ||\n\nMore magic numbers above.\n\n>  \t\t\t    write_str_in_full(get_lock_file_fd(lock->lk), \"\\n\") != 1 ||\n>  \t\t\t    close_ref(lock) < 0)) {\n>  \t\t\tstatus |= error(\"couldn't write %s\",\n> [...]\n\nI thought it would make sense to convert `struct read_ref_at_cb` in\n`refs.c` to use `struct object_id` at the same time, but I see that\nwould require the interface to `read_ref_at()` to change. I guess it's\nimportant to pick your battles in this campaign :-)\n\nMichael\n\n"},{"id":"308658","messageId":"8c205558-928d-42ac-d401-e73e19c96030@alum.mit.edu","threadId":"44802","inReplyTo":"20170101191847.564741-15-sandals@crustytoothpaste.net","subject":"Re: [PATCH 14/17] sha1_file: introduce an nth_packed_object_oid function","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-01-02T15:30:21Z","receivedAt":"2017-01-02T15:30:41Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/01/2017 08:18 PM, brian m. carlson wrote:\n> There are places in the code where we would like to provide a struct\n> object_id *, yet read the hash directly from the pack.  Provide an\n> nth_packed_object_oid function that mirrors the nth_packed_object_sha1\n> function.\n> \n> The required cast is questionable, but should be safe on all known\n> platforms.  The alternative of allocating an object as an intermediate\n> would be too inefficient and cause memory leaks.  If necessary, an\n> intermediate union could be used; this practice is allowed by GCC and\n> explicitly sanctioned by C11.  However, such a change will likely not be\n> necessary, and can be made if and when it is.\n\nI have the feeling that this design decision has been discussed on the\nmailing list. If so, could you include a URL here?\n\nThe obvious alternative to allocating a new object to return to the\ncaller would be to have the caller of `nth_packed_object_oid()` pass a\n`struct object_id *` argument to be filled in (by copying the hash into\nit). Aside from being legal C, this would also be a more robust step\ntowards a post-SHA-1 world, where the suggested hack wouldn't work.\n\nOf course, the question is what the callers want to do with the\n`object_id`. Are the return values of `nth_packed_object_sha1()` stored\nto other longer-lived structures that rely on the lifetime of the\npackfile mmap to keep the value valid? If so, then keeping track of the\nlifetime of the `struct object_id` could be a big chore, not to mention\nthat needing to keep a 20-byte `struct object_id` around rather than a\n8- or 4-byte pointer would also cost more RAM.\n\nAs you probably can tell, I'm not psyched about straying outside of\nlegal C. It would be nice to see more justification.\n\n> [...]\n\nMichael\n\n"},{"id":"308669","messageId":"4780c459-b40c-3b5c-e780-fd792a35ce8f@alum.mit.edu","threadId":"44802","inReplyTo":"20170101191847.564741-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH 00/17] object_id part 6","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-01-02T15:37:14Z","receivedAt":"2017-01-02T15:37:30Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/01/2017 08:18 PM, brian m. carlson wrote:\n> This is another series in the continuing conversion to struct object_id.\n> \n> This series converts more of the builtin directory and some of the\n> refs code to use struct object_id. Additionally, it implements an\n> nth_packed_object_oid function which provides a struct object_id\n> version of the nth_packed_object function.\n> \n> There is a small known conflict with next, but it can easily be fixed up.\n\nI read through all of the patches, and sent a few comments. I didn't\nnotice any other problems.\n\nMichael\n\n"},{"id":"308681","messageId":"20170102170902.6g6bxvaanewxzm2v@sigill.intra.peff.net","threadId":"44802","inReplyTo":"8c205558-928d-42ac-d401-e73e19c96030@alum.mit.edu","subject":"Re: [PATCH 14/17] sha1_file: introduce an nth_packed_object_oid function","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-01-02T17:09:02Z","receivedAt":"2017-01-02T17:09:16Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 02, 2017 at 04:30:21PM +0100, Michael Haggerty wrote:\n\n> On 01/01/2017 08:18 PM, brian m. carlson wrote:\n> > There are places in the code where we would like to provide a struct\n> > object_id *, yet read the hash directly from the pack.  Provide an\n> > nth_packed_object_oid function that mirrors the nth_packed_object_sha1\n> > function.\n> > \n> > The required cast is questionable, but should be safe on all known\n> > platforms.  The alternative of allocating an object as an intermediate\n> > would be too inefficient and cause memory leaks.  If necessary, an\n> > intermediate union could be used; this practice is allowed by GCC and\n> > explicitly sanctioned by C11.  However, such a change will likely not be\n> > necessary, and can be made if and when it is.\n> \n> I have the feeling that this design decision has been discussed on the\n> mailing list. If so, could you include a URL here?\n\nI don't recall an explicit discussion, but I think we already do this\nfor similar reasons in decode_tree_entry(), where we point to the sha1s\nembedded in the tree buffer (of course, you may argue that the cast\nthere is gross, too :) ).\n\nI'm actually not sure how bad this cast is by the C standard. Conversion\nbetween a struct and its first member is pretty common, and the\nalignment is guaranteed by the standard. I think it probably breaks\nstrict aliasing rules, but then so does \"struct object\". This is\nslightly more exotic in that it's not a struct-to-struct cast, and I\ncould believe that compilers treat those specially.\n\n> The obvious alternative to allocating a new object to return to the\n> caller would be to have the caller of `nth_packed_object_oid()` pass a\n> `struct object_id *` argument to be filled in (by copying the hash into\n> it). Aside from being legal C, this would also be a more robust step\n> towards a post-SHA-1 world, where the suggested hack wouldn't work.\n> \n> Of course, the question is what the callers want to do with the\n> `object_id`. Are the return values of `nth_packed_object_sha1()` stored\n> to other longer-lived structures that rely on the lifetime of the\n> packfile mmap to keep the value valid? If so, then keeping track of the\n> lifetime of the `struct object_id` could be a big chore, not to mention\n> that needing to keep a 20-byte `struct object_id` around rather than a\n> 8- or 4-byte pointer would also cost more RAM.\n\nI agree that in general, copying the values out is a safer and saner\ninterface. There are definitely lifetime and memory-use issues to\nconsider (e.g., the loop in verify_packfile()). And I'd have a slight\nworry that the performance impact might be noticeable, just because this\nis really quite a low-level function that gets called a lot (but of\ncourse measuring trumps everything there).\n\nBut I think the thing that gives me the most pause is that the oid\nversion of the function feels bolted-on. The nth_packed_object_sha1()\nfunction is there specifically to give access to the mmap'd pack-index\ndata. And at least for now, that only stores sha1s, not any kind of\nstruct. If and when it does learn about other hashes, I'm not sure if\nwe're going to want a generic nth_packed_object_oid() function, or if\nthe callers would need to handle the various cases specially.\n\nGiven that this patch only converts one caller, I'd be more inclined to\njust have the caller do its own hashcpy. Like:\n\ndiff --git a/sha1_file.c b/sha1_file.c\nindex 1173071859..16345688b5 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -3769,12 +3769,14 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c\n \n \tfor (i = 0; i < p->num_objects; i++) {\n \t\tconst unsigned char *sha1 = nth_packed_object_sha1(p, i);\n+\t\tstruct object_id oid;\n \n \t\tif (!sha1)\n \t\t\treturn error(\"unable to get sha1 of object %u in %s\",\n \t\t\t\t     i, p->pack_name);\n \n-\t\tr = cb(sha1, p, i, data);\n+\t\thashcpy(oid.hash, sha1);\n+\t\tr = cb(&oid, p, i, data);\n \t\tif (r)\n \t\t\tbreak;\n \t}\n\nThat punts on the issue for all the other callers, but like I said, I'm\nnot quite sure if, when, and how it would make sense to convert them to\nusing a \"struct oid\".\n\n-Peff\n"},{"id":"308685","messageId":"eb8a3dad-9ca7-e0e6-3c31-9cd2e02e0bf9@alum.mit.edu","threadId":"44802","inReplyTo":"20170102170902.6g6bxvaanewxzm2v@sigill.intra.peff.net","subject":"Re: [PATCH 14/17] sha1_file: introduce an nth_packed_object_oid function","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-01-02T18:18:58Z","receivedAt":"2017-01-02T18:20:32Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/02/2017 06:09 PM, Jeff King wrote:\n> [...]\n> But I think the thing that gives me the most pause is that the oid\n> version of the function feels bolted-on. The nth_packed_object_sha1()\n> function is there specifically to give access to the mmap'd pack-index\n> data. And at least for now, that only stores sha1s, not any kind of\n> struct. If and when it does learn about other hashes, I'm not sure if\n> we're going to want a generic nth_packed_object_oid() function, or if\n> the callers would need to handle the various cases specially.\n> \n> Given that this patch only converts one caller, I'd be more inclined to\n> just have the caller do its own hashcpy. Like:\n> \n> diff --git a/sha1_file.c b/sha1_file.c\n> index 1173071859..16345688b5 100644\n> --- a/sha1_file.c\n> +++ b/sha1_file.c\n> @@ -3769,12 +3769,14 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c\n>  \n>  \tfor (i = 0; i < p->num_objects; i++) {\n>  \t\tconst unsigned char *sha1 = nth_packed_object_sha1(p, i);\n> +\t\tstruct object_id oid;\n>  \n>  \t\tif (!sha1)\n>  \t\t\treturn error(\"unable to get sha1 of object %u in %s\",\n>  \t\t\t\t     i, p->pack_name);\n>  \n> -\t\tr = cb(sha1, p, i, data);\n> +\t\thashcpy(oid.hash, sha1);\n> +\t\tr = cb(&oid, p, i, data);\n>  \t\tif (r)\n>  \t\t\tbreak;\n>  \t}\n> \n> That punts on the issue for all the other callers, but like I said, I'm\n> not quite sure if, when, and how it would make sense to convert them to\n> using a \"struct oid\".\n\nYour change is not safe if any of the callback functions (\"cb\") tuck\naway a copy of the pointer that they are passed, expecting it to contain\nthe same object id later.\n\nMichael\n\n"},{"id":"308686","messageId":"20170102182226.6ddpmhmng2cqf4wf@sigill.intra.peff.net","threadId":"44802","inReplyTo":"eb8a3dad-9ca7-e0e6-3c31-9cd2e02e0bf9@alum.mit.edu","subject":"Re: [PATCH 14/17] sha1_file: introduce an nth_packed_object_oid function","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-01-02T18:22:26Z","receivedAt":"2017-01-02T18:23:46Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Mon, Jan 02, 2017 at 07:18:58PM +0100, Michael Haggerty wrote:\n\n> > Given that this patch only converts one caller, I'd be more inclined to\n> > just have the caller do its own hashcpy. Like:\n> > \n> > diff --git a/sha1_file.c b/sha1_file.c\n> > index 1173071859..16345688b5 100644\n> > --- a/sha1_file.c\n> > +++ b/sha1_file.c\n> > @@ -3769,12 +3769,14 @@ static int for_each_object_in_pack(struct packed_git *p, each_packed_object_fn c\n> >  \n> >  \tfor (i = 0; i < p->num_objects; i++) {\n> >  \t\tconst unsigned char *sha1 = nth_packed_object_sha1(p, i);\n> > +\t\tstruct object_id oid;\n> >  \n> >  \t\tif (!sha1)\n> >  \t\t\treturn error(\"unable to get sha1 of object %u in %s\",\n> >  \t\t\t\t     i, p->pack_name);\n> >  \n> > -\t\tr = cb(sha1, p, i, data);\n> > +\t\thashcpy(oid.hash, sha1);\n> > +\t\tr = cb(&oid, p, i, data);\n> >  \t\tif (r)\n> >  \t\t\tbreak;\n> >  \t}\n> > \n> > That punts on the issue for all the other callers, but like I said, I'm\n> > not quite sure if, when, and how it would make sense to convert them to\n> > using a \"struct oid\".\n> \n> Your change is not safe if any of the callback functions (\"cb\") tuck\n> away a copy of the pointer that they are passed, expecting it to contain\n> the same object id later.\n\nI think it's generally a given that callback functions should not assume\nthe lifetime of parameters extend beyond the end of the callback. That\nsaid, I didn't audit the callers (although I'm pretty sure I wrote all\nof them myself in this particular case).\n\n-Peff\n"},{"id":"308693","messageId":"d5fc2830-37c2-9274-77b7-97ecc5f9b763@alum.mit.edu","threadId":"44802","inReplyTo":"20170102191256.fjqsns3rgjyehzgp@genre.crustytoothpaste.net","subject":"Re: [PATCH 13/17] refs: convert each_reflog_ent_fn to struct object_id","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-01-02T23:30:40Z","receivedAt":"2017-01-02T23:34:05Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 01/02/2017 08:12 PM, brian m. carlson wrote:\n> On Mon, Jan 02, 2017 at 04:07:16PM +0100, Michael Haggerty wrote:\n>> On 01/01/2017 08:18 PM, brian m. carlson wrote:\n>>>  \t/* old SP new SP name <email> SP time TAB msg LF */\n>>>  \tif (sb->len < 83 || sb->buf[sb->len - 1] != '\\n' ||\n>>> -\t    get_sha1_hex(sb->buf, osha1) || sb->buf[40] != ' ' ||\n>>> -\t    get_sha1_hex(sb->buf + 41, nsha1) || sb->buf[81] != ' ' ||\n>>> +\t    get_oid_hex(sb->buf, &ooid) || sb->buf[40] != ' ' ||\n>>> +\t    get_oid_hex(sb->buf + 41, &noid) || sb->buf[81] != ' ' ||\n>>\n>> Some magic numbers above could be converted to use constants.\n> \n> Yes, I saw that.  I opted to leave it as it is for the moment.\n\nTotally understandable.\n\n> I think\n> my next series is going to include a small sscanf-style parser to parse\n> these.  Right now, using constants here is going to leave it extremely\n> difficult to read.  Something like the following for the OIDs:\n> \n>   strbuf_git_scanf(sb, \"%h %h \", &ooid, &noid);\n> \n> and then following up parsing the remainder.\n\nMaybe something with an interface like skip_prefix wouldn't be too\nobnoxious:\n\n    const char *p = sb.buf;\n    if (oid_prefix(p, &ooid, &p) &&\n        *p++ == ' ' &&\n        oid_prefix(p, &noid, &p) && ...\n\n> [...]\n\nMichael\n\n"},{"id":"308695","messageId":"20170103013217.vctawyhpsd73frjc@sigill.intra.peff.net","threadId":"44802","inReplyTo":"d5fc2830-37c2-9274-77b7-97ecc5f9b763@alum.mit.edu","subject":"Re: [PATCH 13/17] refs: convert each_reflog_ent_fn to struct object_id","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2017-01-03T01:32:18Z","receivedAt":"2017-01-03T01:32:25Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Tue, Jan 03, 2017 at 12:30:40AM +0100, Michael Haggerty wrote:\n\n> > I think\n> > my next series is going to include a small sscanf-style parser to parse\n> > these.  Right now, using constants here is going to leave it extremely\n> > difficult to read.  Something like the following for the OIDs:\n> > \n> >   strbuf_git_scanf(sb, \"%h %h \", &ooid, &noid);\n> > \n> > and then following up parsing the remainder.\n> \n> Maybe something with an interface like skip_prefix wouldn't be too\n> obnoxious:\n> \n>     const char *p = sb.buf;\n>     if (oid_prefix(p, &ooid, &p) &&\n>         *p++ == ' ' &&\n>         oid_prefix(p, &noid, &p) && ...\n\nYeah, I've used C code before that had a very similar interface for\nparsing, and when used consistently it's pretty pleasant. Something\nlike:\n\n  if (parse_oid(p, &oid, &p) &&\n      skip_whitespace(p, &p) &&\n      parse_refname(p, &refname, &p))\n\netc is nicer than some of the magic numbers we end up using in the\nvarious parsers (I don't think anybody needs to mass-convert, I just\nmean that something like parse_oid() seems like a step in a good\ndirection).\n\n-Peff\n"}]}