Beispiel #1
0
		/// <exception cref="System.IO.IOException"></exception>
		private InputStream Inflate(PackParser.Source src, long inflatedSize)
		{
			inflater.Open(src, inflatedSize);
			return inflater;
		}
Beispiel #2
0
			internal virtual void Add(PackParser.UnresolvedDelta d)
			{
				d.next = head;
				head = d;
			}
Beispiel #3
0
		/// <exception cref="System.IO.IOException"></exception>
		private void InflateAndSkip(PackParser.Source src, long inflatedSize)
		{
			InputStream inf = Inflate(src, inflatedSize);
			IOUtil.SkipFully(inf, inflatedSize);
			inf.Close();
		}
Beispiel #4
0
		/// <exception cref="System.IO.IOException"></exception>
		private byte[] InflateAndReturn(PackParser.Source src, long inflatedSize)
		{
			byte[] dst = new byte[(int)inflatedSize];
			InputStream inf = Inflate(src, inflatedSize);
			IOUtil.ReadFully(inf, dst, 0, dst.Length);
			inf.Close();
			return dst;
		}
Beispiel #5
0
		/// <summary>Read the header of the current object.</summary>
		/// <remarks>
		/// Read the header of the current object.
		/// <p>
		/// After the header has been parsed, this method automatically invokes
		/// <see cref="OnObjectHeader(Source, byte[], int, int)">OnObjectHeader(Source, byte[], int, int)
		/// 	</see>
		/// to allow the
		/// implementation to update its internal checksums for the bytes read.
		/// <p>
		/// When this method returns the database will be positioned on the first
		/// byte of the deflated data stream.
		/// </remarks>
		/// <param name="info">the info object to populate.</param>
		/// <returns>
		/// 
		/// <code>info</code>
		/// , after populating.
		/// </returns>
		/// <exception cref="System.IO.IOException">the size cannot be read.</exception>
		protected internal virtual PackParser.ObjectTypeAndSize ReadObjectHeader(PackParser.ObjectTypeAndSize
			 info)
		{
			int hdrPtr = 0;
			int c = ReadFrom(PackParser.Source.DATABASE);
			hdrBuf[hdrPtr++] = unchecked((byte)c);
			info.type = (c >> 4) & 7;
			long sz = c & 15;
			int shift = 4;
			while ((c & unchecked((int)(0x80))) != 0)
			{
				c = ReadFrom(PackParser.Source.DATABASE);
				hdrBuf[hdrPtr++] = unchecked((byte)c);
				sz += ((long)(c & unchecked((int)(0x7f)))) << shift;
				shift += 7;
			}
			info.size = sz;
			switch (info.type)
			{
				case Constants.OBJ_COMMIT:
				case Constants.OBJ_TREE:
				case Constants.OBJ_BLOB:
				case Constants.OBJ_TAG:
				{
					OnObjectHeader(PackParser.Source.DATABASE, hdrBuf, 0, hdrPtr);
					break;
				}

				case Constants.OBJ_OFS_DELTA:
				{
					c = ReadFrom(PackParser.Source.DATABASE);
					hdrBuf[hdrPtr++] = unchecked((byte)c);
					while ((c & 128) != 0)
					{
						c = ReadFrom(PackParser.Source.DATABASE);
						hdrBuf[hdrPtr++] = unchecked((byte)c);
					}
					OnObjectHeader(PackParser.Source.DATABASE, hdrBuf, 0, hdrPtr);
					break;
				}

				case Constants.OBJ_REF_DELTA:
				{
					System.Array.Copy(buf, Fill(PackParser.Source.DATABASE, 20), hdrBuf, hdrPtr, 20);
					hdrPtr += 20;
					Use(20);
					OnObjectHeader(PackParser.Source.DATABASE, hdrBuf, 0, hdrPtr);
					break;
				}

				default:
				{
					throw new IOException(MessageFormat.Format(JGitText.Get().unknownObjectType, Sharpen.Extensions.ValueOf
						(info.type)));
				}
			}
			return info;
		}
		/// <exception cref="System.IO.IOException"></exception>
		protected internal override PackParser.ObjectTypeAndSize SeekDatabase(PackParser.UnresolvedDelta
			 delta, PackParser.ObjectTypeAndSize info)
		{
			@out.Seek(delta.GetOffset());
			crc.Reset();
			return ReadObjectHeader(info);
		}
Beispiel #7
0
		/// <summary>Construct a PackedObjectInfo instance for this parser.</summary>
		/// <remarks>Construct a PackedObjectInfo instance for this parser.</remarks>
		/// <param name="id">identity of the object to be tracked.</param>
		/// <param name="delta">
		/// if the object was previously an unresolved delta, this is the
		/// delta object that was tracking it. Otherwise null.
		/// </param>
		/// <param name="deltaBase">
		/// if the object was previously an unresolved delta, this is the
		/// ObjectId of the base of the delta. The base may be outside of
		/// the pack stream if the stream was a thin-pack.
		/// </param>
		/// <returns>info object containing this object's data.</returns>
		protected internal virtual PackedObjectInfo NewInfo(AnyObjectId id, PackParser.UnresolvedDelta
			 delta, ObjectId deltaBase)
		{
			PackedObjectInfo oe = new PackedObjectInfo(id);
			if (delta != null)
			{
				oe.SetCRC(delta.crc);
			}
			return oe;
		}
Beispiel #8
0
			/// <exception cref="System.IO.IOException"></exception>
			internal virtual void Open(PackParser.Source source, long inflatedSize)
			{
				this.src = source;
				this.expectedSize = inflatedSize;
				this.actualSize = 0;
				this.p = this._enclosing.Fill(this.src, 1);
				this.inf.SetInput(this._enclosing.buf, this.p, this._enclosing.bAvail);
			}
Beispiel #9
0
		// Consume exactly one byte from the buffer and return it.
		/// <exception cref="System.IO.IOException"></exception>
		private int ReadFrom(PackParser.Source src)
		{
			if (bAvail == 0)
			{
				Fill(src, 1);
			}
			bAvail--;
			return buf[bOffset++] & unchecked((int)(0xff));
		}
Beispiel #10
0
		// Ensure at least need bytes are available in in {@link #buf}.
		/// <exception cref="System.IO.IOException"></exception>
		private int Fill(PackParser.Source src, int need)
		{
			while (bAvail < need)
			{
				int next = bOffset + bAvail;
				int free = buf.Length - next;
				if (free + bAvail < need)
				{
					switch (src)
					{
						case PackParser.Source.INPUT:
						{
							Sync();
							break;
						}

						case PackParser.Source.DATABASE:
						{
							if (bAvail > 0)
							{
								System.Array.Copy(buf, bOffset, buf, 0, bAvail);
							}
							bOffset = 0;
							break;
						}
					}
					next = bAvail;
					free = buf.Length - next;
				}
				switch (src)
				{
					case PackParser.Source.INPUT:
					{
						next = @in.Read(buf, next, free);
						break;
					}

					case PackParser.Source.DATABASE:
					{
						next = ReadDatabase(buf, next, free);
						break;
					}
				}
				if (next <= 0)
				{
					throw new EOFException(JGitText.Get().packfileIsTruncated);
				}
				bAvail += next;
			}
			return bOffset;
		}
Beispiel #11
0
		/// <exception cref="System.IO.IOException"></exception>
		private PackParser.ObjectTypeAndSize OpenDatabase(PackParser.UnresolvedDelta delta
			, PackParser.ObjectTypeAndSize info)
		{
			bOffset = 0;
			bAvail = 0;
			return SeekDatabase(delta, info);
		}
Beispiel #12
0
		/// <exception cref="System.IO.IOException"></exception>
		private PackParser.ObjectTypeAndSize OpenDatabase(PackedObjectInfo obj, PackParser.ObjectTypeAndSize
			 info)
		{
			bOffset = 0;
			bAvail = 0;
			return SeekDatabase(obj, info);
		}
		/// <exception cref="System.IO.IOException"></exception>
		protected internal override PackParser.ObjectTypeAndSize SeekDatabase(PackedObjectInfo
			 obj, PackParser.ObjectTypeAndSize info)
		{
			@out.Seek(obj.GetOffset());
			crc.Reset();
			return ReadObjectHeader(info);
		}
Beispiel #14
0
			internal DeltaVisit(PackParser.DeltaVisit parent)
			{
				// At the root of the stack we have a base.
				this.parent = parent;
				this.delta = parent.nextChild;
				parent.nextChild = delta.next;
			}
Beispiel #15
0
		/// <summary>Store (and/or checksum) a portion of an object's data.</summary>
		/// <remarks>
		/// Store (and/or checksum) a portion of an object's data.
		/// <p>
		/// This method may be invoked multiple times per object, depending on the
		/// size of the object, the size of the parser's internal read buffer, and
		/// the alignment of the object relative to the read buffer.
		/// <p>
		/// Invoked after
		/// <see cref="OnObjectHeader(Source, byte[], int, int)">OnObjectHeader(Source, byte[], int, int)
		/// 	</see>
		/// .
		/// </remarks>
		/// <param name="src">where the data came from</param>
		/// <param name="raw">buffer to read data from.</param>
		/// <param name="pos">first offset within buffer that is valid.</param>
		/// <param name="len">number of bytes in buffer that are valid.</param>
		/// <exception cref="System.IO.IOException">the stream cannot be archived.</exception>
		protected internal abstract void OnObjectData(PackParser.Source src, byte[] raw, 
			int pos, int len);
Beispiel #16
0
			public InflaterStream(PackParser _enclosing)
			{
				this._enclosing = _enclosing;
				this.inf = InflaterCache.Get();
				this.skipBuffer = new byte[512];
			}
Beispiel #17
0
		/// <summary>Reposition the database to re-read a previously stored object.</summary>
		/// <remarks>
		/// Reposition the database to re-read a previously stored object.
		/// <p>
		/// If the database is computing CRC-32 checksums for object data, it should
		/// reset its internal CRC instance during this method call.
		/// </remarks>
		/// <param name="obj">
		/// the object position to begin reading from. This is from
		/// <see cref="NewInfo(NGit.AnyObjectId, UnresolvedDelta, NGit.ObjectId)">NewInfo(NGit.AnyObjectId, UnresolvedDelta, NGit.ObjectId)
		/// 	</see>
		/// .
		/// </param>
		/// <param name="info">object to populate with type and size.</param>
		/// <returns>
		/// the
		/// <code>info</code>
		/// object.
		/// </returns>
		/// <exception cref="System.IO.IOException">the database cannot reposition to this location.
		/// 	</exception>
		protected internal abstract PackParser.ObjectTypeAndSize SeekDatabase(PackedObjectInfo
			 obj, PackParser.ObjectTypeAndSize info);
Beispiel #18
0
		/// <exception cref="System.IO.IOException"></exception>
		private void ResolveDeltas(PackParser.DeltaVisit visit, int type, PackParser.ObjectTypeAndSize
			 info, ProgressMonitor progress)
		{
			do
			{
				progress.Update(1);
				info = OpenDatabase(visit.delta, info);
				switch (info.type)
				{
					case Constants.OBJ_OFS_DELTA:
					case Constants.OBJ_REF_DELTA:
					{
						break;
					}

					default:
					{
						throw new IOException(MessageFormat.Format(JGitText.Get().unknownObjectType, Sharpen.Extensions.ValueOf
							(info.type)));
					}
				}
				byte[] delta = InflateAndReturn(PackParser.Source.DATABASE, info.size);
				CheckIfTooLarge(type, BinaryDelta.GetResultSize(delta));
				visit.data = BinaryDelta.Apply(visit.parent.data, delta);
				delta = null;
				if (!CheckCRC(visit.delta.crc))
				{
					throw new IOException(MessageFormat.Format(JGitText.Get().corruptionDetectedReReadingAt
						, Sharpen.Extensions.ValueOf(visit.delta.position)));
				}
				objectDigest.Update(Constants.EncodedTypeString(type));
				objectDigest.Update(unchecked((byte)' '));
				objectDigest.Update(Constants.EncodeASCII(visit.data.Length));
				objectDigest.Update(unchecked((byte)0));
				objectDigest.Update(visit.data);
				tempObjectId.FromRaw(objectDigest.Digest(), 0);
				VerifySafeObject(tempObjectId, type, visit.data);
				PackedObjectInfo oe;
				oe = NewInfo(tempObjectId, visit.delta, visit.parent.id);
				oe.SetOffset(visit.delta.position);
				OnInflatedObjectData(oe, type, visit.data);
				AddObjectAndTrack(oe);
				visit.id = oe;
				visit.nextChild = FirstChildOf(oe);
				visit = visit.Next();
			}
			while (visit != null);
		}
Beispiel #19
0
		/// <summary>Reposition the database to re-read a previously stored object.</summary>
		/// <remarks>
		/// Reposition the database to re-read a previously stored object.
		/// <p>
		/// If the database is computing CRC-32 checksums for object data, it should
		/// reset its internal CRC instance during this method call.
		/// </remarks>
		/// <param name="delta">
		/// the object position to begin reading from. This is an instance
		/// previously returned by
		/// <see cref="OnEndDelta()">OnEndDelta()</see>
		/// .
		/// </param>
		/// <param name="info">object to populate with type and size.</param>
		/// <returns>
		/// the
		/// <code>info</code>
		/// object.
		/// </returns>
		/// <exception cref="System.IO.IOException">the database cannot reposition to this location.
		/// 	</exception>
		protected internal abstract PackParser.ObjectTypeAndSize SeekDatabase(PackParser.UnresolvedDelta
			 delta, PackParser.ObjectTypeAndSize info);
Beispiel #20
0
		private static PackParser.UnresolvedDelta Reverse(PackParser.UnresolvedDelta c)
		{
			PackParser.UnresolvedDelta tail = null;
			while (c != null)
			{
				PackParser.UnresolvedDelta n = c.next;
				c.next = tail;
				tail = c;
				c = n;
			}
			return tail;
		}
		/// <exception cref="System.IO.IOException"></exception>
		protected internal override void OnObjectData(PackParser.Source src, byte[] raw, 
			int pos, int len)
		{
			crc.Update(raw, pos, len);
		}