public virtual void TestWhole_SmallObject() { int type = Constants.OBJ_BLOB; byte[] data = GetRng().NextBytes(300); RevBlob id = tr.Blob(data); tr.Branch("master").Commit().Add("A", id).Create(); tr.PackAndPrune(); NUnit.Framework.Assert.IsTrue(wc.Has(id), "has blob"); ObjectLoader ol = wc.Open(id); NUnit.Framework.Assert.IsNotNull(ol, "created loader"); NUnit.Framework.Assert.AreEqual(type, ol.GetType()); NUnit.Framework.Assert.AreEqual(data.Length, ol.GetSize()); NUnit.Framework.Assert.IsFalse(ol.IsLarge(), "is not large"); NUnit.Framework.Assert.IsTrue(Arrays.Equals(data, ol.GetCachedBytes()), "same content" ); ObjectStream @in = ol.OpenStream(); NUnit.Framework.Assert.IsNotNull(@in, "have stream"); NUnit.Framework.Assert.AreEqual(type, @in.GetType()); NUnit.Framework.Assert.AreEqual(data.Length, @in.GetSize()); byte[] data2 = new byte[data.Length]; IOUtil.ReadFully(@in, data2, 0, data.Length); NUnit.Framework.Assert.IsTrue(Arrays.Equals(data2, data), "same content"); NUnit.Framework.Assert.AreEqual(-1, @in.Read(), "stream at EOF"); @in.Close(); }
public override void SetUp() { base.SetUp(); src = CreateBareRepository(); dst = CreateBareRepository(); // Fill dst with a some common history. // TestRepository d = new TestRepository <Repository>(dst); a = d.Blob("a"); A = d.Commit(d.Tree(d.File("a", a))); B = d.Commit().Parent(A).Create(); d.Update(R_MASTER, B); // Clone from dst into src // NGit.Transport.Transport t = NGit.Transport.Transport.Open(src, UriOf(dst)); try { t.Fetch(PM, Collections.Singleton(new RefSpec("+refs/*:refs/*"))); NUnit.Framework.Assert.AreEqual(B, src.Resolve(R_MASTER)); } finally { t.Close(); } // Now put private stuff into dst. // b = d.Blob("b"); P = d.Commit(d.Tree(d.File("b", b)), A); d.Update(R_PRIVATE, P); }
public virtual void TestEditEdit() { Note edit1 = NewNote("edit1"); Note edit2 = NewNote("edit2"); Note result = merger.Merge(baseNote, edit1, edit2, reader, inserter); NUnit.Framework.Assert.AreEqual(result, noteOn); // same note NUnit.Framework.Assert.AreEqual(result.GetData(), tr.Blob("edit1edit2")); result = merger.Merge(baseNote, edit2, edit1, reader, inserter); NUnit.Framework.Assert.AreEqual(result, noteOn); // same note NUnit.Framework.Assert.AreEqual(result.GetData(), tr.Blob("edit2edit1")); }
public virtual void TestAbbreviateLooseBlob() { ObjectId id = test.Blob("test"); NUnit.Framework.Assert.AreEqual(id.Abbreviate(2), reader.Abbreviate(id, 2)); NUnit.Framework.Assert.AreEqual(id.Abbreviate(7), reader.Abbreviate(id, 7)); NUnit.Framework.Assert.AreEqual(id.Abbreviate(8), reader.Abbreviate(id, 8)); NUnit.Framework.Assert.AreEqual(id.Abbreviate(10), reader.Abbreviate(id, 10)); NUnit.Framework.Assert.AreEqual(id.Abbreviate(16), reader.Abbreviate(id, 16)); ICollection <ObjectId> matches = reader.Resolve(reader.Abbreviate(id, 8)); NUnit.Framework.Assert.IsNotNull(matches); NUnit.Framework.Assert.AreEqual(1, matches.Count); NUnit.Framework.Assert.AreEqual(id, matches.Iterator().Next()); NUnit.Framework.Assert.AreEqual(id, db.Resolve(reader.Abbreviate(id, 8).Name)); }
public virtual void TestDataAfterPackFooterSplitHeaderRead() { TestRepository d = new TestRepository <FileRepository>(db); 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 & unchecked ((int)(0x0F))); offset >>= 4; if (offset > 0) { lenByte |= 1 << 7; } pack.Write(lenByte); while (offset > 0) { lenByte = offset & unchecked ((int)(0x7F)); offset >>= 6; if (offset > 0) { lenByte |= 1 << 7; } pack.Write(lenByte); } Deflate(pack, Constants.Encode(sb.ToString())); for (int i_1 = 0; i_1 < objects; i_1++) { // 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[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); } Digest(pack); byte[] packData = pack.ToByteArray(); byte[] streamData = new byte[packData.Length + 1]; System.Array.Copy(packData, 0, streamData, 0, packData.Length); streamData[packData.Length] = unchecked ((int)(0x7e)); InputStream @in = new ByteArrayInputStream(streamData); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x7e)), @in.Read()); }
public virtual void TestNonMarkingInputStream() { TestRepository d = new TestRepository <FileRepository>(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[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); InputStream @in = new _ByteArrayInputStream_319(pack.ToByteArray()); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (IOException e) { NUnit.Framework.Assert.AreEqual(e.Message, JGitText.Get().inputStreamMustSupportMark ); } }
public virtual void TestDataAfterPackFooterSingleRead() { TestRepository d = new TestRepository <FileRepository>(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[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); byte[] packData = pack.ToByteArray(); byte[] streamData = new byte[packData.Length + 1]; System.Array.Copy(packData, 0, streamData, 0, packData.Length); streamData[packData.Length] = unchecked ((int)(0x7e)); InputStream @in = new ByteArrayInputStream(streamData); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x7e)), @in.Read()); }
public virtual void TestMaxObjectSizeFullBlob() { TestRepository d = new TestRepository <FileRepository>(db); byte[] data = Constants.Encode("0123456789"); d.Blob(data); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_BLOB) << 4 | 10); Deflate(pack, data); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetMaxObjectSizeLimit(11); p.Parse(NullProgressMonitor.INSTANCE); p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetMaxObjectSizeLimit(10); p.Parse(NullProgressMonitor.INSTANCE); p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetMaxObjectSizeLimit(9); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (TooLargeObjectInPackException e) { NUnit.Framework.Assert.IsTrue(e.Message.Contains("10")); // obj size NUnit.Framework.Assert.IsTrue(e.Message.Contains("9")); } }
public virtual void TestMaxObjectSizeDeltaResultSize() { TestRepository d = new TestRepository <FileRepository>(db); RevBlob a = d.Blob("0123456789"); 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[] { 10, 11, 1, (byte)('a') }); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.SetMaxObjectSizeLimit(11); p.Parse(NullProgressMonitor.INSTANCE); p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.SetMaxObjectSizeLimit(10); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (TooLargeObjectInPackException e) { NUnit.Framework.Assert.IsTrue(e.Message.Contains("11")); // result obj size NUnit.Framework.Assert.IsTrue(e.Message.Contains("10")); } }
public virtual void TestPackWithTrailingGarbage() { TestRepository d = new TestRepository <FileRepository>(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[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); PackParser p = Index(new UnionInputStream(new ByteArrayInputStream(pack.ToByteArray ()), new ByteArrayInputStream(new byte[] { unchecked ((int)(0x7e)) }))); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(true); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("Pack with trailing garbage was accepted"); } catch (IOException err) { NUnit.Framework.Assert.AreEqual(MessageFormat.Format(JGitText.Get().expectedEOFReceived , "\\x7e"), err.Message); } }
public override void SetUp() { base.SetUp(); tr = new TestRepository <Repository>(db); reader = db.NewObjectReader(); inserter = db.NewObjectInserter(); merger = new DefaultNoteMerger(); noteOn = tr.Blob("a"); baseNote = NewNote("data"); }
public override void SetUp() { base.SetUp(); tr = new TestRepository<Repository>(db); reader = db.NewObjectReader(); inserter = db.NewObjectInserter(); merger = new DefaultNoteMerger(); noteOn = tr.Blob("a"); baseNote = NewNote("data"); }
public virtual void TestUsingHiddenDeltaBaseFails() { byte[] delta = new byte[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('c') }; TestRepository <Repository> s = new TestRepository <Repository>(src); RevCommit N = s.Commit().Parent(B).Add("q", s.Blob(BinaryDelta.Apply(dst.Open(b). GetCachedBytes(), delta))).Create(); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 3); Copy(pack, src.Open(N)); Copy(pack, src.Open(s.ParseBody(N).Tree)); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); b.CopyRawTo(pack); Deflate(pack, delta); Digest(pack); TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024); PacketLineOut inPckLine = new PacketLineOut(inBuf); inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s" + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS); inPckLine.End(); pack.WriteTo(inBuf, PM); TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024); ReceivePack rp = new ReceivePack(dst); rp.SetCheckReceivedObjects(true); rp.SetCheckReferencedObjectsAreReachable(true); rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook()); try { Receive(rp, inBuf, outBuf); NUnit.Framework.Assert.Fail("Expected UnpackException"); } catch (UnpackException failed) { Exception err = failed.InnerException; NUnit.Framework.Assert.IsTrue(err is MissingObjectException); MissingObjectException moe = (MissingObjectException)err; NUnit.Framework.Assert.AreEqual(b, moe.GetObjectId()); } PacketLineIn r = AsPacketLineIn(outBuf); string master = r.ReadString(); int nul = master.IndexOf('\0'); NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list"); NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring (master, 0, nul)); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + b.Name, r.ReadString ()); NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString ()); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); }
public virtual void TestUsingUnknownBlobFails() { // Try to use the 'n' blob that is not on the server. // TestRepository <Repository> s = new TestRepository <Repository>(src); RevBlob n = s.Blob("n"); RevCommit N = s.Commit().Parent(B).Add("q", n).Create(); // But don't include it in the pack. // TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 2); Copy(pack, src.Open(N)); Copy(pack, src.Open(s.ParseBody(N).Tree)); Digest(pack); TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024); PacketLineOut inPckLine = new PacketLineOut(inBuf); inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s" + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS); inPckLine.End(); pack.WriteTo(inBuf, PM); TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024); ReceivePack rp = new ReceivePack(dst); rp.SetCheckReceivedObjects(true); rp.SetCheckReferencedObjectsAreReachable(true); rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook()); try { Receive(rp, inBuf, outBuf); NUnit.Framework.Assert.Fail("Expected UnpackException"); } catch (UnpackException failed) { Exception err = failed.InnerException; NUnit.Framework.Assert.IsTrue(err is MissingObjectException); MissingObjectException moe = (MissingObjectException)err; NUnit.Framework.Assert.AreEqual(n, moe.GetObjectId()); } PacketLineIn r = AsPacketLineIn(outBuf); string master = r.ReadString(); int nul = master.IndexOf('\0'); NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list"); NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring (master, 0, nul)); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + n.Name, r.ReadString ()); NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString ()); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); }
public override void SetUp() { base.SetUp(); tr = new TestRepository <Repository>(db); reader = db.NewObjectReader(); inserter = db.NewObjectInserter(); noRoot = NoteMap.NewMap(null, reader); empty = NoteMap.NewEmptyMap(); noteAId = tr.Blob("a"); noteAContent = "noteAContent"; noteABlob = tr.Blob(noteAContent); sampleTree_a = tr.Commit().Add(noteAId.Name, noteABlob).Create(); tr.ParseBody(sampleTree_a); map_a = NoteMap.Read(reader, sampleTree_a); noteBId = tr.Blob("b"); noteBContent = "noteBContent"; noteBBlob = tr.Blob(noteBContent); sampleTree_a_b = tr.Commit().Add(noteAId.Name, noteABlob).Add(noteBId.Name, noteBBlob ).Create(); tr.ParseBody(sampleTree_a_b); map_a_b = NoteMap.Read(reader, sampleTree_a_b); }
public virtual void TestExclude() { FileRepository repo = CreateBareRepository(); TestRepository <FileRepository> testRepo = new TestRepository <FileRepository>(repo ); BranchBuilder bb = testRepo.Branch("refs/heads/master"); RevBlob contentA = testRepo.Blob("A"); RevCommit c1 = bb.Commit().Add("f", contentA).Create(); testRepo.GetRevWalk().ParseHeaders(c1); PackIndex pf1 = WritePack(repo, Sharpen.Collections.Singleton(c1), Sharpen.Collections .EmptySet <PackIndex>()); AssertContent(pf1, Arrays.AsList(c1.Id, c1.Tree.Id, contentA.Id)); RevBlob contentB = testRepo.Blob("B"); RevCommit c2 = bb.Commit().Add("f", contentB).Create(); testRepo.GetRevWalk().ParseHeaders(c2); PackIndex pf2 = WritePack(repo, Sharpen.Collections.Singleton(c2), Sharpen.Collections .Singleton(pf1)); AssertContent(pf2, Arrays.AsList(c2.Id, c2.Tree.Id, contentB.Id)); }
public virtual void TestTinyThinPack() { TestRepository d = new TestRepository <FileRepository>(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[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.Parse(NullProgressMonitor.INSTANCE); }
public virtual void TestPackWithDuplicateBlob() { byte[] data = Constants.Encode("0123456789abcdefg"); TestRepository <Repository> d = new TestRepository <Repository>(db); NUnit.Framework.Assert.IsTrue(db.HasObject(d.Blob(data))); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_BLOB) << 4 | unchecked ((int)(0x80)) | 1); pack.Write(1); Deflate(pack, data); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(false); p.Parse(NullProgressMonitor.INSTANCE); }
public virtual void TestTinyThinPack() { 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[] { unchecked ((int)(0x1)), unchecked ((int)(0x1)), unchecked ( (int)(0x1)), (byte)('b') }); Digest(pack); byte[] raw = pack.ToByteArray(); IndexPack ip = IndexPack.Create(db, new ByteArrayInputStream(raw)); ip.SetFixThin(true); ip.Index(NullProgressMonitor.INSTANCE); ip.RenameAndOpenPack(); }
/// <exception cref="System.Exception"></exception> public override void SetUp() { base.SetUp(); tr = new TestRepository<Repository>(db); git = new Git(db); // commit something WriteTrashFile("Test.txt", "Hello world"); git.Add().AddFilepattern("Test.txt").Call(); git.Commit().SetMessage("Initial commit").Call(); // create a master branch and switch to it git.BranchCreate().SetName("test").Call(); RefUpdate rup = db.UpdateRef(Constants.HEAD); rup.Link("refs/heads/test"); // commit something on the test branch WriteTrashFile("Test.txt", "Some change"); git.Add().AddFilepattern("Test.txt").Call(); git.Commit().SetMessage("Second commit").Call(); RevBlob blob = tr.Blob("blob-not-in-master-branch"); git.Tag().SetName("tag-for-blob").SetObjectId(blob).Call(); }
/// <exception cref="System.Exception"></exception> public override void SetUp() { base.SetUp(); tr = new TestRepository <Repository>(db); git = new Git(db); // commit something WriteTrashFile("Test.txt", "Hello world"); git.Add().AddFilepattern("Test.txt").Call(); git.Commit().SetMessage("Initial commit").Call(); // create a master branch and switch to it git.BranchCreate().SetName("test").Call(); RefUpdate rup = db.UpdateRef(Constants.HEAD); rup.Link("refs/heads/test"); // commit something on the test branch WriteTrashFile("Test.txt", "Some change"); git.Add().AddFilepattern("Test.txt").Call(); git.Commit().SetMessage("Second commit").Call(); RevBlob blob = tr.Blob("blob-not-in-master-branch"); git.Tag().SetName("tag-for-blob").SetObjectId(blob).Call(); }
public virtual void TestMaxObjectSizeDeltaResultSize() { TestRepository d = new TestRepository(db); RevBlob a = d.Blob("0123456789"); 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[] { 10, 11, 1, (byte)('a') }); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.SetMaxObjectSizeLimit(11); p.Parse(NullProgressMonitor.INSTANCE); p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.SetMaxObjectSizeLimit(10); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (TooLargeObjectInPackException e) { NUnit.Framework.Assert.IsTrue(e.Message.Contains("11")); // result obj size NUnit.Framework.Assert.IsTrue(e.Message.Contains("10")); } }
public virtual void PackRefs_looseRefPacked() { RevBlob a = tr.Blob("a"); tr.LightweightTag("t", a); gc.PackRefs(); NUnit.Framework.Assert.AreEqual(repo.GetRef("t").GetStorage(), RefStorage.PACKED); }
public override void SetUp() { base.SetUp(); tr = new TestRepository<Repository>(db); reader = db.NewObjectReader(); inserter = db.NewObjectInserter(); noRoot = NoteMap.NewMap(null, reader); empty = NoteMap.NewEmptyMap(); noteAId = tr.Blob("a"); noteAContent = "noteAContent"; noteABlob = tr.Blob(noteAContent); sampleTree_a = tr.Commit().Add(noteAId.Name, noteABlob).Create(); tr.ParseBody(sampleTree_a); map_a = NoteMap.Read(reader, sampleTree_a); noteBId = tr.Blob("b"); noteBContent = "noteBContent"; noteBBlob = tr.Blob(noteBContent); sampleTree_a_b = tr.Commit().Add(noteAId.Name, noteABlob).Add(noteBId.Name, noteBBlob ).Create(); tr.ParseBody(sampleTree_a_b); map_a_b = NoteMap.Read(reader, sampleTree_a_b); }
public override void SetUp() { base.SetUp(); src = CreateBareRepository(); dst = CreateBareRepository(); // Fill dst with a some common history. // TestRepository d = new TestRepository<Repository>(dst); a = d.Blob("a"); A = d.Commit(d.Tree(d.File("a", a))); B = d.Commit().Parent(A).Create(); d.Update(R_MASTER, B); // Clone from dst into src // NGit.Transport.Transport t = NGit.Transport.Transport.Open(src, UriOf(dst)); try { t.Fetch(PM, Collections.Singleton(new RefSpec("+refs/*:refs/*"))); NUnit.Framework.Assert.AreEqual(B, src.Resolve(R_MASTER)); } finally { t.Close(); } // Now put private stuff into dst. // b = d.Blob("b"); P = d.Commit(d.Tree(d.File("b", b)), A); d.Update(R_PRIVATE, P); }
public virtual void TestReadFlatTwoNotes() { RevBlob a = tr.Blob("a"); RevBlob b = tr.Blob("b"); RevBlob data1 = tr.Blob("data1"); RevBlob data2 = tr.Blob("data2"); RevCommit r = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Create(); // // // tr.ParseBody(r); NoteMap map = NoteMap.Read(reader, r); NUnit.Framework.Assert.IsNotNull(map, "have map"); NUnit.Framework.Assert.IsTrue(map.Contains(a), "has note for a"); NUnit.Framework.Assert.IsTrue(map.Contains(b), "has note for b"); NUnit.Framework.Assert.AreEqual(data1, map.Get(a)); NUnit.Framework.Assert.AreEqual(data2, map.Get(b)); NUnit.Framework.Assert.IsFalse(map.Contains(data1), "no note for data1"); NUnit.Framework.Assert.IsNull(map.Get(data1), "no note for data1"); }
public virtual void TestUsingHiddenDeltaBaseFails() { byte[] delta = new byte[] { unchecked((int)(0x1)), unchecked((int)(0x1)), unchecked( (int)(0x1)), (byte)('c') }; TestRepository<Repository> s = new TestRepository<Repository>(src); RevCommit N = s.Commit().Parent(B).Add("q", s.Blob(BinaryDelta.Apply(dst.Open(b). GetCachedBytes(), delta))).Create(); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 3); Copy(pack, src.Open(N)); Copy(pack, src.Open(s.ParseBody(N).Tree)); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 4); b.CopyRawTo(pack); Deflate(pack, delta); Digest(pack); TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024); PacketLineOut inPckLine = new PacketLineOut(inBuf); inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s" + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS); inPckLine.End(); pack.WriteTo(inBuf, PM); TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024); ReceivePack rp = new ReceivePack(dst); rp.SetCheckReceivedObjects(true); rp.SetCheckReferencedObjectsAreReachable(true); rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook()); try { Receive(rp, inBuf, outBuf); NUnit.Framework.Assert.Fail("Expected UnpackException"); } catch (UnpackException failed) { Exception err = failed.InnerException; NUnit.Framework.Assert.IsTrue(err is MissingObjectException); MissingObjectException moe = (MissingObjectException)err; NUnit.Framework.Assert.AreEqual(b, moe.GetObjectId()); } PacketLineIn r = AsPacketLineIn(outBuf); string master = r.ReadString(); int nul = master.IndexOf('\0'); NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list"); NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring (master, 0, nul)); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); NUnit.Framework.Assert.AreEqual("unpack error Missing blob " + b.Name, r.ReadString ()); NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString ()); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); }
public virtual void TestUsingUnknownTreeFails() { TestRepository<Repository> s = new TestRepository<Repository>(src); RevCommit N = s.Commit().Parent(B).Add("q", s.Blob("a")).Create(); RevTree t = s.ParseBody(N).Tree; // Don't include the tree in the pack. // TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); Copy(pack, src.Open(N)); Digest(pack); TemporaryBuffer.Heap inBuf = new TemporaryBuffer.Heap(1024); PacketLineOut inPckLine = new PacketLineOut(inBuf); inPckLine.WriteString(ObjectId.ZeroId.Name + ' ' + N.Name + ' ' + "refs/heads/s" + '\0' + BasePackPushConnection.CAPABILITY_REPORT_STATUS); inPckLine.End(); pack.WriteTo(inBuf, PM); TemporaryBuffer.Heap outBuf = new TemporaryBuffer.Heap(1024); ReceivePack rp = new ReceivePack(dst); rp.SetCheckReceivedObjects(true); rp.SetCheckReferencedObjectsAreReachable(true); rp.SetAdvertiseRefsHook(new ReceivePackAdvertiseRefsHookTest.HidePrivateHook()); try { Receive(rp, inBuf, outBuf); NUnit.Framework.Assert.Fail("Expected UnpackException"); } catch (UnpackException failed) { Exception err = failed.InnerException; NUnit.Framework.Assert.IsTrue(err is MissingObjectException); MissingObjectException moe = (MissingObjectException)err; NUnit.Framework.Assert.AreEqual(t, moe.GetObjectId()); } PacketLineIn r = AsPacketLineIn(outBuf); string master = r.ReadString(); int nul = master.IndexOf('\0'); NUnit.Framework.Assert.IsTrue(nul > 0, "has capability list"); NUnit.Framework.Assert.AreEqual(B.Name + ' ' + R_MASTER, Sharpen.Runtime.Substring (master, 0, nul)); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); NUnit.Framework.Assert.AreEqual("unpack error Missing tree " + t.Name, r.ReadString ()); NUnit.Framework.Assert.AreEqual("ng refs/heads/s n/a (unpacker error)", r.ReadString ()); NUnit.Framework.Assert.AreSame(PacketLineIn.END, r.ReadString()); }
// // // // // /// <exception cref="System.Exception"></exception> private ObjectId Blob(string content) { return(testDb.Blob(content).Copy()); }
/// <exception cref="System.Exception"></exception> protected internal virtual RevBlob Blob(string content) { return(util.Blob(content)); }
public virtual void TestMaxObjectSizeFullBlob() { TestRepository d = new TestRepository(db); byte[] data = Constants.Encode("0123456789"); d.Blob(data); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_BLOB) << 4 | 10); Deflate(pack, data); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetMaxObjectSizeLimit(11); p.Parse(NullProgressMonitor.INSTANCE); p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetMaxObjectSizeLimit(10); p.Parse(NullProgressMonitor.INSTANCE); p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetMaxObjectSizeLimit(9); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (TooLargeObjectInPackException e) { NUnit.Framework.Assert.IsTrue(e.Message.Contains("10")); // obj size NUnit.Framework.Assert.IsTrue(e.Message.Contains("9")); } }
public virtual void TestPackWithTrailingGarbage() { 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[] { unchecked((int)(0x1)), unchecked((int)(0x1)), unchecked( (int)(0x1)), (byte)('b') }); Digest(pack); PackParser p = Index(new UnionInputStream(new ByteArrayInputStream(pack.ToByteArray ()), new ByteArrayInputStream(new byte[] { unchecked((int)(0x7e)) }))); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(true); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("Pack with trailing garbage was accepted"); } catch (IOException err) { NUnit.Framework.Assert.AreEqual(MessageFormat.Format(JGitText.Get().expectedEOFReceived , "\\x7e"), err.Message); } }
public virtual void TestDataAfterPackFooterSplitHeaderRead() { TestRepository d = new TestRepository<FileRepository>(db); 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 & unchecked((int)(0x0F))); offset >>= 4; if (offset > 0) { lenByte |= 1 << 7; } pack.Write(lenByte); while (offset > 0) { lenByte = offset & unchecked((int)(0x7F)); offset >>= 6; if (offset > 0) { lenByte |= 1 << 7; } pack.Write(lenByte); } Deflate(pack, Constants.Encode(sb.ToString())); for (int i_1 = 0; i_1 < objects; i_1++) { // 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[] { unchecked((int)(0x1)), unchecked((int)(0x1)), unchecked( (int)(0x1)), (byte)('b') }); } Digest(pack); byte[] packData = pack.ToByteArray(); byte[] streamData = new byte[packData.Length + 1]; System.Array.Copy(packData, 0, streamData, 0, packData.Length); streamData[packData.Length] = unchecked((int)(0x7e)); InputStream @in = new ByteArrayInputStream(streamData); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.AreEqual(unchecked((int)(0x7e)), @in.Read()); }
public virtual void TestDataAfterPackFooterSingleRead() { TestRepository d = new TestRepository<FileRepository>(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[] { unchecked((int)(0x1)), unchecked((int)(0x1)), unchecked( (int)(0x1)), (byte)('b') }); Digest(pack); byte[] packData = pack.ToByteArray(); byte[] streamData = new byte[packData.Length + 1]; System.Array.Copy(packData, 0, streamData, 0, packData.Length); streamData[packData.Length] = unchecked((int)(0x7e)); InputStream @in = new ByteArrayInputStream(streamData); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.AreEqual(unchecked((int)(0x7e)), @in.Read()); }
public virtual void TestNonMarkingInputStream() { TestRepository d = new TestRepository<FileRepository>(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[] { unchecked((int)(0x1)), unchecked((int)(0x1)), unchecked( (int)(0x1)), (byte)('b') }); Digest(pack); InputStream @in = new _ByteArrayInputStream_319(pack.ToByteArray()); PackParser p = Index(@in); p.SetAllowThin(true); p.SetCheckEofAfterPackFooter(false); p.SetExpectDataAfterPackFooter(true); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (IOException e) { NUnit.Framework.Assert.AreEqual(e.Message, JGitText.Get().inputStreamMustSupportMark ); } }
public virtual void TestPackWithDuplicateBlob() { byte[] data = Constants.Encode("0123456789abcdefg"); TestRepository<Repository> d = new TestRepository<Repository>(db); NUnit.Framework.Assert.IsTrue(db.HasObject(d.Blob(data))); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_BLOB) << 4 | unchecked((int)(0x80)) | 1); pack.Write(1); Deflate(pack, data); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(false); p.Parse(NullProgressMonitor.INSTANCE); }
public virtual void TestMaxObjectSizeDeltaBlock() { TestRepository d = new TestRepository<FileRepository>(db); RevBlob a = d.Blob("a"); TemporaryBuffer.Heap pack = new TemporaryBuffer.Heap(1024); PackHeader(pack, 1); pack.Write((Constants.OBJ_REF_DELTA) << 4 | 14); a.CopyRawTo(pack); Deflate(pack, new byte[] { 1, 11, 11, (byte)('a'), (byte)('0'), (byte)('1'), (byte )('2'), (byte)('3'), (byte)('4'), (byte)('5'), (byte)('6'), (byte)('7'), (byte)( '8'), (byte)('9') }); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.SetMaxObjectSizeLimit(14); p.Parse(NullProgressMonitor.INSTANCE); p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.SetMaxObjectSizeLimit(13); try { p.Parse(NullProgressMonitor.INSTANCE); NUnit.Framework.Assert.Fail("PackParser should have failed"); } catch (TooLargeObjectInPackException e) { NUnit.Framework.Assert.IsTrue(e.Message.Contains("13")); // max obj size NUnit.Framework.Assert.IsFalse(e.Message.Contains("14")); } }
public virtual void TestTinyThinPack() { 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[] { unchecked((int)(0x1)), unchecked((int)(0x1)), unchecked( (int)(0x1)), (byte)('b') }); Digest(pack); PackParser p = Index(new ByteArrayInputStream(pack.ToByteArray())); p.SetAllowThin(true); p.Parse(NullProgressMonitor.INSTANCE); }
public virtual void TestAddDifferentNotes() { NoteMapMerger merger = new NoteMapMerger(db, null, null); NoteMap result; NoteMap map_a_c = NoteMap.Read(reader, sampleTree_a); RevBlob noteCId = tr.Blob("c"); RevBlob noteCBlob = tr.Blob("noteCContent"); map_a_c.Set(noteCId, noteCBlob); map_a_c.WriteTree(inserter); result = merger.Merge(map_a, map_a_b, map_a_c); NUnit.Framework.Assert.AreEqual(3, CountNotes(result)); NUnit.Framework.Assert.AreEqual(noteABlob, result.Get(noteAId)); NUnit.Framework.Assert.AreEqual(noteBBlob, result.Get(noteBId)); NUnit.Framework.Assert.AreEqual(noteCBlob, result.Get(noteCId)); }