git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: git@vger.kernel.org
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
	"Patryk Obara" <patryk.obara@gmail.com>,
	"Jeff King" <peff@peff.net>,
	"Eric Sunshine" <sunshine@sunshineco.com>
Subject: [PATCH v2 31/36] tree-walk: convert tree entry functions to object_id
Date: Sun, 25 Feb 2018 21:12:07 +0000	[thread overview]
Message-ID: <20180225211212.477570-32-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20180225211212.477570-1-sandals@crustytoothpaste.net>

Convert get_tree_entry and find_tree_entry to take pointers to struct
object_id.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 archive.c              |  4 ++--
 blame.c                |  6 ++----
 builtin/rm.c           |  2 +-
 builtin/update-index.c |  2 +-
 line-log.c             |  3 +--
 match-trees.c          |  6 +++---
 merge-recursive.c      | 12 ++++++------
 notes.c                |  2 +-
 sha1_name.c            |  7 +++----
 tree-walk.c            | 20 ++++++++++----------
 tree-walk.h            |  2 +-
 11 files changed, 31 insertions(+), 35 deletions(-)

diff --git a/archive.c b/archive.c
index da62b2f541..1ab62d426e 100644
--- a/archive.c
+++ b/archive.c
@@ -397,8 +397,8 @@ static void parse_treeish_arg(const char **argv,
 		unsigned int mode;
 		int err;
 
-		err = get_tree_entry(tree->object.oid.hash, prefix,
-				     tree_oid.hash, &mode);
+		err = get_tree_entry(&tree->object.oid, prefix, &tree_oid,
+				     &mode);
 		if (err || !S_ISDIR(mode))
 			die("current working directory is untracked");
 
diff --git a/blame.c b/blame.c
index c1df10cdd2..3f9bd29615 100644
--- a/blame.c
+++ b/blame.c
@@ -80,7 +80,7 @@ static void verify_working_tree_path(struct commit *work_tree, const char *path)
 		struct object_id blob_oid;
 		unsigned mode;
 
-		if (!get_tree_entry(commit_oid->hash, path, blob_oid.hash, &mode) &&
+		if (!get_tree_entry(commit_oid, path, &blob_oid, &mode) &&
 		    oid_object_info(&blob_oid, NULL) == OBJ_BLOB)
 			return;
 	}
@@ -502,9 +502,7 @@ static int fill_blob_sha1_and_mode(struct blame_origin *origin)
 {
 	if (!is_null_oid(&origin->blob_oid))
 		return 0;
-	if (get_tree_entry(origin->commit->object.oid.hash,
-			   origin->path,
-			   origin->blob_oid.hash, &origin->mode))
+	if (get_tree_entry(&origin->commit->object.oid, origin->path, &origin->blob_oid, &origin->mode))
 		goto error_out;
 	if (oid_object_info(&origin->blob_oid, NULL) != OBJ_BLOB)
 		goto error_out;
diff --git a/builtin/rm.c b/builtin/rm.c
index 4a2fcca27b..974a7ef5bf 100644
--- a/builtin/rm.c
+++ b/builtin/rm.c
@@ -178,7 +178,7 @@ static int check_local_mod(struct object_id *head, int index_only)
 		 * way as changed from the HEAD.
 		 */
 		if (no_head
-		     || get_tree_entry(head->hash, name, oid.hash, &mode)
+		     || get_tree_entry(head, name, &oid, &mode)
 		     || ce->ce_mode != create_ce_mode(mode)
 		     || oidcmp(&ce->oid, &oid))
 			staged_changes = 1;
diff --git a/builtin/update-index.c b/builtin/update-index.c
index 58d1c2d282..9625d1e10a 100644
--- a/builtin/update-index.c
+++ b/builtin/update-index.c
@@ -592,7 +592,7 @@ static struct cache_entry *read_one_ent(const char *which,
 	int size;
 	struct cache_entry *ce;
 
-	if (get_tree_entry(ent->hash, path, oid.hash, &mode)) {
+	if (get_tree_entry(ent, path, &oid, &mode)) {
 		if (which)
 			error("%s: not in %s branch.", path, which);
 		return NULL;
diff --git a/line-log.c b/line-log.c
index 545ad0f28b..700121eb92 100644
--- a/line-log.c
+++ b/line-log.c
@@ -501,8 +501,7 @@ static void fill_blob_sha1(struct commit *commit, struct diff_filespec *spec)
 	unsigned mode;
 	struct object_id oid;
 
-	if (get_tree_entry(commit->object.oid.hash, spec->path,
-			   oid.hash, &mode))
+	if (get_tree_entry(&commit->object.oid, spec->path, &oid, &mode))
 		die("There is no path %s in the commit", spec->path);
 	fill_filespec(spec, &oid, 1, mode);
 
diff --git a/match-trees.c b/match-trees.c
index 0ca99d5162..10d6c39d47 100644
--- a/match-trees.c
+++ b/match-trees.c
@@ -269,7 +269,7 @@ void shift_tree(const struct object_id *hash1,
 		if (!*del_prefix)
 			return;
 
-		if (get_tree_entry(hash2->hash, del_prefix, shifted->hash, &mode))
+		if (get_tree_entry(hash2, del_prefix, shifted, &mode))
 			die("cannot find path %s in tree %s",
 			    del_prefix, oid_to_hex(hash2));
 		return;
@@ -296,12 +296,12 @@ void shift_tree_by(const struct object_id *hash1,
 	unsigned candidate = 0;
 
 	/* Can hash2 be a tree at shift_prefix in tree hash1? */
-	if (!get_tree_entry(hash1->hash, shift_prefix, sub1.hash, &mode1) &&
+	if (!get_tree_entry(hash1, shift_prefix, &sub1, &mode1) &&
 	    S_ISDIR(mode1))
 		candidate |= 1;
 
 	/* Can hash1 be a tree at shift_prefix in tree hash2? */
-	if (!get_tree_entry(hash2->hash, shift_prefix, sub2.hash, &mode2) &&
+	if (!get_tree_entry(hash2, shift_prefix, &sub2, &mode2) &&
 	    S_ISDIR(mode2))
 		candidate |= 2;
 
diff --git a/merge-recursive.c b/merge-recursive.c
index f58f13957e..85f8cbee99 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -370,12 +370,12 @@ static struct stage_data *insert_stage_data(const char *path,
 {
 	struct string_list_item *item;
 	struct stage_data *e = xcalloc(1, sizeof(struct stage_data));
-	get_tree_entry(o->object.oid.hash, path,
-			e->stages[1].oid.hash, &e->stages[1].mode);
-	get_tree_entry(a->object.oid.hash, path,
-			e->stages[2].oid.hash, &e->stages[2].mode);
-	get_tree_entry(b->object.oid.hash, path,
-			e->stages[3].oid.hash, &e->stages[3].mode);
+	get_tree_entry(&o->object.oid, path,
+			&e->stages[1].oid, &e->stages[1].mode);
+	get_tree_entry(&a->object.oid, path,
+			&e->stages[2].oid, &e->stages[2].mode);
+	get_tree_entry(&b->object.oid, path,
+			&e->stages[3].oid, &e->stages[3].mode);
 	item = string_list_insert(entries, path);
 	item->util = e;
 	return e;
diff --git a/notes.c b/notes.c
index ce9a8f53f8..d25121a65d 100644
--- a/notes.c
+++ b/notes.c
@@ -1012,7 +1012,7 @@ void init_notes(struct notes_tree *t, const char *notes_ref,
 		return;
 	if (flags & NOTES_INIT_WRITABLE && read_ref(notes_ref, &object_oid))
 		die("Cannot use notes ref %s", notes_ref);
-	if (get_tree_entry(object_oid.hash, "", oid.hash, &mode))
+	if (get_tree_entry(&object_oid, "", &oid, &mode))
 		die("Failed to read notes tree referenced by %s (%s)",
 		    notes_ref, oid_to_hex(&object_oid));
 
diff --git a/sha1_name.c b/sha1_name.c
index 6d4c6033c8..8b0012c253 100644
--- a/sha1_name.c
+++ b/sha1_name.c
@@ -1529,8 +1529,7 @@ static void diagnose_invalid_oid_path(const char *prefix,
 	if (is_missing_file_error(errno)) {
 		char *fullname = xstrfmt("%s%s", prefix, filename);
 
-		if (!get_tree_entry(tree_oid->hash, fullname,
-				    oid.hash, &mode)) {
+		if (!get_tree_entry(tree_oid, fullname, &oid, &mode)) {
 			die("Path '%s' exists, but not '%s'.\n"
 			    "Did you mean '%.*s:%s' aka '%.*s:./%s'?",
 			    fullname,
@@ -1722,8 +1721,8 @@ static int get_oid_with_context_1(const char *name,
 					filename, oid->hash, &oc->symlink_path,
 					&oc->mode);
 			} else {
-				ret = get_tree_entry(tree_oid.hash, filename,
-						     oid->hash, &oc->mode);
+				ret = get_tree_entry(&tree_oid, filename, oid,
+						     &oc->mode);
 				if (ret && only_to_die) {
 					diagnose_invalid_oid_path(prefix,
 								   filename,
diff --git a/tree-walk.c b/tree-walk.c
index 521defdaa2..a60837c491 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -492,7 +492,7 @@ struct dir_state {
 	unsigned char sha1[20];
 };
 
-static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char *result, unsigned *mode)
+static int find_tree_entry(struct tree_desc *t, const char *name, struct object_id *result, unsigned *mode)
 {
 	int namelen = strlen(name);
 	while (t->size) {
@@ -511,7 +511,7 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
 		if (cmp < 0)
 			break;
 		if (entrylen == namelen) {
-			hashcpy(result, oid->hash);
+			oidcpy(result, oid);
 			return 0;
 		}
 		if (name[entrylen] != '/')
@@ -519,27 +519,27 @@ static int find_tree_entry(struct tree_desc *t, const char *name, unsigned char
 		if (!S_ISDIR(*mode))
 			break;
 		if (++entrylen == namelen) {
-			hashcpy(result, oid->hash);
+			oidcpy(result, oid);
 			return 0;
 		}
-		return get_tree_entry(oid->hash, name + entrylen, result, mode);
+		return get_tree_entry(oid, name + entrylen, result, mode);
 	}
 	return -1;
 }
 
-int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned char *sha1, unsigned *mode)
+int get_tree_entry(const struct object_id *tree_oid, const char *name, struct object_id *oid, unsigned *mode)
 {
 	int retval;
 	void *tree;
 	unsigned long size;
-	unsigned char root[20];
+	struct object_id root;
 
-	tree = read_object_with_reference(tree_sha1, tree_type, &size, root);
+	tree = read_object_with_reference(tree_oid->hash, tree_type, &size, root.hash);
 	if (!tree)
 		return -1;
 
 	if (name[0] == '\0') {
-		hashcpy(sha1, root);
+		oidcpy(oid, &root);
 		free(tree);
 		return 0;
 	}
@@ -549,7 +549,7 @@ int get_tree_entry(const unsigned char *tree_sha1, const char *name, unsigned ch
 	} else {
 		struct tree_desc t;
 		init_tree_desc(&t, tree, size);
-		retval = find_tree_entry(&t, name, sha1, mode);
+		retval = find_tree_entry(&t, name, oid, mode);
 	}
 	free(tree);
 	return retval;
@@ -671,7 +671,7 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
 
 		/* Look up the first (or only) path component in the tree. */
 		find_result = find_tree_entry(&t, namebuf.buf,
-					      current_tree_oid.hash, mode);
+					      &current_tree_oid, mode);
 		if (find_result) {
 			goto done;
 		}
diff --git a/tree-walk.h b/tree-walk.h
index b6bd1b4ccf..4617deeb0e 100644
--- a/tree-walk.h
+++ b/tree-walk.h
@@ -79,7 +79,7 @@ struct traverse_info {
 	int show_all_errors;
 };
 
-int get_tree_entry(const unsigned char *, const char *, unsigned char *, unsigned *);
+int get_tree_entry(const struct object_id *, const char *, struct object_id *, unsigned *);
 extern char *make_traverse_path(char *path, const struct traverse_info *info, const struct name_entry *n);
 extern void setup_traverse_info(struct traverse_info *info, const char *base);
 

  parent reply	other threads:[~2018-02-25 21:13 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-25 21:11 [PATCH v2 00/36] object_id part 12 brian m. carlson
2018-02-25 21:11 ` [PATCH v2 01/36] bulk-checkin: convert index_bulk_checkin to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 02/36] builtin/write-tree: convert " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 03/36] cache-tree: convert write_*_as_tree to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 04/36] cache-tree: convert remnants to struct object_id brian m. carlson
2018-02-26 11:15   ` Duy Nguyen
2018-02-25 21:11 ` [PATCH v2 05/36] resolve-undo: convert struct resolve_undo_info to object_id brian m. carlson
2018-02-26 11:25   ` Duy Nguyen
2018-02-27  2:01     ` brian m. carlson
2018-02-28  9:38       ` Duy Nguyen
2018-02-25 21:11 ` [PATCH v2 06/36] tree: convert read_tree_recursive to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 07/36] ref-filter: convert grab_objectname " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 08/36] strbuf: convert strbuf_add_unique_abbrev to use " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 09/36] wt-status: convert struct wt_status_state to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 10/36] Convert find_unique_abbrev* to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 11/36] http-walker: convert struct object_request to use " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 12/36] send-pack: convert remaining functions to " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 13/36] replace_object: convert struct replace_object to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 14/36] builtin/mktag: convert to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 15/36] archive: convert write_archive_entry_fn_t to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 16/36] archive: convert sha1_file_to_archive to struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 17/36] builtin/index-pack: convert struct ref_delta_entry to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 18/36] sha1_file: convert read_loose_object to use struct object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 19/36] sha1_file: convert check_sha1_signature to " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 20/36] streaming: convert open_istream to use " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 21/36] builtin/mktree: convert to " brian m. carlson
2018-02-25 21:11 ` [PATCH v2 22/36] sha1_file: convert assert_sha1_type to object_id brian m. carlson
2018-02-25 21:11 ` [PATCH v2 23/36] sha1_file: convert retry_bad_packed_offset to struct object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 24/36] packfile: convert unpack_entry " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 25/36] Convert remaining callers of sha1_object_info_extended to object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 26/36] sha1_file: convert sha1_object_info* " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 27/36] builtin/fmt-merge-msg: convert remaining code " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 28/36] builtin/notes: convert static functions " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 29/36] tree-walk: convert get_tree_entry_follow_symlinks internals " brian m. carlson
2018-02-25 21:12 ` [PATCH v2 30/36] streaming: convert istream internals to struct object_id brian m. carlson
2018-02-25 21:12 ` brian m. carlson [this message]
2018-02-25 21:12 ` [PATCH v2 32/36] sha1_file: convert read_object_with_reference to object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 33/36] sha1_file: convert read_sha1_file to struct object_id brian m. carlson
2018-02-25 21:12 ` [PATCH v2 34/36] Convert lookup_replace_object " brian m. carlson
2018-02-26 11:37   ` Duy Nguyen
2018-02-25 21:12 ` [PATCH v2 35/36] sha1_file: introduce a constant for max header length brian m. carlson
2018-02-25 21:12 ` [PATCH v2 36/36] convert: convert to struct object_id 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=20180225211212.477570-32-sandals@crustytoothpaste.net \
    --to=sandals@crustytoothpaste.net \
    --cc=git@vger.kernel.org \
    --cc=patryk.obara@gmail.com \
    --cc=pclouds@gmail.com \
    --cc=peff@peff.net \
    --cc=sunshine@sunshineco.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.
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).