public override void SetUp() { base.SetUp(); // index with both small (< 2^31) and big offsets idx = PackIndex.Open(JGitTestUtil.GetTestResourceFile("pack-huge.idx")); reverseIdx = new PackReverseIndex(idx); }
/// <exception cref="System.IO.IOException"></exception> private void OnOpenPack() { PackIndex idx = Idx(); byte[] buf = new byte[20]; fd.Seek(0); fd.ReadFully(buf, 0, 12); if (RawParseUtils.Match(buf, 0, Constants.PACK_SIGNATURE) != 4) { throw new IOException(JGitText.Get().notAPACKFile); } long vers = NB.DecodeUInt32(buf, 4); long packCnt = NB.DecodeUInt32(buf, 8); if (vers != 2 && vers != 3) { throw new IOException(MessageFormat.Format(JGitText.Get().unsupportedPackVersion, Sharpen.Extensions.ValueOf(vers))); } if (packCnt != idx.GetObjectCount()) { throw new PackMismatchException(MessageFormat.Format(JGitText.Get().packObjectCountMismatch , Sharpen.Extensions.ValueOf(packCnt), Sharpen.Extensions.ValueOf(idx.GetObjectCount ()), GetPackFile())); } fd.Seek(length - 20); fd.ReadFully(buf, 0, 20); if (!Arrays.Equals(buf, packChecksum)) { throw new PackMismatchException(MessageFormat.Format(JGitText.Get().packObjectCountMismatch , ObjectId.FromRaw(buf).Name, ObjectId.FromRaw(idx.packChecksum).Name, GetPackFile ())); } }
/// <exception cref="System.IO.IOException"></exception> private PackIndex Idx() { lock (this) { if (loadedIdx == null) { if (invalid) { throw new PackInvalidException(packFile); } try { PackIndex idx = PackIndex.Open(idxFile); if (packChecksum == null) { packChecksum = idx.packChecksum; } else { if (!Arrays.Equals(packChecksum, idx.packChecksum)) { throw new PackMismatchException(JGitText.Get().packChecksumMismatch); } } loadedIdx = idx; } catch (IOException e) { invalid = true; throw; } } return(loadedIdx); } }
/// <exception cref="System.IO.IOException"></exception> private PackIndex WritePack <_T0>(FileRepository repo, ICollection <_T0> want, ICollection <PackIndex> excludeObjects) where _T0 : ObjectId { PackWriter pw = new PackWriter(repo); pw.SetDeltaBaseAsOffset(true); pw.SetReuseDeltaCommits(false); foreach (PackIndex idx in excludeObjects) { pw.ExcludeObjects(idx); } pw.PreparePack(NullProgressMonitor.INSTANCE, want, Sharpen.Collections.EmptySet <ObjectId >()); string id = pw.ComputeName().GetName(); FilePath packdir = new FilePath(repo.ObjectsDirectory, "pack"); FilePath packFile = new FilePath(packdir, "pack-" + id + ".pack"); FileOutputStream packOS = new FileOutputStream(packFile); pw.WritePack(NullProgressMonitor.INSTANCE, NullProgressMonitor.INSTANCE, packOS); packOS.Close(); FilePath idxFile = new FilePath(packdir, "pack-" + id + ".idx"); FileOutputStream idxOS = new FileOutputStream(idxFile); pw.WriteIndex(idxOS); idxOS.Close(); pw.Release(); return(PackIndex.Open(idxFile)); }
/// <summary>Close the resources utilized by this repository</summary> public virtual void Close() { WindowCache.Purge(this); lock (this) { loadedIdx = null; reverseIdx = null; } }
private void AssertContent(PackIndex pi, IList <ObjectId> expected) { NUnit.Framework.Assert.AreEqual(expected.Count, pi.GetObjectCount(), "Pack index has wrong size." ); for (int i = 0; i < pi.GetObjectCount(); i++) { NUnit.Framework.Assert.IsTrue(expected.Contains(pi.GetObjectId(i)), "Pack index didn't contain the expected id " + pi.GetObjectId(i)); } }
public virtual void TestKeepFiles() { BranchBuilder bb = tr.Branch("refs/heads/master"); bb.Commit().Add("A", "A").Add("B", "B").Create(); stats = gc.GetStatistics(); NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects); NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackedObjects); NUnit.Framework.Assert.AreEqual(0, stats.numberOfPackFiles); gc.Gc(); stats = gc.GetStatistics(); NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects); NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects); NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles); Iterator <PackFile> packIt = ((ObjectDirectory)repo.ObjectDatabase).GetPacks().Iterator (); PackFile singlePack = packIt.Next(); NUnit.Framework.Assert.IsFalse(packIt.HasNext()); FilePath keepFile = new FilePath(singlePack.GetPackFile().GetPath() + ".keep"); NUnit.Framework.Assert.IsFalse(keepFile.Exists()); NUnit.Framework.Assert.IsTrue(keepFile.CreateNewFile()); bb.Commit().Add("A", "A2").Add("B", "B2").Create(); stats = gc.GetStatistics(); NUnit.Framework.Assert.AreEqual(4, stats.numberOfLooseObjects); NUnit.Framework.Assert.AreEqual(4, stats.numberOfPackedObjects); NUnit.Framework.Assert.AreEqual(1, stats.numberOfPackFiles); gc.Gc(); stats = gc.GetStatistics(); NUnit.Framework.Assert.AreEqual(0, stats.numberOfLooseObjects); NUnit.Framework.Assert.AreEqual(8, stats.numberOfPackedObjects); NUnit.Framework.Assert.AreEqual(2, stats.numberOfPackFiles); // check that no object is packed twice Iterator <PackFile> packs = ((ObjectDirectory)repo.ObjectDatabase).GetPacks().Iterator (); PackIndex ind1 = packs.Next().GetIndex(); NUnit.Framework.Assert.AreEqual(4, ind1.GetObjectCount()); PackIndex ind2 = packs.Next().GetIndex(); NUnit.Framework.Assert.AreEqual(4, ind2.GetObjectCount()); foreach (PackIndex.MutableEntry e in ind1) { if (ind2.HasObject(e.ToObjectId())) { NUnit.Framework.Assert.IsFalse(ind2.HasObject(e.ToObjectId()), "the following object is in both packfiles: " + e.ToObjectId()); } } }
/// <summary> /// Create reverse index from straight/forward pack index, by indexing all /// its entries. /// </summary> /// <remarks> /// Create reverse index from straight/forward pack index, by indexing all /// its entries. /// </remarks> /// <param name="packIndex">forward index - entries to (reverse) index.</param> public PackReverseIndex(PackIndex packIndex) { index = packIndex; long cnt = index.GetObjectCount(); long n64 = index.GetOffset64Count(); long n32 = cnt - n64; if (n32 > int.MaxValue || n64 > int.MaxValue || cnt > unchecked ((long)(0xffffffffL ))) { throw new ArgumentException(JGitText.Get().hugeIndexesAreNotSupportedByJgitYet); } offsets32 = new int[(int)n32]; offsets64 = new long[(int)n64]; nth32 = new int[offsets32.Length]; nth64 = new int[offsets64.Length]; int i32 = 0; int i64 = 0; foreach (PackIndex.MutableEntry me in index) { long o = me.GetOffset(); if (o < int.MaxValue) { offsets32[i32++] = (int)o; } else { offsets64[i64++] = o; } } Arrays.Sort(offsets32); Arrays.Sort(offsets64); int nth = 0; foreach (PackIndex.MutableEntry me_1 in index) { long o = me_1.GetOffset(); if (o < int.MaxValue) { nth32[System.Array.BinarySearch(offsets32, (int)o)] = nth++; } else { nth64[System.Array.BinarySearch(offsets64, o)] = nth++; } } }
public virtual void TestWriteIndex() { config.SetIndexVersion(2); WriteVerifyPack4(false); FilePath packFile = pack.GetPackFile(); string name = packFile.GetName(); string @base = Sharpen.Runtime.Substring(name, 0, name.LastIndexOf('.')); FilePath indexFile = new FilePath(packFile.GetParentFile(), @base + ".idx"); // Validate that IndexPack came up with the right CRC32 value. PackIndex idx1 = PackIndex.Open(indexFile); NUnit.Framework.Assert.IsTrue(idx1 is PackIndexV2); NUnit.Framework.Assert.AreEqual(unchecked ((long)(0x4743F1E4L)), idx1.FindCRC32(ObjectId .FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"))); // Validate that an index written by PackWriter is the same. FilePath idx2File = new FilePath(indexFile.GetAbsolutePath() + ".2"); FileOutputStream @is = new FileOutputStream(idx2File); try { writer.WriteIndex(@is); } finally { @is.Close(); } PackIndex idx2 = PackIndex.Open(idx2File); NUnit.Framework.Assert.IsTrue(idx2 is PackIndexV2); NUnit.Framework.Assert.AreEqual(idx1.GetObjectCount(), idx2.GetObjectCount()); NUnit.Framework.Assert.AreEqual(idx1.GetOffset64Count(), idx2.GetOffset64Count()); for (int i = 0; i < idx1.GetObjectCount(); i++) { ObjectId id = idx1.GetObjectId(i); NUnit.Framework.Assert.AreEqual(id, idx2.GetObjectId(i)); NUnit.Framework.Assert.AreEqual(idx1.FindOffset(id), idx2.FindOffset(id)); NUnit.Framework.Assert.AreEqual(idx1.FindCRC32(id), idx2.FindCRC32(id)); } }
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)); }
internal EntriesIterator(PackIndex _enclosing) { entry = InitEntry(); this._enclosing = _enclosing; }
/// <exception cref="System.Exception"></exception> public override void SetUp() { base.SetUp(); smallIdx = PackIndex.Open(GetFileForPack34be9032()); denseIdx = PackIndex.Open(GetFileForPackdf2982f28()); }