[PATCH 2/5] verify_pack(): allow a quicker verification for a pack with version 2 idx

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

 



This adds an extra flag parameter to verify_pack() so that the caller can
affect what kind of checks are performed.

For a packfile, we always validate its whole SHA-1 checksum and the pack
header.  By default, we make sure that we can unpack all the objects in
the packfile, and the unpacked data actually matches their object name.
In addition, for a pack with version 2 idx that has per-object CRC, we
verify their CRC checksum match what is recorded.

By specifying VERIFY_PACK_QUICK, you can omit the expensive per-object
unpacking and object name validation. Per-object CRC check that is done
for objects in a pack with version 2 idx file is still performed as it is
inexpensive.

Signed-off-by: Junio C Hamano <gitster@xxxxxxxxx>
---
 builtin-fsck.c        |    2 +-
 builtin-verify-pack.c |    2 +-
 http-push.c           |    2 +-
 http-walker.c         |    2 +-
 pack-check.c          |   17 +++++++++++++----
 pack.h                |    5 ++++-
 6 files changed, 21 insertions(+), 9 deletions(-)

diff --git a/builtin-fsck.c b/builtin-fsck.c
index 64dffa5..8dc7881 100644
--- a/builtin-fsck.c
+++ b/builtin-fsck.c
@@ -614,7 +614,7 @@ int cmd_fsck(int argc, const char **argv, const char *prefix)
 		prepare_packed_git();
 		for (p = packed_git; p; p = p->next)
 			/* verify gives error messages itself */
-			verify_pack(p);
+			verify_pack(p, 0);
 
 		for (p = packed_git; p; p = p->next) {
 			uint32_t j, num;
diff --git a/builtin-verify-pack.c b/builtin-verify-pack.c
index 25a29f1..42ae406 100644
--- a/builtin-verify-pack.c
+++ b/builtin-verify-pack.c
@@ -93,7 +93,7 @@ static int verify_one_pack(const char *path, int verbose)
 		return error("packfile %s not found.", arg);
 
 	install_packed_git(pack);
-	err = verify_pack(pack);
+	err = verify_pack(pack, 0);
 
 	if (verbose) {
 		if (err)
diff --git a/http-push.c b/http-push.c
index 59037df..0cd2926 100644
--- a/http-push.c
+++ b/http-push.c
@@ -809,7 +809,7 @@ static void finish_request(struct transfer_request *request)
 					lst = &((*lst)->next);
 				*lst = (*lst)->next;
 
-				if (!verify_pack(target))
+				if (!verify_pack(target, 0))
 					install_packed_git(target);
 				else
 					remote->can_update_info_refs = 0;
diff --git a/http-walker.c b/http-walker.c
index 0dbad3c..7f314b0 100644
--- a/http-walker.c
+++ b/http-walker.c
@@ -797,7 +797,7 @@ static int fetch_pack(struct walker *walker, struct alt_base *repo, unsigned cha
 		lst = &((*lst)->next);
 	*lst = (*lst)->next;
 
-	if (verify_pack(target))
+	if (verify_pack(target, 0))
 		return -1;
 	install_packed_git(target);
 
diff --git a/pack-check.c b/pack-check.c
index 2c5f521..256370c 100644
--- a/pack-check.c
+++ b/pack-check.c
@@ -42,8 +42,8 @@ int check_pack_crc(struct packed_git *p, struct pack_window **w_curs,
 	return data_crc != ntohl(*index_crc);
 }
 
-static int verify_packfile(struct packed_git *p,
-			   struct pack_window **w_curs)
+static int verify_packfile(struct packed_git *p, struct pack_window **w_curs,
+			   unsigned flag)
 {
 	off_t index_size = p->index_size;
 	const unsigned char *index_base = p->index_data;
@@ -78,6 +78,12 @@ static int verify_packfile(struct packed_git *p,
 		err = error("%s SHA1 does not match its index", p->pack_name);
 	unuse_pack(w_curs);
 
+	if ((flag & VERIFY_PACK_QUICK) && p->index_version <= 1) {
+		warning("contents not checked for %s as its .idx does not have CRC",
+			p->pack_name);
+		return err;
+	}
+
 	/*
 	 * Make sure everything reachable from idx is valid.  Since we
 	 * have verified that nr_objects matches between idx and pack,
@@ -114,6 +120,9 @@ static int verify_packfile(struct packed_git *p,
 					    sha1_to_hex(entries[i].sha1),
 					    p->pack_name, (uintmax_t)offset);
 		}
+
+		if (flag & VERIFY_PACK_QUICK)
+			continue;
 		data = unpack_entry(p, entries[i].offset, &type, &size);
 		if (!data) {
 			err = error("cannot unpack %s from %s at offset %"PRIuMAX"",
@@ -134,7 +143,7 @@ static int verify_packfile(struct packed_git *p,
 	return err;
 }
 
-int verify_pack(struct packed_git *p)
+int verify_pack(struct packed_git *p, unsigned flag)
 {
 	off_t index_size;
 	const unsigned char *index_base;
@@ -157,7 +166,7 @@ int verify_pack(struct packed_git *p)
 			    p->pack_name);
 
 	/* Verify pack file */
-	err |= verify_packfile(p, &w_curs);
+	err |= verify_packfile(p, &w_curs, flag);
 	unuse_pack(&w_curs);
 
 	return err;
diff --git a/pack.h b/pack.h
index a883334..b9e381c 100644
--- a/pack.h
+++ b/pack.h
@@ -57,7 +57,10 @@ struct pack_idx_entry {
 
 extern char *write_idx_file(char *index_name, struct pack_idx_entry **objects, int nr_objects, unsigned char *sha1);
 extern int check_pack_crc(struct packed_git *p, struct pack_window **w_curs, off_t offset, off_t len, unsigned int nr);
-extern int verify_pack(struct packed_git *);
+
+#define VERIFY_PACK_QUICK 01
+extern int verify_pack(struct packed_git *, unsigned flag);
+
 extern void fixup_pack_header_footer(int, unsigned char *, const char *, uint32_t, unsigned char *, off_t);
 extern char *index_pack_lockfile(int fd);
 
-- 
1.6.1.2.312.g5be3c

--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[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