{"thread":{"id":"45136","subject":"[PATCH v2 03/19] builtin/describe: convert to struct object_id","startedAt":"2017-02-14T02:32:19Z","lastAt":"2017-02-17T21:45:26Z","messageCount":26,"participants":["brian m. carlson","Junio C Hamano","Michael Haggerty"],"isPatch":true,"patchVersion":2,"patchTotal":19},"messages":[{"id":"311484","messageId":"20170214023141.842922-4-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 03/19] builtin/describe: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:25Z","receivedAt":"2017-02-14T02:32:19Z","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 01490a157e..738e68f95b 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":"311485","messageId":"20170214023141.842922-17-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 16/19] sha1_file: introduce an nth_packed_object_oid function","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:38Z","receivedAt":"2017-02-14T02:32:22Z","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 is similar to the\nnth_packed_object_sha1 function.\n\nIn order to avoid a potentially invalid cast, nth_packed_object_oid\nprovides a variable into which to store the value, which it returns on\nsuccess; on error, it returns NULL, as nth_packed_object_sha1 does.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h     |  6 ++++++\n sha1_file.c | 17 ++++++++++++++---\n 2 files changed, 20 insertions(+), 3 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 5dc89a058c..04b1d923f3 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1607,6 +1607,12 @@ 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+/*\n+ * Like nth_packed_object_oid, but write the data into the object specified by\n+ * the the first argument.  Returns the first argument on success, and NULL on\n+ * error.\n+ */\n+extern const struct object_id *nth_packed_object_oid(struct object_id *, 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 ec957db5e1..777b8e8eae 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -2628,6 +2628,17 @@ 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 object_id *oid,\n+\t\t\t\t\t      struct packed_git *p,\n+\t\t\t\t\t      uint32_t n)\n+{\n+\tconst unsigned char *hash = nth_packed_object_sha1(p, n);\n+\tif (!hash)\n+\t\treturn NULL;\n+\thashcpy(oid->hash, hash);\n+\treturn oid;\n+}\n+\n void check_pack_index_ptr(const struct packed_git *p, const void *vptr)\n {\n \tconst unsigned char *ptr = vptr;\n@@ -3788,13 +3799,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\tstruct object_id oid;\n \n-\t\tif (!sha1)\n+\t\tif (!nth_packed_object_oid(&oid, p, i))\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":"311486","messageId":"20170214023141.842922-12-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 11/19] builtin/replace: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:33Z","receivedAt":"2017-02-14T02:32:25Z","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 b58c714cb8..f7716a5472 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":"311487","messageId":"20170214023141.842922-11-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 10/19] Convert remaining callers of resolve_refdup to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:32Z","receivedAt":"2017-02-14T02:32:28Z","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 5248a9bad8..8c569a49a0 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 1dbb8a0692..7966f4f4df 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 3820b21cc7..f0de30e2ef 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 a246af2767..f98748e2ae 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 d72e089484..141af31e8e 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 d47012048f..0ec090a338 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":"311488","messageId":"20170214023141.842922-10-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 09/19] builtin/merge: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:31Z","receivedAt":"2017-02-14T02:32:32Z","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 | 134 ++++++++++++++++++++++++++++----------------------------\n 1 file changed, 66 insertions(+), 68 deletions(-)\n\ndiff --git a/builtin/merge.c b/builtin/merge.c\nindex a96d4fb501..099cfab447 100644\n--- a/builtin/merge.c\n+++ b/builtin/merge.c\n@@ -244,7 +244,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@@ -265,7 +265,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@@ -305,18 +305,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@@ -376,10 +376,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@@ -397,7 +397,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@@ -416,7 +416,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@@ -431,7 +431,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@@ -441,25 +441,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+\toidclr(&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@@ -590,8 +590,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@@ -606,13 +606,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@@ -626,9 +626,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@@ -781,7 +781,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@@ -792,15 +792,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@@ -809,12 +809,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@@ -822,11 +822,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@@ -854,18 +854,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@@ -1038,7 +1038,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@@ -1048,16 +1048,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@@ -1117,9 +1117,7 @@ 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, stash, head_oid;\n \tstruct commit *head_commit;\n \tstruct strbuf buf = STRBUF_INIT;\n \tconst char *head_arg;\n@@ -1138,13 +1136,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@@ -1242,7 +1240,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@@ -1254,9 +1252,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@@ -1270,7 +1268,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@@ -1422,7 +1420,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@@ -1441,9 +1439,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@@ -1495,14 +1493,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@@ -1547,7 +1545,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@@ -1559,7 +1557,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@@ -1568,7 +1566,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@@ -1581,7 +1579,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":"311489","messageId":"20170214023141.842922-9-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 08/19] builtin/clone: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:30Z","receivedAt":"2017-02-14T02:32:35Z","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 3f63edbbf9..b4c929bb8a 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":"311490","messageId":"20170214023141.842922-14-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 13/19] refs: convert each_reflog_ent_fn to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:35Z","receivedAt":"2017-02-14T02:32:36Z","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 1a5caccd0f..9b37606858 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -396,13 +396,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 && (obj->flags & HAS_OBJ)) {\n \t\t\tif (timestamp && name_objects)\n \t\t\t\tadd_decoration(fsck_walk_options.object_names,\n@@ -411,13 +411,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@@ -425,10 +425,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 b572a37c26..db95bc29cf 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 7a7136e53e..7472775778 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 fe5be41471..99679f5825 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 cd36b64ed9..b900626d3f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -674,7 +674,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@@ -698,30 +698,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@@ -735,9 +735,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 9fbff90e79..a075117a2a 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -292,7 +292,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 c041d4ba21..d7a5fd2a7c 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), GIT_SHA1_HEXSZ) != GIT_SHA1_HEXSZ ||\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 b37dbec378..d9fe73318a 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 73a915ff1b..744e9f884a 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 0ec090a338..5fac8437b0 100644\n--- a/wt-status.c\n+++ b/wt-status.c\n@@ -1373,7 +1373,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@@ -1387,13 +1387,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":"311491","messageId":"20170214023141.842922-7-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 06/19] builtin/grep: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:28Z","receivedAt":"2017-02-14T02:32:39Z","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 2c727ef499..0393b0fdc4 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -294,17 +294,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@@ -323,7 +323,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@@ -332,7 +332,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@@ -690,7 +690,7 @@ static int grep_cache(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\t\t    ce_skip_worktree(ce)) {\n \t\t\t\tif (ce_stage(ce) || ce_intent_to_add(ce))\n \t\t\t\t\tcontinue;\n-\t\t\t\thit |= grep_sha1(opt, ce->oid.hash, ce->name,\n+\t\t\t\thit |= grep_oid(opt, &ce->oid, ce->name,\n \t\t\t\t\t\t 0, ce->name);\n \t\t\t} else {\n \t\t\t\thit |= grep_file(opt, ce->name);\n@@ -750,7 +750,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} else if (S_ISDIR(entry.mode)) {\n \t\t\tenum object_type type;\n@@ -758,7 +758,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@@ -787,7 +787,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@@ -1152,11 +1152,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":"311492","messageId":"20170214023141.842922-16-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 15/19] refs: simplify parsing of reflog entries","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:37Z","receivedAt":"2017-02-14T02:32:40Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"The current code for reflog entries uses a lot of hard-coded constants,\nmaking it hard to read and modify.  Use parse_oid_hex and two temporary\nvariables to simplify the code and reduce the use of magic constants.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n refs/files-backend.c | 12 +++++++-----\n 1 file changed, 7 insertions(+), 5 deletions(-)\n\ndiff --git a/refs/files-backend.c b/refs/files-backend.c\nindex d7a5fd2a7c..09227a3f63 100644\n--- a/refs/files-backend.c\n+++ b/refs/files-backend.c\n@@ -3117,12 +3117,14 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c\n \tchar *email_end, *message;\n \tunsigned long timestamp;\n \tint tz;\n+\tconst char *p = sb->buf;\n+\tconst int minlen = 2 * GIT_SHA1_HEXSZ + 3;\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_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+\tif (sb->len < minlen || sb->buf[sb->len - 1] != '\\n' ||\n+\t    parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||\n+\t    parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||\n+\t    !(email_end = strchr(p, '>')) ||\n \t    email_end[1] != ' ' ||\n \t    !(timestamp = strtoul(email_end + 2, &message, 10)) ||\n \t    !message || message[0] != ' ' ||\n@@ -3136,7 +3138,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(&ooid, &noid, sb->buf + 82, timestamp, tz, message, cb_data);\n+\treturn fn(&ooid, &noid, sb->buf + minlen - 1, timestamp, tz, message, cb_data);\n }\n \n static char *find_beginning_of_line(char *bob, char *scan)\n-- \n2.11.0\n\n"},{"id":"311493","messageId":"20170214023141.842922-13-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 12/19] reflog-walk: convert struct reflog_info to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:34Z","receivedAt":"2017-02-14T02:32:43Z","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 f98748e2ae..fe5be41471 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":"311494","messageId":"20170214023141.842922-15-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 14/19] hex: introduce parse_oid_hex","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:36Z","receivedAt":"2017-02-14T02:32:45Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Introduce a function, parse_oid_hex, which parses a hexadecimal object\nID and if successful, sets a pointer to just beyond the last character.\nThis allows for simpler, more robust parsing without needing to\nhard-code integer values throughout the codebase.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h | 8 ++++++++\n hex.c   | 8 ++++++++\n 2 files changed, 16 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 61fc86e6d7..5dc89a058c 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1319,6 +1319,14 @@ extern char *oid_to_hex_r(char *out, const struct object_id *oid);\n extern char *sha1_to_hex(const unsigned char *sha1);\t/* static buffer result! */\n extern char *oid_to_hex(const struct object_id *oid);\t/* same static buffer as sha1_to_hex */\n \n+/*\n+ * Parse a hexadecimal object ID starting from hex, updating the pointer\n+ * specified by p when parsing stops.  The resulting object ID is stored in oid.\n+ * Returns 0 on success.  Parsing will stop on the first NUL or other invalid\n+ * character.\n+ */\n+extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **p);\n+\n extern int interpret_branch_name(const char *str, int len, struct strbuf *);\n extern int get_oid_mb(const char *str, struct object_id *oid);\n \ndiff --git a/hex.c b/hex.c\nindex 845b01a874..54252b1445 100644\n--- a/hex.c\n+++ b/hex.c\n@@ -53,6 +53,14 @@ int get_oid_hex(const char *hex, struct object_id *oid)\n \treturn get_sha1_hex(hex, oid->hash);\n }\n \n+int parse_oid_hex(const char *hex, struct object_id *oid, const char **p)\n+{\n+\tint ret = get_oid_hex(hex, oid);\n+\tif (!ret)\n+\t\t*p = hex + GIT_SHA1_HEXSZ;\n+\treturn ret;\n+}\n+\n char *sha1_to_hex_r(char *buffer, const unsigned char *sha1)\n {\n \tstatic const char hex[] = \"0123456789abcdef\";\n-- \n2.11.0\n\n"},{"id":"311495","messageId":"20170214023141.842922-18-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 17/19] Convert object iteration callbacks to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:39Z","receivedAt":"2017-02-14T02:32:48Z","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          | 24 ++++++++++++------------\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, 50 insertions(+), 50 deletions(-)\n\ndiff --git a/builtin/cat-file.c b/builtin/cat-file.c\nindex 30383e9eb4..8b85cb8cf0 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 a04b4f2ef3..acb05940fc 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 9b37606858..f76e4163ab 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -491,7 +491,7 @@ static void get_default_heads(void)\n \t}\n }\n \n-static struct object *parse_loose_object(const unsigned char *sha1,\n+static struct object *parse_loose_object(const struct object_id *oid,\n \t\t\t\t\t const char *path)\n {\n \tstruct object *obj;\n@@ -500,27 +500,27 @@ static struct object *parse_loose_object(const unsigned char *sha1,\n \tunsigned long size;\n \tint eaten;\n \n-\tif (read_loose_object(path, sha1, &type, &size, &contents) < 0)\n+\tif (read_loose_object(path, oid->hash, &type, &size, &contents) < 0)\n \t\treturn NULL;\n \n \tif (!contents && type != OBJ_BLOB)\n \t\tdie(\"BUG: read_loose_object streamed a non-blob\");\n \n-\tobj = parse_object_buffer(sha1, type, size, contents, &eaten);\n+\tobj = parse_object_buffer(oid->hash, type, size, contents, &eaten);\n \n \tif (!eaten)\n \t\tfree(contents);\n \treturn obj;\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-\tstruct object *obj = parse_loose_object(sha1, path);\n+\tstruct object *obj = parse_loose_object(oid, path);\n \n \tif (!obj) {\n \t\terrors_found |= ERROR_OBJECT;\n \t\terror(\"%s: object corrupt or missing: %s\",\n-\t\t      sha1_to_hex(sha1), path);\n+\t\t      oid_to_hex(oid), path);\n \t\treturn 0; /* keep checking other objects */\n \t}\n \n@@ -619,26 +619,26 @@ static int fsck_cache_tree(struct cache_tree *it)\n \treturn err;\n }\n \n-static void mark_object_for_connectivity(const unsigned char *sha1)\n+static void mark_object_for_connectivity(const struct object_id *oid)\n {\n-\tstruct object *obj = lookup_unknown_object(sha1);\n+\tstruct object *obj = lookup_unknown_object(oid->hash);\n \tobj->flags |= HAS_OBJ;\n }\n \n-static int mark_loose_for_connectivity(const unsigned char *sha1,\n+static int mark_loose_for_connectivity(const struct object_id *oid,\n \t\t\t\t       const char *path,\n \t\t\t\t       void *data)\n {\n-\tmark_object_for_connectivity(sha1);\n+\tmark_object_for_connectivity(oid);\n \treturn 0;\n }\n \n-static int mark_packed_for_connectivity(const unsigned char *sha1,\n+static int mark_packed_for_connectivity(const struct object_id *oid,\n \t\t\t\t\tstruct packed_git *pack,\n \t\t\t\t\tuint32_t pos,\n \t\t\t\t\tvoid *data)\n {\n-\tmark_object_for_connectivity(sha1);\n+\tmark_object_for_connectivity(oid);\n \treturn 0;\n }\n \ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 8841f8b366..6e7c3a6575 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2534,17 +2534,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 7cf900ea07..c026299e78 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 8f4f052285..42633e0c6e 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 04b1d923f3..32278400d2 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1654,7 +1654,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@@ -1680,7 +1680,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 d0199cace4..a8a979bd4f 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 777b8e8eae..6b74c7d3bc 100644\n--- a/sha1_file.c\n+++ b/sha1_file.c\n@@ -3685,15 +3685,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@@ -3805,7 +3805,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":"311496","messageId":"20170214023141.842922-20-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 19/19] wt-status: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:41Z","receivedAt":"2017-02-14T02:32:51Z","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 5fac8437b0..a8d1faf80d 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@@ -1340,7 +1340,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@@ -1354,9 +1354,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@@ -1370,7 +1370,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@@ -1387,7 +1387,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@@ -1402,7 +1402,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@@ -1411,22 +1411,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@@ -1476,22 +1476,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":"311497","messageId":"20170214023141.842922-19-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 18/19] builtin/merge-base: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:40Z","receivedAt":"2017-02-14T02:32:54Z","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 db95bc29cf..cfe2a796f8 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":"311498","messageId":"20170214023141.842922-8-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 07/19] builtin/branch: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:29Z","receivedAt":"2017-02-14T02:32:57Z","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 9d30f55b0b..faf472ff8f 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":"311499","messageId":"20170214023141.842922-6-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 05/19] builtin/fmt-merge-message: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:27Z","receivedAt":"2017-02-14T02:32:59Z","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 efab62fd85..6faa3c0d24 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":"311500","messageId":"20170214023141.842922-2-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 01/19] builtin/commit: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:23Z","receivedAt":"2017-02-14T02:33:02Z","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 2de5f6cc64..4e288bc513 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 \tstruct child_process proc = CHILD_PROCESS_INIT;\n \tconst char *argv[3];\n@@ -1544,7 +1544,7 @@ static int run_rewrite_hook(const unsigned char *oldsha1,\n \tcode = start_command(&proc);\n \tif (code)\n \t\treturn code;\n-\tstrbuf_addf(&sb, \"%s %s\\n\", sha1_to_hex(oldsha1), sha1_to_hex(newsha1));\n+\tstrbuf_addf(&sb, \"%s %s\\n\", oid_to_hex(oldoid), oid_to_hex(newoid));\n \tsigchain_push(SIGPIPE, SIG_IGN);\n \twrite_in_full(proc.in, sb.buf, sb.len);\n \tclose(proc.in);\n@@ -1636,7 +1636,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@@ -1651,10 +1651,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@@ -1759,7 +1759,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@@ -1776,7 +1776,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@@ -1805,13 +1805,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":"311501","messageId":"20170214023141.842922-1-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":null,"subject":"[PATCH v2 00/19] object_id part 6","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:22Z","receivedAt":"2017-02-14T02:33:03Z","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 refs\ncode to use struct object_id. Additionally, it implements an\nnth_packed_object_oid function which provides a struct object_id version\nof the nth_packed_object function, and a parse_oid_hex function that\nmakes parsing easier.\n\nThe patch to use parse_oid_hex in the refs code has been split out into\nits own patch, just because I'm wary of that code and potentially\nbreaking things, and I want it to be easy to revert in case things go\nwrong.  I have no reason to believe it is anything other than fully\nfunctional, however.\n\nChanges from v1:\n* Implement parse_oid_hex and use it.\n* Make nth_packed_object_oid take a variable into which to store the\n  object ID.  This avoids concerns about unsafe casts.\n* Rebase on master.\n\nbrian m. carlson (19):\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  hex: introduce parse_oid_hex\n  refs: simplify parsing of reflog entries\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          |  40 +++++++--------\n builtin/grep.c          |  24 ++++-----\n builtin/merge-base.c    |  30 +++++------\n builtin/merge.c         | 134 ++++++++++++++++++++++++------------------------\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                 |  18 ++++++-\n hex.c                   |   8 +++\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    |  30 ++++++-----\n revision.c              |  12 ++---\n sha1_file.c             |  27 +++++++---\n sha1_name.c             |   2 +-\n transport.c             |   4 +-\n wt-status.c             |  52 +++++++++----------\n 33 files changed, 483 insertions(+), 448 deletions(-)\n\n-- \n2.11.0\n\n"},{"id":"311502","messageId":"20170214023141.842922-5-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 04/19] builtin/fast-export: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:26Z","receivedAt":"2017-02-14T02:33:06Z","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 1e815b5577..e0220630d0 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":"311503","messageId":"20170214023141.842922-3-sandals@crustytoothpaste.net","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"[PATCH v2 02/19] builtin/diff-tree: convert to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-14T02:31:24Z","receivedAt":"2017-02-14T02:33:09Z","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 806dd7a885..516860e4f9 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":"311592","messageId":"xmqqvasc77nz.fsf@gitster.mtv.corp.google.com","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 00/19] object_id part 6","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2017-02-14T22:02:24Z","receivedAt":"2017-02-14T22:02:31Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> This is another series in the continuing conversion to struct object_id.\n>\n> This series converts more of the builtin directory and some of the refs\n> code to use struct object_id. Additionally, it implements an\n> nth_packed_object_oid function which provides a struct object_id version\n> of the nth_packed_object function, and a parse_oid_hex function that\n> makes parsing easier.\n>\n> The patch to use parse_oid_hex in the refs code has been split out into\n> its own patch, just because I'm wary of that code and potentially\n> breaking things, and I want it to be easy to revert in case things go\n> wrong.  I have no reason to believe it is anything other than fully\n> functional, however.\n\nThanks.  Will queue.\n\nThere are a few hunks in builtin/merge.c that ends up getting discarded\nwhen merged to 'pu' as is-old-style-invocation will just be removed,\nbut the conflict resolution was trivial.\n\n"},{"id":"311850","messageId":"f7e35bf8-a320-6ac1-6184-977d6bf6de08@alum.mit.edu","threadId":"45136","inReplyTo":"20170214023141.842922-12-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 11/19] builtin/replace: convert to struct object_id","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-02-17T08:44:59Z","receivedAt":"2017-02-17T08:45:18Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 02/14/2017 03:31 AM, brian m. carlson wrote:\n> Convert various uses of unsigned char [20] to struct object_id.  Rename\n> replace_object_sha1 to rename_object_oid.  Finally, specify a constant\n> in terms of GIT_SHA1_HEXSZ.\n\nThe new name is not rename_object_oid but rather replace_object_oid.\n\n> [...]\n\nMichael\n\n"},{"id":"311851","messageId":"dc402492-8b69-cf43-22d0-e4ec3af04e8c@alum.mit.edu","threadId":"45136","inReplyTo":"20170214023141.842922-15-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 14/19] hex: introduce parse_oid_hex","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-02-17T09:26:14Z","receivedAt":"2017-02-17T09:26:31Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 02/14/2017 03:31 AM, brian m. carlson wrote:\n> Introduce a function, parse_oid_hex, which parses a hexadecimal object\n> ID and if successful, sets a pointer to just beyond the last character.\n> This allows for simpler, more robust parsing without needing to\n> hard-code integer values throughout the codebase.\n> \n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  cache.h | 8 ++++++++\n>  hex.c   | 8 ++++++++\n>  2 files changed, 16 insertions(+)\n> \n> diff --git a/cache.h b/cache.h\n> index 61fc86e6d7..5dc89a058c 100644\n> --- a/cache.h\n> +++ b/cache.h\n> @@ -1319,6 +1319,14 @@ extern char *oid_to_hex_r(char *out, const struct object_id *oid);\n>  extern char *sha1_to_hex(const unsigned char *sha1);\t/* static buffer result! */\n>  extern char *oid_to_hex(const struct object_id *oid);\t/* same static buffer as sha1_to_hex */\n>  \n> +/*\n> + * Parse a hexadecimal object ID starting from hex, updating the pointer\n> + * specified by p when parsing stops.  The resulting object ID is stored in oid.\n> + * Returns 0 on success.  Parsing will stop on the first NUL or other invalid\n> + * character.\n> + */\n> +extern int parse_oid_hex(const char *hex, struct object_id *oid, const char **p);\n> +\n\nI like this function. This is a convenient kind of interface to work\nwith. A few minor comments:\n\nIf you rename the nondescript `p` parameter to, say, `end`, its purpose\nwould be more transparent. Alternatively, `skip_prefix()` calls the\ncorresponding parameter `out`.\n\nIt would be nice for the docstring to mention that the object ID must be\na full, 40-character hex string. Otherwise \"Parsing will stop on the\nfirst NUL or other invalid character\" makes it sound like the function\nmight be satisfied with fewer than 40 characters.\n\nFinally, you might mention the useful fact that `p` is only updated if\nthe function succeeds.\n\n> [...]\n\nMichael\n\n"},{"id":"311854","messageId":"784a4960-e890-eec4-0349-3e27b4c7997a@alum.mit.edu","threadId":"45136","inReplyTo":"20170214023141.842922-16-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 15/19] refs: simplify parsing of reflog entries","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-02-17T09:41:32Z","receivedAt":"2017-02-17T09:41:54Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 02/14/2017 03:31 AM, brian m. carlson wrote:\n> The current code for reflog entries uses a lot of hard-coded constants,\n> making it hard to read and modify.  Use parse_oid_hex and two temporary\n> variables to simplify the code and reduce the use of magic constants.\n> \n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  refs/files-backend.c | 12 +++++++-----\n>  1 file changed, 7 insertions(+), 5 deletions(-)\n> \n> diff --git a/refs/files-backend.c b/refs/files-backend.c\n> index d7a5fd2a7c..09227a3f63 100644\n> --- a/refs/files-backend.c\n> +++ b/refs/files-backend.c\n> @@ -3117,12 +3117,14 @@ static int show_one_reflog_ent(struct strbuf *sb, each_reflog_ent_fn fn, void *c\n>  \tchar *email_end, *message;\n>  \tunsigned long timestamp;\n>  \tint tz;\n> +\tconst char *p = sb->buf;\n> +\tconst int minlen = 2 * GIT_SHA1_HEXSZ + 3;\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_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> +\tif (sb->len < minlen || sb->buf[sb->len - 1] != '\\n' ||\n> +\t    parse_oid_hex(p, &ooid, &p) || *p++ != ' ' ||\n> +\t    parse_oid_hex(p, &noid, &p) || *p++ != ' ' ||\n> +\t    !(email_end = strchr(p, '>')) ||\n>  \t    email_end[1] != ' ' ||\n>  \t    !(timestamp = strtoul(email_end + 2, &message, 10)) ||\n>  \t    !message || message[0] != ' ' ||\n> @@ -3136,7 +3138,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(&ooid, &noid, sb->buf + 82, timestamp, tz, message, cb_data);\n> +\treturn fn(&ooid, &noid, sb->buf + minlen - 1, timestamp, tz, message, cb_data);\n\nI think `sb->buf + minlen - 1` is just `p` here, isn't it?\n\nAlso, I think instead of the initial test `sb->len < minlen`, it would\nbe enough to check `!sb->len` (i.e., error if it's zero to avoid a\nbuffer underflow in `sb->buf[sb->len - 1])`, because the\n`parse_oid_hex()` calls together with the `*p++ != ' '` and\n`sb->buf[sb->len - 1] != '\\n'` checks already ensure that the string has\nat least the minimum length.\n\nThen you could do away with `minlen` entirely.\n\nMichael\n\n"},{"id":"311855","messageId":"3644df30-71e2-584b-ebed-ae117a5ded3f@alum.mit.edu","threadId":"45136","inReplyTo":"20170214023141.842922-1-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 00/19] object_id part 6","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2017-02-17T09:55:03Z","receivedAt":"2017-02-17T09:55:40Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 02/14/2017 03:31 AM, 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 refs\n> code to use struct object_id. Additionally, it implements an\n> nth_packed_object_oid function which provides a struct object_id version\n> of the nth_packed_object function, and a parse_oid_hex function that\n> makes parsing easier.\n> \n> The patch to use parse_oid_hex in the refs code has been split out into\n> its own patch, just because I'm wary of that code and potentially\n> breaking things, and I want it to be easy to revert in case things go\n> wrong.  I have no reason to believe it is anything other than fully\n> functional, however.\n> \n> Changes from v1:\n> * Implement parse_oid_hex and use it.\n> * Make nth_packed_object_oid take a variable into which to store the\n>   object ID.  This avoids concerns about unsafe casts.\n> * Rebase on master.\n\nThanks as always for working on this!\n\nI skimmed over the patches (looking more carefully at the refs-related\nones) and left a few minor comments but didn't find anything serious.\n\nI'm curious; what fraction of the overall convert-to-object_id campaign\ndo you estimate is done so far? Are you getting close to the promised\nland yet?\n\nMichael\n\n"},{"id":"311941","messageId":"20170217214513.giua5ksuiqqs2laj@genre.crustytoothpaste.net","threadId":"45136","inReplyTo":"3644df30-71e2-584b-ebed-ae117a5ded3f@alum.mit.edu","subject":"Re: [PATCH v2 00/19] object_id part 6","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2017-02-17T21:45:13Z","receivedAt":"2017-02-17T21:45:26Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Fri, Feb 17, 2017 at 10:55:03AM +0100, Michael Haggerty wrote:\n> On 02/14/2017 03:31 AM, 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 refs\n> > code to use struct object_id. Additionally, it implements an\n> > nth_packed_object_oid function which provides a struct object_id version\n> > of the nth_packed_object function, and a parse_oid_hex function that\n> > makes parsing easier.\n> > \n> > The patch to use parse_oid_hex in the refs code has been split out into\n> > its own patch, just because I'm wary of that code and potentially\n> > breaking things, and I want it to be easy to revert in case things go\n> > wrong.  I have no reason to believe it is anything other than fully\n> > functional, however.\n> > \n> > Changes from v1:\n> > * Implement parse_oid_hex and use it.\n> > * Make nth_packed_object_oid take a variable into which to store the\n> >   object ID.  This avoids concerns about unsafe casts.\n> > * Rebase on master.\n> \n> Thanks as always for working on this!\n> \n> I skimmed over the patches (looking more carefully at the refs-related\n> ones) and left a few minor comments but didn't find anything serious.\n\nI'll send out a new series shortly with those changes.\n\n> I'm curious; what fraction of the overall convert-to-object_id campaign\n> do you estimate is done so far? Are you getting close to the promised\n> land yet?\n\nSo I think that the current scope left is best estimated by the\nfollowing command:\n\n  git grep -P 'unsigned char\\s+(\\*|.*20)' | grep -v '^Documentation'\n\nSo there are approximately 1200 call sites left, which is quite a bit of\nwork.  I estimate between the work I've done and other people's\nrefactoring work (such as the refs backend refactor), we're about 40%\ndone.\n\nI'm hoping to send out more smaller series in the future, since running\nmake test on a huge series takes a long time.\n\nPart of the problem is that some places are almost completely\nconvertible, except for one or two components that rely on something\nlike sha1_array.  I have patches somewhere that convert that to\noid_array, but I'm not sure how well they'll be received at this point.\nI think converting a lot of shallow-related code requires that\nconversion, though.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"}]}