public virtual void TestWrite_SmallBlocks3() { SideBandOutputStream @out = new SideBandOutputStream(SideBandOutputStream.CH_DATA , 7, rawOut); @out.Write('a'); @out.Write(new byte[] { (byte)('b'), (byte)('c') }); @out.Flush(); AssertBuffer("0007\x0001ab0006\x0001c"); }
public virtual void TestWrite_SmallBlocks1() { SideBandOutputStream @out = new SideBandOutputStream(SideBandOutputStream.CH_DATA , 6, rawOut); @out.Write('a'); @out.Write('b'); @out.Write('c'); @out.Flush(); AssertBuffer("0006\x0001a0006\x0001b0006\x0001c"); }
public virtual void TestWrite_Small() { SideBandOutputStream @out = new SideBandOutputStream(SideBandOutputStream.CH_DATA , SideBandOutputStream.SMALL_BUF, rawOut); @out.Write('a'); @out.Write('b'); @out.Write('c'); @out.Flush(); AssertBuffer("0008\x0001abc"); }
public virtual void TestWrite_Large() { int buflen = SideBandOutputStream.MAX_BUF - SideBandOutputStream.HDR_SIZE; byte[] buf = new byte[buflen]; for (int i = 0; i < buf.Length; i++) { buf[i] = unchecked ((byte)i); } SideBandOutputStream @out = new SideBandOutputStream(SideBandOutputStream.CH_DATA , SideBandOutputStream.MAX_BUF, rawOut); @out.Write(buf); @out.Flush(); byte[] act = rawOut.ToByteArray(); string explen = Sharpen.Extensions.ToString(buf.Length + SideBandOutputStream.HDR_SIZE , 16); NUnit.Framework.Assert.AreEqual(SideBandOutputStream.HDR_SIZE + buf.Length, act.Length ); NUnit.Framework.Assert.AreEqual(Sharpen.Runtime.GetStringForBytes(act, 0, 4, "UTF-8" ), explen); NUnit.Framework.Assert.AreEqual(1, act[4]); for (int i_1 = 0, j = SideBandOutputStream.HDR_SIZE; i_1 < buf.Length; i_1++, j++) { NUnit.Framework.Assert.AreEqual(buf[i_1], act[j]); } }
public virtual void TestWrite_CH_PROGRESS() { SideBandOutputStream @out = new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS , SideBandOutputStream.SMALL_BUF, rawOut); @out.Write(new byte[] { (byte)('a'), (byte)('b'), (byte)('c') }); @out.Flush(); AssertBuffer("0008\x0002abc"); }
public virtual void TestWrite_CH_ERROR() { SideBandOutputStream @out = new SideBandOutputStream(SideBandOutputStream.CH_ERROR , SideBandOutputStream.SMALL_BUF, rawOut); @out.Write(new byte[] { (byte)('a'), (byte)('b'), (byte)('c') }); @out.Flush(); AssertBuffer("0008\x0003abc"); }
/// <exception cref="System.IO.IOException"></exception> private void SendPack(bool sideband) { ProgressMonitor pm = NullProgressMonitor.INSTANCE; OutputStream packOut = rawOut; SideBandOutputStream msgOut = null; if (sideband) { int bufsz = SideBandOutputStream.SMALL_BUF; if (options.Contains(OPTION_SIDE_BAND_64K)) { bufsz = SideBandOutputStream.MAX_BUF; } packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, rawOut); if (!options.Contains(OPTION_NO_PROGRESS)) { msgOut = new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, bufsz, rawOut ); pm = new SideBandProgressMonitor(msgOut); } } try { if (wantAll.IsEmpty()) { preUploadHook.OnSendPack(this, wantIds, commonBase); } else { preUploadHook.OnSendPack(this, wantAll, commonBase); } } catch (ServiceMayNotContinueException noPack) { if (sideband && noPack.Message != null) { noPack.SetOutput(); SideBandOutputStream err = new SideBandOutputStream(SideBandOutputStream.CH_ERROR , SideBandOutputStream.SMALL_BUF, rawOut); err.Write(Constants.Encode(noPack.Message)); err.Flush(); } throw; } PackConfig cfg = packConfig; if (cfg == null) { cfg = new PackConfig(db); } PackWriter pw = new PackWriter(cfg, walk.GetObjectReader()); try { pw.SetUseCachedPacks(true); pw.SetReuseDeltaCommits(true); pw.SetDeltaBaseAsOffset(options.Contains(OPTION_OFS_DELTA)); pw.SetThin(options.Contains(OPTION_THIN_PACK)); pw.SetReuseValidatingObjects(false); if (commonBase.IsEmpty() && refs != null) { ICollection<ObjectId> tagTargets = new HashSet<ObjectId>(); foreach (Ref @ref in refs.Values) { if (@ref.GetPeeledObjectId() != null) { tagTargets.AddItem(@ref.GetPeeledObjectId()); } else { if (@ref.GetObjectId() == null) { continue; } else { if (@ref.GetName().StartsWith(Constants.R_HEADS)) { tagTargets.AddItem(@ref.GetObjectId()); } } } } pw.SetTagTargets(tagTargets); } if (depth > 0) { pw.SetShallowPack(depth, unshallowCommits); } RevWalk rw = walk; if (wantAll.IsEmpty()) { pw.PreparePack(pm, wantIds, commonBase); } else { walk.Reset(); ObjectWalk ow = walk.ToObjectWalkWithSameObjects(); pw.PreparePack(pm, ow, wantAll, commonBase); rw = ow; } if (options.Contains(OPTION_INCLUDE_TAG) && refs != null) { foreach (Ref vref in refs.Values) { Ref @ref = vref; ObjectId objectId = @ref.GetObjectId(); // If the object was already requested, skip it. if (wantAll.IsEmpty()) { if (wantIds.Contains(objectId)) { continue; } } else { RevObject obj = rw.LookupOrNull(objectId); if (obj != null && obj.Has(WANT)) { continue; } } if ([email protected]()) { @ref = db.Peel(@ref); } ObjectId peeledId = @ref.GetPeeledObjectId(); if (peeledId == null) { continue; } objectId = @ref.GetObjectId(); if (pw.WillInclude(peeledId) && !pw.WillInclude(objectId)) { pw.AddObject(rw.ParseAny(objectId)); } } } pw.WritePack(pm, NullProgressMonitor.INSTANCE, packOut); statistics = pw.GetStatistics(); if (msgOut != null) { string msg = pw.GetStatistics().GetMessage() + '\n'; msgOut.Write(Constants.Encode(msg)); msgOut.Flush(); } } finally { pw.Release(); } if (sideband) { pckOut.End(); } if (statistics != null) { logger.OnPackStatistics(statistics); } }
private bool ReportInternalServerErrorOverSideband() { try { SideBandOutputStream err = new SideBandOutputStream(SideBandOutputStream.CH_ERROR , SideBandOutputStream.SMALL_BUF, rawOut); err.Write(Constants.Encode(JGitText.Get().internalServerError)); err.Flush(); return true; } catch { // Ignore the reason. This is a secondary failure. return false; } }
public virtual void TestWrite_SmallBlocks3() { SideBandOutputStream @out; @out = new SideBandOutputStream(SideBandOutputStream.CH_DATA, 7, rawOut); @out.Write('a'); @out.Write(new byte[] { (byte)('b'), (byte)('c') }); @out.Flush(); AssertBuffer("0007\x1ab0006\x1c"); }
public virtual void TestWrite_SmallBlocks1() { SideBandOutputStream @out; @out = new SideBandOutputStream(SideBandOutputStream.CH_DATA, 6, rawOut); @out.Write('a'); @out.Write('b'); @out.Write('c'); @out.Flush(); AssertBuffer("0006\x1a0006\x1b0006\x1c"); }
public virtual void TestWrite_Small() { SideBandOutputStream @out; @out = new SideBandOutputStream(SideBandOutputStream.CH_DATA, SideBandOutputStream .SMALL_BUF, rawOut); @out.Write('a'); @out.Write('b'); @out.Write('c'); @out.Flush(); AssertBuffer("0008\x1abc"); }
public virtual void TestWrite_Large() { int buflen = SideBandOutputStream.MAX_BUF - SideBandOutputStream.HDR_SIZE; byte[] buf = new byte[buflen]; for (int i = 0; i < buf.Length; i++) { buf[i] = unchecked((byte)i); } SideBandOutputStream @out; @out = new SideBandOutputStream(SideBandOutputStream.CH_DATA, SideBandOutputStream .MAX_BUF, rawOut); @out.Write(buf); @out.Flush(); byte[] act = rawOut.ToByteArray(); string explen = Sharpen.Extensions.ToString(buf.Length + SideBandOutputStream.HDR_SIZE , 16); NUnit.Framework.Assert.AreEqual(SideBandOutputStream.HDR_SIZE + buf.Length, act.Length ); NUnit.Framework.Assert.AreEqual(Sharpen.Extensions.CreateString(act, 0, 4, "UTF-8" ), explen); NUnit.Framework.Assert.AreEqual(1, act[4]); for (int i_1 = 0; i_1 < buf.Length; i_1++, j++) { NUnit.Framework.Assert.AreEqual(buf[i_1], act[j]); } }
/// <exception cref="System.IO.IOException"></exception> private void SendPack() { bool sideband = options.Contains(OPTION_SIDE_BAND) || options.Contains(OPTION_SIDE_BAND_64K ); if (!biDirectionalPipe) { // Ensure the request was fully consumed. Any remaining input must // be a protocol error. If we aren't at EOF the implementation is broken. int eof = rawIn.Read(); if (0 <= eof) { throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().expectedEOFReceived , "\\x" + Sharpen.Extensions.ToHexString(eof))); } } ProgressMonitor pm = NullProgressMonitor.INSTANCE; OutputStream packOut = rawOut; SideBandOutputStream msgOut = null; if (sideband) { int bufsz = SideBandOutputStream.SMALL_BUF; if (options.Contains(OPTION_SIDE_BAND_64K)) { bufsz = SideBandOutputStream.MAX_BUF; } packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, rawOut); if (!options.Contains(OPTION_NO_PROGRESS)) { msgOut = new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, bufsz, rawOut ); pm = new SideBandProgressMonitor(msgOut); } } try { if (wantAll.IsEmpty()) { preUploadHook.OnSendPack(this, wantIds, commonBase); } else { preUploadHook.OnSendPack(this, wantAll, commonBase); } } catch (UploadPackMayNotContinueException noPack) { if (sideband && noPack.Message != null) { noPack.SetOutput(); SideBandOutputStream err = new SideBandOutputStream(SideBandOutputStream.CH_ERROR , SideBandOutputStream.SMALL_BUF, rawOut); err.Write(Constants.Encode(noPack.Message)); err.Flush(); } throw; } PackConfig cfg = packConfig; if (cfg == null) { cfg = new PackConfig(db); } PackWriter pw = new PackWriter(cfg, walk.GetObjectReader()); try { pw.SetUseCachedPacks(true); pw.SetReuseDeltaCommits(true); pw.SetDeltaBaseAsOffset(options.Contains(OPTION_OFS_DELTA)); pw.SetThin(options.Contains(OPTION_THIN_PACK)); pw.SetReuseValidatingObjects(false); if (commonBase.IsEmpty()) { ICollection <ObjectId> tagTargets = new HashSet <ObjectId>(); foreach (Ref @ref in refs.Values) { if (@ref.GetPeeledObjectId() != null) { tagTargets.AddItem(@ref.GetPeeledObjectId()); } else { if (@ref.GetObjectId() == null) { continue; } else { if (@ref.GetName().StartsWith(Constants.R_HEADS)) { tagTargets.AddItem(@ref.GetObjectId()); } } } } pw.SetTagTargets(tagTargets); } RevWalk rw = walk; if (wantAll.IsEmpty()) { pw.PreparePack(pm, wantIds, commonBase); } else { walk.Reset(); ObjectWalk ow = walk.ToObjectWalkWithSameObjects(); pw.PreparePack(pm, ow, wantAll, commonBase); rw = ow; } if (options.Contains(OPTION_INCLUDE_TAG)) { foreach (Ref vref in refs.Values) { Ref @ref = vref; ObjectId objectId = @ref.GetObjectId(); // If the object was already requested, skip it. if (wantAll.IsEmpty()) { if (wantIds.Contains(objectId)) { continue; } } else { RevObject obj = rw.LookupOrNull(objectId); if (obj != null && obj.Has(WANT)) { continue; } } if ([email protected]()) { @ref = db.Peel(@ref); } ObjectId peeledId = @ref.GetPeeledObjectId(); if (peeledId == null) { continue; } objectId = @ref.GetObjectId(); if (pw.WillInclude(peeledId) && !pw.WillInclude(objectId)) { pw.AddObject(rw.ParseAny(objectId)); } } } pw.WritePack(pm, NullProgressMonitor.INSTANCE, packOut); statistics = pw.GetStatistics(); if (msgOut != null) { string msg = pw.GetStatistics().GetMessage() + '\n'; msgOut.Write(Constants.Encode(msg)); msgOut.Flush(); } } finally { pw.Release(); } if (sideband) { pckOut.End(); } if (logger != null && statistics != null) { logger.OnPackStatistics(statistics); } }
/// <exception cref="System.IO.IOException"></exception> private void SendPack() { bool sideband = options.Contains(OPTION_SIDE_BAND) || options.Contains(OPTION_SIDE_BAND_64K ); if (!biDirectionalPipe) { // Ensure the request was fully consumed. Any remaining input must // be a protocol error. If we aren't at EOF the implementation is broken. int eof = rawIn.Read(); if (0 <= eof) { throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().expectedEOFReceived , "\\x" + Sharpen.Extensions.ToHexString(eof))); } } ProgressMonitor pm = NullProgressMonitor.INSTANCE; OutputStream packOut = rawOut; SideBandOutputStream msgOut = null; if (sideband) { int bufsz = SideBandOutputStream.SMALL_BUF; if (options.Contains(OPTION_SIDE_BAND_64K)) { bufsz = SideBandOutputStream.MAX_BUF; } packOut = new SideBandOutputStream(SideBandOutputStream.CH_DATA, bufsz, rawOut); if (!options.Contains(OPTION_NO_PROGRESS)) { msgOut = new SideBandOutputStream(SideBandOutputStream.CH_PROGRESS, bufsz, rawOut ); pm = new SideBandProgressMonitor(msgOut); } } try { if (wantAll.IsEmpty()) { preUploadHook.OnSendPack(this, wantIds, commonBase); } else { preUploadHook.OnSendPack(this, wantAll, commonBase); } } catch (UploadPackMayNotContinueException noPack) { if (sideband && noPack.Message != null) { noPack.SetOutput(); SideBandOutputStream err = new SideBandOutputStream(SideBandOutputStream.CH_ERROR , SideBandOutputStream.SMALL_BUF, rawOut); err.Write(Constants.Encode(noPack.Message)); err.Flush(); } throw; } PackConfig cfg = packConfig; if (cfg == null) { cfg = new PackConfig(db); } PackWriter pw = new PackWriter(cfg, walk.GetObjectReader()); try { pw.SetUseCachedPacks(true); pw.SetReuseDeltaCommits(true); pw.SetDeltaBaseAsOffset(options.Contains(OPTION_OFS_DELTA)); pw.SetThin(options.Contains(OPTION_THIN_PACK)); pw.SetReuseValidatingObjects(false); if (commonBase.IsEmpty()) { ICollection<ObjectId> tagTargets = new HashSet<ObjectId>(); foreach (Ref @ref in refs.Values) { if (@ref.GetPeeledObjectId() != null) { tagTargets.AddItem(@ref.GetPeeledObjectId()); } else { if (@ref.GetObjectId() == null) { continue; } else { if (@ref.GetName().StartsWith(Constants.R_HEADS)) { tagTargets.AddItem(@ref.GetObjectId()); } } } } pw.SetTagTargets(tagTargets); } RevWalk rw = walk; if (wantAll.IsEmpty()) { pw.PreparePack(pm, wantIds, commonBase); } else { walk.Reset(); ObjectWalk ow = walk.ToObjectWalkWithSameObjects(); pw.PreparePack(pm, ow, wantAll, commonBase); rw = ow; } if (options.Contains(OPTION_INCLUDE_TAG)) { foreach (Ref vref in refs.Values) { Ref @ref = vref; ObjectId objectId = @ref.GetObjectId(); // If the object was already requested, skip it. if (wantAll.IsEmpty()) { if (wantIds.Contains(objectId)) { continue; } } else { RevObject obj = rw.LookupOrNull(objectId); if (obj != null && obj.Has(WANT)) { continue; } } if ([email protected]()) { @ref = db.Peel(@ref); } ObjectId peeledId = @ref.GetPeeledObjectId(); if (peeledId == null) { continue; } objectId = @ref.GetObjectId(); if (pw.WillInclude(peeledId) && !pw.WillInclude(objectId)) { pw.AddObject(rw.ParseAny(objectId)); } } } pw.WritePack(pm, NullProgressMonitor.INSTANCE, packOut); statistics = pw.GetStatistics(); if (msgOut != null) { string msg = pw.GetStatistics().GetMessage() + '\n'; msgOut.Write(Constants.Encode(msg)); msgOut.Flush(); } } finally { pw.Release(); } if (sideband) { pckOut.End(); } if (logger != null && statistics != null) { logger.OnPackStatistics(statistics); } }