]> git.ipfire.org Git - thirdparty/git.git/commitdiff
match-trees: convert shift_tree() and shift_tree_by() to use object_id
authorbrian m. carlson <sandals@crustytoothpaste.net>
Sun, 17 Apr 2016 23:10:38 +0000 (23:10 +0000)
committerJunio C Hamano <gitster@pobox.com>
Tue, 19 Apr 2016 22:33:06 +0000 (15:33 -0700)
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
match-trees.c
merge-recursive.c
test-match-trees.c

diff --git a/cache.h b/cache.h
index f837732f79de6b731eb71d5fc7e876616c82e493..33584119049c91b5e739979004855c39e2cf5fc8 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1738,8 +1738,8 @@ int add_files_to_cache(const char *prefix, const struct pathspec *pathspec, int
 extern int diff_auto_refresh_index;
 
 /* match-trees.c */
-void shift_tree(const unsigned char *, const unsigned char *, unsigned char *, int);
-void shift_tree_by(const unsigned char *, const unsigned char *, unsigned char *, const char *);
+void shift_tree(const struct object_id *, const struct object_id *, struct object_id *, int);
+void shift_tree_by(const struct object_id *, const struct object_id *, struct object_id *, const char *);
 
 /*
  * whitespace rules.
index 1ce0954a3e5915a6bcc30448c9d99fdaba32bcab..9977752a6763c4462a8fe08f042f1a7fca5fef3d 100644 (file)
@@ -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);
 }
index b880ae50e7ee4f8e88bda83618529ea30462e4ef..a47c80f87596b9b20afb644a5a238e4ebf2f2a3c 100644 (file)
@@ -29,9 +29,9 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
        struct object_id shifted;
 
        if (!*subtree_shift) {
-               shift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, 0);
+               shift_tree(&one->object.oid, &two->object.oid, &shifted, 0);
        } else {
-               shift_tree_by(one->object.oid.hash, two->object.oid.hash, shifted.hash,
+               shift_tree_by(&one->object.oid, &two->object.oid, &shifted,
                              subtree_shift);
        }
        if (!oidcmp(&two->object.oid, &shifted))
index a4eea75a15824adce01eeb356c864665e98d2d83..17ebdf80bece3846679c9367ee0741c272db4994 100644 (file)
@@ -17,7 +17,7 @@ int main(int ac, char **av)
        if (!two)
                die("not a tree-ish %s", av[2]);
 
-       shift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, -1);
+       shift_tree(&one->object.oid, &two->object.oid, &shifted, -1);
        printf("shifted: %s\n", oid_to_hex(&shifted));
 
        exit(0);