{"thread":{"id":"42058","subject":"[PATCH 6/6] match-trees: convert several leaf functions to struct object_id","startedAt":"2016-04-17T23:10:35Z","lastAt":"2016-04-20T00:17:20Z","messageCount":10,"participants":["brian m. carlson","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":6},"messages":[{"id":"283712","messageId":"1460934641-435791-1-git-send-email-sandals@crustytoothpaste.net","threadId":"42058","inReplyTo":null,"subject":"[PATCH 0/6] object_id Part 3","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-04-17T23:10:35Z","receivedAt":"2016-04-17T23:10:35Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"This is the third of a series of patches to convert instances of\nunsigned char[20] to struct object_id.  The focus in this series was to\nconvert test-match-trees, related functions, and some dependencies.\nstruct name_entry was converted as part of these dependencies.\n\nThe riskiest part of this series is the conversion of struct name_entry.\nCompatibility with unconverted code requires dereferencing the new oid\nmember, but there are at least some places where we explicitly check\nthat it is not NULL.  These seem to be limited to empty entries in\nmerge-tree.c, and it doesn't appear that we ever pass an empty entry to\na function which might dereference it.\n\nThis series rebases onto next cleanly and is not likely to conflict with\nother topics in flight.  My intention is to send smaller series more\nfrequently, with the goal of avoiding or minimizing conflicts where\npossible.\n\nbrian m. carlson (6):\n  Introduce a get_oid function.\n  test-match-trees: convert to use struct object_id\n  match-trees: convert shift_tree and shift_tree_by to object_id\n  Convert struct name_entry to use struct object_id.\n  tree-walk: convert tree_entry_extract to struct object_id\n  match-trees: convert several leaf functions to struct object_id\n\n builtin/grep.c         |  6 ++---\n builtin/merge-tree.c   | 18 +++++++--------\n builtin/pack-objects.c |  4 ++--\n builtin/reflog.c       |  4 ++--\n cache-tree.c           |  4 ++--\n cache.h                |  6 +++--\n fsck.c                 | 10 ++++-----\n http-push.c            |  4 ++--\n list-objects.c         |  6 ++---\n match-trees.c          | 60 +++++++++++++++++++++++++-------------------------\n merge-recursive.c      |  4 ++--\n notes.c                |  4 ++--\n revision.c             |  4 ++--\n sha1_name.c            |  9 ++++++++\n test-match-trees.c     | 14 ++++++------\n tree-diff.c            |  8 +++----\n tree-walk.c            | 16 +++++++-------\n tree-walk.h            |  8 +++----\n tree.c                 | 10 ++++-----\n unpack-trees.c         |  4 ++--\n walker.c               |  4 ++--\n 21 files changed, 109 insertions(+), 98 deletions(-)\n\n-- \n2.8.0.rc3.226.g39d4020\n"},{"id":"283715","messageId":"1460934641-435791-2-git-send-email-sandals@crustytoothpaste.net","threadId":"42058","inReplyTo":"1460934641-435791-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 1/6] Introduce a get_oid function.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-04-17T23:10:36Z","receivedAt":"2016-04-17T23:10:36Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"The get_oid function is equivalent to the get_sha1 function, but uses a\nstruct object_id instead.\n\nSigned-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h     | 2 ++\n sha1_name.c | 9 +++++++++\n 2 files changed, 11 insertions(+)\n\ndiff --git a/cache.h b/cache.h\nindex 2711048c..22b73646 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1156,6 +1156,8 @@ extern int get_sha1_blob(const char *str, unsigned char *sha1);\n extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);\n extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc);\n \n+extern int get_oid(const char *str, struct object_id *oid);\n+\n typedef int each_abbrev_fn(const unsigned char *sha1, void *);\n extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);\n \ndiff --git a/sha1_name.c b/sha1_name.c\nindex 776101e8..ca7ddd6f 100644\n--- a/sha1_name.c\n+++ b/sha1_name.c\n@@ -1215,6 +1215,15 @@ int get_sha1(const char *name, unsigned char *sha1)\n }\n \n /*\n+ * This is like \"get_sha1()\", but for struct object_id.\n+ */\n+int get_oid(const char *name, struct object_id *oid)\n+{\n+\treturn get_sha1(name, oid->hash);\n+}\n+\n+\n+/*\n  * Many callers know that the user meant to name a commit-ish by\n  * syntactical positions where the object name appears.  Calling this\n  * function allows the machinery to disambiguate shorter-than-unique\n-- \n2.8.0.rc3.226.g39d4020\n"},{"id":"283713","messageId":"1460934641-435791-3-git-send-email-sandals@crustytoothpaste.net","threadId":"42058","inReplyTo":"1460934641-435791-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 2/6] test-match-trees: convert to use struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-04-17T23:10:37Z","receivedAt":"2016-04-17T23:10:37Z","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 test-match-trees.c | 14 +++++++-------\n 1 file changed, 7 insertions(+), 7 deletions(-)\n\ndiff --git a/test-match-trees.c b/test-match-trees.c\nindex 4dad7095..41aff841 100644\n--- a/test-match-trees.c\n+++ b/test-match-trees.c\n@@ -3,24 +3,24 @@\n \n int main(int ac, char **av)\n {\n-\tunsigned char hash1[20], hash2[20], shifted[20];\n+\tstruct object_id hash1, hash2, shifted;\n \tstruct tree *one, *two;\n \n \tsetup_git_directory();\n \n-\tif (get_sha1(av[1], hash1))\n+\tif (get_oid(av[1], &hash1))\n \t\tdie(\"cannot parse %s as an object name\", av[1]);\n-\tif (get_sha1(av[2], hash2))\n+\tif (get_oid(av[2], &hash2))\n \t\tdie(\"cannot parse %s as an object name\", av[2]);\n-\tone = parse_tree_indirect(hash1);\n+\tone = parse_tree_indirect(hash1.hash);\n \tif (!one)\n \t\tdie(\"not a tree-ish %s\", av[1]);\n-\ttwo = parse_tree_indirect(hash2);\n+\ttwo = parse_tree_indirect(hash2.hash);\n \tif (!two)\n \t\tdie(\"not a tree-ish %s\", av[2]);\n \n-\tshift_tree(one->object.oid.hash, two->object.oid.hash, shifted, -1);\n-\tprintf(\"shifted: %s\\n\", sha1_to_hex(shifted));\n+\tshift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, -1);\n+\tprintf(\"shifted: %s\\n\", oid_to_hex(&shifted));\n \n \texit(0);\n }\n-- \n2.8.0.rc3.226.g39d4020\n"},{"id":"283717","messageId":"1460934641-435791-4-git-send-email-sandals@crustytoothpaste.net","threadId":"42058","inReplyTo":"1460934641-435791-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 3/6] match-trees: convert shift_tree and shift_tree_by to object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-04-17T23:10:38Z","receivedAt":"2016-04-17T23:10:38Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>\n---\n cache.h            |  4 ++--\n match-trees.c      | 44 ++++++++++++++++++++++----------------------\n merge-recursive.c  |  4 ++--\n test-match-trees.c |  2 +-\n 4 files changed, 27 insertions(+), 27 deletions(-)\n\ndiff --git a/cache.h b/cache.h\nindex 22b73646..70091e73 100644\n--- a/cache.h\n+++ b/cache.h\n@@ -1768,8 +1768,8 @@ int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int\n extern int diff_auto_refresh_index;\n \n /* match-trees.c */\n-void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);\n-void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *, const char *);\n+void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);\n+void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);\n \n /*\n  * whitespace rules.\ndiff --git a/match-trees.c b/match-trees.c\nindex 1ce0954a..9977752a 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -229,9 +229,9 @@ static int splice_tree(const unsigned char *hash1,\n  * other hand, it could cover tree one and we might need to pick a\n  * subtree of it.\n  */\n-void shift_tree(const unsigned char *hash1,\n-\t\tconst unsigned char *hash2,\n-\t\tunsigned char *shifted,\n+void shift_tree(const struct object_id *hash1,\n+\t\tconst struct object_id *hash2,\n+\t\tstruct object_id *shifted,\n \t\tint depth_limit)\n {\n \tchar *add_prefix;\n@@ -245,7 +245,7 @@ void shift_tree(const unsigned char *hash1,\n \tif (!depth_limit)\n \t\tdepth_limit = 2;\n \n-\tadd_score = del_score = score_trees(hash1, hash2);\n+\tadd_score = del_score = score_trees(hash1->hash, hash2->hash);\n \tadd_prefix = xcalloc(1, 1);\n \tdel_prefix = xcalloc(1, 1);\n \n@@ -253,16 +253,16 @@ void shift_tree(const unsigned char *hash1,\n \t * See if one's subtree resembles two; if so we need to prefix\n \t * two with a few fake trees to match the prefix.\n \t */\n-\tmatch_trees(hash1, hash2, &add_score, &add_prefix, \"\", depth_limit);\n+\tmatch_trees(hash1->hash, hash2->hash, &add_score, &add_prefix, \"\", depth_limit);\n \n \t/*\n \t * See if two's subtree resembles one; if so we need to\n \t * pick only subtree of two.\n \t */\n-\tmatch_trees(hash2, hash1, &del_score, &del_prefix, \"\", depth_limit);\n+\tmatch_trees(hash2->hash, hash1->hash, &del_score, &del_prefix, \"\", depth_limit);\n \n \t/* Assume we do not have to do any shifting */\n-\thashcpy(shifted, hash2);\n+\toidcpy(shifted, hash2);\n \n \tif (add_score < del_score) {\n \t\t/* We need to pick a subtree of two */\n@@ -271,16 +271,16 @@ void shift_tree(const unsigned char *hash1,\n \t\tif (!*del_prefix)\n \t\t\treturn;\n \n-\t\tif (get_tree_entry(hash2, del_prefix, shifted, &mode))\n+\t\tif (get_tree_entry(hash2->hash, del_prefix, shifted->hash, &mode))\n \t\t\tdie(\"cannot find path %s in tree %s\",\n-\t\t\t    del_prefix, sha1_to_hex(hash2));\n+\t\t\t    del_prefix, oid_to_hex(hash2));\n \t\treturn;\n \t}\n \n \tif (!*add_prefix)\n \t\treturn;\n \n-\tsplice_tree(hash1, add_prefix, hash2, shifted);\n+\tsplice_tree(hash1->hash, add_prefix, hash2->hash, shifted->hash);\n }\n \n /*\n@@ -288,44 +288,44 @@ void shift_tree(const unsigned char *hash1,\n  * Unfortunately we cannot fundamentally tell which one to\n  * be prefixed, as recursive merge can work in either direction.\n  */\n-void shift_tree_by(const unsigned char *hash1,\n-\t\t   const unsigned char *hash2,\n-\t\t   unsigned char *shifted,\n+void shift_tree_by(const struct object_id *hash1,\n+\t\t   const struct object_id *hash2,\n+\t\t   struct object_id *shifted,\n \t\t   const char *shift_prefix)\n {\n-\tunsigned char sub1[20], sub2[20];\n+\tstruct object_id sub1, sub2;\n \tunsigned mode1, mode2;\n \tunsigned candidate = 0;\n \n \t/* Can hash2 be a tree at shift_prefix in tree hash1? */\n-\tif (!get_tree_entry(hash1, shift_prefix, sub1, &mode1) &&\n+\tif (!get_tree_entry(hash1->hash, shift_prefix, sub1.hash, &mode1) &&\n \t    S_ISDIR(mode1))\n \t\tcandidate |= 1;\n \n \t/* Can hash1 be a tree at shift_prefix in tree hash2? */\n-\tif (!get_tree_entry(hash2, shift_prefix, sub2, &mode2) &&\n+\tif (!get_tree_entry(hash2->hash, shift_prefix, sub2.hash, &mode2) &&\n \t    S_ISDIR(mode2))\n \t\tcandidate |= 2;\n \n \tif (candidate == 3) {\n \t\t/* Both are plausible -- we need to evaluate the score */\n-\t\tint best_score = score_trees(hash1, hash2);\n+\t\tint best_score = score_trees(hash1->hash, hash2->hash);\n \t\tint score;\n \n \t\tcandidate = 0;\n-\t\tscore = score_trees(sub1, hash2);\n+\t\tscore = score_trees(sub1.hash, hash2->hash);\n \t\tif (score > best_score) {\n \t\t\tcandidate = 1;\n \t\t\tbest_score = score;\n \t\t}\n-\t\tscore = score_trees(sub2, hash1);\n+\t\tscore = score_trees(sub2.hash, hash1->hash);\n \t\tif (score > best_score)\n \t\t\tcandidate = 2;\n \t}\n \n \tif (!candidate) {\n \t\t/* Neither is plausible -- do not shift */\n-\t\thashcpy(shifted, hash2);\n+\t\toidcpy(shifted, hash2);\n \t\treturn;\n \t}\n \n@@ -334,11 +334,11 @@ void shift_tree_by(const unsigned char *hash1,\n \t\t * shift tree2 down by adding shift_prefix above it\n \t\t * to match tree1.\n \t\t */\n-\t\tsplice_tree(hash1, shift_prefix, hash2, shifted);\n+\t\tsplice_tree(hash1->hash, shift_prefix, hash2->hash, shifted->hash);\n \telse\n \t\t/*\n \t\t * shift tree2 up by removing shift_prefix from it\n \t\t * to match tree1.\n \t\t */\n-\t\thashcpy(shifted, sub2);\n+\t\toidcpy(shifted, &sub2);\n }\ndiff --git a/merge-recursive.c b/merge-recursive.c\nindex b880ae50..a47c80f8 100644\n--- a/merge-recursive.c\n+++ b/merge-recursive.c\n@@ -29,9 +29,9 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,\n \tstruct object_id shifted;\n \n \tif (!*subtree_shift) {\n-\t\tshift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, 0);\n+\t\tshift_tree(&one->object.oid, &two->object.oid, &shifted, 0);\n \t} else {\n-\t\tshift_tree_by(one->object.oid.hash, two->object.oid.hash, shifted.hash,\n+\t\tshift_tree_by(&one->object.oid, &two->object.oid, &shifted,\n \t\t\t      subtree_shift);\n \t}\n \tif (!oidcmp(&two->object.oid, &shifted))\ndiff --git a/test-match-trees.c b/test-match-trees.c\nindex 41aff841..d446b8ea 100644\n--- a/test-match-trees.c\n+++ b/test-match-trees.c\n@@ -19,7 +19,7 @@ int main(int ac, char **av)\n \tif (!two)\n \t\tdie(\"not a tree-ish %s\", av[2]);\n \n-\tshift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, -1);\n+\tshift_tree(&one->object.oid, &two->object.oid, &shifted, -1);\n \tprintf(\"shifted: %s\\n\", oid_to_hex(&shifted));\n \n \texit(0);\n-- \n2.8.0.rc3.226.g39d4020\n"},{"id":"283711","messageId":"1460934641-435791-5-git-send-email-sandals@crustytoothpaste.net","threadId":"42058","inReplyTo":"1460934641-435791-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 4/6] Convert struct name_entry to use struct object_id.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-04-17T23:10:39Z","receivedAt":"2016-04-17T23:10:39Z","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/grep.c         |  6 +++---\n builtin/merge-tree.c   | 18 +++++++++---------\n builtin/pack-objects.c |  4 ++--\n builtin/reflog.c       |  4 ++--\n cache-tree.c           |  4 ++--\n fsck.c                 |  4 ++--\n http-push.c            |  4 ++--\n list-objects.c         |  6 +++---\n match-trees.c          |  2 +-\n notes.c                |  4 ++--\n revision.c             |  4 ++--\n tree-diff.c            |  6 +++---\n tree-walk.c            |  6 +++---\n tree-walk.h            |  6 +++---\n tree.c                 | 10 +++++-----\n unpack-trees.c         |  4 ++--\n walker.c               |  4 ++--\n 17 files changed, 48 insertions(+), 48 deletions(-)\n\ndiff --git a/builtin/grep.c b/builtin/grep.c\nindex 111b6f6c..462e6079 100644\n--- a/builtin/grep.c\n+++ b/builtin/grep.c\n@@ -438,7 +438,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\tstrbuf_add(base, entry.path, te_len);\n \n \t\tif (S_ISREG(entry.mode)) {\n-\t\t\thit |= grep_sha1(opt, entry.sha1, base->buf, tn_len,\n+\t\t\thit |= grep_sha1(opt, entry.oid->hash, base->buf, tn_len,\n \t\t\t\t\t check_attr ? base->buf + tn_len : NULL);\n \t\t}\n \t\telse if (S_ISDIR(entry.mode)) {\n@@ -447,10 +447,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,\n \t\t\tvoid *data;\n \t\t\tunsigned long size;\n \n-\t\t\tdata = lock_and_read_sha1_file(entry.sha1, &type, &size);\n+\t\t\tdata = lock_and_read_sha1_file(entry.oid->hash, &type, &size);\n \t\t\tif (!data)\n \t\t\t\tdie(_(\"unable to read tree (%s)\"),\n-\t\t\t\t    sha1_to_hex(entry.sha1));\n+\t\t\t\t    oid_to_hex(entry.oid));\n \n \t\t\tstrbuf_addch(base, '/');\n \t\t\tinit_tree_desc(&sub, data, size);\ndiff --git a/builtin/merge-tree.c b/builtin/merge-tree.c\nindex ca570041..81cced50 100644\n--- a/builtin/merge-tree.c\n+++ b/builtin/merge-tree.c\n@@ -150,15 +150,15 @@ static void show_result(void)\n /* An empty entry never compares same, not even to another empty entry */\n static int same_entry(struct name_entry *a, struct name_entry *b)\n {\n-\treturn\ta->sha1 &&\n-\t\tb->sha1 &&\n-\t\t!hashcmp(a->sha1, b->sha1) &&\n+\treturn\ta->oid &&\n+\t\tb->oid &&\n+\t\t!oidcmp(a->oid, b->oid) &&\n \t\ta->mode == b->mode;\n }\n \n static int both_empty(struct name_entry *a, struct name_entry *b)\n {\n-\treturn !(a->sha1 || b->sha1);\n+\treturn !(a->oid || b->oid);\n }\n \n static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)\n@@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s\n \t\treturn;\n \n \tpath = traverse_path(info, result);\n-\torig = create_entry(2, ours->mode, ours->sha1, path);\n-\tfinal = create_entry(0, result->mode, result->sha1, path);\n+\torig = create_entry(2, ours->mode, ours->oid->hash, path);\n+\tfinal = create_entry(0, result->mode, result->oid->hash, path);\n \n \tfinal->link = orig;\n \n@@ -213,7 +213,7 @@ static void unresolved_directory(const struct traverse_info *info,\n \n \tnewbase = traverse_path(info, p);\n \n-#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->sha1 : NULL)\n+#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid->hash : NULL)\n \tbuf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));\n \tbuf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));\n \tbuf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));\n@@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info\n \t\tpath = entry->path;\n \telse\n \t\tpath = traverse_path(info, n);\n-\tlink = create_entry(stage, n->mode, n->sha1, path);\n+\tlink = create_entry(stage, n->mode, n->oid->hash, path);\n \tlink->link = entry;\n \treturn link;\n }\n@@ -314,7 +314,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s\n \t}\n \n \tif (same_entry(entry+0, entry+1)) {\n-\t\tif (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {\n+\t\tif (entry[2].oid->hash && !S_ISDIR(entry[2].mode)) {\n \t\t\t/* We did not touch, they modified -- take theirs */\n \t\t\tresolve(info, entry+1, entry+2);\n \t\t\treturn mask;\ndiff --git a/builtin/pack-objects.c b/builtin/pack-objects.c\nindex a27de5b3..d56b2c2d 100644\n--- a/builtin/pack-objects.c\n+++ b/builtin/pack-objects.c\n@@ -1186,7 +1186,7 @@ static void add_pbase_object(struct tree_desc *tree,\n \t\tif (cmp < 0)\n \t\t\treturn;\n \t\tif (name[cmplen] != '/') {\n-\t\t\tadd_object_entry(entry.sha1,\n+\t\t\tadd_object_entry(entry.oid->hash,\n \t\t\t\t\t object_type(entry.mode),\n \t\t\t\t\t fullname, 1);\n \t\t\treturn;\n@@ -1197,7 +1197,7 @@ static void add_pbase_object(struct tree_desc *tree,\n \t\t\tconst char *down = name+cmplen+1;\n \t\t\tint downlen = name_cmp_len(down);\n \n-\t\t\ttree = pbase_tree_get(entry.sha1);\n+\t\t\ttree = pbase_tree_get(entry.oid->hash);\n \t\t\tif (!tree)\n \t\t\t\treturn;\n \t\t\tinit_tree_desc(&sub, tree->tree_data, tree->tree_size);\ndiff --git a/builtin/reflog.c b/builtin/reflog.c\nindex 2d46b648..7a7136e5 100644\n--- a/builtin/reflog.c\n+++ b/builtin/reflog.c\n@@ -84,8 +84,8 @@ static int tree_is_complete(const unsigned char *sha1)\n \tinit_tree_desc(&desc, tree->buffer, tree->size);\n \tcomplete = 1;\n \twhile (tree_entry(&desc, &entry)) {\n-\t\tif (!has_sha1_file(entry.sha1) ||\n-\t\t    (S_ISDIR(entry.mode) && !tree_is_complete(entry.sha1))) {\n+\t\tif (!has_sha1_file(entry.oid->hash) ||\n+\t\t    (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid->hash))) {\n \t\t\ttree->object.flags |= INCOMPLETE;\n \t\t\tcomplete = 0;\n \t\t}\ndiff --git a/cache-tree.c b/cache-tree.c\nindex 3ebf9c3a..ddf0cc9f 100644\n--- a/cache-tree.c\n+++ b/cache-tree.c\n@@ -663,7 +663,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)\n \t\t\tcnt++;\n \t\telse {\n \t\t\tstruct cache_tree_sub *sub;\n-\t\t\tstruct tree *subtree = lookup_tree(entry.sha1);\n+\t\t\tstruct tree *subtree = lookup_tree(entry.oid->hash);\n \t\t\tif (!subtree->object.parsed)\n \t\t\t\tparse_tree(subtree);\n \t\t\tsub = cache_tree_sub(it, entry.path);\n@@ -710,7 +710,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,\n \n \tit = find_cache_tree_from_traversal(root, info);\n \tit = cache_tree_find(it, ent->path);\n-\tif (it && it->entry_count > 0 && !hashcmp(ent->sha1, it->sha1))\n+\tif (it && it->entry_count > 0 && !hashcmp(ent->oid->hash, it->sha1))\n \t\treturn it->entry_count;\n \treturn 0;\n }\ndiff --git a/fsck.c b/fsck.c\nindex ca4c6853..606eba8c 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -312,9 +312,9 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op\n \t\tif (S_ISGITLINK(entry.mode))\n \t\t\tcontinue;\n \t\tif (S_ISDIR(entry.mode))\n-\t\t\tresult = options->walk(&lookup_tree(entry.sha1)->object, OBJ_TREE, data, options);\n+\t\t\tresult = options->walk(&lookup_tree(entry.oid->hash)->object, OBJ_TREE, data, options);\n \t\telse if (S_ISREG(entry.mode) || S_ISLNK(entry.mode))\n-\t\t\tresult = options->walk(&lookup_blob(entry.sha1)->object, OBJ_BLOB, data, options);\n+\t\t\tresult = options->walk(&lookup_blob(entry.oid->hash)->object, OBJ_BLOB, data, options);\n \t\telse {\n \t\t\tresult = error(\"in tree %s: entry %s has bad mode %.6o\",\n \t\t\t\t\toid_to_hex(&tree->object.oid), entry.path, entry.mode);\ndiff --git a/http-push.c b/http-push.c\nindex bd606687..ded0b742 100644\n--- a/http-push.c\n+++ b/http-push.c\n@@ -1312,10 +1312,10 @@ static struct object_list **process_tree(struct tree *tree,\n \twhile (tree_entry(&desc, &entry))\n \t\tswitch (object_type(entry.mode)) {\n \t\tcase OBJ_TREE:\n-\t\t\tp = process_tree(lookup_tree(entry.sha1), p);\n+\t\t\tp = process_tree(lookup_tree(entry.oid->hash), p);\n \t\t\tbreak;\n \t\tcase OBJ_BLOB:\n-\t\t\tp = process_blob(lookup_blob(entry.sha1), p);\n+\t\t\tp = process_blob(lookup_blob(entry.oid->hash), p);\n \t\t\tbreak;\n \t\tdefault:\n \t\t\t/* Subproject commit - not in this repository */\ndiff --git a/list-objects.c b/list-objects.c\nindex 917cc5d7..f3ca6aaf 100644\n--- a/list-objects.c\n+++ b/list-objects.c\n@@ -110,16 +110,16 @@ static void process_tree(struct rev_info *revs,\n \n \t\tif (S_ISDIR(entry.mode))\n \t\t\tprocess_tree(revs,\n-\t\t\t\t     lookup_tree(entry.sha1),\n+\t\t\t\t     lookup_tree(entry.oid->hash),\n \t\t\t\t     show, base, entry.path,\n \t\t\t\t     cb_data);\n \t\telse if (S_ISGITLINK(entry.mode))\n-\t\t\tprocess_gitlink(revs, entry.sha1,\n+\t\t\tprocess_gitlink(revs, entry.oid->hash,\n \t\t\t\t\tshow, base, entry.path,\n \t\t\t\t\tcb_data);\n \t\telse\n \t\t\tprocess_blob(revs,\n-\t\t\t\t     lookup_blob(entry.sha1),\n+\t\t\t\t     lookup_blob(entry.oid->hash),\n \t\t\t\t     show, base, entry.path,\n \t\t\t\t     cb_data);\n \t}\ndiff --git a/match-trees.c b/match-trees.c\nindex 9977752a..751f8f20 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -104,7 +104,7 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)\n \t\telse if (cmp > 0)\n \t\t\t/* path2 does not appear in one */\n \t\t\tscore += score_missing(e2.mode, e2.path);\n-\t\telse if (hashcmp(e1.sha1, e2.sha1))\n+\t\telse if (oidcmp(e1.oid, e2.oid))\n \t\t\t/* they are different */\n \t\t\tscore += score_differs(e1.mode, e2.mode, e1.path);\n \t\telse\ndiff --git a/notes.c b/notes.c\nindex 88cf4747..e4e4854d 100644\n--- a/notes.c\n+++ b/notes.c\n@@ -446,7 +446,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,\n \t\t\tl = (struct leaf_node *)\n \t\t\t\txcalloc(1, sizeof(struct leaf_node));\n \t\t\thashcpy(l->key_sha1, object_sha1);\n-\t\t\thashcpy(l->val_sha1, entry.sha1);\n+\t\t\thashcpy(l->val_sha1, entry.oid->hash);\n \t\t\tif (len < 20) {\n \t\t\t\tif (!S_ISDIR(entry.mode) || path_len != 2)\n \t\t\t\t\tgoto handle_non_note; /* not subtree */\n@@ -493,7 +493,7 @@ handle_non_note:\n \t\t\t}\n \t\t\tstrbuf_addstr(&non_note_path, entry.path);\n \t\t\tadd_non_note(t, strbuf_detach(&non_note_path, NULL),\n-\t\t\t\t     entry.mode, entry.sha1);\n+\t\t\t\t     entry.mode, entry.oid->hash);\n \t\t}\n \t}\n \tfree(buf);\ndiff --git a/revision.c b/revision.c\nindex b683476b..d30d1c4f 100644\n--- a/revision.c\n+++ b/revision.c\n@@ -59,10 +59,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)\n \twhile (tree_entry(&desc, &entry)) {\n \t\tswitch (object_type(entry.mode)) {\n \t\tcase OBJ_TREE:\n-\t\t\tmark_tree_uninteresting(lookup_tree(entry.sha1));\n+\t\t\tmark_tree_uninteresting(lookup_tree(entry.oid->hash));\n \t\t\tbreak;\n \t\tcase OBJ_BLOB:\n-\t\t\tmark_blob_uninteresting(lookup_blob(entry.sha1));\n+\t\t\tmark_blob_uninteresting(lookup_blob(entry.oid->hash));\n \t\t\tbreak;\n \t\tdefault:\n \t\t\t/* Subproject commit - not in this repository */\ndiff --git a/tree-diff.c b/tree-diff.c\nindex 4dda9a14..402f9ff2 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -229,7 +229,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,\n \t\t\t\t\t\tDIFF_STATUS_ADDED;\n \n \t\t\tif (tpi_valid) {\n-\t\t\t\tsha1_i = tp[i].entry.sha1;\n+\t\t\t\tsha1_i = tp[i].entry.oid->hash;\n \t\t\t\tmode_i = tp[i].entry.mode;\n \t\t\t}\n \t\t\telse {\n@@ -270,7 +270,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,\n \t\t\t/* same rule as in emitthis */\n \t\t\tint tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);\n \n-\t\t\tparents_sha1[i] = tpi_valid ? tp[i].entry.sha1\n+\t\t\tparents_sha1[i] = tpi_valid ? tp[i].entry.oid->hash\n \t\t\t\t\t\t    : NULL;\n \t\t}\n \n@@ -482,7 +482,7 @@ static struct combine_diff_path *ll_diff_tree_paths(\n \t\t\t\t\t\tcontinue;\n \n \t\t\t\t\t/* diff(t,pi) != ø */\n-\t\t\t\t\tif (hashcmp(t.entry.sha1, tp[i].entry.sha1) ||\n+\t\t\t\t\tif (oidcmp(t.entry.oid, tp[i].entry.oid) ||\n \t\t\t\t\t    (t.entry.mode != tp[i].entry.mode))\n \t\t\t\t\t\tcontinue;\n \ndiff --git a/tree-walk.c b/tree-walk.c\nindex cd4bb2c3..fab57dd5 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -38,7 +38,7 @@ static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned\n \t/* Initialize the descriptor entry */\n \tdesc->entry.path = path;\n \tdesc->entry.mode = canon_mode(mode);\n-\tdesc->entry.sha1 = (const unsigned char *)(path + len);\n+\tdesc->entry.oid  = (const struct object_id *)(path + len);\n }\n \n void init_tree_desc(struct tree_desc *desc, const void *buffer, unsigned long size)\n@@ -76,7 +76,7 @@ static void entry_extract(struct tree_desc *t, struct name_entry *a)\n void update_tree_entry(struct tree_desc *desc)\n {\n \tconst void *buf = desc->buffer;\n-\tconst unsigned char *end = desc->entry.sha1 + 20;\n+\tconst unsigned char *end = desc->entry.oid->hash + 20;\n \tunsigned long size = desc->size;\n \tunsigned long len = end - (const unsigned char *)buf;\n \n@@ -110,7 +110,7 @@ void setup_traverse_info(struct traverse_info *info, const char *base)\n \t\tpathlen--;\n \tinfo->pathlen = pathlen ? pathlen + 1 : 0;\n \tinfo->name.path = base;\n-\tinfo->name.sha1 = (void *)(base + pathlen + 1);\n+\tinfo->name.oid = (void *)(base + pathlen + 1);\n \tif (pathlen)\n \t\tinfo->prev = &dummy;\n }\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 174eb617..58f31f55 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -2,7 +2,7 @@\n #define TREE_WALK_H\n \n struct name_entry {\n-\tconst unsigned char *sha1;\n+\tconst struct object_id *oid;\n \tconst char *path;\n \tunsigned int mode;\n };\n@@ -17,12 +17,12 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co\n {\n \t*pathp = desc->entry.path;\n \t*modep = desc->entry.mode;\n-\treturn desc->entry.sha1;\n+\treturn desc->entry.oid->hash;\n }\n \n static inline int tree_entry_len(const struct name_entry *ne)\n {\n-\treturn (const char *)ne->sha1 - ne->path - 1;\n+\treturn (const char *)ne->oid - ne->path - 1;\n }\n \n void update_tree_entry(struct tree_desc *);\ndiff --git a/tree.c b/tree.c\nindex f79ff981..0089e52d 100644\n--- a/tree.c\n+++ b/tree.c\n@@ -76,7 +76,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,\n \t\t\t\tcontinue;\n \t\t}\n \n-\t\tswitch (fn(entry.sha1, base,\n+\t\tswitch (fn(entry.oid->hash, base,\n \t\t\t   entry.path, entry.mode, stage, context)) {\n \t\tcase 0:\n \t\t\tcontinue;\n@@ -87,19 +87,19 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,\n \t\t}\n \n \t\tif (S_ISDIR(entry.mode))\n-\t\t\thashcpy(sha1, entry.sha1);\n+\t\t\thashcpy(sha1, entry.oid->hash);\n \t\telse if (S_ISGITLINK(entry.mode)) {\n \t\t\tstruct commit *commit;\n \n-\t\t\tcommit = lookup_commit(entry.sha1);\n+\t\t\tcommit = lookup_commit(entry.oid->hash);\n \t\t\tif (!commit)\n \t\t\t\tdie(\"Commit %s in submodule path %s%s not found\",\n-\t\t\t\t    sha1_to_hex(entry.sha1),\n+\t\t\t\t    oid_to_hex(entry.oid),\n \t\t\t\t    base->buf, entry.path);\n \n \t\t\tif (parse_commit(commit))\n \t\t\t\tdie(\"Invalid commit %s in submodule path %s%s\",\n-\t\t\t\t    sha1_to_hex(entry.sha1),\n+\t\t\t\t    oid_to_hex(entry.oid),\n \t\t\t\t    base->buf, entry.path);\n \n \t\t\thashcpy(sha1, commit->tree->object.oid.hash);\ndiff --git a/unpack-trees.c b/unpack-trees.c\nindex 9f55cc28..11308e9e 100644\n--- a/unpack-trees.c\n+++ b/unpack-trees.c\n@@ -475,7 +475,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,\n \tfor (i = 0; i < n; i++, dirmask >>= 1) {\n \t\tconst unsigned char *sha1 = NULL;\n \t\tif (dirmask & 1)\n-\t\t\tsha1 = names[i].sha1;\n+\t\t\tsha1 = names[i].oid->hash;\n \t\tbuf[i] = fill_tree_descriptor(t+i, sha1);\n \t}\n \n@@ -591,7 +591,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con\n \tce->ce_mode = create_ce_mode(n->mode);\n \tce->ce_flags = create_ce_flags(stage);\n \tce->ce_namelen = len;\n-\thashcpy(ce->sha1, n->sha1);\n+\thashcpy(ce->sha1, n->oid->hash);\n \tmake_traverse_path(ce->name, info, n);\n \n \treturn ce;\ndiff --git a/walker.c b/walker.c\nindex 08773d41..d95b0072 100644\n--- a/walker.c\n+++ b/walker.c\n@@ -43,12 +43,12 @@ static int process_tree(struct walker *walker, struct tree *tree)\n \t\tif (S_ISGITLINK(entry.mode))\n \t\t\tcontinue;\n \t\tif (S_ISDIR(entry.mode)) {\n-\t\t\tstruct tree *tree = lookup_tree(entry.sha1);\n+\t\t\tstruct tree *tree = lookup_tree(entry.oid->hash);\n \t\t\tif (tree)\n \t\t\t\tobj = &tree->object;\n \t\t}\n \t\telse {\n-\t\t\tstruct blob *blob = lookup_blob(entry.sha1);\n+\t\t\tstruct blob *blob = lookup_blob(entry.oid->hash);\n \t\t\tif (blob)\n \t\t\t\tobj = &blob->object;\n \t\t}\n-- \n2.8.0.rc3.226.g39d4020\n"},{"id":"283710","messageId":"1460934641-435791-6-git-send-email-sandals@crustytoothpaste.net","threadId":"42058","inReplyTo":"1460934641-435791-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 5/6] tree-walk: convert tree_entry_extract to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-04-17T23:10:40Z","receivedAt":"2016-04-17T23:10:40Z","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 fsck.c        |  6 +++---\n match-trees.c | 12 ++++++------\n tree-diff.c   |  2 +-\n tree-walk.c   | 10 +++++-----\n tree-walk.h   |  4 ++--\n 5 files changed, 17 insertions(+), 17 deletions(-)\n\ndiff --git a/fsck.c b/fsck.c\nindex 606eba8c..92b17f5d 100644\n--- a/fsck.c\n+++ b/fsck.c\n@@ -450,11 +450,11 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)\n \twhile (desc.size) {\n \t\tunsigned mode;\n \t\tconst char *name;\n-\t\tconst unsigned char *sha1;\n+\t\tconst struct object_id *oid;\n \n-\t\tsha1 = tree_entry_extract(&desc, &name, &mode);\n+\t\toid = tree_entry_extract(&desc, &name, &mode);\n \n-\t\thas_null_sha1 |= is_null_sha1(sha1);\n+\t\thas_null_sha1 |= is_null_oid(oid);\n \t\thas_full_path |= !!strchr(name, '/');\n \t\thas_empty_name |= !*name;\n \t\thas_dot |= !strcmp(name, \".\");\ndiff --git a/match-trees.c b/match-trees.c\nindex 751f8f20..8ca7c68f 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -131,14 +131,14 @@ static void match_trees(const unsigned char *hash1,\n \n \twhile (one.size) {\n \t\tconst char *path;\n-\t\tconst unsigned char *elem;\n+\t\tconst struct object_id *elem;\n \t\tunsigned mode;\n \t\tint score;\n \n \t\telem = tree_entry_extract(&one, &path, &mode);\n \t\tif (!S_ISDIR(mode))\n \t\t\tgoto next;\n-\t\tscore = score_trees(elem, hash2);\n+\t\tscore = score_trees(elem->hash, hash2);\n \t\tif (*best_score < score) {\n \t\t\tfree(*best_match);\n \t\t\t*best_match = xstrfmt(\"%s%s\", base, path);\n@@ -146,7 +146,7 @@ static void match_trees(const unsigned char *hash1,\n \t\t}\n \t\tif (recurse_limit) {\n \t\t\tchar *newbase = xstrfmt(\"%s%s/\", base, path);\n-\t\t\tmatch_trees(elem, hash2, best_score, best_match,\n+\t\t\tmatch_trees(elem->hash, hash2, best_score, best_match,\n \t\t\t\t    newbase, recurse_limit - 1);\n \t\t\tfree(newbase);\n \t\t}\n@@ -191,15 +191,15 @@ static int splice_tree(const unsigned char *hash1,\n \twhile (desc.size) {\n \t\tconst char *name;\n \t\tunsigned mode;\n-\t\tconst unsigned char *sha1;\n+\t\tconst struct object_id *oid;\n \n-\t\tsha1 = tree_entry_extract(&desc, &name, &mode);\n+\t\toid = tree_entry_extract(&desc, &name, &mode);\n \t\tif (strlen(name) == toplen &&\n \t\t    !memcmp(name, prefix, toplen)) {\n \t\t\tif (!S_ISDIR(mode))\n \t\t\t\tdie(\"entry %s in tree %s is not a tree\",\n \t\t\t\t    name, sha1_to_hex(hash1));\n-\t\t\trewrite_here = (unsigned char *) sha1;\n+\t\t\trewrite_here = (unsigned char *) oid->hash;\n \t\t\tbreak;\n \t\t}\n \t\tupdate_tree_entry(&desc);\ndiff --git a/tree-diff.c b/tree-diff.c\nindex 402f9ff2..ff4e0d3c 100644\n--- a/tree-diff.c\n+++ b/tree-diff.c\n@@ -183,7 +183,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,\n \n \tif (t) {\n \t\t/* path present in resulting tree */\n-\t\tsha1 = tree_entry_extract(t, &path, &mode);\n+\t\tsha1 = tree_entry_extract(t, &path, &mode)->hash;\n \t\tpathlen = tree_entry_len(&t->entry);\n \t\tisdir = S_ISDIR(mode);\n \t} else {\ndiff --git a/tree-walk.c b/tree-walk.c\nindex fab57dd5..ce278424 100644\n--- a/tree-walk.c\n+++ b/tree-walk.c\n@@ -433,10 +433,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char\n \tint namelen = strlen(name);\n \twhile (t->size) {\n \t\tconst char *entry;\n-\t\tconst unsigned char *sha1;\n+\t\tconst struct object_id *oid;\n \t\tint entrylen, cmp;\n \n-\t\tsha1 = tree_entry_extract(t, &entry, mode);\n+\t\toid = tree_entry_extract(t, &entry, mode);\n \t\tentrylen = tree_entry_len(&t->entry);\n \t\tupdate_tree_entry(t);\n \t\tif (entrylen > namelen)\n@@ -447,7 +447,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char\n \t\tif (cmp < 0)\n \t\t\tbreak;\n \t\tif (entrylen == namelen) {\n-\t\t\thashcpy(result, sha1);\n+\t\t\thashcpy(result, oid->hash);\n \t\t\treturn 0;\n \t\t}\n \t\tif (name[entrylen] != '/')\n@@ -455,10 +455,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char\n \t\tif (!S_ISDIR(*mode))\n \t\t\tbreak;\n \t\tif (++entrylen == namelen) {\n-\t\t\thashcpy(result, sha1);\n+\t\t\thashcpy(result, oid->hash);\n \t\t\treturn 0;\n \t\t}\n-\t\treturn get_tree_entry(sha1, name + entrylen, result, mode);\n+\t\treturn get_tree_entry(oid->hash, name + entrylen, result, mode);\n \t}\n \treturn -1;\n }\ndiff --git a/tree-walk.h b/tree-walk.h\nindex 58f31f55..97a7d695 100644\n--- a/tree-walk.h\n+++ b/tree-walk.h\n@@ -13,11 +13,11 @@ struct tree_desc {\n \tunsigned int size;\n };\n \n-static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)\n+static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)\n {\n \t*pathp = desc->entry.path;\n \t*modep = desc->entry.mode;\n-\treturn desc->entry.oid->hash;\n+\treturn desc->entry.oid;\n }\n \n static inline int tree_entry_len(const struct name_entry *ne)\n-- \n2.8.0.rc3.226.g39d4020\n"},{"id":"283709","messageId":"1460934641-435791-7-git-send-email-sandals@crustytoothpaste.net","threadId":"42058","inReplyTo":"1460934641-435791-1-git-send-email-sandals@crustytoothpaste.net","subject":"[PATCH 6/6] match-trees: convert several leaf functions to struct object_id","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-04-17T23:10:41Z","receivedAt":"2016-04-17T23:10:41Z","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 match-trees.c | 30 +++++++++++++++---------------\n 1 file changed, 15 insertions(+), 15 deletions(-)\n\ndiff --git a/match-trees.c b/match-trees.c\nindex 8ca7c68f..396b7338 100644\n--- a/match-trees.c\n+++ b/match-trees.c\n@@ -48,17 +48,17 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)\n }\n \n static void *fill_tree_desc_strict(struct tree_desc *desc,\n-\t\t\t\t   const unsigned char *hash)\n+\t\t\t\t   const struct object_id *hash)\n {\n \tvoid *buffer;\n \tenum object_type type;\n \tunsigned long size;\n \n-\tbuffer = read_sha1_file(hash, &type, &size);\n+\tbuffer = read_sha1_file(hash->hash, &type, &size);\n \tif (!buffer)\n-\t\tdie(\"unable to read tree (%s)\", sha1_to_hex(hash));\n+\t\tdie(\"unable to read tree (%s)\", oid_to_hex(hash));\n \tif (type != OBJ_TREE)\n-\t\tdie(\"%s is not a tree\", sha1_to_hex(hash));\n+\t\tdie(\"%s is not a tree\", oid_to_hex(hash));\n \tinit_tree_desc(desc, buffer, size);\n \treturn buffer;\n }\n@@ -73,7 +73,7 @@ static int base_name_entries_compare(const struct name_entry *a,\n /*\n  * Inspect two trees, and give a score that tells how similar they are.\n  */\n-static int score_trees(const unsigned char *hash1, const unsigned char *hash2)\n+static int score_trees(const struct object_id *hash1, const struct object_id *hash2)\n {\n \tstruct tree_desc one;\n \tstruct tree_desc two;\n@@ -119,8 +119,8 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)\n /*\n  * Match one itself and its subtrees with two and pick the best match.\n  */\n-static void match_trees(const unsigned char *hash1,\n-\t\t\tconst unsigned char *hash2,\n+static void match_trees(const struct object_id *hash1,\n+\t\t\tconst struct object_id *hash2,\n \t\t\tint *best_score,\n \t\t\tchar **best_match,\n \t\t\tconst char *base,\n@@ -138,7 +138,7 @@ static void match_trees(const unsigned char *hash1,\n \t\telem = tree_entry_extract(&one, &path, &mode);\n \t\tif (!S_ISDIR(mode))\n \t\t\tgoto next;\n-\t\tscore = score_trees(elem->hash, hash2);\n+\t\tscore = score_trees(elem, hash2);\n \t\tif (*best_score < score) {\n \t\t\tfree(*best_match);\n \t\t\t*best_match = xstrfmt(\"%s%s\", base, path);\n@@ -146,7 +146,7 @@ static void match_trees(const unsigned char *hash1,\n \t\t}\n \t\tif (recurse_limit) {\n \t\t\tchar *newbase = xstrfmt(\"%s%s/\", base, path);\n-\t\t\tmatch_trees(elem->hash, hash2, best_score, best_match,\n+\t\t\tmatch_trees(elem, hash2, best_score, best_match,\n \t\t\t\t    newbase, recurse_limit - 1);\n \t\t\tfree(newbase);\n \t\t}\n@@ -245,7 +245,7 @@ void shift_tree(const struct object_id *hash1,\n \tif (!depth_limit)\n \t\tdepth_limit = 2;\n \n-\tadd_score = del_score = score_trees(hash1->hash, hash2->hash);\n+\tadd_score = del_score = score_trees(hash1, hash2);\n \tadd_prefix = xcalloc(1, 1);\n \tdel_prefix = xcalloc(1, 1);\n \n@@ -253,13 +253,13 @@ void shift_tree(const struct object_id *hash1,\n \t * See if one's subtree resembles two; if so we need to prefix\n \t * two with a few fake trees to match the prefix.\n \t */\n-\tmatch_trees(hash1->hash, hash2->hash, &add_score, &add_prefix, \"\", depth_limit);\n+\tmatch_trees(hash1, hash2, &add_score, &add_prefix, \"\", depth_limit);\n \n \t/*\n \t * See if two's subtree resembles one; if so we need to\n \t * pick only subtree of two.\n \t */\n-\tmatch_trees(hash2->hash, hash1->hash, &del_score, &del_prefix, \"\", depth_limit);\n+\tmatch_trees(hash2, hash1, &del_score, &del_prefix, \"\", depth_limit);\n \n \t/* Assume we do not have to do any shifting */\n \toidcpy(shifted, hash2);\n@@ -309,16 +309,16 @@ void shift_tree_by(const struct object_id *hash1,\n \n \tif (candidate == 3) {\n \t\t/* Both are plausible -- we need to evaluate the score */\n-\t\tint best_score = score_trees(hash1->hash, hash2->hash);\n+\t\tint best_score = score_trees(hash1, hash2);\n \t\tint score;\n \n \t\tcandidate = 0;\n-\t\tscore = score_trees(sub1.hash, hash2->hash);\n+\t\tscore = score_trees(&sub1, hash2);\n \t\tif (score > best_score) {\n \t\t\tcandidate = 1;\n \t\t\tbest_score = score;\n \t\t}\n-\t\tscore = score_trees(sub2.hash, hash1->hash);\n+\t\tscore = score_trees(&sub2, hash1);\n \t\tif (score > best_score)\n \t\t\tcandidate = 2;\n \t}\n-- \n2.8.0.rc3.226.g39d4020\n"},{"id":"283870","messageId":"xmqqshyhxkw1.fsf@gitster.mtv.corp.google.com","threadId":"42058","inReplyTo":"1460934641-435791-5-git-send-email-sandals@crustytoothpaste.net","subject":"Re: [PATCH 4/6] Convert struct name_entry to use struct object_id.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-19T23:02:22Z","receivedAt":"2016-04-19T23:02:22Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> @@ -314,7 +314,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s\n>  \t}\n>  \n>  \tif (same_entry(entry+0, entry+1)) {\n> -\t\tif (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {\n> +\t\tif (entry[2].oid->hash && !S_ISDIR(entry[2].mode)) {\n\nThanks for a warning in the cover letter.\n\n\"if (entry[2].oid && !S_ISDIR(entry[2].mode)\" would be a faithful\nconversion, wouldn't it?\n\nthreeway-callback is called from the unpack-trees codepath and\ntree-walk.c::traverse_trees() is what prepared these entries.\n\nAn entry[] which is an N-element array represents the traversal\nstate of walking N trees in parallel, and the callback function like\nthis one gets an entry that has been tree-walk.c::entry_clear()ed\n(i.e. memset to full of '\\0's) for a tree that lacks the corresponding\npath.\n\nTry to do merge-tree of two trees, where there is a path that we did\nnot change since common ancestor, while the other side removed it,\nand you would hit this if () statement, I would think.\n"},{"id":"283873","messageId":"20160419231617.GA572694@vauxhall.crustytoothpaste.net","threadId":"42058","inReplyTo":"xmqqshyhxkw1.fsf@gitster.mtv.corp.google.com","subject":"Re: [PATCH 4/6] Convert struct name_entry to use struct object_id.","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2016-04-19T23:16:17Z","receivedAt":"2016-04-19T23:16:17Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On Tue, Apr 19, 2016 at 04:02:22PM -0700, Junio C Hamano wrote:\n> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n> \n> > @@ -314,7 +314,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s\n> >  \t}\n> >  \n> >  \tif (same_entry(entry+0, entry+1)) {\n> > -\t\tif (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {\n> > +\t\tif (entry[2].oid->hash && !S_ISDIR(entry[2].mode)) {\n> \n> Thanks for a warning in the cover letter.\n> \n> \"if (entry[2].oid && !S_ISDIR(entry[2].mode)\" would be a faithful\n> conversion, wouldn't it?\n\nYes, I think that would be a better conversion.  I'll reroll after\nwaiting for further comments.\n-- \nbrian m. carlson / brian with sandals: Houston, Texas, US\n+1 832 623 2791 | https://www.crustytoothpaste.net/~bmc | My opinion only\nOpenPGP: https://keybase.io/bk2204\n"},{"id":"283895","messageId":"xmqqk2jtxhf3.fsf@gitster.mtv.corp.google.com","threadId":"42058","inReplyTo":"20160419231617.GA572694@vauxhall.crustytoothpaste.net","subject":"Re: [PATCH 4/6] Convert struct name_entry to use struct object_id.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2016-04-20T00:17:20Z","receivedAt":"2016-04-20T00:17:20Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n\n> On Tue, Apr 19, 2016 at 04:02:22PM -0700, Junio C Hamano wrote:\n>> \"brian m. carlson\" <sandals@crustytoothpaste.net> writes:\n>> \n>> > @@ -314,7 +314,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s\n>> >  \t}\n>> >  \n>> >  \tif (same_entry(entry+0, entry+1)) {\n>> > -\t\tif (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {\n>> > +\t\tif (entry[2].oid->hash && !S_ISDIR(entry[2].mode)) {\n>> \n>> Thanks for a warning in the cover letter.\n>> \n>> \"if (entry[2].oid && !S_ISDIR(entry[2].mode)\" would be a faithful\n>> conversion, wouldn't it?\n>\n> Yes, I think that would be a better conversion.  I'll reroll after\n> waiting for further comments.\n\nThanks.  A simple general rule to follow is that anything that\nassumed entry.sha1 is non-NULL should become entry.oid->hash, while\nanyting that checked if entry.sha1 is NULL or not should become a\ncheck on entry.oid, I think.  Even though offsetof(oid.hash) might\nhappen to be zero, compiler writers are crazy and \"optimize\" the\nabove entry[2].oid->hash saying \"you are dereerencing into the hash\nfield without first checking if oid pointer is NULL, so we'd assume\nthat you know oid is not NULL here--which makes this always true so\nwe won't even do any check and only check entry[2].mode\"..\n"}]}