git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>, Jeff King <peff@peff.net>
Subject: [PATCH 3/6] match-trees: convert shift_tree and shift_tree_by to object_id
Date: Sun, 17 Apr 2016 23:10:38 +0000	[thread overview]
Message-ID: <1460934641-435791-4-git-send-email-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <1460934641-435791-1-git-send-email-sandals@crustytoothpaste.net>

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 cache.h            |  4 ++--
 match-trees.c      | 44 ++++++++++++++++++++++----------------------
 merge-recursive.c  |  4 ++--
 test-match-trees.c |  2 +-
 4 files changed, 27 insertions(+), 27 deletions(-)

diff --git a/cache.h b/cache.h
index 22b73646..70091e73 100644
--- a/cache.h
+++ b/cache.h
@@ -1768,8 +1768,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.
diff --git a/match-trees.c b/match-trees.c
index 1ce0954a..9977752a 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);
 }
diff --git a/merge-recursive.c b/merge-recursive.c
index b880ae50..a47c80f8 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -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))
diff --git a/test-match-trees.c b/test-match-trees.c
index 41aff841..d446b8ea 100644
--- a/test-match-trees.c
+++ b/test-match-trees.c
@@ -19,7 +19,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);
-- 
2.8.0.rc3.226.g39d4020

  parent reply	other threads:[~2016-04-18  2:20 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-17 23:10 [PATCH 0/6] object_id Part 3 brian m. carlson
2016-04-17 23:10 ` [PATCH 1/6] Introduce a get_oid function brian m. carlson
2016-04-17 23:10 ` [PATCH 2/6] test-match-trees: convert to use struct object_id brian m. carlson
2016-04-17 23:10 ` brian m. carlson [this message]
2016-04-17 23:10 ` [PATCH 4/6] Convert struct name_entry " brian m. carlson
2016-04-19 23:02   ` Junio C Hamano
2016-04-19 23:16     ` brian m. carlson
2016-04-20  0:17       ` Junio C Hamano
2016-04-17 23:10 ` [PATCH 5/6] tree-walk: convert tree_entry_extract to " brian m. carlson
2016-04-17 23:10 ` [PATCH 6/6] match-trees: convert several leaf functions " brian m. carlson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1460934641-435791-4-git-send-email-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=peff@peff.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).