}
static void *fill_tree_desc_strict(struct tree_desc *desc,
- const unsigned char *hash)
+ const struct object_id *hash)
{
void *buffer;
enum object_type type;
unsigned long size;
- buffer = read_sha1_file(hash, &type, &size);
+ buffer = read_sha1_file(hash->hash, &type, &size);
if (!buffer)
- die("unable to read tree (%s)", sha1_to_hex(hash));
+ die("unable to read tree (%s)", oid_to_hex(hash));
if (type != OBJ_TREE)
- die("%s is not a tree", sha1_to_hex(hash));
+ die("%s is not a tree", oid_to_hex(hash));
init_tree_desc(desc, buffer, size);
return buffer;
}
/*
* Inspect two trees, and give a score that tells how similar they are.
*/
-static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
+static int score_trees(const struct object_id *hash1, const struct object_id *hash2)
{
struct tree_desc one;
struct tree_desc two;
/*
* Match one itself and its subtrees with two and pick the best match.
*/
-static void match_trees(const unsigned char *hash1,
- const unsigned char *hash2,
+static void match_trees(const struct object_id *hash1,
+ const struct object_id *hash2,
int *best_score,
char **best_match,
const char *base,
while (one.size) {
const char *path;
- const unsigned char *elem;
+ const struct object_id *elem;
unsigned mode;
int score;
while (desc.size) {
const char *name;
unsigned mode;
- const unsigned char *sha1;
+ const struct object_id *oid;
- sha1 = tree_entry_extract(&desc, &name, &mode);
+ oid = tree_entry_extract(&desc, &name, &mode);
if (strlen(name) == toplen &&
!memcmp(name, prefix, toplen)) {
if (!S_ISDIR(mode))
die("entry %s in tree %s is not a tree",
name, sha1_to_hex(hash1));
- rewrite_here = (unsigned char *) sha1;
+ rewrite_here = (unsigned char *) oid->hash;
break;
}
update_tree_entry(&desc);
if (!depth_limit)
depth_limit = 2;
- add_score = del_score = score_trees(hash1->hash, hash2->hash);
+ add_score = del_score = score_trees(hash1, hash2);
add_prefix = xcalloc(1, 1);
del_prefix = xcalloc(1, 1);
* See if one's subtree resembles two; if so we need to prefix
* two with a few fake trees to match the prefix.
*/
- match_trees(hash1->hash, hash2->hash, &add_score, &add_prefix, "", depth_limit);
+ match_trees(hash1, hash2, &add_score, &add_prefix, "", depth_limit);
/*
* See if two's subtree resembles one; if so we need to
* pick only subtree of two.
*/
- match_trees(hash2->hash, hash1->hash, &del_score, &del_prefix, "", depth_limit);
+ match_trees(hash2, hash1, &del_score, &del_prefix, "", depth_limit);
/* Assume we do not have to do any shifting */
oidcpy(shifted, hash2);
if (candidate == 3) {
/* Both are plausible -- we need to evaluate the score */
- int best_score = score_trees(hash1->hash, hash2->hash);
+ int best_score = score_trees(hash1, hash2);
int score;
candidate = 0;
- score = score_trees(sub1.hash, hash2->hash);
+ score = score_trees(&sub1, hash2);
if (score > best_score) {
candidate = 1;
best_score = score;
}
- score = score_trees(sub2.hash, hash1->hash);
+ score = score_trees(&sub2, hash1);
if (score > best_score)
candidate = 2;
}