[PATCH 110/194] object-store: add repository argument to check_sha1_signature

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Jonathan Nieder <jrnieder@xxxxxxxxx>

Add a repository argument to allow callers of check_sha1_signature to
be more specific about which repository to handle. This is a small
mechanical change; it doesn't change the implementation to handle
repositories other than the_repository yet.

As with the previous commits, use a macro to catch callers passing a
repository other than the_repository at compile time.

The included coccinelle semantic patch will adapt any new callers in
the diff produced by `make coccicheck`.

Signed-off-by: Jonathan Nieder <jrnieder@xxxxxxxxx>
Signed-off-by: Stefan Beller <sbeller@xxxxxxxxxx>
---
 builtin/fast-export.c                 |  2 +-
 builtin/index-pack.c                  |  2 +-
 builtin/mktag.c                       |  4 +++-
 contrib/coccinelle/object_store.cocci | 10 ++++++++++
 object-store.h                        |  3 ++-
 object.c                              |  4 ++--
 pack-check.c                          |  2 +-
 sha1_file.c                           |  4 ++--
 8 files changed, 22 insertions(+), 9 deletions(-)

diff --git a/builtin/fast-export.c b/builtin/fast-export.c
index b0f229351d..5d524e7dd2 100644
--- a/builtin/fast-export.c
+++ b/builtin/fast-export.c
@@ -242,7 +242,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_sha1_signature(the_repository, oid->hash, buf, size, typename(type)) < 0)
 			die("sha1 mismatch in blob %s", oid_to_hex(oid));
 		object = parse_object_buffer(the_repository, oid, type,
 					     size, buf, &eaten);
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index f570e16bb6..0928ed8dd5 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -1383,7 +1383,7 @@ static void fix_unresolved_deltas(struct sha1file *f)
 		if (!base_obj->data)
 			continue;
 
-		if (check_sha1_signature(d->sha1, base_obj->data,
+		if (check_sha1_signature(the_repository, d->sha1, base_obj->data,
 				base_obj->size, typename(type)))
 			die(_("local object %s is corrupt"), sha1_to_hex(d->sha1));
 		base_obj->obj = append_obj_to_pack(f, d->sha1,
diff --git a/builtin/mktag.c b/builtin/mktag.c
index ab41735f2a..d05fdb824a 100644
--- a/builtin/mktag.c
+++ b/builtin/mktag.c
@@ -30,7 +30,9 @@ static int verify_object(const unsigned char *sha1, const char *expected_type)
 
 	if (buffer) {
 		if (type == type_from_string(expected_type))
-			ret = check_sha1_signature(repl, buffer, size, expected_type);
+			ret = check_sha1_signature(the_repository, repl,
+						   buffer, size,
+						   expected_type);
 		free(buffer);
 	}
 	return ret;
diff --git a/contrib/coccinelle/object_store.cocci b/contrib/coccinelle/object_store.cocci
index 800e0581e5..6e6e5454da 100644
--- a/contrib/coccinelle/object_store.cocci
+++ b/contrib/coccinelle/object_store.cocci
@@ -5,3 +5,13 @@ expression F;
  sha1_object_info(
 +the_repository,
  E, F)
+
+@@
+expression E;
+expression F;
+expression G;
+expression H;
+@@
+ check_sha1_signature(
++the_repository,
+ E, F, G, H)
diff --git a/object-store.h b/object-store.h
index a0e9824406..178268a048 100644
--- a/object-store.h
+++ b/object-store.h
@@ -106,7 +106,8 @@ extern void *map_sha1_file(struct repository *r, const unsigned char *sha1, unsi
  * The in-core object data should be in "map". If "map" == NULL, reads the
  * named object using the streaming interface and rehashes it on the fly.
  */
-extern int check_sha1_signature(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
+#define check_sha1_signature(r, s, m, sz, t) check_sha1_signature_##r(s, m, sz, t)
+extern int check_sha1_signature_the_repository(const unsigned char *sha1, void *buf, unsigned long size, const char *type);
 
 /*
  * Convenience for sha1_object_info_extended() with a NULL struct
diff --git a/object.c b/object.c
index a10983755c..85b0360e0a 100644
--- a/object.c
+++ b/object.c
@@ -260,7 +260,7 @@ struct object *parse_object_the_repository(const struct object_id *oid)
 	if ((obj && obj->type == OBJ_BLOB) ||
 	    (!obj && has_object_file(oid) &&
 	     sha1_object_info(the_repository, oid->hash, NULL) == OBJ_BLOB)) {
-		if (check_sha1_signature(repl, NULL, 0, NULL) < 0) {
+		if (check_sha1_signature(the_repository, repl, NULL, 0, NULL) < 0) {
 			error("sha1 mismatch %s", oid_to_hex(oid));
 			return NULL;
 		}
@@ -270,7 +270,7 @@ struct object *parse_object_the_repository(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) {
+		if (check_sha1_signature(the_repository, repl, 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 25afd59c7d..2eb07cf596 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -143,7 +143,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_sha1_signature(the_repository, entries[i].oid.hash, 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 3262075497..9ef25e6154 100644
--- a/sha1_file.c
+++ b/sha1_file.c
@@ -802,7 +802,7 @@ void *xmmap(void *start, size_t length,
 	return ret;
 }
 
-int check_sha1_signature(const unsigned char *sha1, void *map,
+int check_sha1_signature_the_repository(const unsigned char *sha1, void *map,
 			 unsigned long size, const char *type)
 {
 	unsigned char real_sha1[20];
@@ -2207,7 +2207,7 @@ int read_loose_object(const char *path,
 			git_inflate_end(&stream);
 			goto out;
 		}
-		if (check_sha1_signature(expected_sha1, *contents,
+		if (check_sha1_signature(the_repository, expected_sha1, *contents,
 					 *size, typename(*type))) {
 			error("sha1 mismatch for %s (expected %s)", path,
 			      sha1_to_hex(expected_sha1));
-- 
2.15.1.433.g936d1b9894.dirty




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux