public void test2() { FileInfo packFile = GetPack("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack"); using (Stream @is = packFile.Open(System.IO.FileMode.Open, FileAccess.Read)) { var tmppack = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2")); var pack = new IndexPack(db, @is, tmppack); pack.index(new TextProgressMonitor()); var idxFile = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2.idx")); var tmpPackFile = new FileInfo(Path.Combine(trash.FullName, "tmp_pack2.pack")); using (var file = new PackFile(idxFile, tmpPackFile)) { Assert.IsTrue(file.HasObject(ObjectId.FromString("02ba32d3649e510002c21651936b7077aa75ffa9"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("0966a434eb1a025db6b71485ab63a3bfbea520b6"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("09efc7e59a839528ac7bda9fa020dc9101278680"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("0a3d7772488b6b106fb62813c4d6d627918d9181"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("1004d0d7ac26fbf63050a234c9b88a46075719d3"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("10da5895682013006950e7da534b705252b03be6"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("1203b03dc816ccbb67773f28b3c19318654b0bc8"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("15fae9e651043de0fd1deef588aa3fbf5a7a41c6"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("16f9ec009e5568c435f473ba3a1df732d49ce8c3"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("1fd7d579fb6ae3fe942dc09c2c783443d04cf21e"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("20a8ade77639491ea0bd667bf95de8abf3a434c8"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("2675188fd86978d5bc4d7211698b2118ae3bf658"))); // and lots more... } } }
public virtual void Test1() { FilePath packFile = JGitTestUtil.GetTestResourceFile("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack" ); InputStream @is = new FileInputStream(packFile); try { IndexPack pack = new IndexPack(db, @is, new FilePath(trash, "tmp_pack1")); pack.Index(new TextProgressMonitor()); PackFile file = new PackFile(new FilePath(trash, "tmp_pack1.idx"), new FilePath(trash , "tmp_pack1.pack")); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799" ))); } finally { @is.Close(); } }
public void test1() { FileInfo packFile = GetPack("pack-34be9032ac282b11fa9babdc2b2a93ca996c9c2f.pack"); using (Stream @is = packFile.Open(System.IO.FileMode.Open, FileAccess.Read)) { var tmppack = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1")); var pack = new IndexPack(db, @is, tmppack); pack.index(new TextProgressMonitor()); var idxFile = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1.idx")); var tmpPackFile = new FileInfo(Path.Combine(trash.FullName, "tmp_pack1.pack")); //return; using (var file = new PackFile(idxFile, tmpPackFile)) { Assert.IsTrue(file.HasObject(ObjectId.FromString("4b825dc642cb6eb9a060e54bf8d69288fbee4904"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("540a36d136cf413e4b064c2b0e0a4db60f77feab"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035"))); Assert.IsTrue(file.HasObject(ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799"))); } } }
private void VerifyOpenPack(bool thin) { IndexPack indexer; Stream @is; if (thin) { @is = new MemoryStream(_os.ToArray()); indexer = new IndexPack(db, @is, _packBase); try { indexer.index(new TextProgressMonitor()); Assert.Fail("indexer should grumble about missing object"); } catch (IOException) { // expected } } @is = new MemoryStream(_os.ToArray()); indexer = new IndexPack(db, @is, _packBase); indexer.setKeepEmpty(true); indexer.setFixThin(thin); indexer.setIndexVersion(2); indexer.index(new TextProgressMonitor()); _pack = new PackFile(_indexFile, _packFile); }
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); byte[] raw = pack.ToByteArray(); IndexPack ip = IndexPack.Create(db, new ByteArrayInputStream(raw)); ip.Index(NullProgressMonitor.INSTANCE); ip.RenameAndOpenPack(); }
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(); }
public virtual void Test2() { FilePath packFile = JGitTestUtil.GetTestResourceFile("pack-df2982f284bbabb6bdb59ee3fcc6eb0983e20371.pack" ); InputStream @is = new FileInputStream(packFile); try { IndexPack pack = new IndexPack(db, @is, new FilePath(trash, "tmp_pack2")); pack.Index(new TextProgressMonitor()); PackFile file = new PackFile(new FilePath(trash, "tmp_pack2.idx"), new FilePath(trash , "tmp_pack2.pack")); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("02ba32d3649e510002c21651936b7077aa75ffa9" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("0966a434eb1a025db6b71485ab63a3bfbea520b6" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("09efc7e59a839528ac7bda9fa020dc9101278680" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("0a3d7772488b6b106fb62813c4d6d627918d9181" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("1004d0d7ac26fbf63050a234c9b88a46075719d3" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("10da5895682013006950e7da534b705252b03be6" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("1203b03dc816ccbb67773f28b3c19318654b0bc8" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("15fae9e651043de0fd1deef588aa3fbf5a7a41c6" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("16f9ec009e5568c435f473ba3a1df732d49ce8c3" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("1fd7d579fb6ae3fe942dc09c2c783443d04cf21e" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("20a8ade77639491ea0bd667bf95de8abf3a434c8" ))); NUnit.Framework.Assert.IsTrue(file.HasObject(ObjectId.FromString("2675188fd86978d5bc4d7211698b2118ae3bf658" ))); } finally { // and lots more... @is.Close(); } }
private PackList ScanPacksImpl(PackList old) { Dictionary <string, PackFile> forReuse = ReuseMap(old); long lastRead = DateTime.Now.Ticks; long lastModified = _packDirectory.LastWriteTime.Ticks; HashSet <String> names = listPackDirectory(); var list = new List <PackFile>(names.Count >> 2); bool foundNew = false; foreach (string indexName in names) { // Must match "pack-[0-9a-f]{40}.idx" to be an index. // if (indexName.Length != 49 || !indexName.EndsWith(".idx")) { continue; } string @base = indexName.Slice(0, indexName.Length - 4); string packName = IndexPack.GetPackFileName(@base); if (!names.Contains(packName)) { // Sometimes C Git's HTTP fetch transport leaves a // .idx file behind and does not download the .pack. // We have to skip over such useless indexes. // continue; } PackFile oldPack; forReuse.TryGetValue(packName, out oldPack); forReuse.Remove(packName); if (oldPack != null) { list.Add(oldPack); continue; } var packFile = new FileInfo(_packDirectory.FullName + "/" + packName); var idxFile = new FileInfo(_packDirectory + "/" + indexName); list.Add(new PackFile(idxFile, packFile)); foundNew = true; } // If we did not discover any new files, the modification time was not // changed, and we did not remove any files, then the set of files is // the same as the set we were given. Instead of building a new object // return the same collection. // if (!foundNew && lastModified == old.lastModified && forReuse.isEmpty()) { return(old.updateLastRead(lastRead)); } foreach (PackFile p in forReuse.Values) { p.Close(); } if (list.Count == 0) { return(new PackList(lastRead, lastModified, NoPacks.packs)); } PackFile[] r = list.ToArray(); Array.Sort(r, PackFile.PackFileSortComparison); return(new PackList(lastRead, lastModified, r)); }