diff options
author | Ian Wetherbee <wetherbeei@google.com> | 2012-06-06 19:29:34 -0700 |
---|---|---|
committer | Ian Wetherbee <wetherbeei@google.com> | 2012-06-15 15:16:36 -0700 |
commit | b1e4d6bca251c1919674a46c982965ee12fdcfaa (patch) | |
tree | a8ddb0d869f7dd81587c838f85aaee98e0bd348c /org.eclipse.jgit.test | |
parent | fe1f1b8f8aba60fdd1ad6f0f72e9c9180978cc60 (diff) | |
download | jgit-b1e4d6bca251c1919674a46c982965ee12fdcfaa.tar.gz jgit-b1e4d6bca251c1919674a46c982965ee12fdcfaa.zip |
ReceivePack supports InputStream data after pack
When receiving a pack, data buffered after the pack can restored
to the InputStream if the stream supports mark and reset.
Change-Id: If04915c32c91be28db8df7e8491ed3e9fe0e1608
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java index d779300e15..9514aaa5ee 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/PackParserTest.java @@ -304,6 +304,154 @@ public class PackParserTest extends RepositoryTestCase { } } + @Test + public void testNonMarkingInputStream() throws Exception { + TestRepository d = new TestRepository(db); + RevBlob a = d.blob("a"); + + TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); + packHeader(pack, 1); + pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + a.copyRawTo(pack); + deflate(pack, new byte[] { 0x1, 0x1, 0x1, 'b' }); + digest(pack); + + InputStream in = new ByteArrayInputStream(pack.toByteArray()) { + @Override + public boolean markSupported() { + return false; + } + + @Override + public void mark(int maxlength) { + fail("Mark should not be called"); + } + }; + + PackParser p = index(in); + p.setAllowThin(true); + p.setCheckEofAfterPackFooter(false); + p.setExpectDataAfterPackFooter(true); + + try { + p.parse(NullProgressMonitor.INSTANCE); + fail("PackParser should have failed"); + } catch (IOException e) { + assertEquals(e.getMessage(), + JGitText.get().inputStreamMustSupportMark); + } + } + + @Test + public void testDataAfterPackFooterSingleRead() throws Exception { + TestRepository d = new TestRepository(db); + RevBlob a = d.blob("a"); + + TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32*1024); + packHeader(pack, 1); + pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + a.copyRawTo(pack); + deflate(pack, new byte[] { 0x1, 0x1, 0x1, 'b' }); + digest(pack); + + byte packData[] = pack.toByteArray(); + byte streamData[] = new byte[packData.length + 1]; + System.arraycopy(packData, 0, streamData, 0, packData.length); + streamData[packData.length] = 0x7e; + + InputStream in = new ByteArrayInputStream(streamData); + PackParser p = index(in); + p.setAllowThin(true); + p.setCheckEofAfterPackFooter(false); + p.setExpectDataAfterPackFooter(true); + + p.parse(NullProgressMonitor.INSTANCE); + + assertEquals(0x7e, in.read()); + } + + @Test + public void testDataAfterPackFooterSplitObjectRead() throws Exception { + final byte[] data = Constants.encode("0123456789"); + + // Build a pack ~17k + int objects = 900; + TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32 * 1024); + packHeader(pack, objects); + + for (int i = 0; i < objects; i++) { + pack.write((Constants.OBJ_BLOB) << 4 | 10); + deflate(pack, data); + } + digest(pack); + + byte packData[] = pack.toByteArray(); + byte streamData[] = new byte[packData.length + 1]; + System.arraycopy(packData, 0, streamData, 0, packData.length); + streamData[packData.length] = 0x7e; + InputStream in = new ByteArrayInputStream(streamData); + PackParser p = index(in); + p.setAllowThin(true); + p.setCheckEofAfterPackFooter(false); + p.setExpectDataAfterPackFooter(true); + + p.parse(NullProgressMonitor.INSTANCE); + + assertEquals(0x7e, in.read()); + } + + @Test + public void testDataAfterPackFooterSplitHeaderRead() throws Exception { + TestRepository d = new TestRepository(db); + final byte[] data = Constants.encode("a"); + RevBlob b = d.blob(data); + + int objects = 248; + TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(32 * 1024); + packHeader(pack, objects + 1); + int offset = 13; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < offset; i++) + sb.append(i); + offset = sb.toString().length(); + int lenByte = (Constants.OBJ_BLOB) << 4 | (offset & 0x0F); + offset >>= 4; + if (offset > 0) + lenByte |= 1 << 7; + pack.write(lenByte); + while (offset > 0) { + lenByte = offset & 0x7F; + offset >>= 6; + if (offset > 0) + lenByte |= 1 << 7; + pack.write(lenByte); + } + deflate(pack, Constants.encode(sb.toString())); + + for (int i = 0; i < objects; i++) { + // The last pack header written falls across the 8192 byte boundary + // between [8189:8210] + pack.write((Constants.OBJ_REF_DELTA) << 4 | 4); + b.copyRawTo(pack); + deflate(pack, new byte[] { 0x1, 0x1, 0x1, 'b' }); + } + digest(pack); + + byte packData[] = pack.toByteArray(); + byte streamData[] = new byte[packData.length + 1]; + System.arraycopy(packData, 0, streamData, 0, packData.length); + streamData[packData.length] = 0x7e; + InputStream in = new ByteArrayInputStream(streamData); + PackParser p = index(in); + p.setAllowThin(true); + p.setCheckEofAfterPackFooter(false); + p.setExpectDataAfterPackFooter(true); + + p.parse(NullProgressMonitor.INSTANCE); + + assertEquals(0x7e, in.read()); + } + private void packHeader(TemporaryBuffer.Heap tinyPack, int cnt) throws IOException { final byte[] hdr = new byte[8]; |