From 2e674a9d090f0d9be71c8143ae6c0fba04a160cc Mon Sep 17 00:00:00 2001
From: Junio C Hamano <gitster@pobox.com>
Date: Fri, 7 Aug 2009 20:12:13 -0700
Subject: [PATCH 1/2] t5510: harden the way verify-pack is used

The test ignored the exit status from verify pack command, and also relied
on not seeing any delta chain statistics.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 t/t5510-fetch.sh | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/t/t5510-fetch.sh b/t/t5510-fetch.sh
index 52094e78dc..61a02a91a1 100755
--- a/t/t5510-fetch.sh
+++ b/t/t5510-fetch.sh
@@ -9,6 +9,11 @@ test_description='Per branch config variables affects "git fetch".
 
 D=`pwd`
 
+test_bundle_object_count () {
+	git verify-pack -v "$1" >verify.out &&
+	test "$2" = $(grep '^[0-9a-f]\{40\} ' verify.out | wc -l)
+}
+
 test_expect_success setup '
 	echo >file original &&
 	git add file &&
@@ -146,6 +151,7 @@ test_expect_success 'unbundle 1' '
 	test_must_fail git fetch "$D/bundle1" master:master
 '
 
+
 test_expect_success 'bundle 1 has only 3 files ' '
 	cd "$D" &&
 	(
@@ -156,8 +162,7 @@ test_expect_success 'bundle 1 has only 3 files ' '
 		cat
 	) <bundle1 >bundle.pack &&
 	git index-pack bundle.pack &&
-	verify=$(git verify-pack -v bundle.pack) &&
-	test 4 = $(echo "$verify" | wc -l)
+	test_bundle_object_count bundle.pack 3
 '
 
 test_expect_success 'unbundle 2' '
@@ -180,7 +185,7 @@ test_expect_success 'bundle does not prerequisite objects' '
 		cat
 	) <bundle3 >bundle.pack &&
 	git index-pack bundle.pack &&
-	test 4 = $(git verify-pack -v bundle.pack | wc -l)
+	test_bundle_object_count bundle.pack 3
 '
 
 test_expect_success 'bundle should be able to create a full history' '

From 262b04fa8dce84596738fd8c0dbff52994388efa Mon Sep 17 00:00:00 2001
From: Junio C Hamano <gitster@pobox.com>
Date: Fri, 7 Aug 2009 15:36:31 -0700
Subject: [PATCH 2/2] verify-pack -v: do not report "chain length 0"

When making a histogram of delta chain length in the pack, the program
collects number of objects whose delta depth exceeds the MAX_CHAIN limit
in histogram[0], and showed it as the number of items that exceeds the
limit correctly.  HOWEVER, it also showed the same number labeled as
"chain length = 0".

In fact, we are not showing the number of objects whose chain length is
zero, i.e. the base objects.  Correct this.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 builtin-verify-pack.c | 27 +++++++++++++++++++--------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/builtin-verify-pack.c b/builtin-verify-pack.c
index 25a29f11a4..e8fd68bfac 100644
--- a/builtin-verify-pack.c
+++ b/builtin-verify-pack.c
@@ -7,10 +7,13 @@
 
 static void show_pack_info(struct packed_git *p)
 {
-	uint32_t nr_objects, i, chain_histogram[MAX_CHAIN+1];
+	uint32_t nr_objects, i;
+	int cnt;
+	unsigned long chain_histogram[MAX_CHAIN+1], baseobjects;
 
 	nr_objects = p->num_objects;
 	memset(chain_histogram, 0, sizeof(chain_histogram));
+	baseobjects = 0;
 
 	for (i = 0; i < nr_objects; i++) {
 		const unsigned char *sha1;
@@ -29,9 +32,11 @@ static void show_pack_info(struct packed_git *p)
 						 &delta_chain_length,
 						 base_sha1);
 		printf("%s ", sha1_to_hex(sha1));
-		if (!delta_chain_length)
+		if (!delta_chain_length) {
 			printf("%-6s %lu %lu %"PRIuMAX"\n",
 			       type, size, store_size, (uintmax_t)offset);
+			baseobjects++;
+		}
 		else {
 			printf("%-6s %lu %lu %"PRIuMAX" %u %s\n",
 			       type, size, store_size, (uintmax_t)offset,
@@ -43,15 +48,21 @@ static void show_pack_info(struct packed_git *p)
 		}
 	}
 
-	for (i = 0; i <= MAX_CHAIN; i++) {
-		if (!chain_histogram[i])
+	if (baseobjects)
+		printf("non delta: %lu object%s\n",
+		       baseobjects, baseobjects > 1 ? "s" : "");
+
+	for (cnt = 1; cnt <= MAX_CHAIN; cnt++) {
+		if (!chain_histogram[cnt])
 			continue;
-		printf("chain length = %"PRIu32": %"PRIu32" object%s\n", i,
-		       chain_histogram[i], chain_histogram[i] > 1 ? "s" : "");
+		printf("chain length = %d: %lu object%s\n", cnt,
+		       chain_histogram[cnt],
+		       chain_histogram[cnt] > 1 ? "s" : "");
 	}
 	if (chain_histogram[0])
-		printf("chain length > %d: %"PRIu32" object%s\n", MAX_CHAIN,
-		       chain_histogram[0], chain_histogram[0] > 1 ? "s" : "");
+		printf("chain length > %d: %lu object%s\n", MAX_CHAIN,
+		       chain_histogram[0],
+		       chain_histogram[0] > 1 ? "s" : "");
 }
 
 static int verify_one_pack(const char *path, int verbose)