Skip to content

Commit b6aec86

Browse files
bk2204gitster
authored andcommitted
match-trees: convert several leaf functions to use struct object_id
Signed-off-by: brian m. carlson <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ce6663a commit b6aec86

File tree

1 file changed

+15
-15
lines changed

1 file changed

+15
-15
lines changed

match-trees.c

+15-15
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)
4848
}
4949

5050
static void *fill_tree_desc_strict(struct tree_desc *desc,
51-
const unsigned char *hash)
51+
const struct object_id *hash)
5252
{
5353
void *buffer;
5454
enum object_type type;
5555
unsigned long size;
5656

57-
buffer = read_sha1_file(hash, &type, &size);
57+
buffer = read_sha1_file(hash->hash, &type, &size);
5858
if (!buffer)
59-
die("unable to read tree (%s)", sha1_to_hex(hash));
59+
die("unable to read tree (%s)", oid_to_hex(hash));
6060
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));
6262
init_tree_desc(desc, buffer, size);
6363
return buffer;
6464
}
@@ -73,7 +73,7 @@ static int base_name_entries_compare(const struct name_entry *a,
7373
/*
7474
* Inspect two trees, and give a score that tells how similar they are.
7575
*/
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)
7777
{
7878
struct tree_desc one;
7979
struct tree_desc two;
@@ -119,8 +119,8 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
119119
/*
120120
* Match one itself and its subtrees with two and pick the best match.
121121
*/
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,
124124
int *best_score,
125125
char **best_match,
126126
const char *base,
@@ -138,15 +138,15 @@ static void match_trees(const unsigned char *hash1,
138138
elem = tree_entry_extract(&one, &path, &mode);
139139
if (!S_ISDIR(mode))
140140
goto next;
141-
score = score_trees(elem->hash, hash2);
141+
score = score_trees(elem, hash2);
142142
if (*best_score < score) {
143143
free(*best_match);
144144
*best_match = xstrfmt("%s%s", base, path);
145145
*best_score = score;
146146
}
147147
if (recurse_limit) {
148148
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,
150150
newbase, recurse_limit - 1);
151151
free(newbase);
152152
}
@@ -245,21 +245,21 @@ void shift_tree(const struct object_id *hash1,
245245
if (!depth_limit)
246246
depth_limit = 2;
247247

248-
add_score = del_score = score_trees(hash1->hash, hash2->hash);
248+
add_score = del_score = score_trees(hash1, hash2);
249249
add_prefix = xcalloc(1, 1);
250250
del_prefix = xcalloc(1, 1);
251251

252252
/*
253253
* See if one's subtree resembles two; if so we need to prefix
254254
* two with a few fake trees to match the prefix.
255255
*/
256-
match_trees(hash1->hash, hash2->hash, &add_score, &add_prefix, "", depth_limit);
256+
match_trees(hash1, hash2, &add_score, &add_prefix, "", depth_limit);
257257

258258
/*
259259
* See if two's subtree resembles one; if so we need to
260260
* pick only subtree of two.
261261
*/
262-
match_trees(hash2->hash, hash1->hash, &del_score, &del_prefix, "", depth_limit);
262+
match_trees(hash2, hash1, &del_score, &del_prefix, "", depth_limit);
263263

264264
/* Assume we do not have to do any shifting */
265265
oidcpy(shifted, hash2);
@@ -309,16 +309,16 @@ void shift_tree_by(const struct object_id *hash1,
309309

310310
if (candidate == 3) {
311311
/* 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);
313313
int score;
314314

315315
candidate = 0;
316-
score = score_trees(sub1.hash, hash2->hash);
316+
score = score_trees(&sub1, hash2);
317317
if (score > best_score) {
318318
candidate = 1;
319319
best_score = score;
320320
}
321-
score = score_trees(sub2.hash, hash1->hash);
321+
score = score_trees(&sub2, hash1);
322322
if (score > best_score)
323323
candidate = 2;
324324
}

0 commit comments

Comments
 (0)