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 19/36] sha1_file: convert check_sha1_signature to struct object_id
Date: Sun, 25 Feb 2018 21:11:55 +0000	[thread overview]
Message-ID: <20180225211212.477570-20-sandals@crustytoothpaste.net> (raw)
In-Reply-To: <20180225211212.477570-1-sandals@crustytoothpaste.net>

Convert this function to take a pointer to struct object_id and rename
it check_object_signature.  Introduce temporaries to convert the return
values of lookup_replace_object and lookup_replace_object_extended into
struct object_id.

The temporaries are needed because in order to convert
lookup_replace_object, open_istream needs to be converted, and
open_istream needs check_sha1_signature to be converted, causing a loop
of dependencies.  The temporaries will be removed in a future patch.

Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
---
 builtin/fast-export.c |  2 +-
 builtin/index-pack.c  |  2 +-
 builtin/mktag.c       |  5 ++++-
 cache.h               |  2 +-
 object.c              | 10 ++++++++--
 pack-check.c          |  4 ++--
 sha1_file.c           | 12 ++++++------
 7 files changed, 23 insertions(+), 14 deletions(-)

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index 796d0cd66c..293a6615fa 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -240,7 +240,7 @@ static void export_blob(const struct object_id *oid)
 		buf = read_sha1_file(oid->hash, &type, &size);
 		if (!buf)
 			die ("Could not read blob %s", oid_to_hex(oid));
-		if (check_sha1_signature(oid->hash, buf, size, typename(type)) < 0)
+		if (check_object_signature(oid, buf, size, typename(type)) < 0)
 			die("sha1 mismatch in blob %s", oid_to_hex(oid));
 		object = parse_object_buffer(oid, type, size, buf, &eaten);
 	}
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 5c7ab47c36..e0a776f1ac 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1377,7 +1377,7 @@ static void fix_unresolved_deltas(struct hashfile *f)
 		if (!base_obj->data)
 			continue;
 
-		if (check_sha1_signature(d->oid.hash, base_obj->data,
+		if (check_object_signature(&d->oid, base_obj->data,
 				base_obj->size, typename(type)))
 			die(_("local object %s is corrupt"), oid_to_hex(&d->oid));
 		base_obj->obj = append_obj_to_pack(f, d->oid.hash,
diff --git a/builtin/mktag.c b/builtin/mktag.c
index 65bb41e3cd..810b24bef3 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -27,8 +27,11 @@ static int verify_object(const struct object_id *oid, const char *expected_type)
 	const unsigned char *repl = lookup_replace_object(oid->hash);
 
 	if (buffer) {
+		struct object_id reploid;
+		hashcpy(reploid.hash, repl);
+
 		if (type == type_from_string(expected_type))
-			ret = check_sha1_signature(repl, buffer, size, expected_type);
+			ret = check_object_signature(&reploid, buffer, size, expected_type);
 		free(buffer);
 	}
 	return ret;
diff --git a/cache.h b/cache.h
index 8a9055f4e7..f29ff43bbd 100644
--- a/cache.h
+++ b/cache.h
@@ -1236,7 +1236,7 @@ extern void *map_sha1_file(const unsigned char *sha1, unsigned long *size);
 extern int unpack_sha1_header(git_zstream *stream, unsigned char *map, unsigned long mapsize, void *buffer, unsigned long bufsiz);
 extern int parse_sha1_header(const char *hdr, unsigned long *sizep);
 
-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
+extern int check_object_signature(const struct object_id *oid, void *buf, unsigned long size, const char *type);
 
 extern int finalize_object_file(const char *tmpfile, const char *filename);
 
diff --git a/object.c b/object.c
index 9e6f9ff20b..c63f02a40f 100644
--- a/object.c
+++ b/object.c
@@ -255,7 +255,10 @@ struct object *parse_object(const struct object_id *oid)
 	if ((obj && obj->type == OBJ_BLOB && has_object_file(oid)) ||
 	    (!obj && has_object_file(oid) &&
 	     sha1_object_info(oid->hash, NULL) == OBJ_BLOB)) {
-		if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
+		struct object_id reploid;
+		hashcpy(reploid.hash, repl);
+
+		if (check_object_signature(&reploid, NULL, 0, NULL) < 0) {
 			error("sha1 mismatch %s", oid_to_hex(oid));
 			return NULL;
 		}
@@ -265,7 +268,10 @@ struct object *parse_object(const struct object_id *oid)
 
 	buffer = read_sha1_file(oid->hash, &type, &size);
 	if (buffer) {
-		if (check_sha1_signature(repl, buffer, size, typename(type)) < 0) {
+		struct object_id reploid;
+		hashcpy(reploid.hash, repl);
+
+		if (check_object_signature(&reploid, buffer, size, typename(type)) < 0) {
 			free(buffer);
 			error("sha1 mismatch %s", sha1_to_hex(repl));
 			return NULL;
diff --git a/pack-check.c b/pack-check.c
index 403a572567..80ef7c1c63 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -126,7 +126,7 @@ static int verify_packfile(struct packed_git *p,
 
 		if (type == OBJ_BLOB && big_file_threshold <= size) {
 			/*
-			 * Let check_sha1_signature() check it with
+			 * Let check_object_signature() check it with
 			 * the streaming interface; no point slurping
 			 * the data in-core only to discard.
 			 */
@@ -141,7 +141,7 @@ static int verify_packfile(struct packed_git *p,
 			err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
 				    oid_to_hex(entries[i].oid.oid), p->pack_name,
 				    (uintmax_t)entries[i].offset);
-		else if (check_sha1_signature(entries[i].oid.hash, data, size, typename(type)))
+		else if (check_object_signature(entries[i].oid.oid, data, size, typename(type)))
 			err = error("packed %s from %s is corrupt",
 				    oid_to_hex(entries[i].oid.oid), p->pack_name);
 		else if (fn) {
diff --git a/sha1_file.c b/sha1_file.c
index 69e8d27773..64f0905799 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -784,8 +784,8 @@ void *xmmap(void *start, size_t length,
  * With "map" == NULL, try reading the object named with "sha1" using
  * the streaming interface and rehash it to do the same.
  */
-int check_sha1_signature(const unsigned char *sha1, void *map,
-			 unsigned long size, const char *type)
+int check_object_signature(const struct object_id *oid, void *map,
+			   unsigned long size, const char *type)
 {
 	struct object_id real_oid;
 	enum object_type obj_type;
@@ -796,10 +796,10 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
 
 	if (map) {
 		hash_object_file(map, size, type, &real_oid);
-		return hashcmp(sha1, real_oid.hash) ? -1 : 0;
+		return oidcmp(oid, &real_oid) ? -1 : 0;
 	}
 
-	st = open_istream(sha1, &obj_type, &size, NULL);
+	st = open_istream(oid->hash, &obj_type, &size, NULL);
 	if (!st)
 		return -1;
 
@@ -823,7 +823,7 @@ int check_sha1_signature(const unsigned char *sha1, void *map,
 	}
 	the_hash_algo->final_fn(real_oid.hash, &c);
 	close_istream(st);
-	return hashcmp(sha1, real_oid.hash) ? -1 : 0;
+	return oidcmp(oid, &real_oid) ? -1 : 0;
 }
 
 int git_open_cloexec(const char *name, int flags)
@@ -2217,7 +2217,7 @@ int read_loose_object(const char *path,
 			git_inflate_end(&stream);
 			goto out;
 		}
-		if (check_sha1_signature(expected_oid->hash, *contents,
+		if (check_object_signature(expected_oid, *contents,
 					 *size, typename(*type))) {
 			error("sha1 mismatch for %s (expected %s)", path,
 			      oid_to_hex(expected_oid));

  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 ` brian m. carlson [this message]
2018-02-25 21:11 ` [PATCH v2 20/36] streaming: convert open_istream " 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 ` [PATCH v2 32/36] sha1_file: convert read_object_with_reference " 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-20-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).