git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Michael Haggerty" <mhagger@alum.mit.edu>,
	"Jonathan Tan" <jonathantanmy@google.com>,
	"Stefan Beller" <sbeller@google.com>, "Jeff King" <peff@peff.net>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Brandon Williams" <bmwill@google.com>
Subject: [PATCH v3 32/53] Convert lookup_tree to struct object_id
Date: Sat,  6 May 2017 22:10:17 +0000	[thread overview]
Message-ID: <20170506221038.296722-33-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20170506221038.296722-1-sandals@crustytoothpaste.net>

Convert the lookup_tree function to take a pointer to struct object_id.

The commit was created with manual changes to tree.c, tree.h, and
object.c, plus the following semantic patch:

@@
@@
- lookup_tree(EMPTY_TREE_SHA1_BIN)
+ lookup_tree(&empty_tree_oid)

@@
expression E1;
@@
- lookup_tree(E1.hash)
+ lookup_tree(&E1)

@@
expression E1;
@@
- lookup_tree(E1->hash)
+ lookup_tree(E1)

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/am.c        | 4 ++--
 builtin/diff-tree.c | 2 +-
 builtin/diff.c      | 2 +-
 builtin/reflog.c    | 2 +-
 cache-tree.c        | 2 +-
 commit.c            | 2 +-
 fsck.c              | 2 +-
 http-push.c         | 2 +-
 list-objects.c      | 2 +-
 merge-recursive.c   | 6 +++---
 object.c            | 2 +-
 reachable.c         | 2 +-
 revision.c          | 4 ++--
 sequencer.c         | 2 +-
 tag.c               | 2 +-
 tree.c              | 8 ++++----
 tree.h              | 2 +-
 walker.c            | 2 +-
 18 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/builtin/am.c b/builtin/am.c
index 650269ac5..7663f12e6 100644
--- a/builtin/am.c
+++ b/builtin/am.c
@@ -1453,9 +1453,9 @@ static void write_index_patch(const struct am_state *state)
 	FILE *fp;
 
 	if (!get_sha1_tree("HEAD", head.hash))
-		tree = lookup_tree(head.hash);
+		tree = lookup_tree(&head);
 	else
-		tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+		tree = lookup_tree(&empty_tree_oid);
 
 	fp = xfopen(am_path(state, "patch"), "w");
 	init_revisions(&rev_info, NULL);
diff --git a/builtin/diff-tree.c b/builtin/diff-tree.c
index e85a449df..95b8d1ba7 100644
--- a/builtin/diff-tree.c
+++ b/builtin/diff-tree.c
@@ -44,7 +44,7 @@ static int stdin_diff_trees(struct tree *tree1, const char *p)
 	struct tree *tree2;
 	if (!isspace(*p++) || parse_oid_hex(p, &oid, &p) || *p)
 		return error("Need exactly two trees, separated by a space");
-	tree2 = lookup_tree(oid.hash);
+	tree2 = lookup_tree(&oid);
 	if (!tree2 || parse_tree(tree2))
 		return -1;
 	printf("%s %s\n", oid_to_hex(&tree1->object.oid),
diff --git a/builtin/diff.c b/builtin/diff.c
index a25b4e4ae..895f92897 100644
--- a/builtin/diff.c
+++ b/builtin/diff.c
@@ -381,7 +381,7 @@ int cmd_diff(int argc, const char **argv, const char *prefix)
 				add_head_to_pending(&rev);
 				if (!rev.pending.nr) {
 					struct tree *tree;
-					tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+					tree = lookup_tree(&empty_tree_oid);
 					add_pending_object(&rev, &tree->object, "HEAD");
 				}
 				break;
diff --git a/builtin/reflog.c b/builtin/reflog.c
index 7866a0341..7e89e84dc 100644
--- a/builtin/reflog.c
+++ b/builtin/reflog.c
@@ -62,7 +62,7 @@ static int tree_is_complete(const struct object_id *oid)
 	int complete;
 	struct tree *tree;
 
-	tree = lookup_tree(oid->hash);
+	tree = lookup_tree(oid);
 	if (!tree)
 		return 0;
 	if (tree->object.flags & SEEN)
diff --git a/cache-tree.c b/cache-tree.c
index 35d507ed7..489241021 100644
--- a/cache-tree.c
+++ b/cache-tree.c
@@ -672,7 +672,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.oid->hash);
+			struct tree *subtree = lookup_tree(entry.oid);
 			if (!subtree->object.parsed)
 				parse_tree(subtree);
 			sub = cache_tree_sub(it, entry.path);
diff --git a/commit.c b/commit.c
index 0f6c9b6bf..8004008bc 100644
--- a/commit.c
+++ b/commit.c
@@ -331,7 +331,7 @@ int parse_commit_buffer(struct commit *item, const void *buffer, unsigned long s
 	if (get_sha1_hex(bufptr + 5, parent.hash) < 0)
 		return error("bad tree pointer in commit %s",
 			     oid_to_hex(&item->object.oid));
-	item->tree = lookup_tree(parent.hash);
+	item->tree = lookup_tree(&parent);
 	bufptr += tree_entry_len + 1; /* "tree " + "hex sha1" + "\n" */
 	pptr = &item->parents;
 
diff --git a/fsck.c b/fsck.c
index ab3016c0e..ee5224aea 100644
--- a/fsck.c
+++ b/fsck.c
@@ -358,7 +358,7 @@ static int fsck_walk_tree(struct tree *tree, void *data, struct fsck_options *op
 			continue;
 
 		if (S_ISDIR(entry.mode)) {
-			obj = &lookup_tree(entry.oid->hash)->object;
+			obj = &lookup_tree(entry.oid)->object;
 			if (name)
 				put_object_name(options, obj, "%s%s/", name,
 					entry.path);
diff --git a/http-push.c b/http-push.c
index 9bb5e0648..7781f4078 100644
--- a/http-push.c
+++ b/http-push.c
@@ -1312,7 +1312,7 @@ 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.oid->hash), p);
+			p = process_tree(lookup_tree(entry.oid), p);
 			break;
 		case OBJ_BLOB:
 			p = process_blob(lookup_blob(entry.oid), p);
diff --git a/list-objects.c b/list-objects.c
index 721e5fb08..b3931fa43 100644
--- a/list-objects.c
+++ b/list-objects.c
@@ -110,7 +110,7 @@ static void process_tree(struct rev_info *revs,
 
 		if (S_ISDIR(entry.mode))
 			process_tree(revs,
-				     lookup_tree(entry.oid->hash),
+				     lookup_tree(entry.oid),
 				     show, base, entry.path,
 				     cb_data);
 		else if (S_ISGITLINK(entry.mode))
diff --git a/merge-recursive.c b/merge-recursive.c
index 1315a45b9..92e0a63dc 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -67,7 +67,7 @@ static struct tree *shift_tree_object(struct tree *one, struct tree *two,
 	}
 	if (!oidcmp(&two->object.oid, &shifted))
 		return two;
-	return lookup_tree(shifted.hash);
+	return lookup_tree(&shifted);
 }
 
 static struct commit *make_virtual_commit(struct tree *tree, const char *comment)
@@ -304,7 +304,7 @@ struct tree *write_tree_from_memory(struct merge_options *o)
 		return NULL;
 	}
 
-	result = lookup_tree(active_cache_tree->oid.hash);
+	result = lookup_tree(&active_cache_tree->oid);
 
 	return result;
 }
@@ -2042,7 +2042,7 @@ int merge_recursive(struct merge_options *o,
 		/* if there is no common ancestor, use an empty tree */
 		struct tree *tree;
 
-		tree = lookup_tree(EMPTY_TREE_SHA1_BIN);
+		tree = lookup_tree(&empty_tree_oid);
 		merged_common_ancestors = make_virtual_commit(tree, "ancestor");
 	}
 
diff --git a/object.c b/object.c
index 2c8d1e5d3..d23c5fad3 100644
--- a/object.c
+++ b/object.c
@@ -197,7 +197,7 @@ struct object *parse_object_buffer(const unsigned char *sha1, enum object_type t
 			obj = &blob->object;
 		}
 	} else if (type == OBJ_TREE) {
-		struct tree *tree = lookup_tree(sha1);
+		struct tree *tree = lookup_tree(&oid);
 		if (tree) {
 			obj = &tree->object;
 			if (!tree->buffer)
diff --git a/reachable.c b/reachable.c
index 8ea0bdd7c..3bbc84417 100644
--- a/reachable.c
+++ b/reachable.c
@@ -85,7 +85,7 @@ static void add_recent_object(const struct object_id *oid,
 		obj = parse_object_or_die(oid->hash, NULL);
 		break;
 	case OBJ_TREE:
-		obj = (struct object *)lookup_tree(oid->hash);
+		obj = (struct object *)lookup_tree(oid);
 		break;
 	case OBJ_BLOB:
 		obj = (struct object *)lookup_blob(oid);
diff --git a/revision.c b/revision.c
index db2de7a7a..c2091b6de 100644
--- a/revision.c
+++ b/revision.c
@@ -59,7 +59,7 @@ 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.oid->hash));
+			mark_tree_uninteresting(lookup_tree(entry.oid));
 			break;
 		case OBJ_BLOB:
 			mark_blob_uninteresting(lookup_blob(entry.oid));
@@ -1249,7 +1249,7 @@ static void add_cache_tree(struct cache_tree *it, struct rev_info *revs,
 	int i;
 
 	if (it->entry_count >= 0) {
-		struct tree *tree = lookup_tree(it->oid.hash);
+		struct tree *tree = lookup_tree(&it->oid);
 		add_pending_object_with_path(revs, &tree->object, "",
 					     040000, path->buf);
 	}
diff --git a/sequencer.c b/sequencer.c
index 086763360..218895fde 100644
--- a/sequencer.c
+++ b/sequencer.c
@@ -344,7 +344,7 @@ static int read_oneliner(struct strbuf *buf,
 
 static struct tree *empty_tree(void)
 {
-	return lookup_tree(EMPTY_TREE_SHA1_BIN);
+	return lookup_tree(&empty_tree_oid);
 }
 
 static int error_dirty_index(struct replay_opts *opts)
diff --git a/tag.c b/tag.c
index dff251673..062516b40 100644
--- a/tag.c
+++ b/tag.c
@@ -144,7 +144,7 @@ int parse_tag_buffer(struct tag *item, const void *data, unsigned long size)
 	if (!strcmp(type, blob_type)) {
 		item->tagged = &lookup_blob(&oid)->object;
 	} else if (!strcmp(type, tree_type)) {
-		item->tagged = &lookup_tree(oid.hash)->object;
+		item->tagged = &lookup_tree(&oid)->object;
 	} else if (!strcmp(type, commit_type)) {
 		item->tagged = &lookup_commit(&oid)->object;
 	} else if (!strcmp(type, tag_type)) {
diff --git a/tree.c b/tree.c
index 21fd80b80..28ce930b9 100644
--- a/tree.c
+++ b/tree.c
@@ -110,7 +110,7 @@ static int read_tree_1(struct tree *tree, struct strbuf *base,
 		len = tree_entry_len(&entry);
 		strbuf_add(base, entry.path, len);
 		strbuf_addch(base, '/');
-		retval = read_tree_1(lookup_tree(oid.hash),
+		retval = read_tree_1(lookup_tree(&oid),
 				     base, stage, pathspec,
 				     fn, context);
 		strbuf_setlen(base, oldlen);
@@ -184,11 +184,11 @@ int read_tree(struct tree *tree, int stage, struct pathspec *match)
 	return 0;
 }
 
-struct tree *lookup_tree(const unsigned char *sha1)
+struct tree *lookup_tree(const struct object_id *oid)
 {
-	struct object *obj = lookup_object(sha1);
+	struct object *obj = lookup_object(oid->hash);
 	if (!obj)
-		return create_object(sha1, alloc_tree_node());
+		return create_object(oid->hash, alloc_tree_node());
 	return object_as_type(obj, OBJ_TREE, 0);
 }
 
diff --git a/tree.h b/tree.h
index d24786cba..2b2c8dbbe 100644
--- a/tree.h
+++ b/tree.h
@@ -12,7 +12,7 @@ struct tree {
 	unsigned long size;
 };
 
-struct tree *lookup_tree(const unsigned char *sha1);
+struct tree *lookup_tree(const struct object_id *oid);
 
 int parse_tree_buffer(struct tree *item, void *buffer, unsigned long size);
 
diff --git a/walker.c b/walker.c
index 3d6029c8e..eae9fb974 100644
--- a/walker.c
+++ b/walker.c
@@ -47,7 +47,7 @@ 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.oid->hash);
+			struct tree *tree = lookup_tree(entry.oid);
 			if (tree)
 				obj = &tree->object;
 		}

  parent reply	other threads:[~2017-05-06 22:12 UTC|newest]

Thread overview: 56+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-05-06 22:09 [PATCH v3 00/53] object_id part 8 brian m. carlson
2017-05-06 22:09 ` [PATCH v3 01/53] fetch-pack: convert to struct object_id brian m. carlson
2017-05-06 22:09 ` [PATCH v3 02/53] Clean up outstanding object_id transforms brian m. carlson
2017-05-06 22:09 ` [PATCH v3 03/53] Convert struct cache_tree to use struct object_id brian m. carlson
2017-05-06 22:09 ` [PATCH v3 04/53] builtin/name-rev: convert to " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 05/53] builtin/prune: " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 06/53] bundle: " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 07/53] branch: " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 08/53] builtin/blame: convert static function " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 09/53] builtin/rev-parse: convert " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 10/53] fast-import: convert internal structs " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 11/53] fast-import: convert " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 12/53] submodule: convert merge_submodule to use " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 13/53] notes-cache: convert to " brian m. carlson
2017-05-06 22:09 ` [PATCH v3 14/53] parse-options-cb: " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 15/53] reflog_expire: " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 16/53] builtin/verify-commit: " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 17/53] tag: convert parse_tag_buffer " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 18/53] http-push: convert some static functions " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 19/53] notes-utils: convert internals " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 20/53] revision: convert prepare_show_merge " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 21/53] shallow: convert shallow registration functions to object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 22/53] sequencer: convert some functions to struct object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 23/53] builtin/tag: convert " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 24/53] Convert remaining callers of lookup_commit_reference* to object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 25/53] Convert lookup_commit* to struct object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 26/53] pack: convert struct pack_idx_entry " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 27/53] builtin/unpack-objects: convert " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 28/53] Convert remaining callers of lookup_blob to object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 29/53] Convert lookup_blob to struct object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 30/53] tree: convert read_tree_1 to use struct object_id internally brian m. carlson
2017-05-06 22:10 ` [PATCH v3 31/53] builtin/reflog: convert tree_is_complete to take struct object_id brian m. carlson
2017-05-06 22:10 ` brian m. carlson [this message]
2017-05-06 22:10 ` [PATCH v3 33/53] log-tree: convert to " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 34/53] Convert lookup_tag " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 35/53] Convert the verify_pack callback " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 36/53] Convert struct ref_array_item " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 37/53] ref-filter: convert some static functions " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 38/53] refs: convert struct ref_update to use " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 39/53] refs/files-backend: convert many internals to " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 40/53] http-push: convert process_ls_object and descendants to object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 41/53] revision: rename add_pending_sha1 to add_pending_oid brian m. carlson
2017-05-06 22:10 ` [PATCH v3 42/53] revision: convert remaining parse_object callers to object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 43/53] upload-pack: " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 44/53] sha1_name: convert internals of peel_onion " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 45/53] builtin/read-tree: convert to struct object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 46/53] builtin/ls-files: convert overlay_tree_on_cache to object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 47/53] sequencer: convert fast_forward_to to struct object_id brian m. carlson
2017-05-06 22:10 ` [PATCH v3 48/53] merge: convert checkout_fast_forward " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 49/53] builtin/ls-tree: convert " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 50/53] diff-lib: convert do_diff_cache " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 51/53] sequencer: convert do_recursive_merge " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 52/53] tree: convert parse_tree_indirect " brian m. carlson
2017-05-06 22:10 ` [PATCH v3 53/53] object: convert parse_object* to take " brian m. carlson
2017-05-08 21:53 ` [PATCH v3 00/53] object_id part 8 Jonathan Tan
2017-05-09 22:13 ` Brandon Williams

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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=20170506221038.296722-33-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=bmwill@google.com \
    --cc=git@vger.kernel.org \
    --cc=jonathantanmy@google.com \
    --cc=mhagger@alum.mit.edu \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sbeller@google.com \
    /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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).