diff options
author | brian m. carlson <sandals@crustytoothpaste.net> | 2016-04-17 23:10:38 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2016-04-19 15:33:06 -0700 |
commit | 82db3d44e7a9d9219dd8e19607026bae9e435012 (patch) | |
tree | ea9b60d94ecc8cf28d085f43ee6f38aa4aa3b583 /match-trees.c | |
parent | c9baaf9db99dc9f66d9674ab5d467b73f36ab1bf (diff) | |
download | git-82db3d44e7a9d9219dd8e19607026bae9e435012.tar.gz |
match-trees: convert shift_tree() and shift_tree_by() to use object_id
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'match-trees.c')
-rw-r--r-- | match-trees.c | 44 |
1 files changed, 22 insertions, 22 deletions
diff --git a/match-trees.c b/match-trees.c index 1ce0954a3e..9977752a67 100644 --- a/match-trees.c +++ b/match-trees.c @@ -229,9 +229,9 @@ static int splice_tree(const unsigned char *hash1, * other hand, it could cover tree one and we might need to pick a * subtree of it. */ -void shift_tree(const unsigned char *hash1, - const unsigned char *hash2, - unsigned char *shifted, +void shift_tree(const struct object_id *hash1, + const struct object_id *hash2, + struct object_id *shifted, int depth_limit) { char *add_prefix; @@ -245,7 +245,7 @@ void shift_tree(const unsigned char *hash1, if (!depth_limit) depth_limit = 2; - add_score = del_score = score_trees(hash1, hash2); + add_score = del_score = score_trees(hash1->hash, hash2->hash); add_prefix = xcalloc(1, 1); del_prefix = xcalloc(1, 1); @@ -253,16 +253,16 @@ void shift_tree(const unsigned char *hash1, * 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, hash2, &add_score, &add_prefix, "", depth_limit); + match_trees(hash1->hash, hash2->hash, &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, hash1, &del_score, &del_prefix, "", depth_limit); + match_trees(hash2->hash, hash1->hash, &del_score, &del_prefix, "", depth_limit); /* Assume we do not have to do any shifting */ - hashcpy(shifted, hash2); + oidcpy(shifted, hash2); if (add_score < del_score) { /* We need to pick a subtree of two */ @@ -271,16 +271,16 @@ void shift_tree(const unsigned char *hash1, if (!*del_prefix) return; - if (get_tree_entry(hash2, del_prefix, shifted, &mode)) + if (get_tree_entry(hash2->hash, del_prefix, shifted->hash, &mode)) die("cannot find path %s in tree %s", - del_prefix, sha1_to_hex(hash2)); + del_prefix, oid_to_hex(hash2)); return; } if (!*add_prefix) return; - splice_tree(hash1, add_prefix, hash2, shifted); + splice_tree(hash1->hash, add_prefix, hash2->hash, shifted->hash); } /* @@ -288,44 +288,44 @@ void shift_tree(const unsigned char *hash1, * Unfortunately we cannot fundamentally tell which one to * be prefixed, as recursive merge can work in either direction. */ -void shift_tree_by(const unsigned char *hash1, - const unsigned char *hash2, - unsigned char *shifted, +void shift_tree_by(const struct object_id *hash1, + const struct object_id *hash2, + struct object_id *shifted, const char *shift_prefix) { - unsigned char sub1[20], sub2[20]; + struct object_id sub1, sub2; unsigned mode1, mode2; unsigned candidate = 0; /* Can hash2 be a tree at shift_prefix in tree hash1? */ - if (!get_tree_entry(hash1, shift_prefix, sub1, &mode1) && + if (!get_tree_entry(hash1->hash, shift_prefix, sub1.hash, &mode1) && S_ISDIR(mode1)) candidate |= 1; /* Can hash1 be a tree at shift_prefix in tree hash2? */ - if (!get_tree_entry(hash2, shift_prefix, sub2, &mode2) && + if (!get_tree_entry(hash2->hash, shift_prefix, sub2.hash, &mode2) && S_ISDIR(mode2)) candidate |= 2; if (candidate == 3) { /* Both are plausible -- we need to evaluate the score */ - int best_score = score_trees(hash1, hash2); + int best_score = score_trees(hash1->hash, hash2->hash); int score; candidate = 0; - score = score_trees(sub1, hash2); + score = score_trees(sub1.hash, hash2->hash); if (score > best_score) { candidate = 1; best_score = score; } - score = score_trees(sub2, hash1); + score = score_trees(sub2.hash, hash1->hash); if (score > best_score) candidate = 2; } if (!candidate) { /* Neither is plausible -- do not shift */ - hashcpy(shifted, hash2); + oidcpy(shifted, hash2); return; } @@ -334,11 +334,11 @@ void shift_tree_by(const unsigned char *hash1, * shift tree2 down by adding shift_prefix above it * to match tree1. */ - splice_tree(hash1, shift_prefix, hash2, shifted); + splice_tree(hash1->hash, shift_prefix, hash2->hash, shifted->hash); else /* * shift tree2 up by removing shift_prefix from it * to match tree1. */ - hashcpy(shifted, sub2); + oidcpy(shifted, &sub2); } |