git@vger.kernel.org mailing list mirror (one of many)
 help / 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 v3 34/36] Convert lookup_replace_object to struct object_id
Date: Mon, 12 Mar 2018 02:27:54 +0000
Message-ID: <20180312022756.483934-35-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20180312022756.483934-1-sandals@crustytoothpaste.net>

Convert both the argument and the return value to be pointers to struct
object_id.  Update the callers and their internals to deal with the new
type.  Remove several temporaries which are no longer needed.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/mktag.c  |  7 ++-----
 cache.h          |  8 ++++----
 object.c         | 14 ++++----------
 replace_object.c | 14 +++++++-------
 sha1_file.c      | 42 ++++++++++++++++++++----------------------
 streaming.c      | 16 +++++-----------
 6 files changed, 42 insertions(+), 59 deletions(-)

diff --git a/builtin/mktag.c b/builtin/mktag.c
index cfb777b3c8..9f5a50a8fd 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -24,14 +24,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
 	enum object_type type;
 	unsigned long size;
 	void *buffer = read_object_file(oid, &type, &size);
-	const unsigned char *repl = lookup_replace_object(oid->hash);
+	const struct object_id *repl = lookup_replace_object(oid);
 
 	if (buffer) {
-		struct object_id reploid;
-		hashcpy(reploid.hash, repl);
-
 		if (type == type_from_string(expected_type))
-			ret = check_object_signature(&reploid, buffer, size, expected_type);
+			ret = check_object_signature(repl, buffer, size, expected_type);
 		free(buffer);
 	}
 	return ret;
diff --git a/cache.h b/cache.h
index 3c9718cc8c..0491f0cbc4 100644
--- a/cache.h
+++ b/cache.h
@@ -1197,7 +1197,7 @@ static inline void *read_object_file(const struct object_id *oid, enum object_ty
  * This internal function is only declared here for the benefit of
  * lookup_replace_object().  Please do not call it directly.
  */
-extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
+extern const struct object_id *do_lookup_replace_object(const struct object_id *oid);
 
 /*
  * If object sha1 should be replaced, return the replacement object's
@@ -1205,11 +1205,11 @@ extern const unsigned char *do_lookup_replace_object(const unsigned char *sha1);
  * either sha1 or a pointer to a permanently-allocated value.  When
  * object replacement is suppressed, always return sha1.
  */
-static inline const unsigned char *lookup_replace_object(const unsigned char *sha1)
+static inline const struct object_id *lookup_replace_object(const struct object_id *oid)
 {
 	if (!check_replace_refs)
-		return sha1;
-	return do_lookup_replace_object(sha1);
+		return oid;
+	return do_lookup_replace_object(oid);
 }
 
 /* Read and unpack an object file into memory, write memory to an object file */
diff --git a/object.c b/object.c
index 8e32f0d33b..2c909385a7 100644
--- a/object.c
+++ b/object.c
@@ -244,7 +244,7 @@ struct object *parse_object(const struct object_id *oid)
 	unsigned long size;
 	enum object_type type;
 	int eaten;
-	const unsigned char *repl = lookup_replace_object(oid->hash);
+	const struct object_id *repl = lookup_replace_object(oid);
 	void *buffer;
 	struct object *obj;
 
@@ -255,10 +255,7 @@ struct object *parse_object(const struct object_id *oid)
 	if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
 	    (!obj && has_object_file(oid) &&
 	     oid_object_info(oid, NULL) == OBJ_BLOB)) {
-		struct object_id reploid;
-		hashcpy(reploid.hash, repl);
-
-		if (check_object_signature(&reploid, NULL, 0, NULL) < 0) {
+		if (check_object_signature(repl, NULL, 0, NULL) < 0) {
 			error("sha1 mismatch %s", oid_to_hex(oid));
 			return NULL;
 		}
@@ -268,12 +265,9 @@ struct object *parse_object(const struct object_id *oid)
 
 	buffer = read_object_file(oid, &type, &size);
 	if (buffer) {
-		struct object_id reploid;
-		hashcpy(reploid.hash, repl);
-
-		if (check_object_signature(&reploid, buffer, size, type_name(type)) < 0) {
+		if (check_object_signature(repl, buffer, size, type_name(type)) < 0) {
 			free(buffer);
-			error("sha1 mismatch %s", sha1_to_hex(repl));
+			error("sha1 mismatch %s", oid_to_hex(repl));
 			return NULL;
 		}
 
diff --git a/replace_object.c b/replace_object.c
index 232e8b8550..336357394d 100644
--- a/replace_object.c
+++ b/replace_object.c
@@ -92,16 +92,16 @@ static void prepare_replace_object(void)
 #define MAXREPLACEDEPTH 5
 
 /*
- * If a replacement for object sha1 has been set up, return the
+ * If a replacement for object oid has been set up, return the
  * replacement object's name (replaced recursively, if necessary).
- * The return value is either sha1 or a pointer to a
+ * The return value is either oid or a pointer to a
  * permanently-allocated value.  This function always respects replace
  * references, regardless of the value of check_replace_refs.
  */
-const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
+const struct object_id *do_lookup_replace_object(const struct object_id *oid)
 {
 	int pos, depth = MAXREPLACEDEPTH;
-	const unsigned char *cur = sha1;
+	const struct object_id *cur = oid;
 
 	prepare_replace_object();
 
@@ -109,11 +109,11 @@ const unsigned char *do_lookup_replace_object(const unsigned char *sha1)
 	do {
 		if (--depth < 0)
 			die("replace depth too high for object %s",
-			    sha1_to_hex(sha1));
+			    oid_to_hex(oid));
 
-		pos = replace_object_pos(cur);
+		pos = replace_object_pos(cur->hash);
 		if (0 <= pos)
-			cur = replace_object[pos]->replacement.hash;
+			cur = &replace_object[pos]->replacement;
 	} while (0 <= pos);
 
 	return cur;
diff --git a/sha1_file.c b/sha1_file.c
index cdd49e5274..60418da10b 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -1227,22 +1227,20 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
 	static struct object_info blank_oi = OBJECT_INFO_INIT;
 	struct pack_entry e;
 	int rtype;
-	const unsigned char *real = (flags & OBJECT_INFO_LOOKUP_REPLACE) ?
-				    lookup_replace_object(oid->hash) :
-				    oid->hash;
+	const struct object_id *real = oid;
 	int already_retried = 0;
-	struct object_id realoid;
 
-	hashcpy(realoid.hash, real);
+	if (flags & OBJECT_INFO_LOOKUP_REPLACE)
+		real = lookup_replace_object(oid);
 
-	if (is_null_sha1(real))
+	if (is_null_oid(real))
 		return -1;
 
 	if (!oi)
 		oi = &blank_oi;
 
 	if (!(flags & OBJECT_INFO_SKIP_CACHED)) {
-		struct cached_object *co = find_cached_object(real);
+		struct cached_object *co = find_cached_object(real->hash);
 		if (co) {
 			if (oi->typep)
 				*(oi->typep) = co->type;
@@ -1262,16 +1260,16 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
 	}
 
 	while (1) {
-		if (find_pack_entry(real, &e))
+		if (find_pack_entry(real->hash, &e))
 			break;
 
 		/* Most likely it's a loose object. */
-		if (!sha1_loose_object_info(real, oi, flags))
+		if (!sha1_loose_object_info(real->hash, oi, flags))
 			return 0;
 
 		/* Not a loose object; someone else may have just packed it. */
 		reprepare_packed_git();
-		if (find_pack_entry(real, &e))
+		if (find_pack_entry(real->hash, &e))
 			break;
 
 		/* Check if it is a missing object */
@@ -1281,7 +1279,7 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
 			 * TODO Investigate haveing fetch_object() return
 			 * TODO error/success and stopping the music here.
 			 */
-			fetch_object(repository_format_partial_clone, real);
+			fetch_object(repository_format_partial_clone, real->hash);
 			already_retried = 1;
 			continue;
 		}
@@ -1297,8 +1295,8 @@ int oid_object_info_extended(const struct object_id *oid, struct object_info *oi
 		return 0;
 	rtype = packed_object_info(e.p, e.offset, oi);
 	if (rtype < 0) {
-		mark_bad_packed_object(e.p, real);
-		return oid_object_info_extended(&realoid, oi, 0);
+		mark_bad_packed_object(e.p, real->hash);
+		return oid_object_info_extended(real, oi, 0);
 	} else if (oi->whence == OI_PACKED) {
 		oi->u.packed.offset = e.offset;
 		oi->u.packed.pack = e.p;
@@ -1372,11 +1370,11 @@ void *read_object_file_extended(const struct object_id *oid,
 	const struct packed_git *p;
 	const char *path;
 	struct stat st;
-	const unsigned char *repl = lookup_replace ? lookup_replace_object(oid->hash)
-						   : oid->hash;
+	const struct object_id *repl = lookup_replace ? lookup_replace_object(oid)
+						      : oid;
 
 	errno = 0;
-	data = read_object(repl, type, size);
+	data = read_object(repl->hash, type, size);
 	if (data)
 		return data;
 
@@ -1384,17 +1382,17 @@ void *read_object_file_extended(const struct object_id *oid,
 		die_errno("failed to read object %s", oid_to_hex(oid));
 
 	/* die if we replaced an object with one that does not exist */
-	if (repl != oid->hash)
+	if (repl != oid)
 		die("replacement %s not found for %s",
-		    sha1_to_hex(repl), oid_to_hex(oid));
+		    oid_to_hex(repl), oid_to_hex(oid));
 
-	if (!stat_sha1_file(repl, &st, &path))
+	if (!stat_sha1_file(repl->hash, &st, &path))
 		die("loose object %s (stored in %s) is corrupt",
-		    sha1_to_hex(repl), path);
+		    oid_to_hex(repl), path);
 
-	if ((p = has_packed_and_bad(repl)) != NULL)
+	if ((p = has_packed_and_bad(repl->hash)) != NULL)
 		die("packed object %s (stored in %s) is corrupt",
-		    sha1_to_hex(repl), p->pack_name);
+		    oid_to_hex(repl), p->pack_name);
 
 	return NULL;
 }
diff --git a/streaming.c b/streaming.c
index 72a3ca8d08..46fabee3aa 100644
--- a/streaming.c
+++ b/streaming.c
@@ -105,19 +105,16 @@ ssize_t read_istream(struct git_istream *st, void *buf, size_t sz)
 	return st->vtbl->read(st, buf, sz);
 }
 
-static enum input_source istream_source(const unsigned char *sha1,
+static enum input_source istream_source(const struct object_id *oid,
 					enum object_type *type,
 					struct object_info *oi)
 {
 	unsigned long size;
 	int status;
-	struct object_id oid;
-
-	hashcpy(oid.hash, sha1);
 
 	oi->typep = type;
 	oi->sizep = &size;
-	status = oid_object_info_extended(&oid, oi, 0);
+	status = oid_object_info_extended(oid, oi, 0);
 	if (status < 0)
 		return stream_error;
 
@@ -140,18 +137,15 @@ struct git_istream *open_istream(const struct object_id *oid,
 {
 	struct git_istream *st;
 	struct object_info oi = OBJECT_INFO_INIT;
-	const unsigned char *real = lookup_replace_object(oid->hash);
+	const struct object_id *real = lookup_replace_object(oid);
 	enum input_source src = istream_source(real, type, &oi);
-	struct object_id realoid;
-
-	hashcpy(realoid.hash, real);
 
 	if (src < 0)
 		return NULL;
 
 	st = xmalloc(sizeof(*st));
-	if (open_istream_tbl[src](st, &oi, &realoid, type)) {
-		if (open_istream_incore(st, &oi, &realoid, type)) {
+	if (open_istream_tbl[src](st, &oi, real, type)) {
+		if (open_istream_incore(st, &oi, real, type)) {
 			free(st);
 			return NULL;
 		}

  parent reply index

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-12  2:27 [PATCH v3 00/36] object_id part 12 brian m. carlson
2018-03-12  2:27 ` [PATCH v3 01/36] bulk-checkin: convert index_bulk_checkin to struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 02/36] builtin/write-tree: convert " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 03/36] cache-tree: convert write_*_as_tree to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 04/36] cache-tree: convert remnants to struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 05/36] resolve-undo: convert struct resolve_undo_info to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 06/36] tree: convert read_tree_recursive to struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 07/36] ref-filter: convert grab_objectname " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 08/36] strbuf: convert strbuf_add_unique_abbrev to use " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 09/36] wt-status: convert struct wt_status_state to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 10/36] Convert find_unique_abbrev* to struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 11/36] http-walker: convert struct object_request to use " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 12/36] send-pack: convert remaining functions to " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 13/36] replace_object: convert struct replace_object to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 14/36] builtin/mktag: convert to struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 15/36] archive: convert write_archive_entry_fn_t to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 16/36] archive: convert sha1_file_to_archive to struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 17/36] builtin/index-pack: convert struct ref_delta_entry to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 18/36] sha1_file: convert read_loose_object to use struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 19/36] sha1_file: convert check_sha1_signature to " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 20/36] streaming: convert open_istream to use " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 21/36] builtin/mktree: convert to " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 22/36] sha1_file: convert assert_sha1_type to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 23/36] sha1_file: convert retry_bad_packed_offset to struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 24/36] packfile: convert unpack_entry " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 25/36] Convert remaining callers of sha1_object_info_extended to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 26/36] sha1_file: convert sha1_object_info* " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 27/36] builtin/fmt-merge-msg: convert remaining code " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 28/36] builtin/notes: convert static functions " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 29/36] tree-walk: convert get_tree_entry_follow_symlinks internals " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 30/36] streaming: convert istream internals to struct object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 31/36] tree-walk: convert tree entry functions to object_id brian m. carlson
2018-03-12  2:27 ` [PATCH v3 32/36] sha1_file: convert read_object_with_reference " brian m. carlson
2018-03-12  2:27 ` [PATCH v3 33/36] sha1_file: convert read_sha1_file to struct object_id brian m. carlson
2018-03-12  2:27 ` brian m. carlson [this message]
2018-03-12  2:27 ` [PATCH v3 35/36] sha1_file: introduce a constant for max header length brian m. carlson
2018-03-12  2:27 ` [PATCH v3 36/36] convert: convert to struct object_id brian m. carlson
2018-03-14 16:48 ` [PATCH v3 00/36] object_id part 12 Junio C Hamano
2018-03-14 19:46   ` Junio C Hamano
2018-03-15  1:05   ` brian m. carlson
2018-03-14 17:31 ` Junio C Hamano
2018-03-15  0:53   ` brian m. carlson

Reply instructions:

You may reply publically 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=20180312022756.483934-35-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

git@vger.kernel.org mailing list mirror (one of many)

Archives are clonable:
	git clone --mirror https://public-inbox.org/git
	git clone --mirror http://ou63pmih66umazou.onion/git
	git clone --mirror http://czquwvybam4bgbro.onion/git
	git clone --mirror http://hjrcffqmbrq6wope.onion/git

Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.version-control.git
	nntp://ou63pmih66umazou.onion/inbox.comp.version-control.git
	nntp://czquwvybam4bgbro.onion/inbox.comp.version-control.git
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.version-control.git
	nntp://news.gmane.org/gmane.comp.version-control.git

 note: .onion URLs require Tor: https://www.torproject.org/
       or Tor2web: https://www.tor2web.org/

AGPL code for this site: git clone https://public-inbox.org/ public-inbox