match-trees: convert several leaf functions to use struct object_id

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

brian m. carlson committed Apr 17, 2016 at 23:10 UTC b6aec868afb17acdbd486c09602a658e14c98602
1 file changed +15 -15
match-trees.c
+15 -15
@@ -48,17 +48,17 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)
48 }
49
50 static void *fill_tree_desc_strict(struct tree_desc *desc,
51 - const unsigned char *hash)
51 + const struct object_id *hash)
52 {
53 void *buffer;
54 enum object_type type;
55 unsigned long size;
56
57 - buffer = read_sha1_file(hash, &type, &size);
57 + buffer = read_sha1_file(hash->hash, &type, &size);
58 if (!buffer)
59 - die("unable to read tree (%s)", sha1_to_hex(hash));
59 + die("unable to read tree (%s)", oid_to_hex(hash));
60 if (type != OBJ_TREE)
61 - die("%s is not a tree", sha1_to_hex(hash));
61 + die("%s is not a tree", oid_to_hex(hash));
62 init_tree_desc(desc, buffer, size);
63 return buffer;
64 }
@@ -73,7 +73,7 @@ static int base_name_entries_compare(const struct name_entry *a,
73 /*
74 * Inspect two trees, and give a score that tells how similar they are.
75 */
76 -static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
76 +static int score_trees(const struct object_id *hash1, const struct object_id *hash2)
77 {
78 struct tree_desc one;
79 struct tree_desc two;
@@ -119,8 +119,8 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
119 /*
120 * Match one itself and its subtrees with two and pick the best match.
121 */
122 -static void match_trees(const unsigned char *hash1,
123 - const unsigned char *hash2,
122 +static void match_trees(const struct object_id *hash1,
123 + const struct object_id *hash2,
124 int *best_score,
125 char **best_match,
126 const char *base,
@@ -138,7 +138,7 @@ static void match_trees(const unsigned char *hash1,
138 elem = tree_entry_extract(&one, &path, &mode);
139 if (!S_ISDIR(mode))
140 goto next;
141 - score = score_trees(elem->hash, hash2);
141 + score = score_trees(elem, hash2);
142 if (*best_score < score) {
143 free(*best_match);
144 *best_match = xstrfmt("%s%s", base, path);
@@ -146,7 +146,7 @@ static void match_trees(const unsigned char *hash1,
146 }
147 if (recurse_limit) {
148 char *newbase = xstrfmt("%s%s/", base, path);
149 - match_trees(elem->hash, hash2, best_score, best_match,
149 + match_trees(elem, hash2, best_score, best_match,
150 newbase, recurse_limit - 1);
151 free(newbase);
152 }
@@ -245,7 +245,7 @@ void shift_tree(const struct object_id *hash1,
245 if (!depth_limit)
246 depth_limit = 2;
247
248 - add_score = del_score = score_trees(hash1->hash, hash2->hash);
248 + add_score = del_score = score_trees(hash1, hash2);
249 add_prefix = xcalloc(1, 1);
250 del_prefix = xcalloc(1, 1);
251
@@ -253,13 +253,13 @@ void shift_tree(const struct object_id *hash1,
253 * See if one's subtree resembles two; if so we need to prefix
254 * two with a few fake trees to match the prefix.
255 */
256 - match_trees(hash1->hash, hash2->hash, &add_score, &add_prefix, "", depth_limit);
256 + match_trees(hash1, hash2, &add_score, &add_prefix, "", depth_limit);
257
258 /*
259 * See if two's subtree resembles one; if so we need to
260 * pick only subtree of two.
261 */
262 - match_trees(hash2->hash, hash1->hash, &del_score, &del_prefix, "", depth_limit);
262 + match_trees(hash2, hash1, &del_score, &del_prefix, "", depth_limit);
263
264 /* Assume we do not have to do any shifting */
265 oidcpy(shifted, hash2);
@@ -309,16 +309,16 @@ void shift_tree_by(const struct object_id *hash1,
309
310 if (candidate == 3) {
311 /* Both are plausible -- we need to evaluate the score */
312 - int best_score = score_trees(hash1->hash, hash2->hash);
312 + int best_score = score_trees(hash1, hash2);
313 int score;
314
315 candidate = 0;
316 - score = score_trees(sub1.hash, hash2->hash);
316 + score = score_trees(&sub1, hash2);
317 if (score > best_score) {
318 candidate = 1;
319 best_score = score;
320 }
321 - score = score_trees(sub2.hash, hash1->hash);
321 + score = score_trees(&sub2, hash1);
322 if (score > best_score)
323 candidate = 2;
324 }