{"thread":{"id":"39144","subject":"[PATCH v2 00/16] Convert parts of refs.c to struct object_id","startedAt":"2015-04-22T23:24:05Z","lastAt":"2015-05-03T21:45:00Z","messageCount":24,"participants":["brian m. carlson","Stefan Beller","Jeff King","Michael Haggerty"],"isPatch":true,"patchVersion":2,"patchTotal":16},"messages":[{"id":"259859","messageId":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":null,"subject":"[PATCH v2 00/16] Convert parts of refs.c to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:05Z","receivedAt":"2015-04-22T23:24:05Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"This is a conversion of parts of refs.c to use struct object_id.\n\nrefs.c, and the for_each_ref series of functions explicitly, is the\nsource for many instances of object IDs in the codebase.  Therefore, it\nmakes sense to convert this series of functions to provide a basis for\nfurther conversions.\n\nThis series is essentially just for_each_ref and friends, the callbacks,\nand callers.  Other parts of refs.c will be converted in a later series,\nso as to keep the number of patches to a reasonable size.\n\nThere should be no functional change from this patch series.\n\nChanges from v1:\n* Rebase onto next to pick up the first set of object_id patches.\n* Fix a series of nasty conflicts that occurred due to other topics in\n  flight to promote easier testing and integration.\n\nComments and reviews on this series would be greatly appreciated.\n\nbrian m. carlson (16):\n  refs: convert struct ref_entry to use struct object_id\n  refs: convert for_each_tag_ref to struct object_id\n  refs: convert remaining users of for_each_ref_in to object_id\n  refs: convert for_each_ref_in_submodule to object_id\n  refs: convert head_ref to struct object_id\n  refs: convert for_each_ref_submodule to struct object_id\n  revision: remove unused _oid helper.\n  refs: convert for_each_ref to struct object_id\n  refs: convert for_each_replace_ref to struct object_id\n  refs: convert namespaced ref iteration functions to object_id\n  refs: convert for_each_rawref to struct object_id.\n  refs: rename do_for_each_ref_oid to do_for_each_ref\n  refs: convert for_each_reflog to struct object_id\n  refs: rename each_ref_fn_oid to each_ref_fn\n  Remove unneeded *_oid functions.\n  refs: convert struct ref_lock to struct object_id\n\n Documentation/technical/api-ref-iteration.txt |   2 +-\n bisect.c                                      |   8 +-\n builtin/branch.c                              |   4 +-\n builtin/checkout.c                            |   4 +-\n builtin/describe.c                            |  12 +--\n builtin/fetch.c                               |   6 +-\n builtin/for-each-ref.c                        |   4 +-\n builtin/fsck.c                                |  18 ++---\n builtin/name-rev.c                            |   6 +-\n builtin/pack-objects.c                        |  14 ++--\n builtin/receive-pack.c                        |   4 +-\n builtin/reflog.c                              |  10 +--\n builtin/remote.c                              |  14 ++--\n builtin/replace.c                             |  14 ++--\n builtin/rev-parse.c                           |   8 +-\n builtin/show-branch.c                         |  24 +++---\n builtin/show-ref.c                            |  16 ++--\n builtin/tag.c                                 |   8 +-\n fetch-pack.c                                  |  18 ++++-\n help.c                                        |   2 +-\n http-backend.c                                |  14 ++--\n log-tree.c                                    |  10 +--\n notes.c                                       |   2 +-\n reachable.c                                   |   4 +-\n refs.c                                        | 104 +++++++++++++-------------\n refs.h                                        |   4 +-\n remote.c                                      |   8 +-\n replace_object.c                              |   4 +-\n revision.c                                    |  18 +++--\n server-info.c                                 |   6 +-\n sha1_name.c                                   |   4 +-\n shallow.c                                     |   8 +-\n submodule.c                                   |   6 +-\n transport.c                                   |  10 +--\n upload-pack.c                                 |  30 ++++----\n walker.c                                      |   4 +-\n 36 files changed, 225 insertions(+), 207 deletions(-)\n\n-- \n2.3.5\n"},{"id":"259869","messageId":"1429745061-295908-2-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 01/16] refs: convert struct ref_entry to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:06Z","receivedAt":"2015-04-22T23:24:06Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n refs.c | 44 ++++++++++++++++++++++----------------------\n 1 file changed, 22 insertions(+), 22 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 81a455b..522d15d 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -156,7 +156,7 @@ struct ref_value {\n \t * null.  If REF_ISSYMREF, then this is the name of the object\n \t * referred to by the last reference in the symlink chain.\n \t */\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \n \t/*\n \t * If REF_KNOWS_PEELED, then this field holds the peeled value\n@@ -164,7 +164,7 @@ struct ref_value {\n \t * be peelable.  See the documentation for peel_ref() for an\n \t * exact definition of \"peelable\".\n \t */\n-\tunsigned char peeled[20];\n+\tstruct object_id peeled;\n };\n \n struct ref_cache;\n@@ -346,8 +346,8 @@ static struct ref_entry *create_ref_entry(const char *refname,\n \t\tdie(\"Reference has invalid format: '%s'\", refname);\n \tlen = strlen(refname) + 1;\n \tref = xmalloc(sizeof(struct ref_entry) + len);\n-\thashcpy(ref->u.value.sha1, sha1);\n-\thashclr(ref->u.value.peeled);\n+\thashcpy(ref->u.value.oid.hash, sha1);\n+\toidclr(&ref->u.value.peeled);\n \tmemcpy(ref->name, refname, len);\n \tref->flag = flag;\n \treturn ref;\n@@ -621,7 +621,7 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2\n \t\t/* This is impossible by construction */\n \t\tdie(\"Reference directory conflict: %s\", ref1->name);\n \n-\tif (hashcmp(ref1->u.value.sha1, ref2->u.value.sha1))\n+\tif (oidcmp(&ref1->u.value.oid, &ref2->u.value.oid))\n \t\tdie(\"Duplicated ref, and SHA1s don't match: %s\", ref1->name);\n \n \twarning(\"Duplicated ref: %s\", ref1->name);\n@@ -669,7 +669,7 @@ static int ref_resolves_to_object(struct ref_entry *entry)\n {\n \tif (entry->flag & REF_ISBROKEN)\n \t\treturn 0;\n-\tif (!has_sha1_file(entry->u.value.sha1)) {\n+\tif (!has_sha1_file(entry->u.value.oid.hash)) {\n \t\terror(\"%s does not point to a valid object!\", entry->name);\n \t\treturn 0;\n \t}\n@@ -717,7 +717,7 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)\n \t/* Store the old value, in case this is a recursive call: */\n \told_current_ref = current_ref;\n \tcurrent_ref = entry;\n-\tretval = data->fn(entry->name + data->trim, entry->u.value.sha1,\n+\tretval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,\n \t\t\t  entry->flag, data->cb_data);\n \tcurrent_ref = old_current_ref;\n \treturn retval;\n@@ -1193,7 +1193,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)\n \t\t    line.len == PEELED_LINE_LENGTH &&\n \t\t    line.buf[PEELED_LINE_LENGTH - 1] == '\\n' &&\n \t\t    !get_sha1_hex(line.buf + 1, sha1)) {\n-\t\t\thashcpy(last->u.value.peeled, sha1);\n+\t\t\thashcpy(last->u.value.peeled.hash, sha1);\n \t\t\t/*\n \t\t\t * Regardless of what the file header said,\n \t\t\t * we definitely know the value of *this*\n@@ -1374,7 +1374,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,\n \tif (ref == NULL)\n \t\treturn -1;\n \n-\thashcpy(sha1, ref->u.value.sha1);\n+\thashcpy(sha1, ref->u.value.oid.hash);\n \treturn 0;\n }\n \n@@ -1461,7 +1461,7 @@ static int resolve_missing_loose_ref(const char *refname,\n \t */\n \tentry = get_packed_ref(refname);\n \tif (entry) {\n-\t\thashcpy(sha1, entry->u.value.sha1);\n+\t\thashcpy(sha1, entry->u.value.oid.hash);\n \t\tif (flags)\n \t\t\t*flags |= REF_ISPACKED;\n \t\treturn 0;\n@@ -1771,9 +1771,9 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)\n \tif (entry->flag & REF_KNOWS_PEELED) {\n \t\tif (repeel) {\n \t\t\tentry->flag &= ~REF_KNOWS_PEELED;\n-\t\t\thashclr(entry->u.value.peeled);\n+\t\t\toidclr(&entry->u.value.peeled);\n \t\t} else {\n-\t\t\treturn is_null_sha1(entry->u.value.peeled) ?\n+\t\t\treturn is_null_oid(&entry->u.value.peeled) ?\n \t\t\t\tPEEL_NON_TAG : PEEL_PEELED;\n \t\t}\n \t}\n@@ -1782,7 +1782,7 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)\n \tif (entry->flag & REF_ISSYMREF)\n \t\treturn PEEL_IS_SYMREF;\n \n-\tstatus = peel_object(entry->u.value.sha1, entry->u.value.peeled);\n+\tstatus = peel_object(entry->u.value.oid.hash, entry->u.value.peeled.hash);\n \tif (status == PEEL_PEELED || status == PEEL_NON_TAG)\n \t\tentry->flag |= REF_KNOWS_PEELED;\n \treturn status;\n@@ -1797,7 +1797,7 @@ int peel_ref(const char *refname, unsigned char *sha1)\n \t\t\t    || !strcmp(current_ref->name, refname))) {\n \t\tif (peel_entry(current_ref, 0))\n \t\t\treturn -1;\n-\t\thashcpy(sha1, current_ref->u.value.peeled);\n+\t\thashcpy(sha1, current_ref->u.value.peeled.hash);\n \t\treturn 0;\n \t}\n \n@@ -1817,7 +1817,7 @@ int peel_ref(const char *refname, unsigned char *sha1)\n \t\tif (r) {\n \t\t\tif (peel_entry(r, 0))\n \t\t\t\treturn -1;\n-\t\t\thashcpy(sha1, r->u.value.peeled);\n+\t\t\thashcpy(sha1, r->u.value.peeled.hash);\n \t\t\treturn 0;\n \t\t}\n \t}\n@@ -2422,9 +2422,9 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)\n \tif (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)\n \t\terror(\"internal error: %s is not a valid packed reference!\",\n \t\t      entry->name);\n-\twrite_packed_entry(cb_data, entry->name, entry->u.value.sha1,\n+\twrite_packed_entry(cb_data, entry->name, entry->u.value.oid.hash,\n \t\t\t   peel_status == PEEL_PEELED ?\n-\t\t\t   entry->u.value.peeled : NULL);\n+\t\t\t   entry->u.value.peeled.hash : NULL);\n \treturn 0;\n }\n \n@@ -2531,24 +2531,24 @@ static int pack_if_possible_fn(struct ref_entry *entry, void *cb_data)\n \tpeel_status = peel_entry(entry, 1);\n \tif (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)\n \t\tdie(\"internal error peeling reference %s (%s)\",\n-\t\t    entry->name, sha1_to_hex(entry->u.value.sha1));\n+\t\t    entry->name, oid_to_hex(&entry->u.value.oid));\n \tpacked_entry = find_ref(cb->packed_refs, entry->name);\n \tif (packed_entry) {\n \t\t/* Overwrite existing packed entry with info from loose entry */\n \t\tpacked_entry->flag = REF_ISPACKED | REF_KNOWS_PEELED;\n-\t\thashcpy(packed_entry->u.value.sha1, entry->u.value.sha1);\n+\t\toidcpy(&packed_entry->u.value.oid, &entry->u.value.oid);\n \t} else {\n-\t\tpacked_entry = create_ref_entry(entry->name, entry->u.value.sha1,\n+\t\tpacked_entry = create_ref_entry(entry->name, entry->u.value.oid.hash,\n \t\t\t\t\t\tREF_ISPACKED | REF_KNOWS_PEELED, 0);\n \t\tadd_ref(cb->packed_refs, packed_entry);\n \t}\n-\thashcpy(packed_entry->u.value.peeled, entry->u.value.peeled);\n+\toidcpy(&packed_entry->u.value.peeled, &entry->u.value.peeled);\n \n \t/* Schedule the loose reference for pruning if requested. */\n \tif ((cb->flags & PACK_REFS_PRUNE)) {\n \t\tint namelen = strlen(entry->name) + 1;\n \t\tstruct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);\n-\t\thashcpy(n->sha1, entry->u.value.sha1);\n+\t\thashcpy(n->sha1, entry->u.value.oid.hash);\n \t\tstrcpy(n->name, entry->name);\n \t\tn->next = cb->ref_to_prune;\n \t\tcb->ref_to_prune = n;\n-- \n2.3.5\n"},{"id":"259875","messageId":"1429745061-295908-3-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 02/16] refs: convert for_each_tag_ref to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:07Z","receivedAt":"2015-04-22T23:24:07Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"To allow piecemeal conversion of the for_each_*_ref functions, introduce\nan additional typedef for a callback function that takes struct\nobject_id * instead of unsigned char *.  Provide an extra field in\nstruct ref_entry_cb for this callback and ensure at most one is set at a\ntime.  Temporarily suffix these new entries with _oid to distinguish\nthem.  Convert for_each_tag_ref and its callers to use the new _oid\nfunctions, introducing temporary wrapper functions to avoid type\nmismatches.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/pack-objects.c |  4 ++--\n builtin/rev-parse.c    |  7 ++++++-\n builtin/tag.c          |  8 ++++----\n refs.c                 | 34 ++++++++++++++++++++++++++++++----\n refs.h                 | 10 +++++++++-\n 5 files changed, 51 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex c067107..0c69b0c 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -540,11 +540,11 @@ static enum write_one_status write_one(struct sha1file *f,\n \treturn WRITE_ONE_WRITTEN;\n }\n \n-static int mark_tagged(const char *path, const unsigned char *sha1, int flag,\n+static int mark_tagged(const char *path, const struct object_id *oid, int flag,\n \t\t       void *cb_data)\n {\n \tunsigned char peeled[20];\n-\tstruct object_entry *entry = packlist_find(&to_pack, sha1, NULL);\n+\tstruct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL);\n \n \tif (entry)\n \t\tentry->tagged = 1;\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 4d10dd9..7b70650 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -198,6 +198,11 @@ static int show_reference(const char *refname, const unsigned char *sha1, int fl\n \treturn 0;\n }\n \n+static int show_reference_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n+{\n+\treturn show_reference(refname, oid->hash, flag, cb_data);\n+}\n+\n static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n {\n \tshow_rev(REVERSED, sha1, refname);\n@@ -682,7 +687,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--tags\")) {\n-\t\t\t\tfor_each_tag_ref(show_reference, NULL);\n+\t\t\t\tfor_each_tag_ref(show_reference_oid, NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/builtin/tag.c b/builtin/tag.c\nindex 6f07ac6..61399b7 100644\n--- a/builtin/tag.c\n+++ b/builtin/tag.c\n@@ -215,7 +215,7 @@ free_return:\n \tfree(buf);\n }\n \n-static int show_reference(const char *refname, const unsigned char *sha1,\n+static int show_reference(const char *refname, const struct object_id *oid,\n \t\t\t  int flag, void *cb_data)\n {\n \tstruct tag_filter *filter = cb_data;\n@@ -224,14 +224,14 @@ static int show_reference(const char *refname, const unsigned char *sha1,\n \t\tif (filter->with_commit) {\n \t\t\tstruct commit *commit;\n \n-\t\t\tcommit = lookup_commit_reference_gently(sha1, 1);\n+\t\t\tcommit = lookup_commit_reference_gently(oid->hash, 1);\n \t\t\tif (!commit)\n \t\t\t\treturn 0;\n \t\t\tif (!contains(commit, filter->with_commit))\n \t\t\t\treturn 0;\n \t\t}\n \n-\t\tif (points_at.nr && !match_points_at(refname, sha1))\n+\t\tif (points_at.nr && !match_points_at(refname, oid->hash))\n \t\t\treturn 0;\n \n \t\tif (!filter->lines) {\n@@ -242,7 +242,7 @@ static int show_reference(const char *refname, const unsigned char *sha1,\n \t\t\treturn 0;\n \t\t}\n \t\tprintf(\"%-15s \", refname);\n-\t\tshow_tag_lines(sha1, filter->lines);\n+\t\tshow_tag_lines(oid->hash, filter->lines);\n \t\tputchar('\\n');\n \t}\n \ndiff --git a/refs.c b/refs.c\nindex 522d15d..95863f2 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -694,6 +694,7 @@ struct ref_entry_cb {\n \tint trim;\n \tint flags;\n \teach_ref_fn *fn;\n+\teach_ref_fn_oid *fn_oid;\n \tvoid *cb_data;\n };\n \n@@ -717,8 +718,13 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)\n \t/* Store the old value, in case this is a recursive call: */\n \told_current_ref = current_ref;\n \tcurrent_ref = entry;\n-\tretval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,\n-\t\t\t  entry->flag, data->cb_data);\n+\tif (data->fn_oid) {\n+\t\tretval = data->fn_oid(entry->name + data->trim, &entry->u.value.oid,\n+\t\t\t\t entry->flag, data->cb_data);\n+\t} else {\n+\t\tretval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,\n+\t\t\t\t entry->flag, data->cb_data);\n+\t}\n \tcurrent_ref = old_current_ref;\n \treturn retval;\n }\n@@ -1950,6 +1956,21 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,\n \tdata.trim = trim;\n \tdata.flags = flags;\n \tdata.fn = fn;\n+\tdata.fn_oid = NULL;\n+\tdata.cb_data = cb_data;\n+\n+\treturn do_for_each_entry(refs, base, do_one_ref, &data);\n+}\n+\n+static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n+\t\t\t   each_ref_fn_oid fn, int trim, int flags, void *cb_data)\n+{\n+\tstruct ref_entry_cb data;\n+\tdata.base = base;\n+\tdata.trim = trim;\n+\tdata.flags = flags;\n+\tdata.fn = NULL;\n+\tdata.fn_oid = fn;\n \tdata.cb_data = cb_data;\n \n \tif (ref_paranoia < 0)\n@@ -1998,6 +2019,11 @@ int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n \treturn do_for_each_ref(get_ref_cache(submodule), \"\", fn, 0, 0, cb_data);\n }\n \n+static int for_each_ref_in_oid(const char *prefix, each_ref_fn_oid fn, void *cb_data)\n+{\n+\treturn do_for_each_ref_oid(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n+}\n+\n int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)\n {\n \treturn do_for_each_ref(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n@@ -2009,9 +2035,9 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n \treturn do_for_each_ref(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);\n }\n \n-int for_each_tag_ref(each_ref_fn fn, void *cb_data)\n+int for_each_tag_ref(each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn for_each_ref_in(\"refs/tags/\", fn, cb_data);\n+\treturn for_each_ref_in_oid(\"refs/tags/\", fn, cb_data);\n }\n \n int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\ndiff --git a/refs.h b/refs.h\nindex 6d7d9b4..b83529b 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -1,6 +1,8 @@\n #ifndef REFS_H\n #define REFS_H\n \n+#include \"cache.h\"\n+\n /*\n  * A ref_transaction represents a collection of ref updates\n  * that should succeed or fail together.\n@@ -70,6 +72,12 @@ typedef int each_ref_fn(const char *refname,\n \t\t\tconst unsigned char *sha1, int flags, void *cb_data);\n \n /*\n+ * Like each_ref_fn, but passes the object ID using a struct.\n+ */\n+typedef int each_ref_fn_oid(const char *refname,\n+\t\t\tconst struct object_id *oid, int flags, void *cb_data);\n+\n+/*\n  * The following functions invoke the specified callback function for\n  * each reference indicated.  If the function ever returns a nonzero\n  * value, stop the iteration and return that value.  Please note that\n@@ -81,7 +89,7 @@ typedef int each_ref_fn(const char *refname,\n extern int head_ref(each_ref_fn, void *);\n extern int for_each_ref(each_ref_fn, void *);\n extern int for_each_ref_in(const char *, each_ref_fn, void *);\n-extern int for_each_tag_ref(each_ref_fn, void *);\n+extern int for_each_tag_ref(each_ref_fn_oid, void *);\n extern int for_each_branch_ref(each_ref_fn, void *);\n extern int for_each_remote_ref(each_ref_fn, void *);\n extern int for_each_replace_ref(each_ref_fn, void *);\n-- \n2.3.5\n"},{"id":"259860","messageId":"1429745061-295908-4-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 03/16] refs: convert remaining users of for_each_ref_in to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:08Z","receivedAt":"2015-04-22T23:24:08Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Remove the temporary for_each_ref_in_oid function and update the users\nof it.  Convert the users of for_each_branch_ref and\nfor_each_remote_ref (which use for_each_ref_in under the hood) as well.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n bisect.c            |  8 ++++----\n builtin/rev-parse.c | 10 +++++-----\n refs.c              | 13 ++++---------\n refs.h              |  6 +++---\n 4 files changed, 16 insertions(+), 21 deletions(-)\n\ndiff --git a/bisect.c b/bisect.c\nindex 10f5e57..03d5cd9 100644\n--- a/bisect.c\n+++ b/bisect.c\n@@ -400,16 +400,16 @@ struct commit_list *find_bisection(struct commit_list *list,\n \treturn best;\n }\n \n-static int register_ref(const char *refname, const unsigned char *sha1,\n+static int register_ref(const char *refname, const struct object_id *oid,\n \t\t\tint flags, void *cb_data)\n {\n \tif (!strcmp(refname, \"bad\")) {\n \t\tcurrent_bad_oid = xmalloc(sizeof(*current_bad_oid));\n-\t\thashcpy(current_bad_oid->hash, sha1);\n+\t\toidcpy(current_bad_oid, oid);\n \t} else if (starts_with(refname, \"good-\")) {\n-\t\tsha1_array_append(&good_revs, sha1);\n+\t\tsha1_array_append(&good_revs, oid->hash);\n \t} else if (starts_with(refname, \"skip-\")) {\n-\t\tsha1_array_append(&skipped_revs, sha1);\n+\t\tsha1_array_append(&skipped_revs, oid->hash);\n \t}\n \n \treturn 0;\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 7b70650..c9f2c93 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -203,9 +203,9 @@ static int show_reference_oid(const char *refname, const struct object_id *oid,\n \treturn show_reference(refname, oid->hash, flag, cb_data);\n }\n \n-static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n-\tshow_rev(REVERSED, sha1, refname);\n+\tshow_rev(REVERSED, oid->hash, refname);\n \treturn 0;\n }\n \n@@ -665,7 +665,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--bisect\")) {\n-\t\t\t\tfor_each_ref_in(\"refs/bisect/bad\", show_reference, NULL);\n+\t\t\t\tfor_each_ref_in(\"refs/bisect/bad\", show_reference_oid, NULL);\n \t\t\t\tfor_each_ref_in(\"refs/bisect/good\", anti_reference, NULL);\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -676,7 +676,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--branches\")) {\n-\t\t\t\tfor_each_branch_ref(show_reference, NULL);\n+\t\t\t\tfor_each_branch_ref(show_reference_oid, NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\n@@ -703,7 +703,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--remotes\")) {\n-\t\t\t\tfor_each_remote_ref(show_reference, NULL);\n+\t\t\t\tfor_each_remote_ref(show_reference_oid, NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/refs.c b/refs.c\nindex 95863f2..a81c301 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2019,16 +2019,11 @@ int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n \treturn do_for_each_ref(get_ref_cache(submodule), \"\", fn, 0, 0, cb_data);\n }\n \n-static int for_each_ref_in_oid(const char *prefix, each_ref_fn_oid fn, void *cb_data)\n+int for_each_ref_in(const char *prefix, each_ref_fn_oid fn, void *cb_data)\n {\n \treturn do_for_each_ref_oid(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n }\n \n-int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)\n-{\n-\treturn do_for_each_ref(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n-}\n-\n int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n \t\teach_ref_fn fn, void *cb_data)\n {\n@@ -2037,7 +2032,7 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n \n int for_each_tag_ref(each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn for_each_ref_in_oid(\"refs/tags/\", fn, cb_data);\n+\treturn for_each_ref_in(\"refs/tags/\", fn, cb_data);\n }\n \n int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n@@ -2045,7 +2040,7 @@ int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_d\n \treturn for_each_ref_in_submodule(submodule, \"refs/tags/\", fn, cb_data);\n }\n \n-int for_each_branch_ref(each_ref_fn fn, void *cb_data)\n+int for_each_branch_ref(each_ref_fn_oid fn, void *cb_data)\n {\n \treturn for_each_ref_in(\"refs/heads/\", fn, cb_data);\n }\n@@ -2055,7 +2050,7 @@ int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *c\n \treturn for_each_ref_in_submodule(submodule, \"refs/heads/\", fn, cb_data);\n }\n \n-int for_each_remote_ref(each_ref_fn fn, void *cb_data)\n+int for_each_remote_ref(each_ref_fn_oid fn, void *cb_data)\n {\n \treturn for_each_ref_in(\"refs/remotes/\", fn, cb_data);\n }\ndiff --git a/refs.h b/refs.h\nindex b83529b..d6ef917 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -88,10 +88,10 @@ typedef int each_ref_fn_oid(const char *refname,\n  */\n extern int head_ref(each_ref_fn, void *);\n extern int for_each_ref(each_ref_fn, void *);\n-extern int for_each_ref_in(const char *, each_ref_fn, void *);\n+extern int for_each_ref_in(const char *, each_ref_fn_oid, void *);\n extern int for_each_tag_ref(each_ref_fn_oid, void *);\n-extern int for_each_branch_ref(each_ref_fn, void *);\n-extern int for_each_remote_ref(each_ref_fn, void *);\n+extern int for_each_branch_ref(each_ref_fn_oid, void *);\n+extern int for_each_remote_ref(each_ref_fn_oid, void *);\n extern int for_each_replace_ref(each_ref_fn, void *);\n extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);\n extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);\n-- \n2.3.5\n"},{"id":"259861","messageId":"1429745061-295908-5-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 04/16] refs: convert for_each_ref_in_submodule to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:09Z","receivedAt":"2015-04-22T23:24:09Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert for_each_ref_in_submodule and all of its caller.  Introduce two\ntemporary wrappers in revision.c to handle the incompatibilities between\neach_ref_fn and each_ref_fn_oid.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n refs.c      | 10 +++++-----\n refs.h      |  8 ++++----\n revision.c  | 28 +++++++++++++++++++++-------\n submodule.c |  2 +-\n 4 files changed, 31 insertions(+), 17 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex a81c301..aa13cc2 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2025,9 +2025,9 @@ int for_each_ref_in(const char *prefix, each_ref_fn_oid fn, void *cb_data)\n }\n \n int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n-\t\teach_ref_fn fn, void *cb_data)\n+\t\teach_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);\n+\treturn do_for_each_ref_oid(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);\n }\n \n int for_each_tag_ref(each_ref_fn_oid fn, void *cb_data)\n@@ -2035,7 +2035,7 @@ int for_each_tag_ref(each_ref_fn_oid fn, void *cb_data)\n \treturn for_each_ref_in(\"refs/tags/\", fn, cb_data);\n }\n \n-int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n+int for_each_tag_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/tags/\", fn, cb_data);\n }\n@@ -2045,7 +2045,7 @@ int for_each_branch_ref(each_ref_fn_oid fn, void *cb_data)\n \treturn for_each_ref_in(\"refs/heads/\", fn, cb_data);\n }\n \n-int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n+int for_each_branch_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/heads/\", fn, cb_data);\n }\n@@ -2055,7 +2055,7 @@ int for_each_remote_ref(each_ref_fn_oid fn, void *cb_data)\n \treturn for_each_ref_in(\"refs/remotes/\", fn, cb_data);\n }\n \n-int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n+int for_each_remote_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/remotes/\", fn, cb_data);\n }\ndiff --git a/refs.h b/refs.h\nindex d6ef917..62eb553 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -99,10 +99,10 @@ extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* pr\n extern int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n extern int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n extern int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n-\t\teach_ref_fn fn, void *cb_data);\n-extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n-extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n-extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n+\t\teach_ref_fn_oid fn, void *cb_data);\n+extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n+extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n+extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n \n extern int head_ref_namespaced(each_ref_fn fn, void *cb_data);\n extern int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);\ndiff --git a/revision.c b/revision.c\nindex 7ddbaa0..93d9311 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1232,6 +1232,12 @@ static int handle_one_ref(const char *path, const unsigned char *sha1, int flag,\n \treturn 0;\n }\n \n+static int handle_one_ref_oid(const char *path, const struct object_id *oid,\n+\tint flag, void *cb_data)\n+{\n+\treturn handle_one_ref(path, oid->hash, flag, cb_data);\n+}\n+\n static void init_all_refs_cb(struct all_refs_cb *cb, struct rev_info *revs,\n \tunsigned flags)\n {\n@@ -1265,6 +1271,14 @@ 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_refs_oid(const char *submodule, struct rev_info *revs, unsigned flags,\n+\t\tint (*for_each)(const char *, each_ref_fn_oid, void *))\n+{\n+\tstruct all_refs_cb cb;\n+\tinit_all_refs_cb(&cb, revs, flags);\n+\tfor_each(submodule, handle_one_ref_oid, &cb);\n+}\n+\n static void handle_one_reflog_commit(unsigned char *sha1, void *cb_data)\n {\n \tstruct all_refs_cb *cb = cb_data;\n@@ -2073,12 +2087,12 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,\n \tctx->argc -= n;\n }\n \n-static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)\n+static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/bisect/bad\", fn, cb_data);\n }\n \n-static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)\n+static int for_each_good_bisect_ref(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/bisect/good\", fn, cb_data);\n }\n@@ -2106,17 +2120,17 @@ static int handle_revision_pseudo_opt(const char *submodule,\n \t\thandle_refs(submodule, revs, *flags, head_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--branches\")) {\n-\t\thandle_refs(submodule, revs, *flags, for_each_branch_ref_submodule);\n+\t\thandle_refs_oid(submodule, revs, *flags, for_each_branch_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--bisect\")) {\n-\t\thandle_refs(submodule, revs, *flags, for_each_bad_bisect_ref);\n-\t\thandle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);\n+\t\thandle_refs_oid(submodule, revs, *flags, for_each_bad_bisect_ref);\n+\t\thandle_refs_oid(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);\n \t\trevs->bisect = 1;\n \t} else if (!strcmp(arg, \"--tags\")) {\n-\t\thandle_refs(submodule, revs, *flags, for_each_tag_ref_submodule);\n+\t\thandle_refs_oid(submodule, revs, *flags, for_each_tag_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--remotes\")) {\n-\t\thandle_refs(submodule, revs, *flags, for_each_remote_ref_submodule);\n+\t\thandle_refs_oid(submodule, revs, *flags, for_each_remote_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if ((argcount = parse_long_opt(\"glob\", argv, &optarg))) {\n \t\tstruct all_refs_cb cb;\ndiff --git a/submodule.c b/submodule.c\nindex d491e6a..97e74c5 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -422,7 +422,7 @@ void set_config_fetch_recurse_submodules(int value)\n \tconfig_fetch_recurse_submodules = value;\n }\n \n-static int has_remote(const char *refname, const unsigned char *sha1, int flags, void *cb_data)\n+static int has_remote(const char *refname, const struct object_id *oid, int flags, void *cb_data)\n {\n \treturn 1;\n }\n-- \n2.3.5\n"},{"id":"259872","messageId":"1429745061-295908-6-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 05/16] refs: convert head_ref to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:10Z","receivedAt":"2015-04-22T23:24:10Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert head_ref and head_ref_submodule to use struct object_id.\nIntroduce some wrappers in some of the callers to handle\nincompatibilities between each_ref_fn and each_ref_fn_oid.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/show-ref.c |  7 ++++++-\n log-tree.c         |  7 ++++++-\n reachable.c        |  7 ++++++-\n refs.c             | 16 ++++++++--------\n refs.h             |  4 ++--\n revision.c         |  2 +-\n shallow.c          | 19 ++++++++++++++++---\n 7 files changed, 45 insertions(+), 17 deletions(-)\n\ndiff --git a/builtin/show-ref.c b/builtin/show-ref.c\nindex afb1030..c6c5939 100644\n--- a/builtin/show-ref.c\n+++ b/builtin/show-ref.c\n@@ -88,6 +88,11 @@ match:\n \treturn 0;\n }\n \n+static int show_ref_oid(const char *refname, const struct object_id *oid, int flag, void *cbdata)\n+{\n+\treturn show_ref(refname, oid->hash, flag, cbdata);\n+}\n+\n static int add_existing(const char *refname, const unsigned char *sha1, int flag, void *cbdata)\n {\n \tstruct string_list *list = (struct string_list *)cbdata;\n@@ -225,7 +230,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (show_head)\n-\t\thead_ref(show_ref, NULL);\n+\t\thead_ref(show_ref_oid, NULL);\n \tfor_each_ref(show_ref, NULL);\n \tif (!found_match) {\n \t\tif (verify && !quiet)\ndiff --git a/log-tree.c b/log-tree.c\nindex cf4646b..a29c17e 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -135,6 +135,11 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in\n \treturn 0;\n }\n \n+static int add_ref_decoration_oid(const char *refname, const struct object_id *oid, int flags, void *cb_data)\n+{\n+\treturn add_ref_decoration(refname, oid->hash, flags, cb_data);\n+}\n+\n static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)\n {\n \tstruct commit *commit = lookup_commit(graft->oid.hash);\n@@ -150,7 +155,7 @@ void load_ref_decorations(int flags)\n \tif (!loaded) {\n \t\tloaded = 1;\n \t\tfor_each_ref(add_ref_decoration, &flags);\n-\t\thead_ref(add_ref_decoration, &flags);\n+\t\thead_ref(add_ref_decoration_oid, &flags);\n \t\tfor_each_commit_graft(add_graft_decoration, NULL);\n \t}\n }\ndiff --git a/reachable.c b/reachable.c\nindex 69fa685..110ce92 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -32,6 +32,11 @@ static int add_one_ref(const char *path, const unsigned char *sha1, int flag, vo\n \treturn 0;\n }\n \n+static int add_one_ref_oid(const char *path, const struct object_id *oid, int flag, void *cb_data)\n+{\n+\treturn add_one_ref(path, oid->hash, flag, cb_data);\n+}\n+\n /*\n  * The traversal will have already marked us as SEEN, so we\n  * only need to handle any progress reporting here.\n@@ -171,7 +176,7 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,\n \tfor_each_ref(add_one_ref, revs);\n \n \t/* detached HEAD is not included in the list above */\n-\thead_ref(add_one_ref, revs);\n+\thead_ref(add_one_ref_oid, revs);\n \n \t/* Add all reflog info */\n \tif (mark_reflog)\ndiff --git a/refs.c b/refs.c\nindex aa13cc2..7a8b579 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1981,30 +1981,30 @@ static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n \treturn do_for_each_entry(refs, base, do_one_ref, &data);\n }\n \n-static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)\n+static int do_head_ref(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tint flag;\n \n \tif (submodule) {\n-\t\tif (resolve_gitlink_ref(submodule, \"HEAD\", sha1) == 0)\n-\t\t\treturn fn(\"HEAD\", sha1, 0, cb_data);\n+\t\tif (resolve_gitlink_ref(submodule, \"HEAD\", oid.hash) == 0)\n+\t\t\treturn fn(\"HEAD\", &oid, 0, cb_data);\n \n \t\treturn 0;\n \t}\n \n-\tif (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, sha1, &flag))\n-\t\treturn fn(\"HEAD\", sha1, flag, cb_data);\n+\tif (!read_ref_full(\"HEAD\", RESOLVE_REF_READING, oid.hash, &flag))\n+\t\treturn fn(\"HEAD\", &oid, flag, cb_data);\n \n \treturn 0;\n }\n \n-int head_ref(each_ref_fn fn, void *cb_data)\n+int head_ref(each_ref_fn_oid fn, void *cb_data)\n {\n \treturn do_head_ref(NULL, fn, cb_data);\n }\n \n-int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n+int head_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n \treturn do_head_ref(submodule, fn, cb_data);\n }\ndiff --git a/refs.h b/refs.h\nindex 62eb553..a14e7ef 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -86,7 +86,7 @@ typedef int each_ref_fn_oid(const char *refname,\n  * modifies the reference also returns a nonzero value to immediately\n  * stop the iteration.\n  */\n-extern int head_ref(each_ref_fn, void *);\n+extern int head_ref(each_ref_fn_oid, void *);\n extern int for_each_ref(each_ref_fn, void *);\n extern int for_each_ref_in(const char *, each_ref_fn_oid, void *);\n extern int for_each_tag_ref(each_ref_fn_oid, void *);\n@@ -96,7 +96,7 @@ extern int for_each_replace_ref(each_ref_fn, void *);\n extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);\n extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);\n \n-extern int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n+extern int head_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n extern int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n extern int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n \t\teach_ref_fn_oid fn, void *cb_data);\ndiff --git a/revision.c b/revision.c\nindex 93d9311..19005e8 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -2117,7 +2117,7 @@ static int handle_revision_pseudo_opt(const char *submodule,\n \t */\n \tif (!strcmp(arg, \"--all\")) {\n \t\thandle_refs(submodule, revs, *flags, for_each_ref_submodule);\n-\t\thandle_refs(submodule, revs, *flags, head_ref_submodule);\n+\t\thandle_refs_oid(submodule, revs, *flags, head_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--branches\")) {\n \t\thandle_refs_oid(submodule, revs, *flags, for_each_branch_ref_submodule);\ndiff --git a/shallow.c b/shallow.c\nindex d08d264..0343b16 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -487,6 +487,13 @@ static int mark_uninteresting(const char *refname,\n \treturn 0;\n }\n \n+static int mark_uninteresting_oid(const char *refname,\n+\t\t\t\tconst struct object_id *oid,\n+\t\t\t\tint flags, void *cb_data)\n+{\n+\treturn mark_uninteresting(refname, oid->hash, flags, cb_data);\n+}\n+\n static void post_assign_shallow(struct shallow_info *info,\n \t\t\t\tstruct ref_bitmap *ref_bitmap,\n \t\t\t\tint *ref_status);\n@@ -542,7 +549,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,\n \t * connect to old refs. If not (e.g. force ref updates) it'll\n \t * have to go down to the current shallow commits.\n \t */\n-\thead_ref(mark_uninteresting, NULL);\n+\thead_ref(mark_uninteresting_oid, NULL);\n \tfor_each_ref(mark_uninteresting, NULL);\n \n \t/* Mark potential bottoms so we won't go out of bound */\n@@ -595,6 +602,12 @@ static int add_ref(const char *refname,\n \treturn 0;\n }\n \n+static int add_ref_oid(const char *refname,\n+\t\t   const struct object_id *oid, int flags, void *cb_data)\n+{\n+\treturn add_ref(refname, oid->hash, flags, cb_data);\n+}\n+\n static void update_refstatus(int *ref_status, int nr, uint32_t *bitmap)\n {\n \tint i;\n@@ -641,7 +654,7 @@ static void post_assign_shallow(struct shallow_info *info,\n \tinfo->nr_theirs = dst;\n \n \tmemset(&ca, 0, sizeof(ca));\n-\thead_ref(add_ref, &ca);\n+\thead_ref(add_ref_oid, &ca);\n \tfor_each_ref(add_ref, &ca);\n \n \t/* Remove unreachable shallow commits from \"ours\" */\n@@ -675,7 +688,7 @@ int delayed_reachability_test(struct shallow_info *si, int c)\n \t\tif (!si->commits) {\n \t\t\tstruct commit_array ca;\n \t\t\tmemset(&ca, 0, sizeof(ca));\n-\t\t\thead_ref(add_ref, &ca);\n+\t\t\thead_ref(add_ref_oid, &ca);\n \t\t\tfor_each_ref(add_ref, &ca);\n \t\t\tsi->commits = ca.commits;\n \t\t\tsi->nr_commits = ca.nr;\n-- \n2.3.5\n"},{"id":"259873","messageId":"1429745061-295908-7-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 06/16] refs: convert for_each_ref_submodule to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:11Z","receivedAt":"2015-04-22T23:24:11Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert the callers as well.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n refs.c     | 4 ++--\n refs.h     | 2 +-\n revision.c | 2 +-\n 3 files changed, 4 insertions(+), 4 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 7a8b579..68d0af8 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2014,9 +2014,9 @@ int for_each_ref(each_ref_fn fn, void *cb_data)\n \treturn do_for_each_ref(&ref_cache, \"\", fn, 0, 0, cb_data);\n }\n \n-int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n+int for_each_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref(get_ref_cache(submodule), \"\", fn, 0, 0, cb_data);\n+\treturn do_for_each_ref_oid(get_ref_cache(submodule), \"\", fn, 0, 0, cb_data);\n }\n \n int for_each_ref_in(const char *prefix, each_ref_fn_oid fn, void *cb_data)\ndiff --git a/refs.h b/refs.h\nindex a14e7ef..2476951 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -97,7 +97,7 @@ extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);\n extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);\n \n extern int head_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n-extern int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n+extern int for_each_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n extern int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n \t\teach_ref_fn_oid fn, void *cb_data);\n extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\ndiff --git a/revision.c b/revision.c\nindex 19005e8..825fbba 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -2116,7 +2116,7 @@ static int handle_revision_pseudo_opt(const char *submodule,\n \t * register it in the list at the top of handle_revision_opt.\n \t */\n \tif (!strcmp(arg, \"--all\")) {\n-\t\thandle_refs(submodule, revs, *flags, for_each_ref_submodule);\n+\t\thandle_refs_oid(submodule, revs, *flags, for_each_ref_submodule);\n \t\thandle_refs_oid(submodule, revs, *flags, head_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--branches\")) {\n-- \n2.3.5\n"},{"id":"259867","messageId":"1429745061-295908-8-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 07/16] revision: remove unused _oid helper.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:12Z","receivedAt":"2015-04-22T23:24:12Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Now that all the callers of handle_refs are gone, rename handle_refs_oid\nto handle_refs and update the callers accordingly.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n revision.c | 22 +++++++---------------\n 1 file changed, 7 insertions(+), 15 deletions(-)\n\ndiff --git a/revision.c b/revision.c\nindex 825fbba..6fb499f 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1264,14 +1264,6 @@ void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude)\n }\n \n static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags,\n-\t\tint (*for_each)(const char *, each_ref_fn, void *))\n-{\n-\tstruct all_refs_cb cb;\n-\tinit_all_refs_cb(&cb, revs, flags);\n-\tfor_each(submodule, handle_one_ref, &cb);\n-}\n-\n-static void handle_refs_oid(const char *submodule, struct rev_info *revs, unsigned flags,\n \t\tint (*for_each)(const char *, each_ref_fn_oid, void *))\n {\n \tstruct all_refs_cb cb;\n@@ -2116,21 +2108,21 @@ static int handle_revision_pseudo_opt(const char *submodule,\n \t * register it in the list at the top of handle_revision_opt.\n \t */\n \tif (!strcmp(arg, \"--all\")) {\n-\t\thandle_refs_oid(submodule, revs, *flags, for_each_ref_submodule);\n-\t\thandle_refs_oid(submodule, revs, *flags, head_ref_submodule);\n+\t\thandle_refs(submodule, revs, *flags, for_each_ref_submodule);\n+\t\thandle_refs(submodule, revs, *flags, head_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--branches\")) {\n-\t\thandle_refs_oid(submodule, revs, *flags, for_each_branch_ref_submodule);\n+\t\thandle_refs(submodule, revs, *flags, for_each_branch_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--bisect\")) {\n-\t\thandle_refs_oid(submodule, revs, *flags, for_each_bad_bisect_ref);\n-\t\thandle_refs_oid(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);\n+\t\thandle_refs(submodule, revs, *flags, for_each_bad_bisect_ref);\n+\t\thandle_refs(submodule, revs, *flags ^ (UNINTERESTING | BOTTOM), for_each_good_bisect_ref);\n \t\trevs->bisect = 1;\n \t} else if (!strcmp(arg, \"--tags\")) {\n-\t\thandle_refs_oid(submodule, revs, *flags, for_each_tag_ref_submodule);\n+\t\thandle_refs(submodule, revs, *flags, for_each_tag_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--remotes\")) {\n-\t\thandle_refs_oid(submodule, revs, *flags, for_each_remote_ref_submodule);\n+\t\thandle_refs(submodule, revs, *flags, for_each_remote_ref_submodule);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if ((argcount = parse_long_opt(\"glob\", argv, &optarg))) {\n \t\tstruct all_refs_cb cb;\n-- \n2.3.5\n"},{"id":"259862","messageId":"1429745061-295908-9-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 08/16] refs: convert for_each_ref to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:13Z","receivedAt":"2015-04-22T23:24:13Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert for_each_ref, for_each_glob_ref, and for_each_glob_ref_in to use\nstruct object_id, as the latter two call the former with the function\npointer they are provided.\n\nConvert callers to refer to properly-typed functions.  Convert uses of\nthe constant 20 to GIT_SHA1_RAWSZ.  Where possible, convert modified\nfunctions to use struct object_id instead of unsigned char [20].\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/checkout.c     |  4 ++--\n builtin/fetch.c        |  6 +++---\n builtin/name-rev.c     |  6 +++---\n builtin/pack-objects.c | 10 +++++-----\n builtin/receive-pack.c |  4 ++--\n builtin/reflog.c       |  6 +++---\n builtin/remote.c       | 14 +++++++-------\n builtin/rev-parse.c    | 10 +++++-----\n builtin/show-branch.c  | 24 ++++++++++++------------\n builtin/show-ref.c     |  4 ++--\n fetch-pack.c           | 18 ++++++++++++++----\n help.c                 |  2 +-\n log-tree.c             |  2 +-\n notes.c                |  2 +-\n reachable.c            |  2 +-\n refs.c                 | 16 ++++++++--------\n refs.h                 |  6 +++---\n remote.c               |  8 ++++----\n revision.c             |  8 ++++----\n server-info.c          |  6 +++---\n sha1_name.c            |  4 ++--\n shallow.c              |  6 +++---\n submodule.c            |  4 ++--\n transport.c            | 10 +++++-----\n walker.c               |  4 ++--\n 25 files changed, 98 insertions(+), 88 deletions(-)\n\ndiff --git a/builtin/checkout.c b/builtin/checkout.c\nindex 2f92328..9b49f0e 100644\n--- a/builtin/checkout.c\n+++ b/builtin/checkout.c\n@@ -702,10 +702,10 @@ static void update_refs_for_switch(const struct checkout_opts *opts,\n }\n \n static int add_pending_uninteresting_ref(const char *refname,\n-\t\t\t\t\t const unsigned char *sha1,\n+\t\t\t\t\t const struct object_id *oid,\n \t\t\t\t\t int flags, void *cb_data)\n {\n-\tadd_pending_sha1(cb_data, refname, sha1, UNINTERESTING);\n+\tadd_pending_sha1(cb_data, refname, oid->hash, UNINTERESTING);\n \treturn 0;\n }\n \ndiff --git a/builtin/fetch.c b/builtin/fetch.c\nindex 7910419..2e792f3 100644\n--- a/builtin/fetch.c\n+++ b/builtin/fetch.c\n@@ -179,13 +179,13 @@ static void add_merge_config(struct ref **head,\n \t}\n }\n \n-static int add_existing(const char *refname, const unsigned char *sha1,\n+static int add_existing(const char *refname, const struct object_id *oid,\n \t\t\tint flag, void *cbdata)\n {\n \tstruct string_list *list = (struct string_list *)cbdata;\n \tstruct string_list_item *item = string_list_insert(list, refname);\n-\titem->util = xmalloc(20);\n-\thashcpy(item->util, sha1);\n+\titem->util = xmalloc(GIT_SHA1_RAWSZ);\n+\thashcpy(item->util, oid->hash);\n \treturn 0;\n }\n \ndiff --git a/builtin/name-rev.c b/builtin/name-rev.c\nindex 9736d44..248a3eb 100644\n--- a/builtin/name-rev.c\n+++ b/builtin/name-rev.c\n@@ -138,9 +138,9 @@ static int tipcmp(const void *a_, const void *b_)\n \treturn hashcmp(a->sha1, b->sha1);\n }\n \n-static int name_ref(const char *path, const unsigned char *sha1, int flags, void *cb_data)\n+static int name_ref(const char *path, const struct object_id *oid, int flags, void *cb_data)\n {\n-\tstruct object *o = parse_object(sha1);\n+\tstruct object *o = parse_object(oid->hash);\n \tstruct name_ref_data *data = cb_data;\n \tint can_abbreviate_output = data->tags_only && data->name_only;\n \tint deref = 0;\n@@ -160,7 +160,7 @@ static int name_ref(const char *path, const unsigned char *sha1, int flags, void\n \t\t}\n \t}\n \n-\tadd_to_tip_table(sha1, path, can_abbreviate_output);\n+\tadd_to_tip_table(oid->hash, path, can_abbreviate_output);\n \n \twhile (o && o->type == OBJ_TAG) {\n \t\tstruct tag *t = (struct tag *) o;\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex 0c69b0c..80fe8c7 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -2097,14 +2097,14 @@ static void ll_find_deltas(struct object_entry **list, unsigned list_size,\n #define ll_find_deltas(l, s, w, d, p)\tfind_deltas(l, &s, w, d, p)\n #endif\n \n-static int add_ref_tag(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n+static int add_ref_tag(const char *path, const struct object_id *oid, int flag, void *cb_data)\n {\n-\tunsigned char peeled[20];\n+\tstruct object_id peeled;\n \n \tif (starts_with(path, \"refs/tags/\") && /* is a tag? */\n-\t    !peel_ref(path, peeled)        && /* peelable? */\n-\t    packlist_find(&to_pack, peeled, NULL))      /* object packed? */\n-\t\tadd_object_entry(sha1, OBJ_TAG, NULL, 0);\n+\t    !peel_ref(path, peeled.hash)    && /* peelable? */\n+\t    packlist_find(&to_pack, peeled.hash, NULL))      /* object packed? */\n+\t\tadd_object_entry(oid->hash, OBJ_TAG, NULL, 0);\n \treturn 0;\n }\n \ndiff --git a/builtin/receive-pack.c b/builtin/receive-pack.c\nindex d2ec52b..85e60e2 100644\n--- a/builtin/receive-pack.c\n+++ b/builtin/receive-pack.c\n@@ -197,7 +197,7 @@ static void show_ref(const char *path, const unsigned char *sha1)\n \t}\n }\n \n-static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, void *unused)\n+static int show_ref_cb(const char *path, const struct object_id *oid, int flag, void *unused)\n {\n \tpath = strip_namespace(path);\n \t/*\n@@ -210,7 +210,7 @@ static int show_ref_cb(const char *path, const unsigned char *sha1, int flag, vo\n \t */\n \tif (!path)\n \t\tpath = \".have\";\n-\tshow_ref(path, sha1);\n+\tshow_ref(path, oid->hash);\n \treturn 0;\n }\n \ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 8182b64..f3f9201 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -313,14 +313,14 @@ static int should_expire_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n \treturn 0;\n }\n \n-static int push_tip_to_list(const char *refname, const unsigned char *sha1,\n-\t\t\t    int flags, void *cb_data)\n+static int push_tip_to_list(const char *refname, const struct object_id *oid,\n+\t\t\t\tint flags, void *cb_data)\n {\n \tstruct commit_list **list = cb_data;\n \tstruct commit *tip_commit;\n \tif (flags & REF_ISSYMREF)\n \t\treturn 0;\n-\ttip_commit = lookup_commit_reference_gently(sha1, 1);\n+\ttip_commit = lookup_commit_reference_gently(oid->hash, 1);\n \tif (!tip_commit)\n \t\treturn 0;\n \tcommit_list_insert(tip_commit, list);\ndiff --git a/builtin/remote.c b/builtin/remote.c\nindex ad57fc9..67307ed 100644\n--- a/builtin/remote.c\n+++ b/builtin/remote.c\n@@ -509,7 +509,7 @@ struct branches_for_remote {\n };\n \n static int add_branch_for_removal(const char *refname,\n-\tconst unsigned char *sha1, int flags, void *cb_data)\n+\tconst struct object_id *oid, int flags, void *cb_data)\n {\n \tstruct branches_for_remote *branches = cb_data;\n \tstruct refspec refspec;\n@@ -544,8 +544,8 @@ static int add_branch_for_removal(const char *refname,\n \t\treturn unlink(git_path(\"%s\", refname));\n \n \titem = string_list_append(branches->branches, refname);\n-\titem->util = xmalloc(20);\n-\thashcpy(item->util, sha1);\n+\titem->util = xmalloc(GIT_SHA1_RAWSZ);\n+\thashcpy(item->util, oid->hash);\n \n \treturn 0;\n }\n@@ -557,20 +557,20 @@ struct rename_info {\n };\n \n static int read_remote_branches(const char *refname,\n-\tconst unsigned char *sha1, int flags, void *cb_data)\n+\tconst struct object_id *oid, int flags, void *cb_data)\n {\n \tstruct rename_info *rename = cb_data;\n \tstruct strbuf buf = STRBUF_INIT;\n \tstruct string_list_item *item;\n \tint flag;\n-\tunsigned char orig_sha1[20];\n+\tstruct object_id orig_oid;\n \tconst char *symref;\n \n \tstrbuf_addf(&buf, \"refs/remotes/%s/\", rename->old);\n \tif (starts_with(refname, buf.buf)) {\n \t\titem = string_list_append(rename->remote_branches, xstrdup(refname));\n \t\tsymref = resolve_ref_unsafe(refname, RESOLVE_REF_READING,\n-\t\t\t\t\t    orig_sha1, &flag);\n+\t\t\t\t\t    orig_oid.hash, &flag);\n \t\tif (flag & REF_ISSYMREF)\n \t\t\titem->util = xstrdup(symref);\n \t\telse\n@@ -867,7 +867,7 @@ static void free_remote_ref_states(struct ref_states *states)\n }\n \n static int append_ref_to_tracked_list(const char *refname,\n-\tconst unsigned char *sha1, int flags, void *cb_data)\n+\tconst struct object_id *oid, int flags, void *cb_data)\n {\n \tstruct ref_states *states = cb_data;\n \tstruct refspec refspec;\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex c9f2c93..4aa7a25 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -657,7 +657,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--all\")) {\n-\t\t\t\tfor_each_ref(show_reference, NULL);\n+\t\t\t\tfor_each_ref(show_reference_oid, NULL);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--disambiguate=\")) {\n@@ -670,7 +670,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--branches=\")) {\n-\t\t\t\tfor_each_glob_ref_in(show_reference, arg + 11,\n+\t\t\t\tfor_each_glob_ref_in(show_reference_oid, arg + 11,\n \t\t\t\t\t\"refs/heads/\", NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n@@ -681,7 +681,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--tags=\")) {\n-\t\t\t\tfor_each_glob_ref_in(show_reference, arg + 7,\n+\t\t\t\tfor_each_glob_ref_in(show_reference_oid, arg + 7,\n \t\t\t\t\t\"refs/tags/\", NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n@@ -692,12 +692,12 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--glob=\")) {\n-\t\t\t\tfor_each_glob_ref(show_reference, arg + 7, NULL);\n+\t\t\t\tfor_each_glob_ref(show_reference_oid, arg + 7, NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--remotes=\")) {\n-\t\t\t\tfor_each_glob_ref_in(show_reference, arg + 10,\n+\t\t\t\tfor_each_glob_ref_in(show_reference_oid, arg + 10,\n \t\t\t\t\t\"refs/remotes/\", NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\ndiff --git a/builtin/show-branch.c b/builtin/show-branch.c\nindex e69fb7c..e04fa8e 100644\n--- a/builtin/show-branch.c\n+++ b/builtin/show-branch.c\n@@ -394,32 +394,32 @@ static int append_ref(const char *refname, const unsigned char *sha1,\n \treturn 0;\n }\n \n-static int append_head_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int append_head_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n-\tunsigned char tmp[20];\n+\tstruct object_id tmp;\n \tint ofs = 11;\n \tif (!starts_with(refname, \"refs/heads/\"))\n \t\treturn 0;\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n-\tif (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))\n+\tif (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))\n \t\tofs = 5;\n-\treturn append_ref(refname + ofs, sha1, 0);\n+\treturn append_ref(refname + ofs, oid->hash, 0);\n }\n \n-static int append_remote_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int append_remote_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n-\tunsigned char tmp[20];\n+\tstruct object_id tmp;\n \tint ofs = 13;\n \tif (!starts_with(refname, \"refs/remotes/\"))\n \t\treturn 0;\n \t/* If both heads/foo and tags/foo exists, get_sha1 would\n \t * get confused.\n \t */\n-\tif (get_sha1(refname + ofs, tmp) || hashcmp(tmp, sha1))\n+\tif (get_sha1(refname + ofs, tmp.hash) || oidcmp(&tmp, oid))\n \t\tofs = 5;\n-\treturn append_ref(refname + ofs, sha1, 0);\n+\treturn append_ref(refname + ofs, oid->hash, 0);\n }\n \n static int append_tag_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n@@ -440,7 +440,7 @@ static int count_slash(const char *s)\n \treturn cnt;\n }\n \n-static int append_matching_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int append_matching_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n \t/* we want to allow pattern hold/<asterisk> to show all\n \t * branches under refs/heads/hold/, and v0.99.9? to show\n@@ -456,10 +456,10 @@ static int append_matching_ref(const char *refname, const unsigned char *sha1, i\n \tif (wildmatch(match_ref_pattern, tail, 0, NULL))\n \t\treturn 0;\n \tif (starts_with(refname, \"refs/heads/\"))\n-\t\treturn append_head_ref(refname, sha1, flag, cb_data);\n+\t\treturn append_head_ref(refname, oid, flag, cb_data);\n \tif (starts_with(refname, \"refs/tags/\"))\n-\t\treturn append_tag_ref(refname, sha1, flag, cb_data);\n-\treturn append_ref(refname, sha1, 0);\n+\t\treturn append_tag_ref(refname, oid->hash, flag, cb_data);\n+\treturn append_ref(refname, oid->hash, 0);\n }\n \n static void snarf_refs(int head, int remotes)\ndiff --git a/builtin/show-ref.c b/builtin/show-ref.c\nindex c6c5939..6731721 100644\n--- a/builtin/show-ref.c\n+++ b/builtin/show-ref.c\n@@ -93,7 +93,7 @@ static int show_ref_oid(const char *refname, const struct object_id *oid, int fl\n \treturn show_ref(refname, oid->hash, flag, cbdata);\n }\n \n-static int add_existing(const char *refname, const unsigned char *sha1, int flag, void *cbdata)\n+static int add_existing(const char *refname, const struct object_id *oid, int flag, void *cbdata)\n {\n \tstruct string_list *list = (struct string_list *)cbdata;\n \tstring_list_insert(list, refname);\n@@ -231,7 +231,7 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)\n \n \tif (show_head)\n \t\thead_ref(show_ref_oid, NULL);\n-\tfor_each_ref(show_ref, NULL);\n+\tfor_each_ref(show_ref_oid, NULL);\n \tif (!found_match) {\n \t\tif (verify && !quiet)\n \t\t\tdie(\"No match\");\ndiff --git a/fetch-pack.c b/fetch-pack.c\nindex 48526aa..65a57e1 100644\n--- a/fetch-pack.c\n+++ b/fetch-pack.c\n@@ -70,9 +70,14 @@ static int rev_list_insert_ref(const char *refname, const unsigned char *sha1, i\n \treturn 0;\n }\n \n-static int clear_marks(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int rev_list_insert_ref_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n-\tstruct object *o = deref_tag(parse_object(sha1), refname, 0);\n+\treturn rev_list_insert_ref(refname, oid->hash, flag, cb_data);\n+}\n+\n+static int clear_marks(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n+{\n+\tstruct object *o = deref_tag(parse_object(oid->hash), refname, 0);\n \n \tif (o && o->type == OBJ_COMMIT)\n \t\tclear_commit_marks((struct commit *)o,\n@@ -263,7 +268,7 @@ static int find_common(struct fetch_pack_args *args,\n \t\tfor_each_ref(clear_marks, NULL);\n \tmarked = 1;\n \n-\tfor_each_ref(rev_list_insert_ref, NULL);\n+\tfor_each_ref(rev_list_insert_ref_oid, NULL);\n \tfor_each_alternate_ref(insert_one_alternate_ref, NULL);\n \n \tfetching = 0;\n@@ -487,6 +492,11 @@ static int mark_complete(const char *refname, const unsigned char *sha1, int fla\n \treturn 0;\n }\n \n+static int mark_complete_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n+{\n+\treturn mark_complete(refname, oid->hash, flag, cb_data);\n+}\n+\n static void mark_recent_complete_commits(struct fetch_pack_args *args,\n \t\t\t\t\t unsigned long cutoff)\n {\n@@ -599,7 +609,7 @@ static int everything_local(struct fetch_pack_args *args,\n \t}\n \n \tif (!args->depth) {\n-\t\tfor_each_ref(mark_complete, NULL);\n+\t\tfor_each_ref(mark_complete_oid, NULL);\n \t\tfor_each_alternate_ref(mark_alternate_complete, NULL);\n \t\tcommit_list_sort_by_date(&complete);\n \t\tif (cutoff)\ndiff --git a/help.c b/help.c\nindex 2072a87..6f3415b 100644\n--- a/help.c\n+++ b/help.c\n@@ -407,7 +407,7 @@ struct similar_ref_cb {\n \tstruct string_list *similar_refs;\n };\n \n-static int append_similar_ref(const char *refname, const unsigned char *sha1,\n+static int append_similar_ref(const char *refname, const struct object_id *oid,\n \t\t\t      int flags, void *cb_data)\n {\n \tstruct similar_ref_cb *cb = (struct similar_ref_cb *)(cb_data);\ndiff --git a/log-tree.c b/log-tree.c\nindex a29c17e..acbc859 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -154,7 +154,7 @@ void load_ref_decorations(int flags)\n \tstatic int loaded;\n \tif (!loaded) {\n \t\tloaded = 1;\n-\t\tfor_each_ref(add_ref_decoration, &flags);\n+\t\tfor_each_ref(add_ref_decoration_oid, &flags);\n \t\thead_ref(add_ref_decoration_oid, &flags);\n \t\tfor_each_commit_graft(add_graft_decoration, NULL);\n \t}\ndiff --git a/notes.c b/notes.c\nindex 2be4d7f..df08209 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -918,7 +918,7 @@ out:\n \treturn ret;\n }\n \n-static int string_list_add_one_ref(const char *refname, const unsigned char *sha1,\n+static int string_list_add_one_ref(const char *refname, const struct object_id *oid,\n \t\t\t\t   int flag, void *cb)\n {\n \tstruct string_list *refs = cb;\ndiff --git a/reachable.c b/reachable.c\nindex 110ce92..b2ca0c3 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -173,7 +173,7 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,\n \tadd_index_objects_to_pending(revs, 0);\n \n \t/* Add all external refs */\n-\tfor_each_ref(add_one_ref, revs);\n+\tfor_each_ref(add_one_ref_oid, revs);\n \n \t/* detached HEAD is not included in the list above */\n \thead_ref(add_one_ref_oid, revs);\ndiff --git a/refs.c b/refs.c\nindex 68d0af8..6bf7abc 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1675,7 +1675,7 @@ char *resolve_refdup(const char *ref, int resolve_flags, unsigned char *sha1, in\n /* The argument to filter_refs */\n struct ref_filter {\n \tconst char *pattern;\n-\teach_ref_fn *fn;\n+\teach_ref_fn_oid *fn;\n \tvoid *cb_data;\n };\n \n@@ -1697,13 +1697,13 @@ int ref_exists(const char *refname)\n \treturn !!resolve_ref_unsafe(refname, RESOLVE_REF_READING, sha1, NULL);\n }\n \n-static int filter_refs(const char *refname, const unsigned char *sha1, int flags,\n-\t\t       void *data)\n+static int filter_refs(const char *refname, const struct object_id *oid,\n+\t\t\t   int flags, void *data)\n {\n \tstruct ref_filter *filter = (struct ref_filter *)data;\n \tif (wildmatch(filter->pattern, refname, 0, NULL))\n \t\treturn 0;\n-\treturn filter->fn(refname, sha1, flags, filter->cb_data);\n+\treturn filter->fn(refname, oid, flags, filter->cb_data);\n }\n \n enum peel_status {\n@@ -2009,9 +2009,9 @@ int head_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n \treturn do_head_ref(submodule, fn, cb_data);\n }\n \n-int for_each_ref(each_ref_fn fn, void *cb_data)\n+int for_each_ref(each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref(&ref_cache, \"\", fn, 0, 0, cb_data);\n+\treturn do_for_each_ref_oid(&ref_cache, \"\", fn, 0, 0, cb_data);\n }\n \n int for_each_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n@@ -2090,7 +2090,7 @@ int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)\n \treturn ret;\n }\n \n-int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,\n+int for_each_glob_ref_in(each_ref_fn_oid fn, const char *pattern,\n \tconst char *prefix, void *cb_data)\n {\n \tstruct strbuf real_pattern = STRBUF_INIT;\n@@ -2120,7 +2120,7 @@ int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,\n \treturn ret;\n }\n \n-int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)\n+int for_each_glob_ref(each_ref_fn_oid fn, const char *pattern, void *cb_data)\n {\n \treturn for_each_glob_ref_in(fn, pattern, NULL, cb_data);\n }\ndiff --git a/refs.h b/refs.h\nindex 2476951..c041cd1 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -87,14 +87,14 @@ typedef int each_ref_fn_oid(const char *refname,\n  * stop the iteration.\n  */\n extern int head_ref(each_ref_fn_oid, void *);\n-extern int for_each_ref(each_ref_fn, void *);\n+extern int for_each_ref(each_ref_fn_oid, void *);\n extern int for_each_ref_in(const char *, each_ref_fn_oid, void *);\n extern int for_each_tag_ref(each_ref_fn_oid, void *);\n extern int for_each_branch_ref(each_ref_fn_oid, void *);\n extern int for_each_remote_ref(each_ref_fn_oid, void *);\n extern int for_each_replace_ref(each_ref_fn, void *);\n-extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);\n-extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);\n+extern int for_each_glob_ref(each_ref_fn_oid, const char *pattern, void *);\n+extern int for_each_glob_ref_in(each_ref_fn_oid, const char *pattern, const char* prefix, void *);\n \n extern int head_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n extern int for_each_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\ndiff --git a/remote.c b/remote.c\nindex 68901b0..b544997 100644\n--- a/remote.c\n+++ b/remote.c\n@@ -2024,7 +2024,7 @@ int format_tracking_info(struct branch *branch, struct strbuf *sb)\n \treturn 1;\n }\n \n-static int one_local_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int one_local_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n \tstruct ref ***local_tail = cb_data;\n \tstruct ref *ref;\n@@ -2036,7 +2036,7 @@ static int one_local_ref(const char *refname, const unsigned char *sha1, int fla\n \n \tlen = strlen(refname) + 1;\n \tref = xcalloc(1, sizeof(*ref) + len);\n-\thashcpy(ref->new_sha1, sha1);\n+\thashcpy(ref->new_sha1, oid->hash);\n \tmemcpy(ref->name, refname, len);\n \t**local_tail = ref;\n \t*local_tail = &ref->next;\n@@ -2099,7 +2099,7 @@ struct stale_heads_info {\n };\n \n static int get_stale_heads_cb(const char *refname,\n-\tconst unsigned char *sha1, int flags, void *cb_data)\n+\tconst struct object_id *oid, int flags, void *cb_data)\n {\n \tstruct stale_heads_info *info = cb_data;\n \tstruct string_list matches = STRING_LIST_INIT_DUP;\n@@ -2128,7 +2128,7 @@ static int get_stale_heads_cb(const char *refname,\n \n \tif (stale) {\n \t\tstruct ref *ref = make_linked_ref(refname, &info->stale_refs_tail);\n-\t\thashcpy(ref->new_sha1, sha1);\n+\t\thashcpy(ref->new_sha1, oid->hash);\n \t}\n \n clean_exit:\ndiff --git a/revision.c b/revision.c\nindex 6fb499f..29af759 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -2127,7 +2127,7 @@ static int handle_revision_pseudo_opt(const char *submodule,\n \t} else if ((argcount = parse_long_opt(\"glob\", argv, &optarg))) {\n \t\tstruct all_refs_cb cb;\n \t\tinit_all_refs_cb(&cb, revs, *flags);\n-\t\tfor_each_glob_ref(handle_one_ref, optarg, &cb);\n+\t\tfor_each_glob_ref(handle_one_ref_oid, optarg, &cb);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t\treturn argcount;\n \t} else if ((argcount = parse_long_opt(\"exclude\", argv, &optarg))) {\n@@ -2136,17 +2136,17 @@ static int handle_revision_pseudo_opt(const char *submodule,\n \t} else if (starts_with(arg, \"--branches=\")) {\n \t\tstruct all_refs_cb cb;\n \t\tinit_all_refs_cb(&cb, revs, *flags);\n-\t\tfor_each_glob_ref_in(handle_one_ref, arg + 11, \"refs/heads/\", &cb);\n+\t\tfor_each_glob_ref_in(handle_one_ref_oid, arg + 11, \"refs/heads/\", &cb);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (starts_with(arg, \"--tags=\")) {\n \t\tstruct all_refs_cb cb;\n \t\tinit_all_refs_cb(&cb, revs, *flags);\n-\t\tfor_each_glob_ref_in(handle_one_ref, arg + 7, \"refs/tags/\", &cb);\n+\t\tfor_each_glob_ref_in(handle_one_ref_oid, arg + 7, \"refs/tags/\", &cb);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (starts_with(arg, \"--remotes=\")) {\n \t\tstruct all_refs_cb cb;\n \t\tinit_all_refs_cb(&cb, revs, *flags);\n-\t\tfor_each_glob_ref_in(handle_one_ref, arg + 10, \"refs/remotes/\", &cb);\n+\t\tfor_each_glob_ref_in(handle_one_ref_oid, arg + 10, \"refs/remotes/\", &cb);\n \t\tclear_ref_exclusion(&revs->ref_excludes);\n \t} else if (!strcmp(arg, \"--reflog\")) {\n \t\tadd_reflogs_to_pending(revs, *flags);\ndiff --git a/server-info.c b/server-info.c\nindex 34b0253..11f21bd 100644\n--- a/server-info.c\n+++ b/server-info.c\n@@ -47,14 +47,14 @@ out:\n \treturn ret;\n }\n \n-static int add_info_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n+static int add_info_ref(const char *path, const struct object_id *oid, int flag, void *cb_data)\n {\n \tFILE *fp = cb_data;\n-\tstruct object *o = parse_object(sha1);\n+\tstruct object *o = parse_object(oid->hash);\n \tif (!o)\n \t\treturn -1;\n \n-\tif (fprintf(fp, \"%s\t%s\\n\", sha1_to_hex(sha1), path) < 0)\n+\tif (fprintf(fp, \"%s\t%s\\n\", oid_to_hex(oid), path) < 0)\n \t\treturn -1;\n \n \tif (o->type == OBJ_TAG) {\ndiff --git a/sha1_name.c b/sha1_name.c\nindex 6d10f05..959e6c1 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -832,10 +832,10 @@ static int get_sha1_1(const char *name, int len, unsigned char *sha1, unsigned l\n #define ONELINE_SEEN (1u<<20)\n \n static int handle_one_ref(const char *path,\n-\t\tconst unsigned char *sha1, int flag, void *cb_data)\n+\t\tconst struct object_id *oid, int flag, void *cb_data)\n {\n \tstruct commit_list **list = cb_data;\n-\tstruct object *object = parse_object(sha1);\n+\tstruct object *object = parse_object(oid->hash);\n \tif (!object)\n \t\treturn 0;\n \tif (object->type == OBJ_TAG) {\ndiff --git a/shallow.c b/shallow.c\nindex 0343b16..6511bbb 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -550,7 +550,7 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,\n \t * have to go down to the current shallow commits.\n \t */\n \thead_ref(mark_uninteresting_oid, NULL);\n-\tfor_each_ref(mark_uninteresting, NULL);\n+\tfor_each_ref(mark_uninteresting_oid, NULL);\n \n \t/* Mark potential bottoms so we won't go out of bound */\n \tfor (i = 0; i < nr_shallow; i++) {\n@@ -655,7 +655,7 @@ static void post_assign_shallow(struct shallow_info *info,\n \n \tmemset(&ca, 0, sizeof(ca));\n \thead_ref(add_ref_oid, &ca);\n-\tfor_each_ref(add_ref, &ca);\n+\tfor_each_ref(add_ref_oid, &ca);\n \n \t/* Remove unreachable shallow commits from \"ours\" */\n \tfor (i = dst = 0; i < info->nr_ours; i++) {\n@@ -689,7 +689,7 @@ int delayed_reachability_test(struct shallow_info *si, int c)\n \t\t\tstruct commit_array ca;\n \t\t\tmemset(&ca, 0, sizeof(ca));\n \t\t\thead_ref(add_ref_oid, &ca);\n-\t\t\tfor_each_ref(add_ref, &ca);\n+\t\t\tfor_each_ref(add_ref_oid, &ca);\n \t\t\tsi->commits = ca.commits;\n \t\t\tsi->nr_commits = ca.nr;\n \t\t}\ndiff --git a/submodule.c b/submodule.c\nindex 97e74c5..b284444 100644\n--- a/submodule.c\n+++ b/submodule.c\n@@ -616,10 +616,10 @@ static void submodule_collect_changed_cb(struct diff_queue_struct *q,\n \t}\n }\n \n-static int add_sha1_to_array(const char *ref, const unsigned char *sha1,\n+static int add_sha1_to_array(const char *ref, const struct object_id *oid,\n \t\t\t     int flags, void *data)\n {\n-\tsha1_array_append(data, sha1);\n+\tsha1_array_append(data, oid->hash);\n \treturn 0;\n }\n \ndiff --git a/transport.c b/transport.c\nindex f080e93..c13108b 100644\n--- a/transport.c\n+++ b/transport.c\n@@ -278,7 +278,7 @@ static int fetch_objs_via_rsync(struct transport *transport,\n \treturn run_command(&rsync);\n }\n \n-static int write_one_ref(const char *name, const unsigned char *sha1,\n+static int write_one_ref(const char *name, const struct object_id *oid,\n \t\tint flags, void *data)\n {\n \tstruct strbuf *buf = data;\n@@ -291,7 +291,7 @@ static int write_one_ref(const char *name, const unsigned char *sha1,\n \n \tstrbuf_addstr(buf, name);\n \tif (safe_create_leading_directories(buf->buf) ||\n-\t    write_file(buf->buf, 0, \"%s\\n\", sha1_to_hex(sha1)))\n+\t    write_file(buf->buf, 0, \"%s\\n\", oid_to_hex(oid)))\n \t\treturn error(\"problems writing temporary file %s: %s\",\n \t\t\t     buf->buf, strerror(errno));\n \tstrbuf_setlen(buf, len);\n@@ -304,13 +304,13 @@ static int write_refs_to_temp_dir(struct strbuf *temp_dir,\n \tint i;\n \n \tfor (i = 0; i < refspec_nr; i++) {\n-\t\tunsigned char sha1[20];\n+\t\tstruct object_id oid;\n \t\tchar *ref;\n \n-\t\tif (dwim_ref(refspec[i], strlen(refspec[i]), sha1, &ref) != 1)\n+\t\tif (dwim_ref(refspec[i], strlen(refspec[i]), oid.hash, &ref) != 1)\n \t\t\treturn error(\"Could not get ref %s\", refspec[i]);\n \n-\t\tif (write_one_ref(ref, sha1, 0, temp_dir)) {\n+\t\tif (write_one_ref(ref, &oid, 0, temp_dir)) {\n \t\t\tfree(ref);\n \t\t\treturn -1;\n \t\t}\ndiff --git a/walker.c b/walker.c\nindex 58ffeca..033c8f2 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -200,9 +200,9 @@ static int interpret_target(struct walker *walker, char *target, unsigned char *\n \treturn -1;\n }\n \n-static int mark_complete(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n+static int mark_complete(const char *path, const struct object_id *oid, int flag, void *cb_data)\n {\n-\tstruct commit *commit = lookup_commit_reference_gently(sha1, 1);\n+\tstruct commit *commit = lookup_commit_reference_gently(oid->hash, 1);\n \tif (commit) {\n \t\tcommit->object.flags |= COMPLETE;\n \t\tcommit_list_insert(commit, &complete);\n-- \n2.3.5\n"},{"id":"259865","messageId":"1429745061-295908-10-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 09/16] refs: convert for_each_replace_ref to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:14Z","receivedAt":"2015-04-22T23:24:14Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Update callbacks to take the proper parameters and use struct object_id\nelsewhere in the callbacks.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/replace.c | 14 +++++++-------\n refs.c            |  4 ++--\n refs.h            |  2 +-\n replace_object.c  |  4 ++--\n 4 files changed, 12 insertions(+), 12 deletions(-)\n\ndiff --git a/builtin/replace.c b/builtin/replace.c\nindex 54bf01a..a569420 100644\n--- a/builtin/replace.c\n+++ b/builtin/replace.c\n@@ -35,7 +35,7 @@ struct show_data {\n \tenum replace_format format;\n };\n \n-static int show_reference(const char *refname, const unsigned char *sha1,\n+static int show_reference(const char *refname, const struct object_id *oid,\n \t\t\t  int flag, void *cb_data)\n {\n \tstruct show_data *data = cb_data;\n@@ -44,19 +44,19 @@ static int show_reference(const char *refname, const unsigned char *sha1,\n \t\tif (data->format == REPLACE_FORMAT_SHORT)\n \t\t\tprintf(\"%s\\n\", refname);\n \t\telse if (data->format == REPLACE_FORMAT_MEDIUM)\n-\t\t\tprintf(\"%s -> %s\\n\", refname, sha1_to_hex(sha1));\n+\t\t\tprintf(\"%s -> %s\\n\", refname, oid_to_hex(oid));\n \t\telse { /* data->format == REPLACE_FORMAT_LONG */\n-\t\t\tunsigned char object[20];\n+\t\t\tstruct object_id object;\n \t\t\tenum object_type obj_type, repl_type;\n \n-\t\t\tif (get_sha1(refname, object))\n+\t\t\tif (get_sha1(refname, object.hash))\n \t\t\t\treturn error(\"Failed to resolve '%s' as a valid ref.\", refname);\n \n-\t\t\tobj_type = sha1_object_info(object, NULL);\n-\t\t\trepl_type = sha1_object_info(sha1, NULL);\n+\t\t\tobj_type = sha1_object_info(object.hash, NULL);\n+\t\t\trepl_type = sha1_object_info(oid->hash, NULL);\n \n \t\t\tprintf(\"%s (%s) -> %s (%s)\\n\", refname, typename(obj_type),\n-\t\t\t       sha1_to_hex(sha1), typename(repl_type));\n+\t\t\t       oid_to_hex(oid), typename(repl_type));\n \t\t}\n \t}\n \ndiff --git a/refs.c b/refs.c\nindex 6bf7abc..89606a7 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2060,9 +2060,9 @@ int for_each_remote_ref_submodule(const char *submodule, each_ref_fn_oid fn, voi\n \treturn for_each_ref_in_submodule(submodule, \"refs/remotes/\", fn, cb_data);\n }\n \n-int for_each_replace_ref(each_ref_fn fn, void *cb_data)\n+int for_each_replace_ref(each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref(&ref_cache, \"refs/replace/\", fn, 13, 0, cb_data);\n+\treturn do_for_each_ref_oid(&ref_cache, \"refs/replace/\", fn, 13, 0, cb_data);\n }\n \n int head_ref_namespaced(each_ref_fn fn, void *cb_data)\ndiff --git a/refs.h b/refs.h\nindex c041cd1..9c6bc06 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -92,7 +92,7 @@ extern int for_each_ref_in(const char *, each_ref_fn_oid, void *);\n extern int for_each_tag_ref(each_ref_fn_oid, void *);\n extern int for_each_branch_ref(each_ref_fn_oid, void *);\n extern int for_each_remote_ref(each_ref_fn_oid, void *);\n-extern int for_each_replace_ref(each_ref_fn, void *);\n+extern int for_each_replace_ref(each_ref_fn_oid, void *);\n extern int for_each_glob_ref(each_ref_fn_oid, const char *pattern, void *);\n extern int for_each_glob_ref_in(each_ref_fn_oid, const char *pattern, const char* prefix, void *);\n \ndiff --git a/replace_object.c b/replace_object.c\nindex 0ab2dc1..f0b39f0 100644\n--- a/replace_object.c\n+++ b/replace_object.c\n@@ -53,7 +53,7 @@ static int register_replace_object(struct replace_object *replace,\n }\n \n static int register_replace_ref(const char *refname,\n-\t\t\t\tconst unsigned char *sha1,\n+\t\t\t\tconst struct object_id *oid,\n \t\t\t\tint flag, void *cb_data)\n {\n \t/* Get sha1 from refname */\n@@ -68,7 +68,7 @@ static int register_replace_ref(const char *refname,\n \t}\n \n \t/* Copy sha1 from the read ref */\n-\thashcpy(repl_obj->replacement, sha1);\n+\thashcpy(repl_obj->replacement, oid->hash);\n \n \t/* Register new object */\n \tif (register_replace_object(repl_obj, 1))\n-- \n2.3.5\n"},{"id":"259864","messageId":"1429745061-295908-11-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 10/16] refs: convert namespaced ref iteration functions to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:15Z","receivedAt":"2015-04-22T23:24:15Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert head_ref_namespaced and for_each_namespaced_ref to use struct\nobject_id.  Update the various callbacks to use struct object_id\ninternally as well.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n http-backend.c | 14 +++++++-------\n refs.c         | 12 ++++++------\n refs.h         |  4 ++--\n upload-pack.c  | 30 +++++++++++++++---------------\n 4 files changed, 30 insertions(+), 30 deletions(-)\n\ndiff --git a/http-backend.c b/http-backend.c\nindex b6c0484..e0d6627 100644\n--- a/http-backend.c\n+++ b/http-backend.c\n@@ -350,16 +350,16 @@ static void run_service(const char **argv)\n \t\texit(1);\n }\n \n-static int show_text_ref(const char *name, const unsigned char *sha1,\n+static int show_text_ref(const char *name, const struct object_id *oid,\n \tint flag, void *cb_data)\n {\n \tconst char *name_nons = strip_namespace(name);\n \tstruct strbuf *buf = cb_data;\n-\tstruct object *o = parse_object(sha1);\n+\tstruct object *o = parse_object(oid->hash);\n \tif (!o)\n \t\treturn 0;\n \n-\tstrbuf_addf(buf, \"%s\\t%s\\n\", sha1_to_hex(sha1), name_nons);\n+\tstrbuf_addf(buf, \"%s\\t%s\\n\", oid_to_hex(oid), name_nons);\n \tif (o->type == OBJ_TAG) {\n \t\to = deref_tag(o, name, 0);\n \t\tif (!o)\n@@ -402,21 +402,21 @@ static void get_info_refs(char *arg)\n \tstrbuf_release(&buf);\n }\n \n-static int show_head_ref(const char *refname, const unsigned char *sha1,\n+static int show_head_ref(const char *refname, const struct object_id *oid,\n \tint flag, void *cb_data)\n {\n \tstruct strbuf *buf = cb_data;\n \n \tif (flag & REF_ISSYMREF) {\n-\t\tunsigned char unused[20];\n+\t\tstruct object_id unused;\n \t\tconst char *target = resolve_ref_unsafe(refname,\n \t\t\t\t\t\t\tRESOLVE_REF_READING,\n-\t\t\t\t\t\t\tunused, NULL);\n+\t\t\t\t\t\t\tunused.hash, NULL);\n \t\tconst char *target_nons = strip_namespace(target);\n \n \t\tstrbuf_addf(buf, \"ref: %s\\n\", target_nons);\n \t} else {\n-\t\tstrbuf_addf(buf, \"%s\\n\", sha1_to_hex(sha1));\n+\t\tstrbuf_addf(buf, \"%s\\n\", oid_to_hex(oid));\n \t}\n \n \treturn 0;\ndiff --git a/refs.c b/refs.c\nindex 89606a7..19ce65a 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -2065,27 +2065,27 @@ int for_each_replace_ref(each_ref_fn_oid fn, void *cb_data)\n \treturn do_for_each_ref_oid(&ref_cache, \"refs/replace/\", fn, 13, 0, cb_data);\n }\n \n-int head_ref_namespaced(each_ref_fn fn, void *cb_data)\n+int head_ref_namespaced(each_ref_fn_oid fn, void *cb_data)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tint ret = 0;\n-\tunsigned char sha1[20];\n+\tstruct object_id oid;\n \tint flag;\n \n \tstrbuf_addf(&buf, \"%sHEAD\", get_git_namespace());\n-\tif (!read_ref_full(buf.buf, RESOLVE_REF_READING, sha1, &flag))\n-\t\tret = fn(buf.buf, sha1, flag, cb_data);\n+\tif (!read_ref_full(buf.buf, RESOLVE_REF_READING, oid.hash, &flag))\n+\t\tret = fn(buf.buf, &oid, flag, cb_data);\n \tstrbuf_release(&buf);\n \n \treturn ret;\n }\n \n-int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)\n+int for_each_namespaced_ref(each_ref_fn_oid fn, void *cb_data)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tint ret;\n \tstrbuf_addf(&buf, \"%srefs/\", get_git_namespace());\n-\tret = do_for_each_ref(&ref_cache, buf.buf, fn, 0, 0, cb_data);\n+\tret = do_for_each_ref_oid(&ref_cache, buf.buf, fn, 0, 0, cb_data);\n \tstrbuf_release(&buf);\n \treturn ret;\n }\ndiff --git a/refs.h b/refs.h\nindex 9c6bc06..2b2a688 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -104,8 +104,8 @@ extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn_oid fn,\n extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n \n-extern int head_ref_namespaced(each_ref_fn fn, void *cb_data);\n-extern int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);\n+extern int head_ref_namespaced(each_ref_fn_oid fn, void *cb_data);\n+extern int for_each_namespaced_ref(each_ref_fn_oid fn, void *cb_data);\n \n static inline const char *has_glob_specials(const char *pattern)\n {\ndiff --git a/upload-pack.c b/upload-pack.c\nindex 745fda8..b60086f 100644\n--- a/upload-pack.c\n+++ b/upload-pack.c\n@@ -681,9 +681,9 @@ static void receive_needs(void)\n }\n \n /* return non-zero if the ref is hidden, otherwise 0 */\n-static int mark_our_ref(const char *refname, const unsigned char *sha1)\n+static int mark_our_ref(const char *refname, const struct object_id *oid)\n {\n-\tstruct object *o = lookup_unknown_object(sha1);\n+\tstruct object *o = lookup_unknown_object(oid->hash);\n \n \tif (ref_is_hidden(refname)) {\n \t\to->flags |= HIDDEN_REF;\n@@ -693,9 +693,9 @@ static int mark_our_ref(const char *refname, const unsigned char *sha1)\n \treturn 0;\n }\n \n-static int check_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int check_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n-\tmark_our_ref(refname, sha1);\n+\tmark_our_ref(refname, oid);\n \treturn 0;\n }\n \n@@ -709,15 +709,15 @@ static void format_symref_info(struct strbuf *buf, struct string_list *symref)\n \t\tstrbuf_addf(buf, \" symref=%s:%s\", item->string, (char *)item->util);\n }\n \n-static int send_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int send_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n \tstatic const char *capabilities = \"multi_ack thin-pack side-band\"\n \t\t\" side-band-64k ofs-delta shallow no-progress\"\n \t\t\" include-tag multi_ack_detailed\";\n \tconst char *refname_nons = strip_namespace(refname);\n-\tunsigned char peeled[20];\n+\tstruct object_id peeled;\n \n-\tif (mark_our_ref(refname, sha1))\n+\tif (mark_our_ref(refname, oid))\n \t\treturn 0;\n \n \tif (capabilities) {\n@@ -725,7 +725,7 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo\n \n \t\tformat_symref_info(&symref_info, cb_data);\n \t\tpacket_write(1, \"%s %s%c%s%s%s%s agent=%s\\n\",\n-\t\t\t     sha1_to_hex(sha1), refname_nons,\n+\t\t\t     oid_to_hex(oid), refname_nons,\n \t\t\t     0, capabilities,\n \t\t\t     allow_tip_sha1_in_want ? \" allow-tip-sha1-in-want\" : \"\",\n \t\t\t     stateless_rpc ? \" no-done\" : \"\",\n@@ -733,24 +733,24 @@ static int send_ref(const char *refname, const unsigned char *sha1, int flag, vo\n \t\t\t     git_user_agent_sanitized());\n \t\tstrbuf_release(&symref_info);\n \t} else {\n-\t\tpacket_write(1, \"%s %s\\n\", sha1_to_hex(sha1), refname_nons);\n+\t\tpacket_write(1, \"%s %s\\n\", oid_to_hex(oid), refname_nons);\n \t}\n \tcapabilities = NULL;\n-\tif (!peel_ref(refname, peeled))\n-\t\tpacket_write(1, \"%s %s^{}\\n\", sha1_to_hex(peeled), refname_nons);\n+\tif (!peel_ref(refname, peeled.hash))\n+\t\tpacket_write(1, \"%s %s^{}\\n\", oid_to_hex(&peeled), refname_nons);\n \treturn 0;\n }\n \n-static int find_symref(const char *refname, const unsigned char *sha1, int flag,\n-\t\t       void *cb_data)\n+static int find_symref(const char *refname, const struct object_id *oid,\n+\t\t\t   int flag, void *cb_data)\n {\n \tconst char *symref_target;\n \tstruct string_list_item *item;\n-\tunsigned char unused[20];\n+\tstruct object_id unused;\n \n \tif ((flag & REF_ISSYMREF) == 0)\n \t\treturn 0;\n-\tsymref_target = resolve_ref_unsafe(refname, 0, unused, &flag);\n+\tsymref_target = resolve_ref_unsafe(refname, 0, unused.hash, &flag);\n \tif (!symref_target || (flag & REF_ISSYMREF) == 0)\n \t\tdie(\"'%s' is a symref but it is not?\", refname);\n \titem = string_list_append(cb_data, refname);\n-- \n2.3.5\n"},{"id":"259870","messageId":"1429745061-295908-12-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 11/16] refs: convert for_each_rawref to struct object_id.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:16Z","receivedAt":"2015-04-22T23:24:16Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Convert callbacks to use struct object_id internally as well.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/branch.c       |  4 ++--\n builtin/describe.c     | 12 ++++++------\n builtin/for-each-ref.c |  4 ++--\n builtin/fsck.c         | 16 ++++++++--------\n refs.c                 | 10 +++++-----\n refs.h                 |  2 +-\n 6 files changed, 24 insertions(+), 24 deletions(-)\n\ndiff --git a/builtin/branch.c b/builtin/branch.c\nindex 258fe2f..ee3e909 100644\n--- a/builtin/branch.c\n+++ b/builtin/branch.c\n@@ -328,7 +328,7 @@ static int match_patterns(const char **pattern, const char *refname)\n \treturn 0;\n }\n \n-static int append_ref(const char *refname, const unsigned char *sha1, int flags, void *cb_data)\n+static int append_ref(const char *refname, const struct object_id *oid, int flags, void *cb_data)\n {\n \tstruct append_ref_cb *cb = (struct append_ref_cb *)(cb_data);\n \tstruct ref_list *ref_list = cb->ref_list;\n@@ -365,7 +365,7 @@ static int append_ref(const char *refname, const unsigned char *sha1, int flags,\n \n \tcommit = NULL;\n \tif (ref_list->verbose || ref_list->with_commit || merge_filter != NO_FILTER) {\n-\t\tcommit = lookup_commit_reference_gently(sha1, 1);\n+\t\tcommit = lookup_commit_reference_gently(oid->hash, 1);\n \t\tif (!commit) {\n \t\t\tcb->ret = error(_(\"branch '%s' does not point at a commit\"), refname);\n \t\t\treturn 0;\ndiff --git a/builtin/describe.c b/builtin/describe.c\nindex e00a75b..a36c829 100644\n--- a/builtin/describe.c\n+++ b/builtin/describe.c\n@@ -119,10 +119,10 @@ static void add_to_known_names(const char *path,\n \t}\n }\n \n-static int get_name(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n+static int get_name(const char *path, const struct object_id *oid, int flag, void *cb_data)\n {\n \tint is_tag = starts_with(path, \"refs/tags/\");\n-\tunsigned char peeled[20];\n+\tstruct object_id peeled;\n \tint is_annotated, prio;\n \n \t/* Reject anything outside refs/tags/ unless --all */\n@@ -134,10 +134,10 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void\n \t\treturn 0;\n \n \t/* Is it annotated? */\n-\tif (!peel_ref(path, peeled)) {\n-\t\tis_annotated = !!hashcmp(sha1, peeled);\n+\tif (!peel_ref(path, peeled.hash)) {\n+\t\tis_annotated = !!oidcmp(oid, &peeled);\n \t} else {\n-\t\thashcpy(peeled, sha1);\n+\t\toidcpy(&peeled, oid);\n \t\tis_annotated = 0;\n \t}\n \n@@ -154,7 +154,7 @@ static int get_name(const char *path, const unsigned char *sha1, int flag, void\n \telse\n \t\tprio = 0;\n \n-\tadd_to_known_names(all ? path + 5 : path + 10, peeled, prio, sha1);\n+\tadd_to_known_names(all ? path + 5 : path + 10, peeled.hash, prio, oid->hash);\n \treturn 0;\n }\n \ndiff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c\nindex 83f9cf9..50c3fbe 100644\n--- a/builtin/for-each-ref.c\n+++ b/builtin/for-each-ref.c\n@@ -840,7 +840,7 @@ struct grab_ref_cbdata {\n  * A call-back given to for_each_ref().  Filter refs and keep them for\n  * later object processing.\n  */\n-static int grab_single_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int grab_single_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n \tstruct grab_ref_cbdata *cb = cb_data;\n \tstruct refinfo *ref;\n@@ -878,7 +878,7 @@ static int grab_single_ref(const char *refname, const unsigned char *sha1, int f\n \t */\n \tref = xcalloc(1, sizeof(*ref));\n \tref->refname = xstrdup(refname);\n-\thashcpy(ref->objectname, sha1);\n+\thashcpy(ref->objectname, oid->hash);\n \tref->flag = flag;\n \n \tcnt = cb->grab_cnt;\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 4783896..85238a7 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -25,7 +25,7 @@ static int include_reflogs = 1;\n static int check_full = 1;\n static int check_strict;\n static int keep_cache_objects;\n-static unsigned char head_sha1[20];\n+static struct object_id head_oid;\n static const char *head_points_at;\n static int errors_found;\n static int write_lost_and_found;\n@@ -482,13 +482,13 @@ static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, in\n \treturn 0;\n }\n \n-static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int fsck_handle_ref(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n \tstruct object *obj;\n \n-\tobj = parse_object(sha1);\n+\tobj = parse_object(oid->hash);\n \tif (!obj) {\n-\t\terror(\"%s: invalid sha1 pointer %s\", refname, sha1_to_hex(sha1));\n+\t\terror(\"%s: invalid sha1 pointer %s\", refname, oid_to_hex(oid));\n \t\terrors_found |= ERROR_REACHABLE;\n \t\t/* We'll continue with the rest despite the error.. */\n \t\treturn 0;\n@@ -504,8 +504,8 @@ static int fsck_handle_ref(const char *refname, const unsigned char *sha1, int f\n \n static void get_default_heads(void)\n {\n-\tif (head_points_at && !is_null_sha1(head_sha1))\n-\t\tfsck_handle_ref(\"HEAD\", head_sha1, 0, NULL);\n+\tif (head_points_at && !is_null_oid(&head_oid))\n+\t\tfsck_handle_ref(\"HEAD\", &head_oid, 0, NULL);\n \tfor_each_rawref(fsck_handle_ref, NULL);\n \tif (include_reflogs)\n \t\tfor_each_reflog(fsck_handle_reflog, NULL);\n@@ -556,7 +556,7 @@ static int fsck_head_link(void)\n \tif (verbose)\n \t\tfprintf(stderr, \"Checking HEAD link\\n\");\n \n-\thead_points_at = resolve_ref_unsafe(\"HEAD\", 0, head_sha1, &flag);\n+\thead_points_at = resolve_ref_unsafe(\"HEAD\", 0, head_oid.hash, &flag);\n \tif (!head_points_at)\n \t\treturn error(\"Invalid HEAD\");\n \tif (!strcmp(head_points_at, \"HEAD\"))\n@@ -565,7 +565,7 @@ static int fsck_head_link(void)\n \telse if (!starts_with(head_points_at, \"refs/heads/\"))\n \t\treturn error(\"HEAD points to something strange (%s)\",\n \t\t\t     head_points_at);\n-\tif (is_null_sha1(head_sha1)) {\n+\tif (is_null_oid(&head_oid)) {\n \t\tif (null_is_error)\n \t\t\treturn error(\"HEAD: detached HEAD points at nothing\");\n \t\tfprintf(stderr, \"notice: HEAD points to an unborn branch (%s)\\n\",\ndiff --git a/refs.c b/refs.c\nindex 19ce65a..185b40f 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1838,17 +1838,17 @@ struct warn_if_dangling_data {\n \tconst char *msg_fmt;\n };\n \n-static int warn_if_dangling_symref(const char *refname, const unsigned char *sha1,\n+static int warn_if_dangling_symref(const char *refname, const struct object_id *oid,\n \t\t\t\t   int flags, void *cb_data)\n {\n \tstruct warn_if_dangling_data *d = cb_data;\n \tconst char *resolves_to;\n-\tunsigned char junk[20];\n+\tstruct object_id junk;\n \n \tif (!(flags & REF_ISSYMREF))\n \t\treturn 0;\n \n-\tresolves_to = resolve_ref_unsafe(refname, 0, junk, NULL);\n+\tresolves_to = resolve_ref_unsafe(refname, 0, junk.hash, NULL);\n \tif (!resolves_to\n \t    || (d->refname\n \t\t? strcmp(resolves_to, d->refname)\n@@ -2125,9 +2125,9 @@ int for_each_glob_ref(each_ref_fn_oid fn, const char *pattern, void *cb_data)\n \treturn for_each_glob_ref_in(fn, pattern, NULL, cb_data);\n }\n \n-int for_each_rawref(each_ref_fn fn, void *cb_data)\n+int for_each_rawref(each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref(&ref_cache, \"\", fn, 0,\n+\treturn do_for_each_ref_oid(&ref_cache, \"\", fn, 0,\n \t\t\t       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);\n }\n \ndiff --git a/refs.h b/refs.h\nindex 2b2a688..6df7d8a 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -113,7 +113,7 @@ static inline const char *has_glob_specials(const char *pattern)\n }\n \n /* can be used to learn about broken ref and symref */\n-extern int for_each_rawref(each_ref_fn, void *);\n+extern int for_each_rawref(each_ref_fn_oid, void *);\n \n extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname);\n extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames);\n-- \n2.3.5\n"},{"id":"259871","messageId":"1429745061-295908-13-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 12/16] refs: rename do_for_each_ref_oid to do_for_each_ref","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:17Z","receivedAt":"2015-04-22T23:24:17Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"do_for_each_ref was unused due to previous patches, so rename\ndo_for_each_ref_oid to do_for_each_ref.  Similarly, remove the unused fn\nmember from struct ref_entry in favor of renaming the fn_oid member.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n refs.c | 43 +++++++++++--------------------------------\n 1 file changed, 11 insertions(+), 32 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 185b40f..9f687e8 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -693,8 +693,7 @@ struct ref_entry_cb {\n \tconst char *base;\n \tint trim;\n \tint flags;\n-\teach_ref_fn *fn;\n-\teach_ref_fn_oid *fn_oid;\n+\teach_ref_fn_oid *fn;\n \tvoid *cb_data;\n };\n \n@@ -718,13 +717,8 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)\n \t/* Store the old value, in case this is a recursive call: */\n \told_current_ref = current_ref;\n \tcurrent_ref = entry;\n-\tif (data->fn_oid) {\n-\t\tretval = data->fn_oid(entry->name + data->trim, &entry->u.value.oid,\n-\t\t\t\t entry->flag, data->cb_data);\n-\t} else {\n-\t\tretval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,\n-\t\t\t\t entry->flag, data->cb_data);\n-\t}\n+\tretval = data->fn(entry->name + data->trim, &entry->u.value.oid,\n+\t\t\t entry->flag, data->cb_data);\n \tcurrent_ref = old_current_ref;\n \treturn retval;\n }\n@@ -1949,28 +1943,13 @@ static int do_for_each_entry(struct ref_cache *refs, const char *base,\n  * 0.\n  */\n static int do_for_each_ref(struct ref_cache *refs, const char *base,\n-\t\t\t   each_ref_fn fn, int trim, int flags, void *cb_data)\n-{\n-\tstruct ref_entry_cb data;\n-\tdata.base = base;\n-\tdata.trim = trim;\n-\tdata.flags = flags;\n-\tdata.fn = fn;\n-\tdata.fn_oid = NULL;\n-\tdata.cb_data = cb_data;\n-\n-\treturn do_for_each_entry(refs, base, do_one_ref, &data);\n-}\n-\n-static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n \t\t\t   each_ref_fn_oid fn, int trim, int flags, void *cb_data)\n {\n \tstruct ref_entry_cb data;\n \tdata.base = base;\n \tdata.trim = trim;\n \tdata.flags = flags;\n-\tdata.fn = NULL;\n-\tdata.fn_oid = fn;\n+\tdata.fn = fn;\n \tdata.cb_data = cb_data;\n \n \tif (ref_paranoia < 0)\n@@ -2011,23 +1990,23 @@ int head_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n \n int for_each_ref(each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref_oid(&ref_cache, \"\", fn, 0, 0, cb_data);\n+\treturn do_for_each_ref(&ref_cache, \"\", fn, 0, 0, cb_data);\n }\n \n int for_each_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref_oid(get_ref_cache(submodule), \"\", fn, 0, 0, cb_data);\n+\treturn do_for_each_ref(get_ref_cache(submodule), \"\", fn, 0, 0, cb_data);\n }\n \n int for_each_ref_in(const char *prefix, each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref_oid(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n+\treturn do_for_each_ref(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n }\n \n int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n \t\teach_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref_oid(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);\n+\treturn do_for_each_ref(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);\n }\n \n int for_each_tag_ref(each_ref_fn_oid fn, void *cb_data)\n@@ -2062,7 +2041,7 @@ int for_each_remote_ref_submodule(const char *submodule, each_ref_fn_oid fn, voi\n \n int for_each_replace_ref(each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref_oid(&ref_cache, \"refs/replace/\", fn, 13, 0, cb_data);\n+\treturn do_for_each_ref(&ref_cache, \"refs/replace/\", fn, 13, 0, cb_data);\n }\n \n int head_ref_namespaced(each_ref_fn_oid fn, void *cb_data)\n@@ -2085,7 +2064,7 @@ int for_each_namespaced_ref(each_ref_fn_oid fn, void *cb_data)\n \tstruct strbuf buf = STRBUF_INIT;\n \tint ret;\n \tstrbuf_addf(&buf, \"%srefs/\", get_git_namespace());\n-\tret = do_for_each_ref_oid(&ref_cache, buf.buf, fn, 0, 0, cb_data);\n+\tret = do_for_each_ref(&ref_cache, buf.buf, fn, 0, 0, cb_data);\n \tstrbuf_release(&buf);\n \treturn ret;\n }\n@@ -2127,7 +2106,7 @@ int for_each_glob_ref(each_ref_fn_oid fn, const char *pattern, void *cb_data)\n \n int for_each_rawref(each_ref_fn_oid fn, void *cb_data)\n {\n-\treturn do_for_each_ref_oid(&ref_cache, \"\", fn, 0,\n+\treturn do_for_each_ref(&ref_cache, \"\", fn, 0,\n \t\t\t       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);\n }\n \n-- \n2.3.5\n"},{"id":"259866","messageId":"1429745061-295908-14-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 13/16] refs: convert for_each_reflog to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:18Z","receivedAt":"2015-04-22T23:24:18Z","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/fsck.c   |  2 +-\n builtin/reflog.c |  4 ++--\n refs.c           | 10 +++++-----\n refs.h           |  2 +-\n revision.c       |  2 +-\n 5 files changed, 10 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/fsck.c b/builtin/fsck.c\nindex 85238a7..6659f81 100644\n--- a/builtin/fsck.c\n+++ b/builtin/fsck.c\n@@ -476,7 +476,7 @@ static int fsck_handle_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n \treturn 0;\n }\n \n-static int fsck_handle_reflog(const char *logname, const unsigned char *sha1, int flag, void *cb_data)\n+static int fsck_handle_reflog(const char *logname, const struct object_id *oid, int flag, void *cb_data)\n {\n \tfor_each_reflog_ent(logname, fsck_handle_reflog_ent, NULL);\n \treturn 0;\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex f3f9201..da890f0 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -379,14 +379,14 @@ static void reflog_expiry_cleanup(void *cb_data)\n \t}\n }\n \n-static int collect_reflog(const char *ref, const unsigned char *sha1, int unused, void *cb_data)\n+static int collect_reflog(const char *ref, const struct object_id *oid, int unused, void *cb_data)\n {\n \tstruct collected_reflog *e;\n \tstruct collect_reflog_cb *cb = cb_data;\n \tsize_t namelen = strlen(ref);\n \n \te = xmalloc(sizeof(*e) + namelen + 1);\n-\thashcpy(e->sha1, sha1);\n+\thashcpy(e->sha1, oid->hash);\n \tmemcpy(e->reflog, ref, namelen + 1);\n \tALLOC_GROW(cb->e, cb->nr + 1, cb->alloc);\n \tcb->e[cb->nr++] = e;\ndiff --git a/refs.c b/refs.c\nindex 9f687e8..38ecc2a 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -3484,7 +3484,7 @@ int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_dat\n  * must be empty or end with '/'.  Name will be used as a scratch\n  * space, but its contents will be restored before return.\n  */\n-static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data)\n+static int do_for_each_reflog(struct strbuf *name, each_ref_fn_oid fn, void *cb_data)\n {\n \tDIR *d = opendir(git_path(\"logs/%s\", name->buf));\n \tint retval = 0;\n@@ -3509,11 +3509,11 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data\n \t\t\t\tstrbuf_addch(name, '/');\n \t\t\t\tretval = do_for_each_reflog(name, fn, cb_data);\n \t\t\t} else {\n-\t\t\t\tunsigned char sha1[20];\n-\t\t\t\tif (read_ref_full(name->buf, 0, sha1, NULL))\n+\t\t\t\tstruct object_id oid;\n+\t\t\t\tif (read_ref_full(name->buf, 0, oid.hash, NULL))\n \t\t\t\t\tretval = error(\"bad ref for %s\", name->buf);\n \t\t\t\telse\n-\t\t\t\t\tretval = fn(name->buf, sha1, 0, cb_data);\n+\t\t\t\t\tretval = fn(name->buf, &oid, 0, cb_data);\n \t\t\t}\n \t\t\tif (retval)\n \t\t\t\tbreak;\n@@ -3524,7 +3524,7 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data\n \treturn retval;\n }\n \n-int for_each_reflog(each_ref_fn fn, void *cb_data)\n+int for_each_reflog(each_ref_fn_oid fn, void *cb_data)\n {\n \tint retval;\n \tstruct strbuf name;\ndiff --git a/refs.h b/refs.h\nindex 6df7d8a..abdfb00 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -222,7 +222,7 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void\n  * Calls the specified function for each reflog file until it returns nonzero,\n  * and returns the value\n  */\n-extern int for_each_reflog(each_ref_fn, void *);\n+extern int for_each_reflog(each_ref_fn_oid, void *);\n \n #define REFNAME_ALLOW_ONELEVEL 1\n #define REFNAME_REFSPEC_PATTERN 2\ndiff --git a/revision.c b/revision.c\nindex 29af759..94eb94b 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1298,7 +1298,7 @@ static int handle_one_reflog_ent(unsigned char *osha1, unsigned char *nsha1,\n \treturn 0;\n }\n \n-static int handle_one_reflog(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n+static int handle_one_reflog(const char *path, const struct object_id *oid, int flag, void *cb_data)\n {\n \tstruct all_refs_cb *cb = cb_data;\n \tcb->warned_bad_reflog = 0;\n-- \n2.3.5\n"},{"id":"259874","messageId":"1429745061-295908-15-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 14/16] refs: rename each_ref_fn_oid to each_ref_fn","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:19Z","receivedAt":"2015-04-22T23:24:19Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"each_ref_fn is no longer used, so rename each_ref_fn_oid to each_ref_fn.\nUpdate the documentation to note the change in function signature.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n Documentation/technical/api-ref-iteration.txt |  2 +-\n refs.c                                        | 48 +++++++++++++--------------\n refs.h                                        | 44 +++++++++++-------------\n revision.c                                    |  6 ++--\n 4 files changed, 47 insertions(+), 53 deletions(-)\n\ndiff --git a/Documentation/technical/api-ref-iteration.txt b/Documentation/technical/api-ref-iteration.txt\nindex 02adfd4..37379d8 100644\n--- a/Documentation/technical/api-ref-iteration.txt\n+++ b/Documentation/technical/api-ref-iteration.txt\n@@ -6,7 +6,7 @@ Iteration of refs is done by using an iterate function which will call a\n callback function for every ref. The callback function has this\n signature:\n \n-\tint handle_one_ref(const char *refname, const unsigned char *sha1,\n+\tint handle_one_ref(const char *refname, const struct object_id *oid,\n \t\t\t   int flags, void *cb_data);\n \n There are different kinds of iterate functions which all take a\ndiff --git a/refs.c b/refs.c\nindex 38ecc2a..9e61b32 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -693,7 +693,7 @@ struct ref_entry_cb {\n \tconst char *base;\n \tint trim;\n \tint flags;\n-\teach_ref_fn_oid *fn;\n+\teach_ref_fn *fn;\n \tvoid *cb_data;\n };\n \n@@ -1669,7 +1669,7 @@ char *resolve_refdup(const char *ref, int resolve_flags, unsigned char *sha1, in\n /* The argument to filter_refs */\n struct ref_filter {\n \tconst char *pattern;\n-\teach_ref_fn_oid *fn;\n+\teach_ref_fn *fn;\n \tvoid *cb_data;\n };\n \n@@ -1943,7 +1943,7 @@ static int do_for_each_entry(struct ref_cache *refs, const char *base,\n  * 0.\n  */\n static int do_for_each_ref(struct ref_cache *refs, const char *base,\n-\t\t\t   each_ref_fn_oid fn, int trim, int flags, void *cb_data)\n+\t\t\t   each_ref_fn fn, int trim, int flags, void *cb_data)\n {\n \tstruct ref_entry_cb data;\n \tdata.base = base;\n@@ -1960,7 +1960,7 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,\n \treturn do_for_each_entry(refs, base, do_one_ref, &data);\n }\n \n-static int do_head_ref(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n+static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \tstruct object_id oid;\n \tint flag;\n@@ -1978,73 +1978,73 @@ static int do_head_ref(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n \treturn 0;\n }\n \n-int head_ref(each_ref_fn_oid fn, void *cb_data)\n+int head_ref(each_ref_fn fn, void *cb_data)\n {\n \treturn do_head_ref(NULL, fn, cb_data);\n }\n \n-int head_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n+int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \treturn do_head_ref(submodule, fn, cb_data);\n }\n \n-int for_each_ref(each_ref_fn_oid fn, void *cb_data)\n+int for_each_ref(each_ref_fn fn, void *cb_data)\n {\n \treturn do_for_each_ref(&ref_cache, \"\", fn, 0, 0, cb_data);\n }\n \n-int for_each_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n+int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \treturn do_for_each_ref(get_ref_cache(submodule), \"\", fn, 0, 0, cb_data);\n }\n \n-int for_each_ref_in(const char *prefix, each_ref_fn_oid fn, void *cb_data)\n+int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)\n {\n \treturn do_for_each_ref(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n }\n \n int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n-\t\teach_ref_fn_oid fn, void *cb_data)\n+\t\teach_ref_fn fn, void *cb_data)\n {\n \treturn do_for_each_ref(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);\n }\n \n-int for_each_tag_ref(each_ref_fn_oid fn, void *cb_data)\n+int for_each_tag_ref(each_ref_fn fn, void *cb_data)\n {\n \treturn for_each_ref_in(\"refs/tags/\", fn, cb_data);\n }\n \n-int for_each_tag_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n+int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/tags/\", fn, cb_data);\n }\n \n-int for_each_branch_ref(each_ref_fn_oid fn, void *cb_data)\n+int for_each_branch_ref(each_ref_fn fn, void *cb_data)\n {\n \treturn for_each_ref_in(\"refs/heads/\", fn, cb_data);\n }\n \n-int for_each_branch_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n+int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/heads/\", fn, cb_data);\n }\n \n-int for_each_remote_ref(each_ref_fn_oid fn, void *cb_data)\n+int for_each_remote_ref(each_ref_fn fn, void *cb_data)\n {\n \treturn for_each_ref_in(\"refs/remotes/\", fn, cb_data);\n }\n \n-int for_each_remote_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n+int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/remotes/\", fn, cb_data);\n }\n \n-int for_each_replace_ref(each_ref_fn_oid fn, void *cb_data)\n+int for_each_replace_ref(each_ref_fn fn, void *cb_data)\n {\n \treturn do_for_each_ref(&ref_cache, \"refs/replace/\", fn, 13, 0, cb_data);\n }\n \n-int head_ref_namespaced(each_ref_fn_oid fn, void *cb_data)\n+int head_ref_namespaced(each_ref_fn fn, void *cb_data)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tint ret = 0;\n@@ -2059,7 +2059,7 @@ int head_ref_namespaced(each_ref_fn_oid fn, void *cb_data)\n \treturn ret;\n }\n \n-int for_each_namespaced_ref(each_ref_fn_oid fn, void *cb_data)\n+int for_each_namespaced_ref(each_ref_fn fn, void *cb_data)\n {\n \tstruct strbuf buf = STRBUF_INIT;\n \tint ret;\n@@ -2069,7 +2069,7 @@ int for_each_namespaced_ref(each_ref_fn_oid fn, void *cb_data)\n \treturn ret;\n }\n \n-int for_each_glob_ref_in(each_ref_fn_oid fn, const char *pattern,\n+int for_each_glob_ref_in(each_ref_fn fn, const char *pattern,\n \tconst char *prefix, void *cb_data)\n {\n \tstruct strbuf real_pattern = STRBUF_INIT;\n@@ -2099,12 +2099,12 @@ int for_each_glob_ref_in(each_ref_fn_oid fn, const char *pattern,\n \treturn ret;\n }\n \n-int for_each_glob_ref(each_ref_fn_oid fn, const char *pattern, void *cb_data)\n+int for_each_glob_ref(each_ref_fn fn, const char *pattern, void *cb_data)\n {\n \treturn for_each_glob_ref_in(fn, pattern, NULL, cb_data);\n }\n \n-int for_each_rawref(each_ref_fn_oid fn, void *cb_data)\n+int for_each_rawref(each_ref_fn fn, void *cb_data)\n {\n \treturn do_for_each_ref(&ref_cache, \"\", fn, 0,\n \t\t\t       DO_FOR_EACH_INCLUDE_BROKEN, cb_data);\n@@ -3484,7 +3484,7 @@ int for_each_reflog_ent(const char *refname, each_reflog_ent_fn fn, void *cb_dat\n  * must be empty or end with '/'.  Name will be used as a scratch\n  * space, but its contents will be restored before return.\n  */\n-static int do_for_each_reflog(struct strbuf *name, each_ref_fn_oid fn, void *cb_data)\n+static int do_for_each_reflog(struct strbuf *name, each_ref_fn fn, void *cb_data)\n {\n \tDIR *d = opendir(git_path(\"logs/%s\", name->buf));\n \tint retval = 0;\n@@ -3524,7 +3524,7 @@ static int do_for_each_reflog(struct strbuf *name, each_ref_fn_oid fn, void *cb_\n \treturn retval;\n }\n \n-int for_each_reflog(each_ref_fn_oid fn, void *cb_data)\n+int for_each_reflog(each_ref_fn fn, void *cb_data)\n {\n \tint retval;\n \tstruct strbuf name;\ndiff --git a/refs.h b/refs.h\nindex abdfb00..0bd2fce 100644\n--- a/refs.h\n+++ b/refs.h\n@@ -69,12 +69,6 @@ struct ref_transaction;\n  * single callback invocation.\n  */\n typedef int each_ref_fn(const char *refname,\n-\t\t\tconst unsigned char *sha1, int flags, void *cb_data);\n-\n-/*\n- * Like each_ref_fn, but passes the object ID using a struct.\n- */\n-typedef int each_ref_fn_oid(const char *refname,\n \t\t\tconst struct object_id *oid, int flags, void *cb_data);\n \n /*\n@@ -86,26 +80,26 @@ typedef int each_ref_fn_oid(const char *refname,\n  * modifies the reference also returns a nonzero value to immediately\n  * stop the iteration.\n  */\n-extern int head_ref(each_ref_fn_oid, void *);\n-extern int for_each_ref(each_ref_fn_oid, void *);\n-extern int for_each_ref_in(const char *, each_ref_fn_oid, void *);\n-extern int for_each_tag_ref(each_ref_fn_oid, void *);\n-extern int for_each_branch_ref(each_ref_fn_oid, void *);\n-extern int for_each_remote_ref(each_ref_fn_oid, void *);\n-extern int for_each_replace_ref(each_ref_fn_oid, void *);\n-extern int for_each_glob_ref(each_ref_fn_oid, const char *pattern, void *);\n-extern int for_each_glob_ref_in(each_ref_fn_oid, const char *pattern, const char* prefix, void *);\n+extern int head_ref(each_ref_fn, void *);\n+extern int for_each_ref(each_ref_fn, void *);\n+extern int for_each_ref_in(const char *, each_ref_fn, void *);\n+extern int for_each_tag_ref(each_ref_fn, void *);\n+extern int for_each_branch_ref(each_ref_fn, void *);\n+extern int for_each_remote_ref(each_ref_fn, void *);\n+extern int for_each_replace_ref(each_ref_fn, void *);\n+extern int for_each_glob_ref(each_ref_fn, const char *pattern, void *);\n+extern int for_each_glob_ref_in(each_ref_fn, const char *pattern, const char* prefix, void *);\n \n-extern int head_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n-extern int for_each_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n+extern int head_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n+extern int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n extern int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n-\t\teach_ref_fn_oid fn, void *cb_data);\n-extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n-extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n-extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn_oid fn, void *cb_data);\n+\t\teach_ref_fn fn, void *cb_data);\n+extern int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n+extern int for_each_branch_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n+extern int for_each_remote_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data);\n \n-extern int head_ref_namespaced(each_ref_fn_oid fn, void *cb_data);\n-extern int for_each_namespaced_ref(each_ref_fn_oid fn, void *cb_data);\n+extern int head_ref_namespaced(each_ref_fn fn, void *cb_data);\n+extern int for_each_namespaced_ref(each_ref_fn fn, void *cb_data);\n \n static inline const char *has_glob_specials(const char *pattern)\n {\n@@ -113,7 +107,7 @@ static inline const char *has_glob_specials(const char *pattern)\n }\n \n /* can be used to learn about broken ref and symref */\n-extern int for_each_rawref(each_ref_fn_oid, void *);\n+extern int for_each_rawref(each_ref_fn, void *);\n \n extern void warn_dangling_symref(FILE *fp, const char *msg_fmt, const char *refname);\n extern void warn_dangling_symrefs(FILE *fp, const char *msg_fmt, const struct string_list *refnames);\n@@ -222,7 +216,7 @@ int for_each_reflog_ent_reverse(const char *refname, each_reflog_ent_fn fn, void\n  * Calls the specified function for each reflog file until it returns nonzero,\n  * and returns the value\n  */\n-extern int for_each_reflog(each_ref_fn_oid, void *);\n+extern int for_each_reflog(each_ref_fn, void *);\n \n #define REFNAME_ALLOW_ONELEVEL 1\n #define REFNAME_REFSPEC_PATTERN 2\ndiff --git a/revision.c b/revision.c\nindex 94eb94b..6d92c0e 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -1264,7 +1264,7 @@ void add_ref_exclusion(struct string_list **ref_excludes_p, const char *exclude)\n }\n \n static void handle_refs(const char *submodule, struct rev_info *revs, unsigned flags,\n-\t\tint (*for_each)(const char *, each_ref_fn_oid, void *))\n+\t\tint (*for_each)(const char *, each_ref_fn, void *))\n {\n \tstruct all_refs_cb cb;\n \tinit_all_refs_cb(&cb, revs, flags);\n@@ -2079,12 +2079,12 @@ void parse_revision_opt(struct rev_info *revs, struct parse_opt_ctx_t *ctx,\n \tctx->argc -= n;\n }\n \n-static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n+static int for_each_bad_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/bisect/bad\", fn, cb_data);\n }\n \n-static int for_each_good_bisect_ref(const char *submodule, each_ref_fn_oid fn, void *cb_data)\n+static int for_each_good_bisect_ref(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \treturn for_each_ref_in_submodule(submodule, \"refs/bisect/good\", fn, cb_data);\n }\n-- \n2.3.5\n"},{"id":"259863","messageId":"1429745061-295908-16-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 15/16] Remove unneeded *_oid functions.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:20Z","receivedAt":"2015-04-22T23:24:20Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"While these functions were needed during the intermediate steps of\nconverting for_each_ref and friends to struct object_id, there is no\nlonger any need to have these wrapper functions.  Update each of the\nfunctions that the wrapper functions call and remove the _oid wrapper\nfunctions themselves.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n builtin/rev-parse.c | 27 +++++++++++----------------\n builtin/show-ref.c  | 23 +++++++++--------------\n log-tree.c          | 19 +++++++------------\n reachable.c         | 13 ++++---------\n shallow.c           | 33 ++++++++++-----------------------\n 5 files changed, 41 insertions(+), 74 deletions(-)\n\ndiff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\nindex 4aa7a25..b623239 100644\n--- a/builtin/rev-parse.c\n+++ b/builtin/rev-parse.c\n@@ -190,19 +190,14 @@ static int show_default(void)\n \treturn 0;\n }\n \n-static int show_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n+static int show_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n \tif (ref_excluded(ref_excludes, refname))\n \t\treturn 0;\n-\tshow_rev(NORMAL, sha1, refname);\n+\tshow_rev(NORMAL, oid->hash, refname);\n \treturn 0;\n }\n \n-static int show_reference_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n-{\n-\treturn show_reference(refname, oid->hash, flag, cb_data);\n-}\n-\n static int anti_reference(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n {\n \tshow_rev(REVERSED, oid->hash, refname);\n@@ -657,7 +652,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--all\")) {\n-\t\t\t\tfor_each_ref(show_reference_oid, NULL);\n+\t\t\t\tfor_each_ref(show_reference, NULL);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--disambiguate=\")) {\n@@ -665,45 +660,45 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--bisect\")) {\n-\t\t\t\tfor_each_ref_in(\"refs/bisect/bad\", show_reference_oid, NULL);\n+\t\t\t\tfor_each_ref_in(\"refs/bisect/bad\", show_reference, NULL);\n \t\t\t\tfor_each_ref_in(\"refs/bisect/good\", anti_reference, NULL);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--branches=\")) {\n-\t\t\t\tfor_each_glob_ref_in(show_reference_oid, arg + 11,\n+\t\t\t\tfor_each_glob_ref_in(show_reference, arg + 11,\n \t\t\t\t\t\"refs/heads/\", NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--branches\")) {\n-\t\t\t\tfor_each_branch_ref(show_reference_oid, NULL);\n+\t\t\t\tfor_each_branch_ref(show_reference, NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--tags=\")) {\n-\t\t\t\tfor_each_glob_ref_in(show_reference_oid, arg + 7,\n+\t\t\t\tfor_each_glob_ref_in(show_reference, arg + 7,\n \t\t\t\t\t\"refs/tags/\", NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--tags\")) {\n-\t\t\t\tfor_each_tag_ref(show_reference_oid, NULL);\n+\t\t\t\tfor_each_tag_ref(show_reference, NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--glob=\")) {\n-\t\t\t\tfor_each_glob_ref(show_reference_oid, arg + 7, NULL);\n+\t\t\t\tfor_each_glob_ref(show_reference, arg + 7, NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (starts_with(arg, \"--remotes=\")) {\n-\t\t\t\tfor_each_glob_ref_in(show_reference_oid, arg + 10,\n+\t\t\t\tfor_each_glob_ref_in(show_reference, arg + 10,\n \t\t\t\t\t\"refs/remotes/\", NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\n \t\t\tif (!strcmp(arg, \"--remotes\")) {\n-\t\t\t\tfor_each_remote_ref(show_reference_oid, NULL);\n+\t\t\t\tfor_each_remote_ref(show_reference, NULL);\n \t\t\t\tclear_ref_exclusion(&ref_excludes);\n \t\t\t\tcontinue;\n \t\t\t}\ndiff --git a/builtin/show-ref.c b/builtin/show-ref.c\nindex 6731721..2d2267e 100644\n--- a/builtin/show-ref.c\n+++ b/builtin/show-ref.c\n@@ -26,10 +26,10 @@ static void show_one(const char *refname, const unsigned char *sha1)\n \t\tprintf(\"%s %s\\n\", hex, refname);\n }\n \n-static int show_ref(const char *refname, const unsigned char *sha1, int flag, void *cbdata)\n+static int show_ref(const char *refname, const struct object_id *oid, int flag, void *cbdata)\n {\n \tconst char *hex;\n-\tunsigned char peeled[20];\n+\tstruct object_id peeled;\n \n \tif (show_head && !strcmp(refname, \"HEAD\"))\n \t\tgoto match;\n@@ -69,30 +69,25 @@ match:\n \t * detect and return error if the repository is corrupt and\n \t * ref points at a nonexistent object.\n \t */\n-\tif (!has_sha1_file(sha1))\n+\tif (!has_sha1_file(oid->hash))\n \t\tdie(\"git show-ref: bad ref %s (%s)\", refname,\n-\t\t    sha1_to_hex(sha1));\n+\t\t    oid_to_hex(oid));\n \n \tif (quiet)\n \t\treturn 0;\n \n-\tshow_one(refname, sha1);\n+\tshow_one(refname, oid->hash);\n \n \tif (!deref_tags)\n \t\treturn 0;\n \n-\tif (!peel_ref(refname, peeled)) {\n-\t\thex = find_unique_abbrev(peeled, abbrev);\n+\tif (!peel_ref(refname, peeled.hash)) {\n+\t\thex = find_unique_abbrev(peeled.hash, abbrev);\n \t\tprintf(\"%s %s^{}\\n\", hex, refname);\n \t}\n \treturn 0;\n }\n \n-static int show_ref_oid(const char *refname, const struct object_id *oid, int flag, void *cbdata)\n-{\n-\treturn show_ref(refname, oid->hash, flag, cbdata);\n-}\n-\n static int add_existing(const char *refname, const struct object_id *oid, int flag, void *cbdata)\n {\n \tstruct string_list *list = (struct string_list *)cbdata;\n@@ -230,8 +225,8 @@ int cmd_show_ref(int argc, const char **argv, const char *prefix)\n \t}\n \n \tif (show_head)\n-\t\thead_ref(show_ref_oid, NULL);\n-\tfor_each_ref(show_ref_oid, NULL);\n+\t\thead_ref(show_ref, NULL);\n+\tfor_each_ref(show_ref, NULL);\n \tif (!found_match) {\n \t\tif (verify && !quiet)\n \t\t\tdie(\"No match\");\ndiff --git a/log-tree.c b/log-tree.c\nindex acbc859..64768f7 100644\n--- a/log-tree.c\n+++ b/log-tree.c\n@@ -87,26 +87,26 @@ const struct name_decoration *get_name_decoration(const struct object *obj)\n \treturn lookup_decoration(&name_decoration, obj);\n }\n \n-static int add_ref_decoration(const char *refname, const unsigned char *sha1, int flags, void *cb_data)\n+static int add_ref_decoration(const char *refname, const struct object_id *oid, int flags, void *cb_data)\n {\n \tstruct object *obj;\n \tenum decoration_type type = DECORATION_NONE;\n \n \tif (starts_with(refname, \"refs/replace/\")) {\n-\t\tunsigned char original_sha1[20];\n+\t\tstruct object_id original_oid;\n \t\tif (!check_replace_refs)\n \t\t\treturn 0;\n-\t\tif (get_sha1_hex(refname + 13, original_sha1)) {\n+\t\tif (get_oid_hex(refname + 13, &original_oid)) {\n \t\t\twarning(\"invalid replace ref %s\", refname);\n \t\t\treturn 0;\n \t\t}\n-\t\tobj = parse_object(original_sha1);\n+\t\tobj = parse_object(original_oid.hash);\n \t\tif (obj)\n \t\t\tadd_name_decoration(DECORATION_GRAFTED, \"replaced\", obj);\n \t\treturn 0;\n \t}\n \n-\tobj = parse_object(sha1);\n+\tobj = parse_object(oid->hash);\n \tif (!obj)\n \t\treturn 0;\n \n@@ -135,11 +135,6 @@ static int add_ref_decoration(const char *refname, const unsigned char *sha1, in\n \treturn 0;\n }\n \n-static int add_ref_decoration_oid(const char *refname, const struct object_id *oid, int flags, void *cb_data)\n-{\n-\treturn add_ref_decoration(refname, oid->hash, flags, cb_data);\n-}\n-\n static int add_graft_decoration(const struct commit_graft *graft, void *cb_data)\n {\n \tstruct commit *commit = lookup_commit(graft->oid.hash);\n@@ -154,8 +149,8 @@ void load_ref_decorations(int flags)\n \tstatic int loaded;\n \tif (!loaded) {\n \t\tloaded = 1;\n-\t\tfor_each_ref(add_ref_decoration_oid, &flags);\n-\t\thead_ref(add_ref_decoration_oid, &flags);\n+\t\tfor_each_ref(add_ref_decoration, &flags);\n+\t\thead_ref(add_ref_decoration, &flags);\n \t\tfor_each_commit_graft(add_graft_decoration, NULL);\n \t}\n }\ndiff --git a/reachable.c b/reachable.c\nindex b2ca0c3..8715eb9 100644\n--- a/reachable.c\n+++ b/reachable.c\n@@ -22,9 +22,9 @@ static void update_progress(struct connectivity_progress *cp)\n \t\tdisplay_progress(cp->progress, cp->count);\n }\n \n-static int add_one_ref(const char *path, const unsigned char *sha1, int flag, void *cb_data)\n+static int add_one_ref(const char *path, const struct object_id *oid, int flag, void *cb_data)\n {\n-\tstruct object *object = parse_object_or_die(sha1, path);\n+\tstruct object *object = parse_object_or_die(oid->hash, path);\n \tstruct rev_info *revs = (struct rev_info *)cb_data;\n \n \tadd_pending_object(revs, object, \"\");\n@@ -32,11 +32,6 @@ static int add_one_ref(const char *path, const unsigned char *sha1, int flag, vo\n \treturn 0;\n }\n \n-static int add_one_ref_oid(const char *path, const struct object_id *oid, int flag, void *cb_data)\n-{\n-\treturn add_one_ref(path, oid->hash, flag, cb_data);\n-}\n-\n /*\n  * The traversal will have already marked us as SEEN, so we\n  * only need to handle any progress reporting here.\n@@ -173,10 +168,10 @@ void mark_reachable_objects(struct rev_info *revs, int mark_reflog,\n \tadd_index_objects_to_pending(revs, 0);\n \n \t/* Add all external refs */\n-\tfor_each_ref(add_one_ref_oid, revs);\n+\tfor_each_ref(add_one_ref, revs);\n \n \t/* detached HEAD is not included in the list above */\n-\thead_ref(add_one_ref_oid, revs);\n+\thead_ref(add_one_ref, revs);\n \n \t/* Add all reflog info */\n \tif (mark_reflog)\ndiff --git a/shallow.c b/shallow.c\nindex 6511bbb..1c6de02 100644\n--- a/shallow.c\n+++ b/shallow.c\n@@ -476,10 +476,10 @@ static void paint_down(struct paint_info *info, const unsigned char *sha1,\n }\n \n static int mark_uninteresting(const char *refname,\n-\t\t\t      const unsigned char *sha1,\n+\t\t\t      const struct object_id *oid,\n \t\t\t      int flags, void *cb_data)\n {\n-\tstruct commit *commit = lookup_commit_reference_gently(sha1, 1);\n+\tstruct commit *commit = lookup_commit_reference_gently(oid->hash, 1);\n \tif (!commit)\n \t\treturn 0;\n \tcommit->object.flags |= UNINTERESTING;\n@@ -487,13 +487,6 @@ static int mark_uninteresting(const char *refname,\n \treturn 0;\n }\n \n-static int mark_uninteresting_oid(const char *refname,\n-\t\t\t\tconst struct object_id *oid,\n-\t\t\t\tint flags, void *cb_data)\n-{\n-\treturn mark_uninteresting(refname, oid->hash, flags, cb_data);\n-}\n-\n static void post_assign_shallow(struct shallow_info *info,\n \t\t\t\tstruct ref_bitmap *ref_bitmap,\n \t\t\t\tint *ref_status);\n@@ -549,8 +542,8 @@ void assign_shallow_commits_to_refs(struct shallow_info *info,\n \t * connect to old refs. If not (e.g. force ref updates) it'll\n \t * have to go down to the current shallow commits.\n \t */\n-\thead_ref(mark_uninteresting_oid, NULL);\n-\tfor_each_ref(mark_uninteresting_oid, NULL);\n+\thead_ref(mark_uninteresting, NULL);\n+\tfor_each_ref(mark_uninteresting, NULL);\n \n \t/* Mark potential bottoms so we won't go out of bound */\n \tfor (i = 0; i < nr_shallow; i++) {\n@@ -592,22 +585,16 @@ struct commit_array {\n };\n \n static int add_ref(const char *refname,\n-\t\t   const unsigned char *sha1, int flags, void *cb_data)\n+\t\t   const struct object_id *oid, int flags, void *cb_data)\n {\n \tstruct commit_array *ca = cb_data;\n \tALLOC_GROW(ca->commits, ca->nr + 1, ca->alloc);\n-\tca->commits[ca->nr] = lookup_commit_reference_gently(sha1, 1);\n+\tca->commits[ca->nr] = lookup_commit_reference_gently(oid->hash, 1);\n \tif (ca->commits[ca->nr])\n \t\tca->nr++;\n \treturn 0;\n }\n \n-static int add_ref_oid(const char *refname,\n-\t\t   const struct object_id *oid, int flags, void *cb_data)\n-{\n-\treturn add_ref(refname, oid->hash, flags, cb_data);\n-}\n-\n static void update_refstatus(int *ref_status, int nr, uint32_t *bitmap)\n {\n \tint i;\n@@ -654,8 +641,8 @@ static void post_assign_shallow(struct shallow_info *info,\n \tinfo->nr_theirs = dst;\n \n \tmemset(&ca, 0, sizeof(ca));\n-\thead_ref(add_ref_oid, &ca);\n-\tfor_each_ref(add_ref_oid, &ca);\n+\thead_ref(add_ref, &ca);\n+\tfor_each_ref(add_ref, &ca);\n \n \t/* Remove unreachable shallow commits from \"ours\" */\n \tfor (i = dst = 0; i < info->nr_ours; i++) {\n@@ -688,8 +675,8 @@ int delayed_reachability_test(struct shallow_info *si, int c)\n \t\tif (!si->commits) {\n \t\t\tstruct commit_array ca;\n \t\t\tmemset(&ca, 0, sizeof(ca));\n-\t\t\thead_ref(add_ref_oid, &ca);\n-\t\t\tfor_each_ref(add_ref_oid, &ca);\n+\t\t\thead_ref(add_ref, &ca);\n+\t\t\tfor_each_ref(add_ref, &ca);\n \t\t\tsi->commits = ca.commits;\n \t\t\tsi->nr_commits = ca.nr;\n \t\t}\n-- \n2.3.5\n"},{"id":"259868","messageId":"1429745061-295908-17-git-send-email-sandals@crustytoothpaste.net","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH v2 16/16] refs: convert struct ref_lock to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-22T23:24:21Z","receivedAt":"2015-04-22T23:24:21Z","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 refs.c | 24 ++++++++++++------------\n 1 file changed, 12 insertions(+), 12 deletions(-)\n\ndiff --git a/refs.c b/refs.c\nindex 9e61b32..6c04189 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -10,7 +10,7 @@ struct ref_lock {\n \tchar *ref_name;\n \tchar *orig_ref_name;\n \tstruct lock_file *lk;\n-\tunsigned char old_sha1[20];\n+\tstruct object_id old_oid;\n \tint lock_fd;\n };\n \n@@ -2159,16 +2159,16 @@ static struct ref_lock *verify_lock(struct ref_lock *lock,\n {\n \tif (read_ref_full(lock->ref_name,\n \t\t\t  mustexist ? RESOLVE_REF_READING : 0,\n-\t\t\t  lock->old_sha1, NULL)) {\n+\t\t\t  lock->old_oid.hash, NULL)) {\n \t\tint save_errno = errno;\n \t\terror(\"Can't verify ref %s\", lock->ref_name);\n \t\tunlock_ref(lock);\n \t\terrno = save_errno;\n \t\treturn NULL;\n \t}\n-\tif (hashcmp(lock->old_sha1, old_sha1)) {\n+\tif (hashcmp(lock->old_oid.hash, old_sha1)) {\n \t\terror(\"Ref %s is at %s but expected %s\", lock->ref_name,\n-\t\t\tsha1_to_hex(lock->old_sha1), sha1_to_hex(old_sha1));\n+\t\t\toid_to_hex(&lock->old_oid), sha1_to_hex(old_sha1));\n \t\tunlock_ref(lock);\n \t\terrno = EBUSY;\n \t\treturn NULL;\n@@ -2313,7 +2313,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n \t}\n \n \trefname = resolve_ref_unsafe(refname, resolve_flags,\n-\t\t\t\t     lock->old_sha1, &type);\n+\t\t\t\t     lock->old_oid.hash, &type);\n \tif (!refname && errno == EISDIR) {\n \t\t/* we are trying to lock foo but we used to\n \t\t * have foo/bar which now does not exist;\n@@ -2327,7 +2327,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n \t\t\tgoto error_return;\n \t\t}\n \t\trefname = resolve_ref_unsafe(orig_refname, resolve_flags,\n-\t\t\t\t\t     lock->old_sha1, &type);\n+\t\t\t\t\t     lock->old_oid.hash, &type);\n \t}\n \tif (type_p)\n \t    *type_p = type;\n@@ -2343,7 +2343,7 @@ static struct ref_lock *lock_ref_sha1_basic(const char *refname,\n \t * refname, nor a packed ref whose name is a proper prefix of\n \t * our refname.\n \t */\n-\tif (is_null_sha1(lock->old_sha1) &&\n+\tif (is_null_oid(&lock->old_oid) &&\n \t     !is_refname_available(refname, skip, get_packed_refs(&ref_cache))) {\n \t\tlast_errno = ENOTDIR;\n \t\tgoto error_return;\n@@ -2849,7 +2849,7 @@ int rename_ref(const char *oldrefname, const char *newrefname, const char *logms\n \t\terror(\"unable to lock %s for update\", newrefname);\n \t\tgoto rollback;\n \t}\n-\thashcpy(lock->old_sha1, orig_sha1);\n+\thashcpy(lock->old_oid.hash, orig_sha1);\n \tif (write_ref_sha1(lock, orig_sha1, logmsg)) {\n \t\terror(\"unable to write current sha1 into %s\", newrefname);\n \t\tgoto rollback;\n@@ -3091,9 +3091,9 @@ static int write_ref_sha1(struct ref_lock *lock,\n \t\treturn -1;\n \t}\n \tclear_loose_ref_cache(&ref_cache);\n-\tif (log_ref_write(lock->ref_name, lock->old_sha1, sha1, logmsg) < 0 ||\n+\tif (log_ref_write(lock->ref_name, lock->old_oid.hash, sha1, logmsg) < 0 ||\n \t    (strcmp(lock->ref_name, lock->orig_ref_name) &&\n-\t     log_ref_write(lock->orig_ref_name, lock->old_sha1, sha1, logmsg) < 0)) {\n+\t     log_ref_write(lock->orig_ref_name, lock->old_oid.hash, sha1, logmsg) < 0)) {\n \t\tunlock_ref(lock);\n \t\treturn -1;\n \t}\n@@ -3117,7 +3117,7 @@ static int write_ref_sha1(struct ref_lock *lock,\n \t\t\t\t\t      head_sha1, &head_flag);\n \t\tif (head_ref && (head_flag & REF_ISSYMREF) &&\n \t\t    !strcmp(head_ref, lock->ref_name))\n-\t\t\tlog_ref_write(\"HEAD\", lock->old_sha1, sha1, logmsg);\n+\t\t\tlog_ref_write(\"HEAD\", lock->old_oid.hash, sha1, logmsg);\n \t}\n \tif (commit_ref(lock)) {\n \t\terror(\"Couldn't set %s\", lock->ref_name);\n@@ -3814,7 +3814,7 @@ int ref_transaction_commit(struct ref_transaction *transaction,\n \t\t\t\t\t\t  (update->flags & REF_NODEREF));\n \n \t\t\tif (!overwriting_symref\n-\t\t\t    && !hashcmp(update->lock->old_sha1, update->new_sha1)) {\n+\t\t\t    && !hashcmp(update->lock->old_oid.hash, update->new_sha1)) {\n \t\t\t\t/*\n \t\t\t\t * The reference already has the desired\n \t\t\t\t * value, so we don't need to write it.\n-- \n2.3.5\n"},{"id":"259879","messageId":"CAGZ79kbjBbuE=KGrW_7a7AOCGgEJgYb9fEE_MLq89ytkaBctRQ@mail.gmail.com","threadId":"39144","inReplyTo":"1429745061-295908-2-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 01/16] refs: convert struct ref_entry to use struct object_id","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2015-04-23T00:52:09Z","receivedAt":"2015-04-23T00:52:09Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Apr 22, 2015 at 4:24 PM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> ---\n>  refs.c | 44 ++++++++++++++++++++++----------------------\n>  1 file changed, 22 insertions(+), 22 deletions(-)\n>\n> diff --git a/refs.c b/refs.c\n> index 81a455b..522d15d 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -156,7 +156,7 @@ struct ref_value {\n>          * null.  If REF_ISSYMREF, then this is the name of the object\n>          * referred to by the last reference in the symlink chain.\n>          */\n> -       unsigned char sha1[20];\n> +       struct object_id oid;\n>\n>         /*\n>          * If REF_KNOWS_PEELED, then this field holds the peeled value\n> @@ -164,7 +164,7 @@ struct ref_value {\n>          * be peelable.  See the documentation for peel_ref() for an\n>          * exact definition of \"peelable\".\n>          */\n> -       unsigned char peeled[20];\n> +       struct object_id peeled;\n>  };\n>\n>  struct ref_cache;\n> @@ -346,8 +346,8 @@ static struct ref_entry *create_ref_entry(const char *refname,\n>                 die(\"Reference has invalid format: '%s'\", refname);\n>         len = strlen(refname) + 1;\n>         ref = xmalloc(sizeof(struct ref_entry) + len);\n> -       hashcpy(ref->u.value.sha1, sha1);\n> -       hashclr(ref->u.value.peeled);\n> +       hashcpy(ref->u.value.oid.hash, sha1);\n> +       oidclr(&ref->u.value.peeled);\n>         memcpy(ref->name, refname, len);\n>         ref->flag = flag;\n>         return ref;\n> @@ -621,7 +621,7 @@ static int is_dup_ref(const struct ref_entry *ref1, const struct ref_entry *ref2\n>                 /* This is impossible by construction */\n>                 die(\"Reference directory conflict: %s\", ref1->name);\n>\n> -       if (hashcmp(ref1->u.value.sha1, ref2->u.value.sha1))\n> +       if (oidcmp(&ref1->u.value.oid, &ref2->u.value.oid))\n>                 die(\"Duplicated ref, and SHA1s don't match: %s\", ref1->name);\n\nSo you're switching the code for a possible future\nIn an earlier series/cover letter you wrote\n\n> The goal of this series to improve type-checking in the codebase and to\n> make it easier to move to a different hash function if the project\n> decides to do that.  This series does not convert all of the codebase,\n> but only parts.  I've dropped some of the patches from earlier (which no\n> longer apply) and added others.\n\nWhich yields the question if you also want to take care of the error message\n(It may not be a SHA1 any more but some $HASHFUNCTION)?\n\nThat said I'll focus on the type checking part in this review\nand not annotate the SHA1s I find any more. ;)\n>\n>         warning(\"Duplicated ref: %s\", ref1->name);\n> @@ -669,7 +669,7 @@ static int ref_resolves_to_object(struct ref_entry *entry)\n>  {\n>         if (entry->flag & REF_ISBROKEN)\n>                 return 0;\n> -       if (!has_sha1_file(entry->u.value.sha1)) {\n> +       if (!has_sha1_file(entry->u.value.oid.hash)) {\n>                 error(\"%s does not point to a valid object!\", entry->name);\n>                 return 0;\n>         }\n> @@ -717,7 +717,7 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)\n>         /* Store the old value, in case this is a recursive call: */\n>         old_current_ref = current_ref;\n>         current_ref = entry;\n> -       retval = data->fn(entry->name + data->trim, entry->u.value.sha1,\n> +       retval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,\n>                           entry->flag, data->cb_data);\n>         current_ref = old_current_ref;\n>         return retval;\n> @@ -1193,7 +1193,7 @@ static void read_packed_refs(FILE *f, struct ref_dir *dir)\n>                     line.len == PEELED_LINE_LENGTH &&\n>                     line.buf[PEELED_LINE_LENGTH - 1] == '\\n' &&\n>                     !get_sha1_hex(line.buf + 1, sha1)) {\n> -                       hashcpy(last->u.value.peeled, sha1);\n> +                       hashcpy(last->u.value.peeled.hash, sha1);\n>                         /*\n>                          * Regardless of what the file header said,\n>                          * we definitely know the value of *this*\n> @@ -1374,7 +1374,7 @@ static int resolve_gitlink_packed_ref(struct ref_cache *refs,\n>         if (ref == NULL)\n>                 return -1;\n>\n> -       hashcpy(sha1, ref->u.value.sha1);\n> +       hashcpy(sha1, ref->u.value.oid.hash);\n>         return 0;\n>  }\n>\n> @@ -1461,7 +1461,7 @@ static int resolve_missing_loose_ref(const char *refname,\n>          */\n>         entry = get_packed_ref(refname);\n>         if (entry) {\n> -               hashcpy(sha1, entry->u.value.sha1);\n> +               hashcpy(sha1, entry->u.value.oid.hash);\n>                 if (flags)\n>                         *flags |= REF_ISPACKED;\n>                 return 0;\n> @@ -1771,9 +1771,9 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)\n>         if (entry->flag & REF_KNOWS_PEELED) {\n>                 if (repeel) {\n>                         entry->flag &= ~REF_KNOWS_PEELED;\n> -                       hashclr(entry->u.value.peeled);\n> +                       oidclr(&entry->u.value.peeled);\n>                 } else {\n> -                       return is_null_sha1(entry->u.value.peeled) ?\n> +                       return is_null_oid(&entry->u.value.peeled) ?\n>                                 PEEL_NON_TAG : PEEL_PEELED;\n>                 }\n>         }\n> @@ -1782,7 +1782,7 @@ static enum peel_status peel_entry(struct ref_entry *entry, int repeel)\n>         if (entry->flag & REF_ISSYMREF)\n>                 return PEEL_IS_SYMREF;\n>\n> -       status = peel_object(entry->u.value.sha1, entry->u.value.peeled);\n> +       status = peel_object(entry->u.value.oid.hash, entry->u.value.peeled.hash);\n>         if (status == PEEL_PEELED || status == PEEL_NON_TAG)\n>                 entry->flag |= REF_KNOWS_PEELED;\n>         return status;\n> @@ -1797,7 +1797,7 @@ int peel_ref(const char *refname, unsigned char *sha1)\n>                             || !strcmp(current_ref->name, refname))) {\n>                 if (peel_entry(current_ref, 0))\n>                         return -1;\n> -               hashcpy(sha1, current_ref->u.value.peeled);\n> +               hashcpy(sha1, current_ref->u.value.peeled.hash);\n>                 return 0;\n>         }\n>\n> @@ -1817,7 +1817,7 @@ int peel_ref(const char *refname, unsigned char *sha1)\n>                 if (r) {\n>                         if (peel_entry(r, 0))\n>                                 return -1;\n> -                       hashcpy(sha1, r->u.value.peeled);\n> +                       hashcpy(sha1, r->u.value.peeled.hash);\n>                         return 0;\n>                 }\n>         }\n> @@ -2422,9 +2422,9 @@ static int write_packed_entry_fn(struct ref_entry *entry, void *cb_data)\n>         if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)\n>                 error(\"internal error: %s is not a valid packed reference!\",\n>                       entry->name);\n> -       write_packed_entry(cb_data, entry->name, entry->u.value.sha1,\n> +       write_packed_entry(cb_data, entry->name, entry->u.value.oid.hash,\n>                            peel_status == PEEL_PEELED ?\n> -                          entry->u.value.peeled : NULL);\n> +                          entry->u.value.peeled.hash : NULL);\n>         return 0;\n>  }\n>\n> @@ -2531,24 +2531,24 @@ static int pack_if_possible_fn(struct ref_entry *entry, void *cb_data)\n>         peel_status = peel_entry(entry, 1);\n>         if (peel_status != PEEL_PEELED && peel_status != PEEL_NON_TAG)\n>                 die(\"internal error peeling reference %s (%s)\",\n> -                   entry->name, sha1_to_hex(entry->u.value.sha1));\n> +                   entry->name, oid_to_hex(&entry->u.value.oid));\n>         packed_entry = find_ref(cb->packed_refs, entry->name);\n>         if (packed_entry) {\n>                 /* Overwrite existing packed entry with info from loose entry */\n>                 packed_entry->flag = REF_ISPACKED | REF_KNOWS_PEELED;\n> -               hashcpy(packed_entry->u.value.sha1, entry->u.value.sha1);\n> +               oidcpy(&packed_entry->u.value.oid, &entry->u.value.oid);\n>         } else {\n> -               packed_entry = create_ref_entry(entry->name, entry->u.value.sha1,\n> +               packed_entry = create_ref_entry(entry->name, entry->u.value.oid.hash,\n>                                                 REF_ISPACKED | REF_KNOWS_PEELED, 0);\n>                 add_ref(cb->packed_refs, packed_entry);\n>         }\n> -       hashcpy(packed_entry->u.value.peeled, entry->u.value.peeled);\n> +       oidcpy(&packed_entry->u.value.peeled, &entry->u.value.peeled);\n>\n>         /* Schedule the loose reference for pruning if requested. */\n>         if ((cb->flags & PACK_REFS_PRUNE)) {\n>                 int namelen = strlen(entry->name) + 1;\n>                 struct ref_to_prune *n = xcalloc(1, sizeof(*n) + namelen);\n> -               hashcpy(n->sha1, entry->u.value.sha1);\n> +               hashcpy(n->sha1, entry->u.value.oid.hash);\n>                 strcpy(n->name, entry->name);\n>                 n->next = cb->ref_to_prune;\n>                 cb->ref_to_prune = n;\n> --\n> 2.3.5\n\nThe patch is\nReviewed-by: Stefan Beller <sbeller@google.com>\n\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"259903","messageId":"CAGZ79kas9QgJy1ooCjHPR+ZGGuTdMhTxO9zSMxnGpPk8rG5_xQ@mail.gmail.com","threadId":"39144","inReplyTo":"1429745061-295908-3-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 02/16] refs: convert for_each_tag_ref to struct object_id","fromName":"Stefan Beller","fromEmail":"sbeller@google.com","sentAt":"2015-04-23T18:13:32Z","receivedAt":"2015-04-23T18:13:32Z","isPatch":true,"sender":{"key":"stefanbeller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/455868?v=4"},"body":"On Wed, Apr 22, 2015 at 4:24 PM, brian m. carlson\n<sandals@crustytoothpaste.net> wrote:\n> To allow piecemeal conversion of the for_each_*_ref functions, introduce\n> an additional typedef for a callback function that takes struct\n> object_id * instead of unsigned char *.  Provide an extra field in\n> struct ref_entry_cb for this callback and ensure at most one is set at a\n> time.  Temporarily suffix these new entries with _oid to distinguish\n> them.  Convert for_each_tag_ref and its callers to use the new _oid\n> functions, introducing temporary wrapper functions to avoid type\n> mismatches.\n>\n> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n\nI am currently running this patch series via\ngit rebase -i origin/next --exec=make --exec=\"make test\"\nthrough the compilation and test suite one by one.\n(My current view of origin/next is (c8da2d582, Sync with 2.4.0-rc3)\nand this commit fails in t5312-prune-corruption.sh test 3 5 and 8\n\n> ---\n>  builtin/pack-objects.c |  4 ++--\n>  builtin/rev-parse.c    |  7 ++++++-\n>  builtin/tag.c          |  8 ++++----\n>  refs.c                 | 34 ++++++++++++++++++++++++++++++----\n>  refs.h                 | 10 +++++++++-\n>  5 files changed, 51 insertions(+), 12 deletions(-)\n>\n> diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\n> index c067107..0c69b0c 100644\n> --- a/builtin/pack-objects.c\n> +++ b/builtin/pack-objects.c\n> @@ -540,11 +540,11 @@ static enum write_one_status write_one(struct sha1file *f,\n>         return WRITE_ONE_WRITTEN;\n>  }\n>\n> -static int mark_tagged(const char *path, const unsigned char *sha1, int flag,\n> +static int mark_tagged(const char *path, const struct object_id *oid, int flag,\n>                        void *cb_data)\n>  {\n>         unsigned char peeled[20];\n> -       struct object_entry *entry = packlist_find(&to_pack, sha1, NULL);\n> +       struct object_entry *entry = packlist_find(&to_pack, oid->hash, NULL);\n>\n>         if (entry)\n>                 entry->tagged = 1;\n> diff --git a/builtin/rev-parse.c b/builtin/rev-parse.c\n> index 4d10dd9..7b70650 100644\n> --- a/builtin/rev-parse.c\n> +++ b/builtin/rev-parse.c\n> @@ -198,6 +198,11 @@ static int show_reference(const char *refname, const unsigned char *sha1, int fl\n>         return 0;\n>  }\n>\n> +static int show_reference_oid(const char *refname, const struct object_id *oid, int flag, void *cb_data)\n> +{\n> +       return show_reference(refname, oid->hash, flag, cb_data);\n> +}\n> +\n>  static int anti_reference(const char *refname, const unsigned char *sha1, int flag, void *cb_data)\n>  {\n>         show_rev(REVERSED, sha1, refname);\n> @@ -682,7 +687,7 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)\n>                                 continue;\n>                         }\n>                         if (!strcmp(arg, \"--tags\")) {\n> -                               for_each_tag_ref(show_reference, NULL);\n> +                               for_each_tag_ref(show_reference_oid, NULL);\n>                                 clear_ref_exclusion(&ref_excludes);\n>                                 continue;\n>                         }\n> diff --git a/builtin/tag.c b/builtin/tag.c\n> index 6f07ac6..61399b7 100644\n> --- a/builtin/tag.c\n> +++ b/builtin/tag.c\n> @@ -215,7 +215,7 @@ free_return:\n>         free(buf);\n>  }\n>\n> -static int show_reference(const char *refname, const unsigned char *sha1,\n> +static int show_reference(const char *refname, const struct object_id *oid,\n>                           int flag, void *cb_data)\n>  {\n>         struct tag_filter *filter = cb_data;\n> @@ -224,14 +224,14 @@ static int show_reference(const char *refname, const unsigned char *sha1,\n>                 if (filter->with_commit) {\n>                         struct commit *commit;\n>\n> -                       commit = lookup_commit_reference_gently(sha1, 1);\n> +                       commit = lookup_commit_reference_gently(oid->hash, 1);\n>                         if (!commit)\n>                                 return 0;\n>                         if (!contains(commit, filter->with_commit))\n>                                 return 0;\n>                 }\n>\n> -               if (points_at.nr && !match_points_at(refname, sha1))\n> +               if (points_at.nr && !match_points_at(refname, oid->hash))\n>                         return 0;\n>\n>                 if (!filter->lines) {\n> @@ -242,7 +242,7 @@ static int show_reference(const char *refname, const unsigned char *sha1,\n>                         return 0;\n>                 }\n>                 printf(\"%-15s \", refname);\n> -               show_tag_lines(sha1, filter->lines);\n> +               show_tag_lines(oid->hash, filter->lines);\n>                 putchar('\\n');\n>         }\n>\n> diff --git a/refs.c b/refs.c\n> index 522d15d..95863f2 100644\n> --- a/refs.c\n> +++ b/refs.c\n> @@ -694,6 +694,7 @@ struct ref_entry_cb {\n>         int trim;\n>         int flags;\n>         each_ref_fn *fn;\n> +       each_ref_fn_oid *fn_oid;\n>         void *cb_data;\n>  };\n>\n> @@ -717,8 +718,13 @@ static int do_one_ref(struct ref_entry *entry, void *cb_data)\n>         /* Store the old value, in case this is a recursive call: */\n>         old_current_ref = current_ref;\n>         current_ref = entry;\n> -       retval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,\n> -                         entry->flag, data->cb_data);\n> +       if (data->fn_oid) {\n> +               retval = data->fn_oid(entry->name + data->trim, &entry->u.value.oid,\n> +                                entry->flag, data->cb_data);\n> +       } else {\n> +               retval = data->fn(entry->name + data->trim, entry->u.value.oid.hash,\n> +                                entry->flag, data->cb_data);\n> +       }\n>         current_ref = old_current_ref;\n>         return retval;\n>  }\n> @@ -1950,6 +1956,21 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,\n>         data.trim = trim;\n>         data.flags = flags;\n>         data.fn = fn;\n> +       data.fn_oid = NULL;\n> +       data.cb_data = cb_data;\n> +\n> +       return do_for_each_entry(refs, base, do_one_ref, &data);\n> +}\n> +\n> +static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n> +                          each_ref_fn_oid fn, int trim, int flags, void *cb_data)\n> +{\n> +       struct ref_entry_cb data;\n> +       data.base = base;\n> +       data.trim = trim;\n> +       data.flags = flags;\n> +       data.fn = NULL;\n> +       data.fn_oid = fn;\n>         data.cb_data = cb_data;\n>\n>         if (ref_paranoia < 0)\n> @@ -1998,6 +2019,11 @@ int for_each_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n>         return do_for_each_ref(get_ref_cache(submodule), \"\", fn, 0, 0, cb_data);\n>  }\n>\n> +static int for_each_ref_in_oid(const char *prefix, each_ref_fn_oid fn, void *cb_data)\n> +{\n> +       return do_for_each_ref_oid(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n> +}\n> +\n>  int for_each_ref_in(const char *prefix, each_ref_fn fn, void *cb_data)\n>  {\n>         return do_for_each_ref(&ref_cache, prefix, fn, strlen(prefix), 0, cb_data);\n> @@ -2009,9 +2035,9 @@ int for_each_ref_in_submodule(const char *submodule, const char *prefix,\n>         return do_for_each_ref(get_ref_cache(submodule), prefix, fn, strlen(prefix), 0, cb_data);\n>  }\n>\n> -int for_each_tag_ref(each_ref_fn fn, void *cb_data)\n> +int for_each_tag_ref(each_ref_fn_oid fn, void *cb_data)\n>  {\n> -       return for_each_ref_in(\"refs/tags/\", fn, cb_data);\n> +       return for_each_ref_in_oid(\"refs/tags/\", fn, cb_data);\n>  }\n>\n>  int for_each_tag_ref_submodule(const char *submodule, each_ref_fn fn, void *cb_data)\n> diff --git a/refs.h b/refs.h\n> index 6d7d9b4..b83529b 100644\n> --- a/refs.h\n> +++ b/refs.h\n> @@ -1,6 +1,8 @@\n>  #ifndef REFS_H\n>  #define REFS_H\n>\n> +#include \"cache.h\"\n> +\n>  /*\n>   * A ref_transaction represents a collection of ref updates\n>   * that should succeed or fail together.\n> @@ -70,6 +72,12 @@ typedef int each_ref_fn(const char *refname,\n>                         const unsigned char *sha1, int flags, void *cb_data);\n>\n>  /*\n> + * Like each_ref_fn, but passes the object ID using a struct.\n> + */\n> +typedef int each_ref_fn_oid(const char *refname,\n> +                       const struct object_id *oid, int flags, void *cb_data);\n> +\n> +/*\n>   * The following functions invoke the specified callback function for\n>   * each reference indicated.  If the function ever returns a nonzero\n>   * value, stop the iteration and return that value.  Please note that\n> @@ -81,7 +89,7 @@ typedef int each_ref_fn(const char *refname,\n>  extern int head_ref(each_ref_fn, void *);\n>  extern int for_each_ref(each_ref_fn, void *);\n>  extern int for_each_ref_in(const char *, each_ref_fn, void *);\n> -extern int for_each_tag_ref(each_ref_fn, void *);\n> +extern int for_each_tag_ref(each_ref_fn_oid, void *);\n>  extern int for_each_branch_ref(each_ref_fn, void *);\n>  extern int for_each_remote_ref(each_ref_fn, void *);\n>  extern int for_each_replace_ref(each_ref_fn, void *);\n> --\n> 2.3.5\n>\n> --\n> To unsubscribe from this list: send the line \"unsubscribe git\" in\n> the body of a message to majordomo@vger.kernel.org\n> More majordomo info at  http://vger.kernel.org/majordomo-info.html\n"},{"id":"259910","messageId":"20150423192723.GA29220@peff.net","threadId":"39144","inReplyTo":"CAGZ79kas9QgJy1ooCjHPR+ZGGuTdMhTxO9zSMxnGpPk8rG5_xQ@mail.gmail.com","subject":"Re: [PATCH v2 02/16] refs: convert for_each_tag_ref to struct object_id","fromName":"Jeff King","fromEmail":"peff@peff.net","sentAt":"2015-04-23T19:27:23Z","receivedAt":"2015-04-23T19:27:23Z","isPatch":true,"sender":{"key":"peff@peff.net","avatar":"https://avatars.githubusercontent.com/u/45925?v=4"},"body":"On Thu, Apr 23, 2015 at 11:13:32AM -0700, Stefan Beller wrote:\n\n> On Wed, Apr 22, 2015 at 4:24 PM, brian m. carlson\n> <sandals@crustytoothpaste.net> wrote:\n> > To allow piecemeal conversion of the for_each_*_ref functions, introduce\n> > an additional typedef for a callback function that takes struct\n> > object_id * instead of unsigned char *.  Provide an extra field in\n> > struct ref_entry_cb for this callback and ensure at most one is set at a\n> > time.  Temporarily suffix these new entries with _oid to distinguish\n> > them.  Convert for_each_tag_ref and its callers to use the new _oid\n> > functions, introducing temporary wrapper functions to avoid type\n> > mismatches.\n> >\n> > Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n> \n> I am currently running this patch series via\n> git rebase -i origin/next --exec=make --exec=\"make test\"\n> through the compilation and test suite one by one.\n> (My current view of origin/next is (c8da2d582, Sync with 2.4.0-rc3)\n> and this commit fails in t5312-prune-corruption.sh test 3 5 and 8\n\nIt's because of this hunk:\n\n> > @@ -1950,6 +1956,21 @@ static int do_for_each_ref(struct ref_cache *refs, const char *base,\n> >         data.trim = trim;\n> >         data.flags = flags;\n> >         data.fn = fn;\n> > +       data.fn_oid = NULL;\n> > +       data.cb_data = cb_data;\n> > +\n> > +       return do_for_each_entry(refs, base, do_one_ref, &data);\n> > +}\n> > +\n> > +static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n> > +                          each_ref_fn_oid fn, int trim, int flags, void *cb_data)\n> > +{\n> > +       struct ref_entry_cb data;\n> > +       data.base = base;\n> > +       data.trim = trim;\n> > +       data.flags = flags;\n> > +       data.fn = NULL;\n> > +       data.fn_oid = fn;\n> >         data.cb_data = cb_data;\n> >\n> >         if (ref_paranoia < 0)\n\nThe ref_paranoia code gets pushed down into do_for_each_ref_oid, but it\nneeds called in both do_for_each_ref variants. This is probably an\nartifact of rebasing the patches (the ref_paranoia stuff was added\nrecently).\n\nI think it would make sense to pull the setup of the data struct into a\nshared function rather than duplicate it. But we want to avoid having to\nupdate do_for_each_ref callsites, so we'll have to provide a wrapper.\n\nLike this:\n\ndiff --git a/refs.c b/refs.c\nindex 95863f2..ad39d74 100644\n--- a/refs.c\n+++ b/refs.c\n@@ -1948,29 +1948,16 @@ static int do_for_each_entry(struct ref_cache *refs, const char *base,\n  * value, stop the iteration and return that value; otherwise, return\n  * 0.\n  */\n-static int do_for_each_ref(struct ref_cache *refs, const char *base,\n-\t\t\t   each_ref_fn fn, int trim, int flags, void *cb_data)\n+static int do_for_each_ref_generic(struct ref_cache *refs, const char *base,\n+\t\t\t\t   each_ref_fn fn, each_ref_fn_oid fn_oid,\n+\t\t\t\t   int trim, int flags, void *cb_data)\n {\n \tstruct ref_entry_cb data;\n \tdata.base = base;\n \tdata.trim = trim;\n \tdata.flags = flags;\n \tdata.fn = fn;\n-\tdata.fn_oid = NULL;\n-\tdata.cb_data = cb_data;\n-\n-\treturn do_for_each_entry(refs, base, do_one_ref, &data);\n-}\n-\n-static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n-\t\t\t   each_ref_fn_oid fn, int trim, int flags, void *cb_data)\n-{\n-\tstruct ref_entry_cb data;\n-\tdata.base = base;\n-\tdata.trim = trim;\n-\tdata.flags = flags;\n-\tdata.fn = NULL;\n-\tdata.fn_oid = fn;\n+\tdata.fn_oid = fn_oid;\n \tdata.cb_data = cb_data;\n \n \tif (ref_paranoia < 0)\n@@ -1981,6 +1968,18 @@ static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n \treturn do_for_each_entry(refs, base, do_one_ref, &data);\n }\n \n+static int do_for_each_ref(struct ref_cache *refs, const char *base,\n+\t\t\t   each_ref_fn fn, int trim, int flags, void *cb_data)\n+{\n+\treturn do_for_each_ref_generic(refs, base, fn, NULL, trim, flags, cb_data);\n+}\n+\n+static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n+\t\t\t       each_ref_fn_oid fn, int trim, int flags, void *cb_data)\n+{\n+\treturn do_for_each_ref_generic(refs, base, NULL, fn, trim, flags, cb_data);\n+}\n+\n static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)\n {\n \tunsigned char sha1[20];\n\nYou can even dispense with the _oid variant wrapper, and just call into\nthe generic version directly from the new callsites.\n\n-Peff\n"},{"id":"259969","messageId":"20150424223603.GA322887@vauxhall.crustytoothpaste.net","threadId":"39144","inReplyTo":"CAGZ79kbjBbuE=KGrW_7a7AOCGgEJgYb9fEE_MLq89ytkaBctRQ@mail.gmail.com","subject":"Re: [PATCH v2 01/16] refs: convert struct ref_entry to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-24T22:36:03Z","receivedAt":"2015-04-24T22:36:03Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Wed, Apr 22, 2015 at 05:52:09PM -0700, Stefan Beller wrote:\n> So you're switching the code for a possible future\n> In an earlier series/cover letter you wrote\n> \n> > The goal of this series to improve type-checking in the codebase and to\n> > make it easier to move to a different hash function if the project\n> > decides to do that.  This series does not convert all of the codebase,\n> > but only parts.  I've dropped some of the patches from earlier (which no\n> > longer apply) and added others.\n> \n> Which yields the question if you also want to take care of the error message\n> (It may not be a SHA1 any more but some $HASHFUNCTION)?\n\nThis is true.  However, I'll clean those up with a future patch series\nwhen we get to that point.  I'll need to pass through the documentation\nas well to make it accurate and consistent, and I'll want to discuss the\nwords we want to use before I make those changes.\n\n> That said I'll focus on the type checking part in this review\n> and not annotate the SHA1s I find any more. ;)\n\nPlease do comment on any hardcoded 20s or 40s (or quantities based off\nthose), as I do want to fix those up.  I want to fix up any hardcoded\nassumptions we may have about the hash that don't involve text or\ndocumentation at this point, if only for maintainability reasons.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"259970","messageId":"20150424223747.GB322887@vauxhall.crustytoothpaste.net","threadId":"39144","inReplyTo":"20150423192723.GA29220@peff.net","subject":"Re: [PATCH v2 02/16] refs: convert for_each_tag_ref to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-04-24T22:37:47Z","receivedAt":"2015-04-24T22:37:47Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Thu, Apr 23, 2015 at 03:27:23PM -0400, Jeff King wrote:\n> +static int do_for_each_ref(struct ref_cache *refs, const char *base,\n> +\t\t\t   each_ref_fn fn, int trim, int flags, void *cb_data)\n> +{\n> +\treturn do_for_each_ref_generic(refs, base, fn, NULL, trim, flags, cb_data);\n> +}\n> +\n> +static int do_for_each_ref_oid(struct ref_cache *refs, const char *base,\n> +\t\t\t       each_ref_fn_oid fn, int trim, int flags, void *cb_data)\n> +{\n> +\treturn do_for_each_ref_generic(refs, base, NULL, fn, trim, flags, cb_data);\n> +}\n> +\n>  static int do_head_ref(const char *submodule, each_ref_fn fn, void *cb_data)\n>  {\n>  \tunsigned char sha1[20];\n> \n> You can even dispense with the _oid variant wrapper, and just call into\n> the generic version directly from the new callsites.\n\nSounds like a good idea.  I'll reroll with that change probably sometime\nthis weekend.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"},{"id":"260039","messageId":"553D49EE.4000801@alum.mit.edu","threadId":"39144","inReplyTo":"1429745061-295908-1-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH v2 00/16] Convert parts of refs.c to struct object_id","fromName":"Michael Haggerty","fromEmail":"mhagger@alum.mit.edu","sentAt":"2015-04-26T20:26:22Z","receivedAt":"2015-04-26T20:26:22Z","isPatch":true,"sender":{"key":"mhagger@alum.mit.edu","avatar":"https://avatars.githubusercontent.com/u/119718?v=4"},"body":"On 04/23/2015 01:24 AM, brian m. carlson wrote:\n> This is a conversion of parts of refs.c to use struct object_id.\n> \n> refs.c, and the for_each_ref series of functions explicitly, is the\n> source for many instances of object IDs in the codebase.  Therefore, it\n> makes sense to convert this series of functions to provide a basis for\n> further conversions.\n> \n> This series is essentially just for_each_ref and friends, the callbacks,\n> and callers.  Other parts of refs.c will be converted in a later series,\n> so as to keep the number of patches to a reasonable size.\n> \n> There should be no functional change from this patch series.\n\nI wanted to review your patches, but wasn't really sure how to go about\nit in a way that would make me confident in the result. In a way these\nrefactoring patch series are easier to implement than to review.\n\n...so that's what I did. I reimplemented your changes \"from scratch\" [1]\nand then checked how my result differed from yours. My conclusion is\nthat the final result of your patches looks good, though there are some\nother changes in the neighborhood that could sensibly be added.\n\n\nHowever, I reached the destination via a different route and I thought\nI'd describe it in case you are interested, and as the technique might\nbe useful for future \"object_id\" refactorings. My patch series is\navailable on my GitHub account at\n\n    https://github.com/mhagger/git branch oid-refs-adapter\n\nMy starting point was to change each_ref_fn to take a \"const object_id\n*\" parameter instead of \"const unsigned char *\". This change requires\nall call sites of all of the for_each_ref functions to be modified,\nbecause they currently pass callback functions that match the old signature.\n\nSo I kept the old typedef (the one that takes \"const unsigned char *\")\nbut renamed it to each_ref_sha1_fn. And I added an adapter that allows\nsuch functions to be wrapped then passed to the new for_each_ref\nfunctions. It looks like this:\n\n    typedef int each_ref_sha1_fn(const char *refname,\n    \t\t\t         const unsigned char *sha1, int flags, void *cb_data);\n\n    struct each_ref_fn_sha1_adapter {\n\t    each_ref_sha1_fn *original_fn;\n\t    void *original_cb_data;\n    };\n\n    extern int each_ref_fn_adapter(const char *refname,\n\t\t\t           const struct object_id *oid, int flags, void *cb_data);\n\nEach callsite has to be changed, but the changes are quite\nstraightforward. At a callsite that would have called\n\n    for_each_ref(my_function, &my_data)\n\nyou wrap my_function and my_data in an each_ref_fn_sha1_adapter and call\nfor_each_ref using each_ref_fn_adapter as the callback:\n\n    struct each_ref_fn_sha1_adapter wrapped_my_function =\n            {my_function, &my_data};\n\n    for_each_ref(each_ref_fn_adapter, &wrapped_my_function);\n\nThe function each_ref_fn_adapter extracts the SHA-1 out of the oid and\ncalls my_function, passing it &my_data as extra data.\n\nThis patch is thus giant but very straightforward.\n\nAfter that, there is one patch for each callsite, rewriting it to use\nfor_each_ref natively (which usually entails modifying my_function to\ntake an object_id parameter then undoing the wrapper). These patches\ninvolve a little bit of thought, but not too much. And the results are\nvery bisectable because each patch makes a single small change. I also\nsuspect it might be easier to rebase and/or merge my patch series, for\nthe same reason.\n\nThe end result was very similar to yours, so I am confident that the net\nresult of your patch series is correct. But the remaining differences in\nthe end results are also interesting. I made a few more changes in the\nneighborhood of the patches, not to mention a few formatting\nimprovements in code that I touched. If you compare the tip of my\nbranch, above, to the tip of yours (I uploaded that to my repo too, as\nbranch \"bc-oid-refs\"), it may give you some ideas for other code that\ncan be changed to object_id.\n\nYours,\nMichael\n\n[1] Obviously I glanced at your patches while I was working to make sure\nthat I was headed in the same direction as you, and to minimize\ngratuitous differences between our versions.\n\n-- \nMichael Haggerty\nmhagger@alum.mit.edu\n"},{"id":"260495","messageId":"20150503214500.GA214319@vauxhall.crustytoothpaste.net","threadId":"39144","inReplyTo":"553D49EE.4000801@alum.mit.edu","subject":"Re: [PATCH v2 00/16] Convert parts of refs.c to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2015-05-03T21:45:00Z","receivedAt":"2015-05-03T21:45:00Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Sun, Apr 26, 2015 at 10:26:22PM +0200, Michael Haggerty wrote:\n> After that, there is one patch for each callsite, rewriting it to use\n> for_each_ref natively (which usually entails modifying my_function to\n> take an object_id parameter then undoing the wrapper). These patches\n> involve a little bit of thought, but not too much. And the results are\n> very bisectable because each patch makes a single small change. I also\n> suspect it might be easier to rebase and/or merge my patch series, for\n> the same reason.\n> \n> The end result was very similar to yours, so I am confident that the net\n> result of your patch series is correct. But the remaining differences in\n> the end results are also interesting. I made a few more changes in the\n> neighborhood of the patches, not to mention a few formatting\n> improvements in code that I touched. If you compare the tip of my\n> branch, above, to the tip of yours (I uploaded that to my repo too, as\n> branch \"bc-oid-refs\"), it may give you some ideas for other code that\n> can be changed to object_id.\n\nThis is a very interesting approach.  I've only just had time to look at\nit, but I like it.\n\nI agree that it's much more bisectable, although your series has a much\nlarger quantity of patches.  I feel like sending an 83-patch series to\nthe list may frighten reviewers away.  That's really the only thing\npreventing me from replacing my series with yours.\n\nJunio, what would you think about such a series?  Would you prefer\nslightly larger patches, one per file, if it meant that we had many\nfewer patches, or would you prefer a large number of patches touching a\nsingle function each?\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | http://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: RSA v4 4096b: 88AC E9B2 9196 305B A994 7552 F1BA 225C 0223 B187\n"}]}