git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[JGIT PATCH 3/5] Test case for pack index CRC32 when written by PackWriter

From
Shawn O. Pearce <spearce@spearce.org>
Date
Mar 26, 2009, 01:21 UTC
Message-ID
<1238030515-31768-3-git-send-email-spearce@spearce.org>
In-Reply-To
<1238030515-31768-2-git-send-email-spearce@spearce.org>
Suggested-by: Daniel Cheng (aka SDiZ) <j16sdiz+freenet@gmail.com>
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 .../tst/org/spearce/jgit/lib/PackWriterTest.java   |   33 ++++++++++++++++++++
 1 files changed, 33 insertions(+), 0 deletions(-)
diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
index 46616e3..636059f 100644
--- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
+++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackWriterTest.java
@@ -40,6 +40,7 @@
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
+import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.util.ArrayList;
@@ -353,6 +354,37 @@ public void testWritePack4SizeThinVsNoThin() throws Exception {
 		assertTrue(sizePack4 > sizePack4Thin);
 	}
 
+	public void testWriteIndex() throws Exception {
+		writer.setIndexVersion(2);
+		writeVerifyPack4(false);
+
+		// Validate that IndexPack came up with the right CRC32 value.
+		final PackIndex idx1 = PackIndex.open(indexFile);
+		assertTrue(idx1 instanceof PackIndexV2);
+		assertEquals(0x4743F1E4L, idx1.findCRC32(ObjectId
+				.fromString("82c6b885ff600be425b4ea96dee75dca255b69e7")));
+
+		// Validate that an index written by PackWriter is the same.
+		final File idx2File = new File(indexFile.getAbsolutePath() + ".2");
+		final FileOutputStream is = new FileOutputStream(idx2File);
+		try {
+			writer.writeIndex(is);
+		} finally {
+			is.close();
+		}
+		final PackIndex idx2 = PackIndex.open(idx2File);
+		assertTrue(idx2 instanceof PackIndexV2);
+		assertEquals(idx1.getObjectCount(), idx2.getObjectCount());
+		assertEquals(idx1.getOffset64Count(), idx2.getOffset64Count());
+
+		for (int i = 0; i < idx1.getObjectCount(); i++) {
+			final ObjectId id = idx1.getObjectId(i);
+			assertEquals(id, idx2.getObjectId(i));
+			assertEquals(idx1.findOffset(id), idx2.findOffset(id));
+			assertEquals(idx1.findCRC32(id), idx2.findCRC32(id));
+		}
+	}
+
 	// TODO: testWritePackDeltasCycle()
 	// TODO: testWritePackDeltasDepth()
 
@@ -469,6 +501,7 @@ private void verifyOpenPack(final boolean thin) throws IOException {
 		final IndexPack indexer = new IndexPack(db, is, packBase);
 		indexer.setKeepEmpty(true);
 		indexer.setFixThin(thin);
+		indexer.setIndexVersion(2);
 		indexer.index(new TextProgressMonitor());
 		pack = new PackFile(indexFile, packFile);
 	}
-- 
1.6.2.1.471.g682837
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 3 of 11 in “Remove dead/unused reset method from CountingOutputStream”
  1. 1/5 Remove dead/unused reset method from CountingOutputStreamShawn O. Pearce, Mar 26, 2009
  2. 2/5 Implement CRC32 computation during PackWriterShawn O. Pearce, Mar 26, 2009
  3. 3/5 Test case for pack index CRC32 when written by PackWriterShawn O. Pearce, Mar 26, 2009
  4. 4/5 Write the pack header in one shotShawn O. Pearce, Mar 26, 2009
  5. 5/5 Use Deflater directly in PackWriterShawn O. Pearce, Mar 26, 2009
  6. Daniel ChengMar 26, 2009
  7. Daniel ChengMar 26, 2009
  8. Robin RosenbergMar 27, 2009
  9. Shawn O. PearceMar 27, 2009
  10. Shawn O. PearceMar 27, 2009
  11. Robin RosenbergMar 27, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.