All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/6] object_id Part 3
@ 2016-04-22 22:02 brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 1/6] Introduce a get_oid function brian m. carlson
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: brian m. carlson @ 2016-04-22 22:02 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King

This is the third of a series of patches to convert instances of
unsigned char[20] to struct object_id.  The focus in this series was to
convert test-match-trees, related functions, and some dependencies.
struct name_entry was converted as part of these dependencies.

The riskiest part of this series is the conversion of struct name_entry.
Compatibility with unconverted code requires dereferencing the new oid
member, but there are at least some places where we explicitly check
that it is not NULL.  Most of these are protected by a check for a
nonzero mode.

This series rebases onto next cleanly and is not likely to conflict with
other topics in flight.  My intention is to send smaller series more
frequently, with the goal of avoiding or minimizing conflicts where
possible.

Changes from v1:
* Remove dereference of object_id pointer in boolean context.

brian m. carlson (6):
  Introduce a get_oid function.
  test-match-trees: convert to use struct object_id
  match-trees: convert shift_tree and shift_tree_by to object_id
  Convert struct name_entry to use struct object_id.
  tree-walk: convert tree_entry_extract to struct object_id
  match-trees: convert several leaf functions to struct object_id

 builtin/grep.c         |  6 ++---
 builtin/merge-tree.c   | 18 +++++++--------
 builtin/pack-objects.c |  4 ++--
 builtin/reflog.c       |  4 ++--
 cache-tree.c           |  4 ++--
 cache.h                |  6 +++--
 fsck.c                 | 10 ++++-----
 http-push.c            |  4 ++--
 list-objects.c         |  6 ++---
 match-trees.c          | 60 +++++++++++++++++++++++++-------------------------
 merge-recursive.c      |  4 ++--
 notes.c                |  4 ++--
 revision.c             |  4 ++--
 sha1_name.c            |  9 ++++++++
 test-match-trees.c     | 14 ++++++------
 tree-diff.c            |  8 +++----
 tree-walk.c            | 16 +++++++-------
 tree-walk.h            |  8 +++----
 tree.c                 | 10 ++++-----
 unpack-trees.c         |  4 ++--
 walker.c               |  4 ++--
 21 files changed, 109 insertions(+), 98 deletions(-)

-- 
2.8.1.369.geae769a

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/6] Introduce a get_oid function.
  2016-04-22 22:02 [PATCH v2 0/6] object_id Part 3 brian m. carlson
@ 2016-04-22 22:02 ` brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 2/6] test-match-trees: convert to use struct object_id brian m. carlson
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2016-04-22 22:02 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King

The get_oid function is equivalent to the get_sha1 function, but uses a
struct object_id instead.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 cache.h     | 2 ++
 sha1_name.c | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/cache.h b/cache.h
index 2711048c..22b73646 100644
--- a/cache.h
+++ b/cache.h
@@ -1156,6 +1156,8 @@ extern int get_sha1_blob(const char *str, unsigned char *sha1);
 extern void maybe_die_on_misspelt_object_name(const char *name, const char *prefix);
 extern int get_sha1_with_context(const char *str, unsigned flags, unsigned char *sha1, struct object_context *orc);
 
+extern int get_oid(const char *str, struct object_id *oid);
+
 typedef int each_abbrev_fn(const unsigned char *sha1, void *);
 extern int for_each_abbrev(const char *prefix, each_abbrev_fn, void *);
 
diff --git a/sha1_name.c b/sha1_name.c
index 776101e8..ca7ddd6f 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1215,6 +1215,15 @@ int get_sha1(const char *name, unsigned char *sha1)
 }
 
 /*
+ * This is like "get_sha1()", but for struct object_id.
+ */
+int get_oid(const char *name, struct object_id *oid)
+{
+	return get_sha1(name, oid->hash);
+}
+
+
+/*
  * Many callers know that the user meant to name a commit-ish by
  * syntactical positions where the object name appears.  Calling this
  * function allows the machinery to disambiguate shorter-than-unique
-- 
2.8.1.369.geae769a

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/6] test-match-trees: convert to use struct object_id
  2016-04-22 22:02 [PATCH v2 0/6] object_id Part 3 brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 1/6] Introduce a get_oid function brian m. carlson
@ 2016-04-22 22:02 ` brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 3/6] match-trees: convert shift_tree and shift_tree_by to object_id brian m. carlson
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2016-04-22 22:02 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 test-match-trees.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/test-match-trees.c b/test-match-trees.c
index 4dad7095..41aff841 100644
--- a/test-match-trees.c
+++ b/test-match-trees.c
@@ -3,24 +3,24 @@
 
 int main(int ac, char **av)
 {
-	unsigned char hash1[20], hash2[20], shifted[20];
+	struct object_id hash1, hash2, shifted;
 	struct tree *one, *two;
 
 	setup_git_directory();
 
-	if (get_sha1(av[1], hash1))
+	if (get_oid(av[1], &hash1))
 		die("cannot parse %s as an object name", av[1]);
-	if (get_sha1(av[2], hash2))
+	if (get_oid(av[2], &hash2))
 		die("cannot parse %s as an object name", av[2]);
-	one = parse_tree_indirect(hash1);
+	one = parse_tree_indirect(hash1.hash);
 	if (!one)
 		die("not a tree-ish %s", av[1]);
-	two = parse_tree_indirect(hash2);
+	two = parse_tree_indirect(hash2.hash);
 	if (!two)
 		die("not a tree-ish %s", av[2]);
 
-	shift_tree(one->object.oid.hash, two->object.oid.hash, shifted, -1);
-	printf("shifted: %s\n", sha1_to_hex(shifted));
+	shift_tree(one->object.oid.hash, two->object.oid.hash, shifted.hash, -1);
+	printf("shifted: %s\n", oid_to_hex(&shifted));
 
 	exit(0);
 }
-- 
2.8.1.369.geae769a

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/6] match-trees: convert shift_tree and shift_tree_by to object_id
  2016-04-22 22:02 [PATCH v2 0/6] object_id Part 3 brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 1/6] Introduce a get_oid function brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 2/6] test-match-trees: convert to use struct object_id brian m. carlson
@ 2016-04-22 22:02 ` brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 4/6] Convert struct name_entry to use struct object_id brian m. carlson
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2016-04-22 22:02 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King

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.1.369.geae769a

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 4/6] Convert struct name_entry to use struct object_id.
  2016-04-22 22:02 [PATCH v2 0/6] object_id Part 3 brian m. carlson
                   ` (2 preceding siblings ...)
  2016-04-22 22:02 ` [PATCH v2 3/6] match-trees: convert shift_tree and shift_tree_by to object_id brian m. carlson
@ 2016-04-22 22:02 ` brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 5/6] tree-walk: convert tree_entry_extract to " brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 6/6] match-trees: convert several leaf functions " brian m. carlson
  5 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2016-04-22 22:02 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/grep.c         |  6 +++---
 builtin/merge-tree.c   | 18 +++++++++---------
 builtin/pack-objects.c |  4 ++--
 builtin/reflog.c       |  4 ++--
 cache-tree.c           |  4 ++--
 fsck.c                 |  4 ++--
 http-push.c            |  4 ++--
 list-objects.c         |  6 +++---
 match-trees.c          |  2 +-
 notes.c                |  4 ++--
 revision.c             |  4 ++--
 tree-diff.c            |  6 +++---
 tree-walk.c            |  6 +++---
 tree-walk.h            |  6 +++---
 tree.c                 | 10 +++++-----
 unpack-trees.c         |  4 ++--
 walker.c               |  4 ++--
 17 files changed, 48 insertions(+), 48 deletions(-)

diff --git a/builtin/grep.c b/builtin/grep.c
index 111b6f6c..462e6079 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -438,7 +438,7 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
 		strbuf_add(base, entry.path, te_len);
 
 		if (S_ISREG(entry.mode)) {
-			hit |= grep_sha1(opt, entry.sha1, base->buf, tn_len,
+			hit |= grep_sha1(opt, entry.oid->hash, base->buf, tn_len,
 					 check_attr ? base->buf + tn_len : NULL);
 		}
 		else if (S_ISDIR(entry.mode)) {
@@ -447,10 +447,10 @@ static int grep_tree(struct grep_opt *opt, const struct pathspec *pathspec,
 			void *data;
 			unsigned long size;
 
-			data = lock_and_read_sha1_file(entry.sha1, &type, &size);
+			data = lock_and_read_sha1_file(entry.oid->hash, &type, &size);
 			if (!data)
 				die(_("unable to read tree (%s)"),
-				    sha1_to_hex(entry.sha1));
+				    oid_to_hex(entry.oid));
 
 			strbuf_addch(base, '/');
 			init_tree_desc(&sub, data, size);
diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index ca570041..5b7ab9b9 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -150,15 +150,15 @@ static void show_result(void)
 /* An empty entry never compares same, not even to another empty entry */
 static int same_entry(struct name_entry *a, struct name_entry *b)
 {
-	return	a->sha1 &&
-		b->sha1 &&
-		!hashcmp(a->sha1, b->sha1) &&
+	return	a->oid &&
+		b->oid &&
+		!oidcmp(a->oid, b->oid) &&
 		a->mode == b->mode;
 }
 
 static int both_empty(struct name_entry *a, struct name_entry *b)
 {
-	return !(a->sha1 || b->sha1);
+	return !(a->oid || b->oid);
 }
 
 static struct merge_list *create_entry(unsigned stage, unsigned mode, const unsigned char *sha1, const char *path)
@@ -188,8 +188,8 @@ static void resolve(const struct traverse_info *info, struct name_entry *ours, s
 		return;
 
 	path = traverse_path(info, result);
-	orig = create_entry(2, ours->mode, ours->sha1, path);
-	final = create_entry(0, result->mode, result->sha1, path);
+	orig = create_entry(2, ours->mode, ours->oid->hash, path);
+	final = create_entry(0, result->mode, result->oid->hash, path);
 
 	final->link = orig;
 
@@ -213,7 +213,7 @@ static void unresolved_directory(const struct traverse_info *info,
 
 	newbase = traverse_path(info, p);
 
-#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->sha1 : NULL)
+#define ENTRY_SHA1(e) (((e)->mode && S_ISDIR((e)->mode)) ? (e)->oid->hash : NULL)
 	buf0 = fill_tree_descriptor(t+0, ENTRY_SHA1(n + 0));
 	buf1 = fill_tree_descriptor(t+1, ENTRY_SHA1(n + 1));
 	buf2 = fill_tree_descriptor(t+2, ENTRY_SHA1(n + 2));
@@ -239,7 +239,7 @@ static struct merge_list *link_entry(unsigned stage, const struct traverse_info
 		path = entry->path;
 	else
 		path = traverse_path(info, n);
-	link = create_entry(stage, n->mode, n->sha1, path);
+	link = create_entry(stage, n->mode, n->oid->hash, path);
 	link->link = entry;
 	return link;
 }
@@ -314,7 +314,7 @@ static int threeway_callback(int n, unsigned long mask, unsigned long dirmask, s
 	}
 
 	if (same_entry(entry+0, entry+1)) {
-		if (entry[2].sha1 && !S_ISDIR(entry[2].mode)) {
+		if (entry[2].oid && !S_ISDIR(entry[2].mode)) {
 			/* We did not touch, they modified -- take theirs */
 			resolve(info, entry+1, entry+2);
 			return mask;
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index a27de5b3..d56b2c2d 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1186,7 +1186,7 @@ static void add_pbase_object(struct tree_desc *tree,
 		if (cmp < 0)
 			return;
 		if (name[cmplen] != '/') {
-			add_object_entry(entry.sha1,
+			add_object_entry(entry.oid->hash,
 					 object_type(entry.mode),
 					 fullname, 1);
 			return;
@@ -1197,7 +1197,7 @@ static void add_pbase_object(struct tree_desc *tree,
 			const char *down = name+cmplen+1;
 			int downlen = name_cmp_len(down);
 
-			tree = pbase_tree_get(entry.sha1);
+			tree = pbase_tree_get(entry.oid->hash);
 			if (!tree)
 				return;
 			init_tree_desc(&sub, tree->tree_data, tree->tree_size);
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 2d46b648..7a7136e5 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -84,8 +84,8 @@ static int tree_is_complete(const unsigned char *sha1)
 	init_tree_desc(&desc, tree->buffer, tree->size);
 	complete = 1;
 	while (tree_entry(&desc, &entry)) {
-		if (!has_sha1_file(entry.sha1) ||
-		    (S_ISDIR(entry.mode) && !tree_is_complete(entry.sha1))) {
+		if (!has_sha1_file(entry.oid->hash) ||
+		    (S_ISDIR(entry.mode) && !tree_is_complete(entry.oid->hash))) {
 			tree->object.flags |= INCOMPLETE;
 			complete = 0;
 		}
diff --git a/cache-tree.c b/cache-tree.c
index 3ebf9c3a..ddf0cc9f 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -663,7 +663,7 @@ static void prime_cache_tree_rec(struct cache_tree *it, struct tree *tree)
 			cnt++;
 		else {
 			struct cache_tree_sub *sub;
-			struct tree *subtree = lookup_tree(entry.sha1);
+			struct tree *subtree = lookup_tree(entry.oid->hash);
 			if (!subtree->object.parsed)
 				parse_tree(subtree);
 			sub = cache_tree_sub(it, entry.path);
@@ -710,7 +710,7 @@ int cache_tree_matches_traversal(struct cache_tree *root,
 
 	it = find_cache_tree_from_traversal(root, info);
 	it = cache_tree_find(it, ent->path);
-	if (it && it->entry_count > 0 && !hashcmp(ent->sha1, it->sha1))
+	if (it && it->entry_count > 0 && !hashcmp(ent->oid->hash, it->sha1))
 		return it->entry_count;
 	return 0;
 }
diff --git a/fsck.c b/fsck.c
index ca4c6853..606eba8c 100644
--- a/fsck.c
+++ b/fsck.c
@@ -312,9 +312,9 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
 		if (S_ISGITLINK(entry.mode))
 			continue;
 		if (S_ISDIR(entry.mode))
-			result = options->walk(&lookup_tree(entry.sha1)->object, OBJ_TREE, data, options);
+			result = options->walk(&lookup_tree(entry.oid->hash)->object, OBJ_TREE, data, options);
 		else if (S_ISREG(entry.mode) || S_ISLNK(entry.mode))
-			result = options->walk(&lookup_blob(entry.sha1)->object, OBJ_BLOB, data, options);
+			result = options->walk(&lookup_blob(entry.oid->hash)->object, OBJ_BLOB, data, options);
 		else {
 			result = error("in tree %s: entry %s has bad mode %.6o",
 					oid_to_hex(&tree->object.oid), entry.path, entry.mode);
diff --git a/http-push.c b/http-push.c
index bd606687..ded0b742 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1312,10 +1312,10 @@ static struct object_list **process_tree(struct tree *tree,
 	while (tree_entry(&desc, &entry))
 		switch (object_type(entry.mode)) {
 		case OBJ_TREE:
-			p = process_tree(lookup_tree(entry.sha1), p);
+			p = process_tree(lookup_tree(entry.oid->hash), p);
 			break;
 		case OBJ_BLOB:
-			p = process_blob(lookup_blob(entry.sha1), p);
+			p = process_blob(lookup_blob(entry.oid->hash), p);
 			break;
 		default:
 			/* Subproject commit - not in this repository */
diff --git a/list-objects.c b/list-objects.c
index 917cc5d7..f3ca6aaf 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -110,16 +110,16 @@ static void process_tree(struct rev_info *revs,
 
 		if (S_ISDIR(entry.mode))
 			process_tree(revs,
-				     lookup_tree(entry.sha1),
+				     lookup_tree(entry.oid->hash),
 				     show, base, entry.path,
 				     cb_data);
 		else if (S_ISGITLINK(entry.mode))
-			process_gitlink(revs, entry.sha1,
+			process_gitlink(revs, entry.oid->hash,
 					show, base, entry.path,
 					cb_data);
 		else
 			process_blob(revs,
-				     lookup_blob(entry.sha1),
+				     lookup_blob(entry.oid->hash),
 				     show, base, entry.path,
 				     cb_data);
 	}
diff --git a/match-trees.c b/match-trees.c
index 9977752a..751f8f20 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -104,7 +104,7 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
 		else if (cmp > 0)
 			/* path2 does not appear in one */
 			score += score_missing(e2.mode, e2.path);
-		else if (hashcmp(e1.sha1, e2.sha1))
+		else if (oidcmp(e1.oid, e2.oid))
 			/* they are different */
 			score += score_differs(e1.mode, e2.mode, e1.path);
 		else
diff --git a/notes.c b/notes.c
index 88cf4747..e4e4854d 100644
--- a/notes.c
+++ b/notes.c
@@ -446,7 +446,7 @@ static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,
 			l = (struct leaf_node *)
 				xcalloc(1, sizeof(struct leaf_node));
 			hashcpy(l->key_sha1, object_sha1);
-			hashcpy(l->val_sha1, entry.sha1);
+			hashcpy(l->val_sha1, entry.oid->hash);
 			if (len < 20) {
 				if (!S_ISDIR(entry.mode) || path_len != 2)
 					goto handle_non_note; /* not subtree */
@@ -493,7 +493,7 @@ handle_non_note:
 			}
 			strbuf_addstr(&non_note_path, entry.path);
 			add_non_note(t, strbuf_detach(&non_note_path, NULL),
-				     entry.mode, entry.sha1);
+				     entry.mode, entry.oid->hash);
 		}
 	}
 	free(buf);
diff --git a/revision.c b/revision.c
index b683476b..d30d1c4f 100644
--- a/revision.c
+++ b/revision.c
@@ -59,10 +59,10 @@ static void mark_tree_contents_uninteresting(struct tree *tree)
 	while (tree_entry(&desc, &entry)) {
 		switch (object_type(entry.mode)) {
 		case OBJ_TREE:
-			mark_tree_uninteresting(lookup_tree(entry.sha1));
+			mark_tree_uninteresting(lookup_tree(entry.oid->hash));
 			break;
 		case OBJ_BLOB:
-			mark_blob_uninteresting(lookup_blob(entry.sha1));
+			mark_blob_uninteresting(lookup_blob(entry.oid->hash));
 			break;
 		default:
 			/* Subproject commit - not in this repository */
diff --git a/tree-diff.c b/tree-diff.c
index 4dda9a14..402f9ff2 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -229,7 +229,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
 						DIFF_STATUS_ADDED;
 
 			if (tpi_valid) {
-				sha1_i = tp[i].entry.sha1;
+				sha1_i = tp[i].entry.oid->hash;
 				mode_i = tp[i].entry.mode;
 			}
 			else {
@@ -270,7 +270,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
 			/* same rule as in emitthis */
 			int tpi_valid = tp && !(tp[i].entry.mode & S_IFXMIN_NEQ);
 
-			parents_sha1[i] = tpi_valid ? tp[i].entry.sha1
+			parents_sha1[i] = tpi_valid ? tp[i].entry.oid->hash
 						    : NULL;
 		}
 
@@ -482,7 +482,7 @@ static struct combine_diff_path *ll_diff_tree_paths(
 						continue;
 
 					/* diff(t,pi) != ø */
-					if (hashcmp(t.entry.sha1, tp[i].entry.sha1) ||
+					if (oidcmp(t.entry.oid, tp[i].entry.oid) ||
 					    (t.entry.mode != tp[i].entry.mode))
 						continue;
 
diff --git a/tree-walk.c b/tree-walk.c
index cd4bb2c3..fab57dd5 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -38,7 +38,7 @@ static void decode_tree_entry(struct tree_desc *desc, const char *buf, unsigned
 	/* Initialize the descriptor entry */
 	desc->entry.path = path;
 	desc->entry.mode = canon_mode(mode);
-	desc->entry.sha1 = (const unsigned char *)(path + len);
+	desc->entry.oid  = (const struct object_id *)(path + len);
 }
 
 void init_tree_desc(struct tree_desc *desc, const void *buffer, unsigned long size)
@@ -76,7 +76,7 @@ static void entry_extract(struct tree_desc *t, struct name_entry *a)
 void update_tree_entry(struct tree_desc *desc)
 {
 	const void *buf = desc->buffer;
-	const unsigned char *end = desc->entry.sha1 + 20;
+	const unsigned char *end = desc->entry.oid->hash + 20;
 	unsigned long size = desc->size;
 	unsigned long len = end - (const unsigned char *)buf;
 
@@ -110,7 +110,7 @@ void setup_traverse_info(struct traverse_info *info, const char *base)
 		pathlen--;
 	info->pathlen = pathlen ? pathlen + 1 : 0;
 	info->name.path = base;
-	info->name.sha1 = (void *)(base + pathlen + 1);
+	info->name.oid = (void *)(base + pathlen + 1);
 	if (pathlen)
 		info->prev = &dummy;
 }
diff --git a/tree-walk.h b/tree-walk.h
index 174eb617..58f31f55 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -2,7 +2,7 @@
 #define TREE_WALK_H
 
 struct name_entry {
-	const unsigned char *sha1;
+	const struct object_id *oid;
 	const char *path;
 	unsigned int mode;
 };
@@ -17,12 +17,12 @@ static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, co
 {
 	*pathp = desc->entry.path;
 	*modep = desc->entry.mode;
-	return desc->entry.sha1;
+	return desc->entry.oid->hash;
 }
 
 static inline int tree_entry_len(const struct name_entry *ne)
 {
-	return (const char *)ne->sha1 - ne->path - 1;
+	return (const char *)ne->oid - ne->path - 1;
 }
 
 void update_tree_entry(struct tree_desc *);
diff --git a/tree.c b/tree.c
index f79ff981..0089e52d 100644
--- a/tree.c
+++ b/tree.c
@@ -76,7 +76,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 				continue;
 		}
 
-		switch (fn(entry.sha1, base,
+		switch (fn(entry.oid->hash, base,
 			   entry.path, entry.mode, stage, context)) {
 		case 0:
 			continue;
@@ -87,19 +87,19 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 		}
 
 		if (S_ISDIR(entry.mode))
-			hashcpy(sha1, entry.sha1);
+			hashcpy(sha1, entry.oid->hash);
 		else if (S_ISGITLINK(entry.mode)) {
 			struct commit *commit;
 
-			commit = lookup_commit(entry.sha1);
+			commit = lookup_commit(entry.oid->hash);
 			if (!commit)
 				die("Commit %s in submodule path %s%s not found",
-				    sha1_to_hex(entry.sha1),
+				    oid_to_hex(entry.oid),
 				    base->buf, entry.path);
 
 			if (parse_commit(commit))
 				die("Invalid commit %s in submodule path %s%s",
-				    sha1_to_hex(entry.sha1),
+				    oid_to_hex(entry.oid),
 				    base->buf, entry.path);
 
 			hashcpy(sha1, commit->tree->object.oid.hash);
diff --git a/unpack-trees.c b/unpack-trees.c
index 9f55cc28..11308e9e 100644
--- a/unpack-trees.c
+++ b/unpack-trees.c
@@ -475,7 +475,7 @@ static int traverse_trees_recursive(int n, unsigned long dirmask,
 	for (i = 0; i < n; i++, dirmask >>= 1) {
 		const unsigned char *sha1 = NULL;
 		if (dirmask & 1)
-			sha1 = names[i].sha1;
+			sha1 = names[i].oid->hash;
 		buf[i] = fill_tree_descriptor(t+i, sha1);
 	}
 
@@ -591,7 +591,7 @@ static struct cache_entry *create_ce_entry(const struct traverse_info *info, con
 	ce->ce_mode = create_ce_mode(n->mode);
 	ce->ce_flags = create_ce_flags(stage);
 	ce->ce_namelen = len;
-	hashcpy(ce->sha1, n->sha1);
+	hashcpy(ce->sha1, n->oid->hash);
 	make_traverse_path(ce->name, info, n);
 
 	return ce;
diff --git a/walker.c b/walker.c
index 08773d41..d95b0072 100644
--- a/walker.c
+++ b/walker.c
@@ -43,12 +43,12 @@ static int process_tree(struct walker *walker, struct tree *tree)
 		if (S_ISGITLINK(entry.mode))
 			continue;
 		if (S_ISDIR(entry.mode)) {
-			struct tree *tree = lookup_tree(entry.sha1);
+			struct tree *tree = lookup_tree(entry.oid->hash);
 			if (tree)
 				obj = &tree->object;
 		}
 		else {
-			struct blob *blob = lookup_blob(entry.sha1);
+			struct blob *blob = lookup_blob(entry.oid->hash);
 			if (blob)
 				obj = &blob->object;
 		}
-- 
2.8.1.369.geae769a

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 5/6] tree-walk: convert tree_entry_extract to struct object_id
  2016-04-22 22:02 [PATCH v2 0/6] object_id Part 3 brian m. carlson
                   ` (3 preceding siblings ...)
  2016-04-22 22:02 ` [PATCH v2 4/6] Convert struct name_entry to use struct object_id brian m. carlson
@ 2016-04-22 22:02 ` brian m. carlson
  2016-04-22 22:02 ` [PATCH v2 6/6] match-trees: convert several leaf functions " brian m. carlson
  5 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2016-04-22 22:02 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 fsck.c        |  6 +++---
 match-trees.c | 12 ++++++------
 tree-diff.c   |  2 +-
 tree-walk.c   | 10 +++++-----
 tree-walk.h   |  4 ++--
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/fsck.c b/fsck.c
index 606eba8c..92b17f5d 100644
--- a/fsck.c
+++ b/fsck.c
@@ -450,11 +450,11 @@ static int fsck_tree(struct tree *item, struct fsck_options *options)
 	while (desc.size) {
 		unsigned mode;
 		const char *name;
-		const unsigned char *sha1;
+		const struct object_id *oid;
 
-		sha1 = tree_entry_extract(&desc, &name, &mode);
+		oid = tree_entry_extract(&desc, &name, &mode);
 
-		has_null_sha1 |= is_null_sha1(sha1);
+		has_null_sha1 |= is_null_oid(oid);
 		has_full_path |= !!strchr(name, '/');
 		has_empty_name |= !*name;
 		has_dot |= !strcmp(name, ".");
diff --git a/match-trees.c b/match-trees.c
index 751f8f20..8ca7c68f 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -131,14 +131,14 @@ static void match_trees(const unsigned char *hash1,
 
 	while (one.size) {
 		const char *path;
-		const unsigned char *elem;
+		const struct object_id *elem;
 		unsigned mode;
 		int score;
 
 		elem = tree_entry_extract(&one, &path, &mode);
 		if (!S_ISDIR(mode))
 			goto next;
-		score = score_trees(elem, hash2);
+		score = score_trees(elem->hash, hash2);
 		if (*best_score < score) {
 			free(*best_match);
 			*best_match = xstrfmt("%s%s", base, path);
@@ -146,7 +146,7 @@ static void match_trees(const unsigned char *hash1,
 		}
 		if (recurse_limit) {
 			char *newbase = xstrfmt("%s%s/", base, path);
-			match_trees(elem, hash2, best_score, best_match,
+			match_trees(elem->hash, hash2, best_score, best_match,
 				    newbase, recurse_limit - 1);
 			free(newbase);
 		}
@@ -191,15 +191,15 @@ static int splice_tree(const unsigned char *hash1,
 	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);
diff --git a/tree-diff.c b/tree-diff.c
index 402f9ff2..ff4e0d3c 100644
--- a/tree-diff.c
+++ b/tree-diff.c
@@ -183,7 +183,7 @@ static struct combine_diff_path *emit_path(struct combine_diff_path *p,
 
 	if (t) {
 		/* path present in resulting tree */
-		sha1 = tree_entry_extract(t, &path, &mode);
+		sha1 = tree_entry_extract(t, &path, &mode)->hash;
 		pathlen = tree_entry_len(&t->entry);
 		isdir = S_ISDIR(mode);
 	} else {
diff --git a/tree-walk.c b/tree-walk.c
index fab57dd5..ce278424 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -433,10 +433,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
 	int namelen = strlen(name);
 	while (t->size) {
 		const char *entry;
-		const unsigned char *sha1;
+		const struct object_id *oid;
 		int entrylen, cmp;
 
-		sha1 = tree_entry_extract(t, &entry, mode);
+		oid = tree_entry_extract(t, &entry, mode);
 		entrylen = tree_entry_len(&t->entry);
 		update_tree_entry(t);
 		if (entrylen > namelen)
@@ -447,7 +447,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
 		if (cmp < 0)
 			break;
 		if (entrylen == namelen) {
-			hashcpy(result, sha1);
+			hashcpy(result, oid->hash);
 			return 0;
 		}
 		if (name[entrylen] != '/')
@@ -455,10 +455,10 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
 		if (!S_ISDIR(*mode))
 			break;
 		if (++entrylen == namelen) {
-			hashcpy(result, sha1);
+			hashcpy(result, oid->hash);
 			return 0;
 		}
-		return get_tree_entry(sha1, name + entrylen, result, mode);
+		return get_tree_entry(oid->hash, name + entrylen, result, mode);
 	}
 	return -1;
 }
diff --git a/tree-walk.h b/tree-walk.h
index 58f31f55..97a7d695 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -13,11 +13,11 @@ struct tree_desc {
 	unsigned int size;
 };
 
-static inline const unsigned char *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
+static inline const struct object_id *tree_entry_extract(struct tree_desc *desc, const char **pathp, unsigned int *modep)
 {
 	*pathp = desc->entry.path;
 	*modep = desc->entry.mode;
-	return desc->entry.oid->hash;
+	return desc->entry.oid;
 }
 
 static inline int tree_entry_len(const struct name_entry *ne)
-- 
2.8.1.369.geae769a

^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 6/6] match-trees: convert several leaf functions to struct object_id
  2016-04-22 22:02 [PATCH v2 0/6] object_id Part 3 brian m. carlson
                   ` (4 preceding siblings ...)
  2016-04-22 22:02 ` [PATCH v2 5/6] tree-walk: convert tree_entry_extract to " brian m. carlson
@ 2016-04-22 22:02 ` brian m. carlson
  5 siblings, 0 replies; 7+ messages in thread
From: brian m. carlson @ 2016-04-22 22:02 UTC (permalink / raw)
  To: git; +Cc: Junio C Hamano, Jeff King

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 match-trees.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/match-trees.c b/match-trees.c
index 8ca7c68f..396b7338 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -48,17 +48,17 @@ static int score_matches(unsigned mode1, unsigned mode2, const char *path)
 }
 
 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;
 }
@@ -73,7 +73,7 @@ static int base_name_entries_compare(const struct name_entry *a,
 /*
  * 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;
@@ -119,8 +119,8 @@ static int score_trees(const unsigned char *hash1, const unsigned char *hash2)
 /*
  * 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,
@@ -138,7 +138,7 @@ static void match_trees(const unsigned char *hash1,
 		elem = tree_entry_extract(&one, &path, &mode);
 		if (!S_ISDIR(mode))
 			goto next;
-		score = score_trees(elem->hash, hash2);
+		score = score_trees(elem, hash2);
 		if (*best_score < score) {
 			free(*best_match);
 			*best_match = xstrfmt("%s%s", base, path);
@@ -146,7 +146,7 @@ static void match_trees(const unsigned char *hash1,
 		}
 		if (recurse_limit) {
 			char *newbase = xstrfmt("%s%s/", base, path);
-			match_trees(elem->hash, hash2, best_score, best_match,
+			match_trees(elem, hash2, best_score, best_match,
 				    newbase, recurse_limit - 1);
 			free(newbase);
 		}
@@ -245,7 +245,7 @@ void shift_tree(const struct object_id *hash1,
 	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);
 
@@ -253,13 +253,13 @@ void shift_tree(const struct object_id *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->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);
@@ -309,16 +309,16 @@ void shift_tree_by(const struct object_id *hash1,
 
 	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;
 	}
-- 
2.8.1.369.geae769a

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-04-22 22:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-04-22 22:02 [PATCH v2 0/6] object_id Part 3 brian m. carlson
2016-04-22 22:02 ` [PATCH v2 1/6] Introduce a get_oid function brian m. carlson
2016-04-22 22:02 ` [PATCH v2 2/6] test-match-trees: convert to use struct object_id brian m. carlson
2016-04-22 22:02 ` [PATCH v2 3/6] match-trees: convert shift_tree and shift_tree_by to object_id brian m. carlson
2016-04-22 22:02 ` [PATCH v2 4/6] Convert struct name_entry to use struct object_id brian m. carlson
2016-04-22 22:02 ` [PATCH v2 5/6] tree-walk: convert tree_entry_extract to " brian m. carlson
2016-04-22 22:02 ` [PATCH v2 6/6] match-trees: convert several leaf functions " brian m. carlson

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.