Пример #1
0
 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();
     }
 }
Пример #2
0
		/// <summary>Create an index pack instance to load a new pack into a repository.</summary>
		/// <remarks>
		/// Create an index pack instance to load a new pack into a repository.
		/// <p>
		/// The received pack data and generated index will be saved to temporary
		/// files within the repository's <code>objects</code> directory. To use the
		/// data contained within them call
		/// <see cref="RenameAndOpenPack()">RenameAndOpenPack()</see>
		/// once the
		/// indexing is complete.
		/// </remarks>
		/// <param name="db">the repository that will receive the new pack.</param>
		/// <param name="is">
		/// stream to read the pack data from. If the stream is buffered
		/// use
		/// <see cref="BUFFER_SIZE">BUFFER_SIZE</see>
		/// as the buffer size for the stream.
		/// </param>
		/// <returns>a new index pack instance.</returns>
		/// <exception cref="System.IO.IOException">a temporary file could not be created.</exception>
		public static NGit.Transport.IndexPack Create(Repository db, InputStream @is)
		{
			string suffix = ".pack";
			FilePath objdir = db.ObjectsDirectory;
			FilePath tmp = FilePath.CreateTempFile("incoming_", suffix, objdir);
			string n = tmp.GetName();
			FilePath @base;
			@base = new FilePath(objdir, Sharpen.Runtime.Substring(n, 0, n.Length - suffix.Length
				));
			NGit.Transport.IndexPack ip = new NGit.Transport.IndexPack(db, @is, @base);
			ip.SetIndexVersion(db.GetConfig().Get(CoreConfig.KEY).GetPackIndexVersion());
			return ip;
		}
Пример #3
0
		/// <exception cref="System.IO.IOException"></exception>
		private void ResolveChildDeltaChain(int type, byte[] data, IndexPack.UnresolvedDelta
			 a)
		{
			while (a != null)
			{
				ResolveDeltas(a.position, a.crc, type, data, null);
				a = a.next;
			}
		}
Пример #4
0
		private static IndexPack.UnresolvedDelta Reverse(IndexPack.UnresolvedDelta c)
		{
			IndexPack.UnresolvedDelta tail = null;
			while (c != null)
			{
				IndexPack.UnresolvedDelta n = c.next;
				c.next = tail;
				tail = c;
				c = n;
			}
			return tail;
		}
Пример #5
0
			/// <exception cref="System.IO.IOException"></exception>
			internal virtual void Open(IndexPack.Source source, long inflatedSize)
			{
				this.src = source;
				this.expectedSize = inflatedSize;
				this.actualSize = 0;
				this.p = this._enclosing.Fill(this.src, 24);
				this.inf.SetInput(this._enclosing.buf, this.p, this._enclosing.bAvail);
			}
Пример #6
0
			public InflaterStream(IndexPack _enclosing)
			{
				this._enclosing = _enclosing;
				this.inf = InflaterCache.Get();
				this.skipBuffer = new byte[512];
			}
Пример #7
0
			internal virtual void Add(IndexPack.UnresolvedDelta d)
			{
				d.next = head;
				head = d;
			}
Пример #8
0
		/// <exception cref="System.IO.IOException"></exception>
		private InputStream Inflate(IndexPack.Source src, long inflatedSize)
		{
			inflater.Open(src, inflatedSize);
			return inflater;
		}
Пример #9
0
		/// <exception cref="System.IO.IOException"></exception>
		private byte[] InflateAndReturn(IndexPack.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;
		}
Пример #10
0
		/// <exception cref="System.IO.IOException"></exception>
		private void InflateAndSkip(IndexPack.Source src, long inflatedSize)
		{
			InputStream inf = Inflate(src, inflatedSize);
			IOUtil.SkipFully(inf, inflatedSize);
			inf.Close();
		}
Пример #11
0
		// Ensure at least need bytes are available in in {@link #buf}.
		/// <exception cref="System.IO.IOException"></exception>
		private int Fill(IndexPack.Source src, int need)
		{
			while (bAvail < need)
			{
				int next = bOffset + bAvail;
				int free = buf.Length - next;
				if (free + bAvail < need)
				{
					switch (src)
					{
						case IndexPack.Source.INPUT:
						{
							Sync();
							break;
						}

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

					case IndexPack.Source.FILE:
					{
						next = packOut.Read(buf, next, free);
						break;
					}
				}
				if (next <= 0)
				{
					throw new EOFException(JGitText.Get().packfileIsTruncated);
				}
				bAvail += next;
			}
			return bOffset;
		}
Пример #12
0
		// Consume exactly one byte from the buffer and return it.
		/// <exception cref="System.IO.IOException"></exception>
		private int ReadFrom(IndexPack.Source src)
		{
			if (bAvail == 0)
			{
				Fill(src, 1);
			}
			bAvail--;
			int b = buf[bOffset++] & unchecked((int)(0xff));
			crc.Update(b);
			return b;
		}
Пример #13
0
 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();
     }
 }