Ejemplo n.º 1
0
        public virtual void TestSetByte()
        {
            byte[] exp = new byte[20];
            for (int i = 0; i < 20; i++)
            {
                exp[i] = unchecked ((byte)(unchecked ((int)(0xa0)) + i));
            }
            MutableObjectId id = new MutableObjectId();

            id.FromRaw(exp);
            NUnit.Framework.Assert.AreEqual(ObjectId.FromRaw(exp).Name, id.Name);
            id.SetByte(0, unchecked ((int)(0x10)));
            NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x10)), id.GetByte(0));
            exp[0] = unchecked ((int)(0x10));
            NUnit.Framework.Assert.AreEqual(ObjectId.FromRaw(exp).Name, id.Name);
            for (int p = 1; p < 20; p++)
            {
                id.SetByte(p, unchecked ((int)(0x10)) + p);
                NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x10)) + p, id.GetByte(p));
                exp[p] = unchecked ((byte)(unchecked ((int)(0x10)) + p));
                NUnit.Framework.Assert.AreEqual(ObjectId.FromRaw(exp).Name, id.Name);
            }
            for (int p_1 = 0; p_1 < 20; p_1++)
            {
                id.SetByte(p_1, unchecked ((int)(0x80)) + p_1);
                NUnit.Framework.Assert.AreEqual(unchecked ((int)(0x80)) + p_1, id.GetByte(p_1));
                exp[p_1] = unchecked ((byte)(unchecked ((int)(0x80)) + p_1));
                NUnit.Framework.Assert.AreEqual(ObjectId.FromRaw(exp).Name, id.Name);
            }
        }
Ejemplo n.º 2
0
		public virtual void Init()
		{
			idBuf = new MutableObjectId();
			id_1 = new ObjectIdSubclassMapTest.SubId(Id(1));
			id_2 = new ObjectIdSubclassMapTest.SubId(Id(2));
			id_3 = new ObjectIdSubclassMapTest.SubId(Id(3));
			id_a31 = new ObjectIdSubclassMapTest.SubId(Id(31));
			id_b31 = new ObjectIdSubclassMapTest.SubId(Id((1 << 8) + 31));
		}
Ejemplo n.º 3
0
 public virtual void Init()
 {
     idBuf  = new MutableObjectId();
     id_1   = new ObjectIdOwnerMapTest.SubId(Id(1));
     id_2   = new ObjectIdOwnerMapTest.SubId(Id(2));
     id_3   = new ObjectIdOwnerMapTest.SubId(Id(3));
     id_a31 = new ObjectIdOwnerMapTest.SubId(Id(31));
     id_b31 = new ObjectIdOwnerMapTest.SubId(Id((1 << 8) + 31));
 }
Ejemplo n.º 4
0
 public virtual void TestReadACK_ACK1()
 {
     ObjectId expid = ObjectId.FromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e");
     MutableObjectId actid = new MutableObjectId();
     Init("0031ACK fcfcfb1fd94829c1a1704f894fc111d14770d34e\n");
     NUnit.Framework.Assert.AreEqual(PacketLineIn.AckNackResult.ACK, @in.ReadACK(actid
         ));
     NUnit.Framework.Assert.IsTrue(actid.Equals(expid));
     AssertEOF();
 }
Ejemplo n.º 5
0
		/// <exception cref="System.IO.IOException"></exception>
		internal virtual PacketLineIn.AckNackResult ReadACK(MutableObjectId returnedId)
		{
			string line = ReadString();
			if (line.Length == 0)
			{
				throw new PackProtocolException(JGitText.Get().expectedACKNAKFoundEOF);
			}
			if ("NAK".Equals(line))
			{
				return PacketLineIn.AckNackResult.NAK;
			}
			if (line.StartsWith("ACK "))
			{
				returnedId.FromString(Sharpen.Runtime.Substring(line, 4, 44));
				if (line.Length == 44)
				{
					return PacketLineIn.AckNackResult.ACK;
				}
				string arg = Sharpen.Runtime.Substring(line, 44);
				if (arg.Equals(" continue"))
				{
					return PacketLineIn.AckNackResult.ACK_CONTINUE;
				}
				else
				{
					if (arg.Equals(" common"))
					{
						return PacketLineIn.AckNackResult.ACK_COMMON;
					}
					else
					{
						if (arg.Equals(" ready"))
						{
							return PacketLineIn.AckNackResult.ACK_READY;
						}
					}
				}
			}
			if (line.StartsWith("ERR "))
			{
				throw new PackProtocolException(Sharpen.Runtime.Substring(line, 4));
			}
			throw new PackProtocolException(MessageFormat.Format(JGitText.Get().expectedACKNAKGot
				, line));
		}
Ejemplo n.º 6
0
		/// <summary>Create a new iterator for the current entry's subtree.</summary>
		/// <remarks>
		/// Create a new iterator for the current entry's subtree.
		/// <p>
		/// The parent reference of the iterator must be <code>this</code>, otherwise
		/// the caller would not be able to exit out of the subtree iterator
		/// correctly and return to continue walking <code>this</code>.
		/// </remarks>
		/// <param name="reader">reader to load the tree data from.</param>
		/// <param name="idBuffer">temporary ObjectId buffer for use by this method.</param>
		/// <returns>a new parser that walks over the current subtree.</returns>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException">
		/// the current entry is not actually a tree and cannot be parsed
		/// as though it were a tree.
		/// </exception>
		/// <exception cref="System.IO.IOException">a loose object or pack file could not be read.
		/// 	</exception>
		public virtual NGit.Treewalk.AbstractTreeIterator CreateSubtreeIterator(ObjectReader
			 reader, MutableObjectId idBuffer)
		{
			return CreateSubtreeIterator(reader);
		}
Ejemplo n.º 7
0
		/// <summary>Obtain the ObjectId for the current entry.</summary>
		/// <remarks>Obtain the ObjectId for the current entry.</remarks>
		/// <param name="out">buffer to copy the object id into.</param>
		public virtual void GetEntryObjectId(MutableObjectId @out)
		{
			@out.FromRaw(IdBuffer, IdOffset);
		}
Ejemplo n.º 8
0
		/// <summary>Initialize a pack parser.</summary>
		/// <remarks>Initialize a pack parser.</remarks>
		/// <param name="odb">database the parser will write its objects into.</param>
		/// <param name="src">the stream the parser will read.</param>
		protected internal PackParser(ObjectDatabase odb, InputStream src)
		{
			objectDatabase = odb.NewCachedDatabase();
			@in = src;
			inflater = new PackParser.InflaterStream(this);
			readCurs = objectDatabase.NewReader();
			buf = new byte[BUFFER_SIZE];
			tempBuffer = new byte[BUFFER_SIZE];
			hdrBuf = new byte[64];
			objectDigest = Constants.NewMessageDigest();
			tempObjectId = new MutableObjectId();
			packDigest = Constants.NewMessageDigest();
		}
Ejemplo n.º 9
0
		// reduce the visibility of the default constructor
		/// <summary>Convert the TreeWalk into DiffEntry headers.</summary>
		/// <remarks>Convert the TreeWalk into DiffEntry headers.</remarks>
		/// <param name="walk">the TreeWalk to walk through. Must have exactly two trees.</param>
		/// <returns>headers describing the changed files.</returns>
		/// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
		public static IList<NGit.Diff.DiffEntry> Scan(TreeWalk walk)
		{
			IList<NGit.Diff.DiffEntry> r = new AList<NGit.Diff.DiffEntry>();
			MutableObjectId idBuf = new MutableObjectId();
			while (walk.Next())
			{
				NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
				walk.GetObjectId(idBuf, 0);
				entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
				walk.GetObjectId(idBuf, 1);
				entry.newId = AbbreviatedObjectId.FromObjectId(idBuf);
				entry.oldMode = walk.GetFileMode(0);
				entry.newMode = walk.GetFileMode(1);
				entry.newPath = entry.oldPath = walk.PathString;
				if (entry.oldMode == FileMode.MISSING)
				{
					entry.oldPath = NGit.Diff.DiffEntry.DEV_NULL;
					entry.changeType = DiffEntry.ChangeType.ADD;
					r.AddItem(entry);
				}
				else
				{
					if (entry.newMode == FileMode.MISSING)
					{
						entry.newPath = NGit.Diff.DiffEntry.DEV_NULL;
						entry.changeType = DiffEntry.ChangeType.DELETE;
						r.AddItem(entry);
					}
					else
					{
						entry.changeType = DiffEntry.ChangeType.MODIFY;
						if (RenameDetector.SameType(entry.oldMode, entry.newMode))
						{
							r.AddItem(entry);
						}
						else
						{
							Sharpen.Collections.AddAll(r, BreakModify(entry));
						}
					}
				}
			}
			return r;
		}
Ejemplo n.º 10
0
		private LeafBucket ParseLeafTree()
		{
			LeafBucket leaf = new LeafBucket(prefix.Length);
			MutableObjectId idBuf = new MutableObjectId();
			for (; !Eof; Next(1))
			{
				if (ParseObjectId(idBuf))
				{
					leaf.ParseOneEntry(idBuf, EntryObjectId);
				}
				else
				{
					StoreNonNote();
				}
			}
			return leaf;
		}
Ejemplo n.º 11
0
 /// <summary>
 /// Convert the TreeWalk into DiffEntry headers, depending on
 /// <code>includeTrees</code>
 /// it will add tree objects into result or not.
 /// </summary>
 /// <param name="walk">
 /// the TreeWalk to walk through. Must have exactly two trees and
 /// when
 /// <code>includeTrees</code>
 /// parameter is
 /// <code>true</code>
 /// it can't
 /// be recursive.
 /// </param>
 /// <param name="includeTrees">include tree object's.</param>
 /// <returns>headers describing the changed files.</returns>
 /// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
 /// <exception cref="System.ArgumentException">
 /// when
 /// <code>includeTrees</code>
 /// is true and given TreeWalk is
 /// recursive. Or when given TreeWalk doesn't have exactly two
 /// trees
 /// </exception>
 public static IList<NGit.Diff.DiffEntry> Scan(TreeWalk walk, bool includeTrees)
 {
     if (walk.TreeCount != 2)
     {
         throw new ArgumentException(JGitText.Get().treeWalkMustHaveExactlyTwoTrees);
     }
     if (includeTrees && walk.Recursive)
     {
         throw new ArgumentException(JGitText.Get().cannotBeRecursiveWhenTreesAreIncluded);
     }
     IList<NGit.Diff.DiffEntry> r = new AList<NGit.Diff.DiffEntry>();
     MutableObjectId idBuf = new MutableObjectId();
     while (walk.Next())
     {
         NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
         walk.GetObjectId(idBuf, 0);
         entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
         walk.GetObjectId(idBuf, 1);
         entry.newId = AbbreviatedObjectId.FromObjectId(idBuf);
         entry.oldMode = walk.GetFileMode(0);
         entry.newMode = walk.GetFileMode(1);
         entry.newPath = entry.oldPath = walk.PathString;
         if (entry.oldMode == FileMode.MISSING)
         {
             entry.oldPath = NGit.Diff.DiffEntry.DEV_NULL;
             entry.changeType = DiffEntry.ChangeType.ADD;
             r.AddItem(entry);
         }
         else
         {
             if (entry.newMode == FileMode.MISSING)
             {
                 entry.newPath = NGit.Diff.DiffEntry.DEV_NULL;
                 entry.changeType = DiffEntry.ChangeType.DELETE;
                 r.AddItem(entry);
             }
             else
             {
                 if (!entry.oldId.Equals(entry.newId))
                 {
                     entry.changeType = DiffEntry.ChangeType.MODIFY;
                     if (RenameDetector.SameType(entry.oldMode, entry.newMode))
                     {
                         r.AddItem(entry);
                     }
                     else
                     {
                         Sharpen.Collections.AddAll(r, BreakModify(entry));
                     }
                 }
                 else
                 {
                     if (entry.oldMode != entry.newMode)
                     {
                         entry.changeType = DiffEntry.ChangeType.MODIFY;
                         r.AddItem(entry);
                     }
                 }
             }
         }
         if (includeTrees && walk.IsSubtree)
         {
             walk.EnterSubtree();
         }
     }
     return r;
 }
 /// <summary>Copying constructor.</summary>
 /// <remarks>Copying constructor.</remarks>
 /// <param name="src">original entry, to copy id from</param>
 internal MutableObjectId(NGit.MutableObjectId src)
 {
     FromObjectId(src);
 }
Ejemplo n.º 13
0
		public virtual void TestReadACK_NAK()
		{
			ObjectId expid = ObjectId.FromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e");
			MutableObjectId actid = new MutableObjectId();
			actid.FromString(expid.Name);
			Init("0008NAK\n");
			NUnit.Framework.Assert.AreEqual(PacketLineIn.AckNackResult.NAK, @in.ReadACK(actid
				));
			NUnit.Framework.Assert.AreEqual(expid, actid);
			AssertEOF();
		}
Ejemplo n.º 14
0
		public virtual void TestSetByte()
		{
			byte[] exp = new byte[20];
			for (int i = 0; i < 20; i++)
			{
				exp[i] = unchecked((byte)(unchecked((int)(0xa0)) + i));
			}
			MutableObjectId id = new MutableObjectId();
			id.FromRaw(exp);
			NUnit.Framework.Assert.AreEqual(ObjectId.FromRaw(exp).Name, id.Name);
			id.SetByte(0, unchecked((int)(0x10)));
			NUnit.Framework.Assert.AreEqual(unchecked((int)(0x10)), id.GetByte(0));
			exp[0] = unchecked((int)(0x10));
			NUnit.Framework.Assert.AreEqual(ObjectId.FromRaw(exp).Name, id.Name);
			for (int p = 1; p < 20; p++)
			{
				id.SetByte(p, unchecked((int)(0x10)) + p);
				NUnit.Framework.Assert.AreEqual(unchecked((int)(0x10)) + p, id.GetByte(p));
				exp[p] = unchecked((byte)(unchecked((int)(0x10)) + p));
				NUnit.Framework.Assert.AreEqual(ObjectId.FromRaw(exp).Name, id.Name);
			}
			for (int p_1 = 0; p_1 < 20; p_1++)
			{
				id.SetByte(p_1, unchecked((int)(0x80)) + p_1);
				NUnit.Framework.Assert.AreEqual(unchecked((int)(0x80)) + p_1, id.GetByte(p_1));
				exp[p_1] = unchecked((byte)(unchecked((int)(0x80)) + p_1));
				NUnit.Framework.Assert.AreEqual(ObjectId.FromRaw(exp).Name, id.Name);
			}
		}
Ejemplo n.º 15
0
		/// <summary>
		/// Constructs a NoteMapMerger with custom
		/// <see cref="NoteMerger">NoteMerger</see>
		/// and custom
		/// <see cref="NGit.Merge.MergeStrategy">NGit.Merge.MergeStrategy</see>
		/// .
		/// </summary>
		/// <param name="db">Git repository</param>
		/// <param name="noteMerger">note merger for merging conflicting changes on a note</param>
		/// <param name="nonNotesMergeStrategy">merge strategy for merging non-note entries</param>
		public NoteMapMerger(Repository db, NoteMerger noteMerger, MergeStrategy nonNotesMergeStrategy
			)
		{
			this.db = db;
			this.reader = db.NewObjectReader();
			this.inserter = db.NewObjectInserter();
			this.noteMerger = noteMerger;
			this.nonNotesMergeStrategy = nonNotesMergeStrategy;
			this.objectIdPrefix = new MutableObjectId();
		}
Ejemplo n.º 16
0
		public virtual void TestLeafSplitsWhenFull()
		{
			RevBlob data1 = tr.Blob("data1");
			MutableObjectId idBuf = new MutableObjectId();
			RevCommit r = tr.Commit().Add(data1.Name, data1).Create();
			//
			//
			tr.ParseBody(r);
			NoteMap map = NoteMap.Read(reader, r);
			for (int i = 0; i < 254; i++)
			{
				idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i);
				map.Set(idBuf, data1);
			}
			RevCommit n = CommitNoteMap(map);
			TreeWalk tw = new TreeWalk(reader);
			tw.Reset(n.Tree);
			while (tw.Next())
			{
				NUnit.Framework.Assert.IsFalse(tw.IsSubtree, "no fan-out subtree");
			}
			for (int i_1 = 254; i_1 < 256; i_1++)
			{
				idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i_1);
				map.Set(idBuf, data1);
			}
			idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 2, 1);
			map.Set(idBuf, data1);
			n = CommitNoteMap(map);
			// The 00 bucket is fully split.
			string path = Fanout(38, idBuf.Name);
			tw = TreeWalk.ForPath(reader, path, n.Tree);
			NUnit.Framework.Assert.IsNotNull(tw, "has " + path);
			// The other bucket is not.
			path = Fanout(2, data1.Name);
			tw = TreeWalk.ForPath(reader, path, n.Tree);
			NUnit.Framework.Assert.IsNotNull(tw, "has " + path);
		}
Ejemplo n.º 17
0
		public virtual void TestEditFlat()
		{
			RevBlob a = tr.Blob("a");
			RevBlob b = tr.Blob("b");
			RevBlob data1 = tr.Blob("data1");
			RevBlob data2 = tr.Blob("data2");
			RevCommit r = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Add(".gitignore", 
				string.Empty).Add("zoo-animals.txt", b).Create();
			//
			//
			//
			//
			//
			tr.ParseBody(r);
			NoteMap map = NoteMap.Read(reader, r);
			map.Set(a, data2);
			map.Set(b, null);
			map.Set(data1, b);
			map.Set(data2, null);
			NUnit.Framework.Assert.AreEqual(data2, map.Get(a));
			NUnit.Framework.Assert.AreEqual(b, map.Get(data1));
			NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
			NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2");
			MutableObjectId id = new MutableObjectId();
			for (int p = 42; p > 0; p--)
			{
				id.SetByte(1, p);
				map.Set(id, data1);
			}
			for (int p_1 = 42; p_1 > 0; p_1--)
			{
				id.SetByte(1, p_1);
				NUnit.Framework.Assert.IsTrue(map.Contains(id), "contains " + id);
			}
			RevCommit n = CommitNoteMap(map);
			map = NoteMap.Read(reader, n);
			NUnit.Framework.Assert.AreEqual(data2, map.Get(a));
			NUnit.Framework.Assert.AreEqual(b, map.Get(data1));
			NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
			NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2");
			NUnit.Framework.Assert.AreEqual(b, TreeWalk.ForPath(reader, "zoo-animals.txt", n.
				Tree).GetObjectId(0));
		}
Ejemplo n.º 18
0
		/// <summary>Create a new pack indexer utility.</summary>
		/// <remarks>Create a new pack indexer utility.</remarks>
		/// <param name="db"></param>
		/// <param name="src">
		/// 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>
		/// <param name="dstBase"></param>
		/// <exception cref="System.IO.IOException">the output packfile could not be created.
		/// 	</exception>
		public IndexPack(Repository db, InputStream src, FilePath dstBase)
		{
			repo = db;
			objectDatabase = db.ObjectDatabase.NewCachedDatabase();
			@in = src;
			inflater = new IndexPack.InflaterStream(this);
			readCurs = objectDatabase.NewReader();
			buf = new byte[BUFFER_SIZE];
			readBuffer = new byte[BUFFER_SIZE];
			objectDigest = Constants.NewMessageDigest();
			tempObjectId = new MutableObjectId();
			packDigest = Constants.NewMessageDigest();
			if (dstBase != null)
			{
				FilePath dir = dstBase.GetParentFile();
				string nam = dstBase.GetName();
				dstPack = new FilePath(dir, nam + ".pack");
				dstIdx = new FilePath(dir, nam + ".idx");
				packOut = new RandomAccessFile(dstPack, "rw");
				packOut.SetLength(0);
			}
			else
			{
				dstPack = null;
				dstIdx = null;
			}
		}
Ejemplo n.º 19
0
		private static AnyObjectId Id(int first)
		{
			MutableObjectId id = new MutableObjectId();
			id.SetByte(1, first);
			return id;
		}
Ejemplo n.º 20
0
		internal BaseSearch(ProgressMonitor countingMonitor, ICollection<RevTree> bases, 
			ObjectIdOwnerMap<ObjectToPack> objects, IList<ObjectToPack> edges, ObjectReader 
			or)
		{
			progress = countingMonitor;
			reader = or;
			baseTrees = Sharpen.Collections.ToArray(bases, new ObjectId[bases.Count]);
			objectsMap = objects;
			edgeObjects = edges;
			alreadyProcessed = new IntSet();
			treeCache = new ObjectIdOwnerMap<BaseSearch.TreeWithData>();
			parser = new CanonicalTreeParser();
			idBuf = new MutableObjectId();
		}
Ejemplo n.º 21
0
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        public override AbstractTreeIterator CreateSubtreeIterator(ObjectReader reader, MutableObjectId
			 idBuffer)
        {
            idBuffer.FromRaw(IdBuffer, IdOffset);
            if (!FileMode.TREE.Equals(mode))
            {
                ObjectId me = idBuffer.ToObjectId();
                throw new IncorrectObjectTypeException(me, Constants.TYPE_TREE);
            }
            return CreateSubtreeIterator0(reader, idBuffer);
        }
Ejemplo n.º 22
0
		private bool ParseObjectId(MutableObjectId id)
		{
			if (pathLen == pathPadding + Constants.OBJECT_ID_STRING_LENGTH)
			{
				try
				{
					id.FromString(path, pathPadding);
					return true;
				}
				catch (IndexOutOfRangeException)
				{
					return false;
				}
			}
			return false;
		}