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 32/36] sha1_file: convert read_object_with_reference to object_id
Date: Sun, 25 Feb 2018 21:12:08 +0000	[thread overview]
Message-ID: <20180225211212.477570-33-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20180225211212.477570-1-sandals@crustytoothpaste.net>

Convert read_object_with_reference to take pointers to struct object_id.
Update the internals of the function accordingly.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/cat-file.c     |  2 +-
 builtin/grep.c         |  4 ++--
 builtin/pack-objects.c |  2 +-
 cache.h                |  4 ++--
 fast-import.c          | 15 ++++++++-------
 sha1_file.c            | 20 ++++++++++----------
 tree-walk.c            |  9 ++++-----
 7 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/builtin/cat-file.c b/builtin/cat-file.c
index 3264bada39..17382f2fa4 100644
--- a/builtin/cat-file.c
+++ b/builtin/cat-file.c
@@ -159,7 +159,7 @@ static int cat_one_file(int opt, const char *exp_type, const char *obj_name,
 			 * fall-back to the usual case.
 			 */
 		}
-		buf = read_object_with_reference(oid.hash, exp_type, &size, NULL);
+		buf = read_object_with_reference(&oid, exp_type, &size, NULL);
 		break;
 
 	default:
diff --git a/builtin/grep.c b/builtin/grep.c
index 3ca4ac80d8..7c2843a492 100644
--- a/builtin/grep.c
+++ b/builtin/grep.c
@@ -445,7 +445,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
 		object = parse_object_or_die(oid, oid_to_hex(oid));
 
 		grep_read_lock();
-		data = read_object_with_reference(object->oid.hash, tree_type,
+		data = read_object_with_reference(&object->oid, tree_type,
 						  &size, NULL);
 		grep_read_unlock();
 
@@ -607,7 +607,7 @@ static int grep_object(struct grep_opt *opt, const struct pathspec *pathspec,
 		int hit, len;
 
 		grep_read_lock();
-		data = read_object_with_reference(obj->oid.hash, tree_type,
+		data = read_object_with_reference(&obj->oid, tree_type,
 						  &size, NULL);
 		grep_read_unlock();
 
diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c
index f8148eb9d5..16d6069e16 100644
--- a/builtin/pack-objects.c
+++ b/builtin/pack-objects.c
@@ -1351,7 +1351,7 @@ static void add_preferred_base(struct object_id *oid)
 	if (window <= num_preferred_base++)
 		return;
 
-	data = read_object_with_reference(oid->hash, tree_type, &size, tree_oid.hash);
+	data = read_object_with_reference(oid, tree_type, &size, &tree_oid);
 	if (!data)
 		return;
 
diff --git a/cache.h b/cache.h
index b965a073f2..c482fb92fe 100644
--- a/cache.h
+++ b/cache.h
@@ -1431,10 +1431,10 @@ extern int df_name_compare(const char *name1, int len1, int mode1, const char *n
 extern int name_compare(const char *name1, size_t len1, const char *name2, size_t len2);
 extern int cache_name_stage_compare(const char *name1, int len1, int stage1, const char *name2, int len2, int stage2);
 
-extern void *read_object_with_reference(const unsigned char *sha1,
+extern void *read_object_with_reference(const struct object_id *oid,
 					const char *required_type,
 					unsigned long *size,
-					unsigned char *sha1_ret);
+					struct object_id *oid_ret);
 
 extern struct object *peel_to_type(const char *name, int namelen,
 				   struct object *o, enum object_type);
diff --git a/fast-import.c b/fast-import.c
index 71b60f9068..004a9c9f99 100644
--- a/fast-import.c
+++ b/fast-import.c
@@ -2583,8 +2583,9 @@ static void note_change_n(const char *p, struct branch *b, unsigned char *old_fa
 		oidcpy(&commit_oid, &commit_oe->idx.oid);
 	} else if (!get_oid(p, &commit_oid)) {
 		unsigned long size;
-		char *buf = read_object_with_reference(commit_oid.hash,
-			commit_type, &size, commit_oid.hash);
+		char *buf = read_object_with_reference(&commit_oid,
+						       commit_type, &size,
+						       &commit_oid);
 		if (!buf || size < 46)
 			die("Not a valid commit: %s", p);
 		free(buf);
@@ -2653,9 +2654,8 @@ static void parse_from_existing(struct branch *b)
 		unsigned long size;
 		char *buf;
 
-		buf = read_object_with_reference(b->oid.hash,
-						 commit_type, &size,
-						 b->oid.hash);
+		buf = read_object_with_reference(&b->oid, commit_type, &size,
+						 &b->oid);
 		parse_from_commit(b, buf, size);
 		free(buf);
 	}
@@ -2732,8 +2732,9 @@ static struct hash_list *parse_merge(unsigned int *count)
 			oidcpy(&n->oid, &oe->idx.oid);
 		} else if (!get_oid(from, &n->oid)) {
 			unsigned long size;
-			char *buf = read_object_with_reference(n->oid.hash,
-				commit_type, &size, n->oid.hash);
+			char *buf = read_object_with_reference(&n->oid,
+							       commit_type,
+							       &size, &n->oid);
 			if (!buf || size < 46)
 				die("Not a valid commit: %s", from);
 			free(buf);
diff --git a/sha1_file.c b/sha1_file.c
index 1719c218e2..bf8a713185 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1399,29 +1399,29 @@ void *read_sha1_file_extended(const unsigned char *sha1,
 	return NULL;
 }
 
-void *read_object_with_reference(const unsigned char *sha1,
+void *read_object_with_reference(const struct object_id *oid,
 				 const char *required_type_name,
 				 unsigned long *size,
-				 unsigned char *actual_sha1_return)
+				 struct object_id *actual_oid_return)
 {
 	enum object_type type, required_type;
 	void *buffer;
 	unsigned long isize;
-	unsigned char actual_sha1[20];
+	struct object_id actual_oid;
 
 	required_type = type_from_string(required_type_name);
-	hashcpy(actual_sha1, sha1);
+	oidcpy(&actual_oid, oid);
 	while (1) {
 		int ref_length = -1;
 		const char *ref_type = NULL;
 
-		buffer = read_sha1_file(actual_sha1, &type, &isize);
+		buffer = read_sha1_file(actual_oid.hash, &type, &isize);
 		if (!buffer)
 			return NULL;
 		if (type == required_type) {
 			*size = isize;
-			if (actual_sha1_return)
-				hashcpy(actual_sha1_return, actual_sha1);
+			if (actual_oid_return)
+				oidcpy(actual_oid_return, &actual_oid);
 			return buffer;
 		}
 		/* Handle references */
@@ -1435,15 +1435,15 @@ void *read_object_with_reference(const unsigned char *sha1,
 		}
 		ref_length = strlen(ref_type);
 
-		if (ref_length + 40 > isize ||
+		if (ref_length + GIT_SHA1_HEXSZ > isize ||
 		    memcmp(buffer, ref_type, ref_length) ||
-		    get_sha1_hex((char *) buffer + ref_length, actual_sha1)) {
+		    get_oid_hex((char *) buffer + ref_length, &actual_oid)) {
 			free(buffer);
 			return NULL;
 		}
 		free(buffer);
 		/* Now we have the ID of the referred-to object in
-		 * actual_sha1.  Check again. */
+		 * actual_oid.  Check again. */
 	}
 }
 
diff --git a/tree-walk.c b/tree-walk.c
index a60837c491..b7e504070c 100644
--- a/tree-walk.c
+++ b/tree-walk.c
@@ -84,8 +84,7 @@ void *fill_tree_descriptor(struct tree_desc *desc, const struct object_id *oid)
 	void *buf = NULL;
 
 	if (oid) {
-		buf = read_object_with_reference(oid->hash, tree_type, &size,
-						 NULL);
+		buf = read_object_with_reference(oid, tree_type, &size, NULL);
 		if (!buf)
 			die("unable to read tree %s", oid_to_hex(oid));
 	}
@@ -534,7 +533,7 @@ int get_tree_entry(const struct object_id *tree_oid, const char *name, struct ob
 	unsigned long size;
 	struct object_id root;
 
-	tree = read_object_with_reference(tree_oid->hash, tree_type, &size, root.hash);
+	tree = read_object_with_reference(tree_oid, tree_type, &size, &root);
 	if (!tree)
 		return -1;
 
@@ -601,9 +600,9 @@ enum follow_symlinks_result get_tree_entry_follow_symlinks(unsigned char *tree_s
 			void *tree;
 			struct object_id root;
 			unsigned long size;
-			tree = read_object_with_reference(current_tree_oid.hash,
+			tree = read_object_with_reference(&current_tree_oid,
 							  tree_type, &size,
-							  root.hash);
+							  &root);
 			if (!tree)
 				goto done;
 

  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 ` [PATCH v2 31/36] tree-walk: convert tree entry functions to object_id brian m. carlson
2018-02-25 21:12 ` brian m. carlson [this message]
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-33-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).