public virtual void TestContructor() { writer = new PackWriter(config, db.NewObjectReader()); NUnit.Framework.Assert.AreEqual(false, writer.IsDeltaBaseAsOffset()); NUnit.Framework.Assert.AreEqual(true, config.IsReuseDeltas()); NUnit.Framework.Assert.AreEqual(true, config.IsReuseObjects()); NUnit.Framework.Assert.AreEqual(0, writer.GetObjectsNumber()); }
/// <exception cref="NGit.Errors.TransportException"></exception> private void Sendpack(IList <RemoteRefUpdate> updates, ProgressMonitor monitor) { string pathPack = null; string pathIdx = null; PackWriter writer = new PackWriter(transport.GetPackConfig(), local.NewObjectReader ()); try { IList <ObjectId> need = new AList <ObjectId>(); IList <ObjectId> have = new AList <ObjectId>(); foreach (RemoteRefUpdate r in updates) { need.AddItem(r.GetNewObjectId()); } foreach (Ref r_1 in GetRefs()) { have.AddItem(r_1.GetObjectId()); if (r_1.GetPeeledObjectId() != null) { have.AddItem(r_1.GetPeeledObjectId()); } } writer.PreparePack(monitor, need, have); // We don't have to continue further if the pack will // be an empty pack, as the remote has all objects it // needs to complete this change. // if (writer.GetObjectsNumber() == 0) { return; } packNames = new LinkedHashMap <string, string>(); foreach (string n in dest.GetPackNames()) { packNames.Put(n, n); } string @base = "pack-" + writer.ComputeName().Name; string packName = @base + ".pack"; pathPack = "pack/" + packName; pathIdx = "pack/" + @base + ".idx"; if (Sharpen.Collections.Remove(packNames, packName) != null) { // The remote already contains this pack. We should // remove the index before overwriting to prevent bad // offsets from appearing to clients. // dest.WriteInfoPacks(packNames.Keys); dest.DeleteFile(pathIdx); } // Write the pack file, then the index, as readers look the // other direction (index, then pack file). // string wt = "Put " + Sharpen.Runtime.Substring(@base, 0, 12); OutputStream os = dest.WriteFile(pathPack, monitor, wt + "..pack"); try { os = new BufferedOutputStream(os); writer.WritePack(monitor, monitor, os); } finally { os.Close(); } os = dest.WriteFile(pathIdx, monitor, wt + "..idx"); try { os = new BufferedOutputStream(os); writer.WriteIndex(os); } finally { os.Close(); } // Record the pack at the start of the pack info list. This // way clients are likely to consult the newest pack first, // and discover the most recent objects there. // AList <string> infoPacks = new AList <string>(); infoPacks.AddItem(packName); Sharpen.Collections.AddAll(infoPacks, packNames.Keys); dest.WriteInfoPacks(infoPacks); } catch (IOException err) { SafeDelete(pathIdx); SafeDelete(pathPack); throw new TransportException(uri, JGitText.Get().cannotStoreObjects, err); } finally { writer.Release(); } }