public void testWriteIndex() { _writer.setIndexVersion(2); WriteVerifyPack4(false); // Validate that IndexPack came up with the right CRC32 value. PackIndex idx1 = PackIndex.Open(_indexFile); Assert.IsTrue(idx1 is PackIndexV2); Assert.AreEqual(0x4743F1E4L, idx1.FindCRC32(ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"))); // Validate that an index written by PackWriter is the same. FileInfo idx2File = new FileInfo(_indexFile.FullName + ".2"); using (var @is = new FileStream(idx2File.FullName, System.IO.FileMode.CreateNew)) { _writer.writeIndex(@is); } PackIndex idx2 = PackIndex.Open(idx2File); #pragma warning disable 0612 Assert.IsInstanceOfType(typeof(PackIndexV2), idx2); // [henon] IsInstanceOfType is obsolete #pragma warning restore 0612 Assert.AreEqual(idx1.ObjectCount, idx2.ObjectCount); Assert.AreEqual(idx1.Offset64Count, idx2.Offset64Count); for (int i = 0; i < idx1.ObjectCount; i++) { ObjectId id = idx1.GetObjectId(i); Assert.AreEqual(id, idx2.GetObjectId(i)); Assert.AreEqual(idx1.FindOffset(id), idx2.FindOffset(id)); Assert.AreEqual(idx1.FindCRC32(id), idx2.FindCRC32(id)); } }
/// <summary> /// Set up tested class instance, test constructor by the way. /// </summary> public override void setUp() { base.setUp(); // index with both small (< 2^31) and big offsets var fi = new FileInfo("Resources/pack-huge.idx"); Assert.IsTrue(fi.Exists, "Does the index exist"); _idx = PackIndex.Open(fi); _reverseIdx = new PackReverseIndex(_idx); }
public override void setUp() { base.setUp(); smallIdx = PackIndex.Open(GetFileForPack34Be9032()); _denseIdx = PackIndex.Open(GetFileForPackdf2982F28()); }
public void OpenIndex(ProgressMonitor pm) { if (Index != null) { return; } if (TmpIdx.IsFile()) { try { Index = PackIndex.Open(TmpIdx); return; } catch (FileNotFoundException) { // Fall through and get the file. } } using (Stream s = _connection.open("pack/" + _idxName)) { pm.BeginTask("Get " + _idxName.Slice(0, 12) + "..idx", !s.CanSeek ? ProgressMonitor.UNKNOWN : (int)(s.Length / 1024)); try { using (var fos = new FileStream(TmpIdx.FullName, System.IO.FileMode.CreateNew, FileAccess.Write)) { var buf = new byte[2048]; int cnt; while (!pm.IsCancelled && (cnt = s.Read(buf, 0, buf.Length)) > 0) { fos.Write(buf, 0, cnt); pm.Update(cnt / 1024); } } } catch (IOException) { TmpIdx.DeleteFile(); throw; } } pm.EndTask(); if (pm.IsCancelled) { TmpIdx.DeleteFile(); return; } try { Index = PackIndex.Open(TmpIdx); } catch (IOException) { TmpIdx.DeleteFile(); throw; } }
/// <exception cref="System.IO.IOException"></exception> internal virtual void OpenIndex(ProgressMonitor pm) { if (this.index != null) { return; } if (this.tmpIdx == null) { this.tmpIdx = FilePath.CreateTempFile("jgit-walk-", ".idx"); } else { if (this.tmpIdx.IsFile()) { try { this.index = PackIndex.Open(this.tmpIdx); return; } catch (FileNotFoundException) { } } } // Fall through and get the file. WalkRemoteObjectDatabase.FileStream s; s = this.connection.Open("pack/" + this.idxName); pm.BeginTask("Get " + Sharpen.Runtime.Substring(this.idxName, 0, 12) + "..idx", s .length < 0 ? ProgressMonitor.UNKNOWN : (int)(s.length / 1024)); try { FileOutputStream fos = new FileOutputStream(this.tmpIdx); try { byte[] buf = new byte[2048]; int cnt; while (!pm.IsCancelled() && (cnt = [email protected](buf)) >= 0) { fos.Write(buf, 0, cnt); pm.Update(cnt / 1024); } } finally { fos.Close(); } } catch (IOException err) { FileUtils.Delete(this.tmpIdx); throw; } finally { [email protected](); } pm.EndTask(); if (pm.IsCancelled()) { FileUtils.Delete(this.tmpIdx); return; } try { this.index = PackIndex.Open(this.tmpIdx); } catch (IOException e) { FileUtils.Delete(this.tmpIdx); throw; } }
public void OpenIndex(ProgressMonitor pm) { if (Index != null) { return; } try { Index = PackIndex.Open(TmpIdx); return; } catch (FileNotFoundException) { } Stream s = _connection.open("pack/" + _idxName); pm.BeginTask("Get " + _idxName.Slice(0, 12) + "..idx", s.Length < 0 ? -1 : (int)(s.Length / 1024)); try { var fos = new FileStream(TmpIdx.ToString(), System.IO.FileMode.Open, FileAccess.ReadWrite); try { var buf = new byte[2048]; int cnt; while (!pm.IsCancelled && (cnt = s.Read(buf, 0, buf.Length)) >= 0) { fos.Write(buf, 0, cnt); pm.Update(cnt / 1024); } } finally { fos.Close(); } } catch (IOException) { TmpIdx.Delete(); throw; } finally { s.Close(); } pm.EndTask(); if (pm.IsCancelled) { TmpIdx.Delete(); return; } try { Index = PackIndex.Open(TmpIdx); } catch (IOException) { TmpIdx.Delete(); throw; } }