Example #1
0
        public virtual void TestCull()
        {
            RevBlob   f1 = Blob("1");
            RevBlob   f2 = Blob("2");
            RevBlob   f3 = Blob("3");
            RevBlob   f4 = Blob("4");
            RevTree   ta = Tree(File("a/1", f1), File("c/3", f3));
            RevCommit a  = Commit(ta);
            RevTree   tb = Tree(File("a/1", f2), File("c/3", f3));
            RevCommit b1 = Commit(tb, a);
            RevCommit b2 = Commit(tb, b1);
            RevTree   tc = Tree(File("a/1", f4));
            RevCommit c1 = Commit(tc, a);
            RevCommit c2 = Commit(tc, c1);

            MarkStart(b2);
            MarkUninteresting(c2);
            AssertCommit(b2, objw.Next());
            AssertCommit(b1, objw.Next());
            NUnit.Framework.Assert.IsNull(objw.Next());
            NUnit.Framework.Assert.IsTrue(a.Has(RevFlag.UNINTERESTING));
            NUnit.Framework.Assert.IsTrue(ta.Has(RevFlag.UNINTERESTING));
            NUnit.Framework.Assert.IsTrue(f1.Has(RevFlag.UNINTERESTING));
            NUnit.Framework.Assert.IsTrue(f3.Has(RevFlag.UNINTERESTING));
            NUnit.Framework.Assert.AreSame(tb, objw.NextObject());
            NUnit.Framework.Assert.AreSame(Get(tb, "a"), objw.NextObject());
            NUnit.Framework.Assert.AreSame(f2, objw.NextObject());
            NUnit.Framework.Assert.IsNull(objw.NextObject());
        }
Example #2
0
 public override void Dispose()
 {
     base.Dispose();
     pendingObjects = new BlockObjQueue();
     treeWalk       = new CanonicalTreeParser();
     currentTree    = null;
     last           = null;
     firstCommit    = null;
     lastCommit     = null;
 }
Example #3
0
 protected internal override void Reset(int retainFlags)
 {
     base.Reset(retainFlags);
     foreach (RevObject obj in rootObjects)
     {
         obj.flags &= ~IN_PENDING;
     }
     rootObjects    = new AList <RevObject>();
     pendingObjects = new BlockObjQueue();
     treeWalk       = new CanonicalTreeParser();
     currentTree    = null;
     last           = null;
     firstCommit    = null;
     lastCommit     = null;
 }
Example #4
0
        public virtual void TestOneCommitOneTreeTwoBlob()
        {
            RevBlob   f0 = Blob("0");
            RevBlob   f1 = Blob("1");
            RevTree   t  = Tree(File("0", f0), File("1", f1), File("2", f1));
            RevCommit a  = Commit(t);

            MarkStart(a);
            AssertCommit(a, objw.Next());
            NUnit.Framework.Assert.IsNull(objw.Next());
            NUnit.Framework.Assert.AreSame(t, objw.NextObject());
            NUnit.Framework.Assert.AreSame(f0, objw.NextObject());
            NUnit.Framework.Assert.AreSame(f1, objw.NextObject());
            NUnit.Framework.Assert.IsNull(objw.NextObject());
        }
Example #5
0
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private void MarkTreeUninteresting(RevTree tree)
        {
            if ((tree.flags & UNINTERESTING) != 0)
            {
                return;
            }
            tree.flags |= UNINTERESTING;
            treeWalk    = treeWalk.ResetRoot(reader, tree);
            while (!treeWalk.Eof)
            {
                FileMode mode  = treeWalk.EntryFileMode;
                int      sType = mode.GetObjectType();
                switch (sType)
                {
                case Constants.OBJ_BLOB:
                {
                    treeWalk.GetEntryObjectId(idBuffer);
                    LookupBlob(idBuffer).flags |= UNINTERESTING;
                    break;
                }

                case Constants.OBJ_TREE:
                {
                    treeWalk.GetEntryObjectId(idBuffer);
                    RevTree t = LookupTree(idBuffer);
                    if ((t.flags & UNINTERESTING) == 0)
                    {
                        t.flags |= UNINTERESTING;
                        treeWalk = treeWalk.CreateSubtreeIterator0(reader, t);
                        continue;
                    }
                    break;
                }

                default:
                {
                    if (FileMode.GITLINK.Equals(mode))
                    {
                        break;
                    }
                    treeWalk.GetEntryObjectId(idBuffer);
                    throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
                                                                          , mode, idBuffer.Name, treeWalk.EntryPathString, tree));
                }
                }
                treeWalk = treeWalk.Next();
            }
        }
Example #6
0
        public virtual void TestTwoCommitTwoTreeTwoBlob()
        {
            RevBlob   f0 = Blob("0");
            RevBlob   f1 = Blob("1");
            RevBlob   f2 = Blob("0v2");
            RevTree   ta = Tree(File("0", f0), File("1", f1), File("2", f1));
            RevTree   tb = Tree(File("0", f2), File("1", f1), File("2", f1));
            RevCommit a  = Commit(ta);
            RevCommit b  = Commit(tb, a);

            MarkStart(b);
            AssertCommit(b, objw.Next());
            AssertCommit(a, objw.Next());
            NUnit.Framework.Assert.IsNull(objw.Next());
            NUnit.Framework.Assert.AreSame(tb, objw.NextObject());
            NUnit.Framework.Assert.AreSame(f2, objw.NextObject());
            NUnit.Framework.Assert.AreSame(f1, objw.NextObject());
            NUnit.Framework.Assert.AreSame(ta, objw.NextObject());
            NUnit.Framework.Assert.AreSame(f0, objw.NextObject());
            NUnit.Framework.Assert.IsNull(objw.NextObject());
        }
Example #7
0
        public virtual void TestTwoCommitDeepTree2()
        {
            RevBlob   f1 = Blob("1");
            RevTree   ta = Tree(File("a/b/0", f1), File("a/c/q", f1));
            RevTree   tb = Tree(File("a/b/1", f1), File("a/c/q", f1));
            RevCommit a  = Commit(ta);
            RevCommit b  = Commit(tb, a);

            MarkStart(b);
            AssertCommit(b, objw.Next());
            AssertCommit(a, objw.Next());
            NUnit.Framework.Assert.IsNull(objw.Next());
            NUnit.Framework.Assert.AreSame(tb, objw.NextObject());
            NUnit.Framework.Assert.AreSame(Get(tb, "a"), objw.NextObject());
            NUnit.Framework.Assert.AreSame(Get(tb, "a/b"), objw.NextObject());
            NUnit.Framework.Assert.AreSame(f1, objw.NextObject());
            NUnit.Framework.Assert.AreSame(Get(tb, "a/c"), objw.NextObject());
            NUnit.Framework.Assert.AreSame(ta, objw.NextObject());
            NUnit.Framework.Assert.AreSame(Get(ta, "a"), objw.NextObject());
            NUnit.Framework.Assert.AreSame(Get(ta, "a/b"), objw.NextObject());
            NUnit.Framework.Assert.IsNull(objw.NextObject());
        }
Example #8
0
		/// <summary>Pop the next most recent object.</summary>
		/// <remarks>Pop the next most recent object.</remarks>
		/// <returns>next most recent object; null if traversal is over.</returns>
		/// <exception cref="NGit.Errors.MissingObjectException">
		/// one or or more of the next objects are not available from the
		/// object database, but were thought to be candidates for
		/// traversal. This usually indicates a broken link.
		/// </exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException">
		/// one or or more of the objects in a tree do not match the type
		/// indicated.
		/// </exception>
		/// <exception cref="System.IO.IOException">a pack file or loose object could not be read.
		/// 	</exception>
		public virtual RevObject NextObject()
		{
			pathLen = 0;
			ObjectWalk.TreeVisit tv = currVisit;
			while (tv != null)
			{
				byte[] buf = tv.buf;
				for (int ptr = tv.ptr; ptr < buf.Length; )
				{
					int startPtr = ptr;
					ptr = FindObjectId(buf, ptr);
					idBuffer.FromRaw(buf, ptr);
					ptr += ID_SZ;
					RevObject obj = objects.Get(idBuffer);
					if (obj != null && (obj.flags & SEEN) != 0)
					{
						continue;
					}
					int mode = ParseMode(buf, startPtr, ptr, tv);
					int flags;
					switch ((int)(((uint)mode) >> TYPE_SHIFT))
					{
						case TYPE_FILE:
						case TYPE_SYMLINK:
						{
							if (obj == null)
							{
								obj = new RevBlob(idBuffer);
								obj.flags = SEEN;
								objects.Add(obj);
								return obj;
							}
							if (!(obj is RevBlob))
							{
								throw new IncorrectObjectTypeException(obj, Constants.OBJ_BLOB);
							}
							obj.flags = flags = obj.flags | SEEN;
							if ((flags & UNINTERESTING) == 0)
							{
								return obj;
							}
							if (boundary)
							{
								return obj;
							}
							continue;
							goto case TYPE_TREE;
						}

						case TYPE_TREE:
						{
							if (obj == null)
							{
								obj = new RevTree(idBuffer);
								obj.flags = SEEN;
								objects.Add(obj);
								return EnterTree(obj);
							}
							if (!(obj is RevTree))
							{
								throw new IncorrectObjectTypeException(obj, Constants.OBJ_TREE);
							}
							obj.flags = flags = obj.flags | SEEN;
							if ((flags & UNINTERESTING) == 0)
							{
								return EnterTree(obj);
							}
							if (boundary)
							{
								return EnterTree(obj);
							}
							continue;
							goto case TYPE_GITLINK;
						}

						case TYPE_GITLINK:
						{
							continue;
							goto default;
						}

						default:
						{
							throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
								, string.Format("%o", Sharpen.Extensions.ValueOf(mode)), idBuffer.Name, RawParseUtils
								.Decode(buf, tv.namePtr, tv.nameEnd), tv.obj));
						}
					}
				}
				currVisit = tv.parent;
				ReleaseTreeVisit(tv);
				tv = currVisit;
			}
			for (; ; )
			{
				RevObject o = pendingObjects.Next();
				if (o == null)
				{
					reader.WalkAdviceEnd();
					return null;
				}
				int flags = o.flags;
				if ((flags & SEEN) != 0)
				{
					continue;
				}
				flags |= SEEN;
				o.flags = flags;
				if ((flags & UNINTERESTING) == 0 | boundary)
				{
					if (o is RevTree)
					{
						tv = NewTreeVisit(o);
						tv.parent = null;
						currVisit = tv;
					}
					return o;
				}
			}
		}
Example #9
0
		internal virtual void ParseCanonical(RevWalk walk, byte[] raw)
		{
			MutableObjectId idBuffer = walk.idBuffer;
			idBuffer.FromString(raw, 5);
			tree = walk.LookupTree(idBuffer);
			int ptr = 46;
			if (parents == null)
			{
				NGit.Revwalk.RevCommit[] pList = new NGit.Revwalk.RevCommit[1];
				int nParents = 0;
				for (; ; )
				{
					if (raw[ptr] != 'p')
					{
						break;
					}
					idBuffer.FromString(raw, ptr + 7);
					NGit.Revwalk.RevCommit p = walk.LookupCommit(idBuffer);
					if (nParents == 0)
					{
						pList[nParents++] = p;
					}
					else
					{
						if (nParents == 1)
						{
							pList = new NGit.Revwalk.RevCommit[] { pList[0], p };
							nParents = 2;
						}
						else
						{
							if (pList.Length <= nParents)
							{
								NGit.Revwalk.RevCommit[] old = pList;
								pList = new NGit.Revwalk.RevCommit[pList.Length + 32];
								System.Array.Copy(old, 0, pList, 0, nParents);
							}
							pList[nParents++] = p;
						}
					}
					ptr += 48;
				}
				if (nParents != pList.Length)
				{
					NGit.Revwalk.RevCommit[] old = pList;
					pList = new NGit.Revwalk.RevCommit[nParents];
					System.Array.Copy(old, 0, pList, 0, nParents);
				}
				parents = pList;
			}
			// extract time from "committer "
			ptr = RawParseUtils.Committer(raw, ptr);
			if (ptr > 0)
			{
				ptr = RawParseUtils.NextLF(raw, ptr, '>');
				// In 2038 commitTime will overflow unless it is changed to long.
				commitTime = RawParseUtils.ParseBase10(raw, ptr, null);
			}
			if (walk.IsRetainBody())
			{
				buffer = raw;
			}
			flags |= PARSED;
		}
Example #10
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private void MarkTreeUninteresting(RevTree tree)
		{
			if ((tree.flags & UNINTERESTING) != 0)
			{
				return;
			}
			tree.flags |= UNINTERESTING;
			treeWalk = treeWalk.ResetRoot(reader, tree);
			while (!treeWalk.Eof)
			{
				FileMode mode = treeWalk.EntryFileMode;
				int sType = mode.GetObjectType();
				switch (sType)
				{
					case Constants.OBJ_BLOB:
					{
						treeWalk.GetEntryObjectId(idBuffer);
						LookupBlob(idBuffer).flags |= UNINTERESTING;
						break;
					}

					case Constants.OBJ_TREE:
					{
						treeWalk.GetEntryObjectId(idBuffer);
						RevTree t = LookupTree(idBuffer);
						if ((t.flags & UNINTERESTING) == 0)
						{
							t.flags |= UNINTERESTING;
							treeWalk = treeWalk.CreateSubtreeIterator0(reader, t);
							continue;
						}
						break;
					}

					default:
					{
						if (FileMode.GITLINK.Equals(mode))
						{
							break;
						}
						treeWalk.GetEntryObjectId(idBuffer);
						throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
							, mode, idBuffer.Name, treeWalk.EntryPathString, tree));
					}
				}
				treeWalk = treeWalk.Next();
			}
		}
Example #11
0
		protected internal override void Reset(int retainFlags)
		{
			base.Reset(retainFlags);
			foreach (RevObject obj in rootObjects)
			{
				obj.flags &= ~IN_PENDING;
			}
			rootObjects = new AList<RevObject>();
			pendingObjects = new BlockObjQueue();
			treeWalk = new CanonicalTreeParser();
			currentTree = null;
			last = null;
			firstCommit = null;
			lastCommit = null;
		}
Example #12
0
		public override void Dispose()
		{
			base.Dispose();
			pendingObjects = new BlockObjQueue();
			treeWalk = new CanonicalTreeParser();
			currentTree = null;
			last = null;
			firstCommit = null;
			lastCommit = null;
		}
Example #13
0
        /// <exception cref="NGit.Errors.MissingObjectException"></exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
        /// <exception cref="System.IO.IOException"></exception>
        private void MarkTreeUninteresting(RevTree tree)
        {
            if ((tree.flags & UNINTERESTING) != 0)
            {
                return;
            }
            tree.flags |= UNINTERESTING;
            byte[] raw = reader.Open(tree, Constants.OBJ_TREE).GetCachedBytes();
            for (int ptr = 0; ptr < raw.Length;)
            {
                byte c    = raw[ptr];
                int  mode = c - '0';
                for (; ;)
                {
                    c = raw[++ptr];
                    if (' ' == c)
                    {
                        break;
                    }
                    mode <<= 3;
                    mode  += c - '0';
                }
                while (raw[++ptr] != 0)
                {
                }
                // Skip entry name.
                ptr++;
                switch ((int)(((uint)mode) >> TYPE_SHIFT))
                {
                case TYPE_FILE:
                case TYPE_SYMLINK:
                {
                    // Skip NUL after entry name.
                    idBuffer.FromRaw(raw, ptr);
                    LookupBlob(idBuffer).flags |= UNINTERESTING;
                    break;
                }

                case TYPE_TREE:
                {
                    idBuffer.FromRaw(raw, ptr);
                    MarkTreeUninteresting(LookupTree(idBuffer));
                    break;
                }

                case TYPE_GITLINK:
                {
                    break;
                }

                default:
                {
                    idBuffer.FromRaw(raw, ptr);
                    throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
                                                                          , string.Format("%o", Sharpen.Extensions.ValueOf(mode)), idBuffer.Name, string.Empty
                                                                          , tree));
                }
                }
                ptr += ID_SZ;
            }
        }
Example #14
0
        internal virtual void ParseCanonical(RevWalk walk, byte[] raw)
        {
            MutableObjectId idBuffer = walk.idBuffer;

            idBuffer.FromString(raw, 5);
            tree = walk.LookupTree(idBuffer);
            int ptr = 46;

            if (parents == null)
            {
                NGit.Revwalk.RevCommit[] pList = new NGit.Revwalk.RevCommit[1];
                int nParents = 0;
                for (; ;)
                {
                    if (raw[ptr] != 'p')
                    {
                        break;
                    }
                    idBuffer.FromString(raw, ptr + 7);
                    NGit.Revwalk.RevCommit p = walk.LookupCommit(idBuffer);
                    if (nParents == 0)
                    {
                        pList[nParents++] = p;
                    }
                    else
                    {
                        if (nParents == 1)
                        {
                            pList    = new NGit.Revwalk.RevCommit[] { pList[0], p };
                            nParents = 2;
                        }
                        else
                        {
                            if (pList.Length <= nParents)
                            {
                                NGit.Revwalk.RevCommit[] old = pList;
                                pList = new NGit.Revwalk.RevCommit[pList.Length + 32];
                                System.Array.Copy(old, 0, pList, 0, nParents);
                            }
                            pList[nParents++] = p;
                        }
                    }
                    ptr += 48;
                }
                if (nParents != pList.Length)
                {
                    NGit.Revwalk.RevCommit[] old = pList;
                    pList = new NGit.Revwalk.RevCommit[nParents];
                    System.Array.Copy(old, 0, pList, 0, nParents);
                }
                parents = pList;
            }
            // extract time from "committer "
            ptr = RawParseUtils.Committer(raw, ptr);
            if (ptr > 0)
            {
                ptr = RawParseUtils.NextLF(raw, ptr, '>');
                // In 2038 commitTime will overflow unless it is changed to long.
                commitTime = RawParseUtils.ParseBase10(raw, ptr, null);
            }
            if (walk.IsRetainBody())
            {
                buffer = raw;
            }
            flags |= PARSED;
        }
		/// <exception cref="System.IO.IOException"></exception>
		private void MarkTreeComplete(RevTree tree)
		{
			if (tree.Has(COMPLETE))
			{
				return;
			}
			tree.Add(COMPLETE);
			treeWalk.Reset(tree);
			while (treeWalk.Next())
			{
				FileMode mode = treeWalk.GetFileMode(0);
				int sType = mode.GetObjectType();
				switch (sType)
				{
					case Constants.OBJ_BLOB:
					{
						treeWalk.GetObjectId(idBuffer, 0);
						revWalk.LookupAny(idBuffer, sType).Add(COMPLETE);
						continue;
						goto case Constants.OBJ_TREE;
					}

					case Constants.OBJ_TREE:
					{
						treeWalk.GetObjectId(idBuffer, 0);
						RevObject o = revWalk.LookupAny(idBuffer, sType);
						if (!o.Has(COMPLETE))
						{
							o.Add(COMPLETE);
							treeWalk.EnterSubtree();
						}
						continue;
						goto default;
					}

					default:
					{
						if (FileMode.GITLINK.Equals(mode))
						{
							continue;
						}
						treeWalk.GetObjectId(idBuffer, 0);
						throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
							, mode, idBuffer.Name, treeWalk.PathString, tree.Name));
					}
				}
			}
		}
Example #16
0
		protected internal override void Reset(int retainFlags)
		{
			base.Reset(retainFlags);
			pendingObjects = new BlockObjQueue();
			treeWalk = new CanonicalTreeParser();
			currentTree = null;
			last = null;
			firstCommit = null;
			lastCommit = null;
		}
Example #17
0
		/// <summary>Load a collection of notes from a tree.</summary>
		/// <remarks>Load a collection of notes from a tree.</remarks>
		/// <param name="reader">
		/// reader to scan the note branch with. This reader may be
		/// retained by the NoteMap for the life of the map in order to
		/// support lazy loading of entries.
		/// </param>
		/// <param name="tree">the note tree to read.</param>
		/// <returns>the note map read from the tree.</returns>
		/// <exception cref="System.IO.IOException">the repository cannot be accessed through the reader.
		/// 	</exception>
		/// <exception cref="NGit.Errors.CorruptObjectException">a tree object is corrupt and cannot be read.
		/// 	</exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException">a tree object wasn't actually a tree.
		/// 	</exception>
		/// <exception cref="NGit.Errors.MissingObjectException">a reference tree object doesn't exist.
		/// 	</exception>
		public static NGit.Notes.NoteMap Read(ObjectReader reader, RevTree tree)
		{
			return ReadTree(reader, tree);
		}
Example #18
0
		/// <exception cref="NGit.Errors.MissingObjectException"></exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
		/// <exception cref="System.IO.IOException"></exception>
		private void MarkTreeUninteresting(RevTree tree)
		{
			if ((tree.flags & UNINTERESTING) != 0)
			{
				return;
			}
			tree.flags |= UNINTERESTING;
			byte[] raw = reader.Open(tree, Constants.OBJ_TREE).GetCachedBytes();
			for (int ptr = 0; ptr < raw.Length; )
			{
				byte c = raw[ptr];
				int mode = c - '0';
				for (; ; )
				{
					c = raw[++ptr];
					if (' ' == c)
					{
						break;
					}
					mode <<= 3;
					mode += c - '0';
				}
				while (raw[++ptr] != 0)
				{
				}
				// Skip entry name.
				ptr++;
				switch ((int)(((uint)mode) >> TYPE_SHIFT))
				{
					case TYPE_FILE:
					case TYPE_SYMLINK:
					{
						// Skip NUL after entry name.
						idBuffer.FromRaw(raw, ptr);
						LookupBlob(idBuffer).flags |= UNINTERESTING;
						break;
					}

					case TYPE_TREE:
					{
						idBuffer.FromRaw(raw, ptr);
						MarkTreeUninteresting(LookupTree(idBuffer));
						break;
					}

					case TYPE_GITLINK:
					{
						break;
					}

					default:
					{
						idBuffer.FromRaw(raw, ptr);
						throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
							, string.Format("%o", Sharpen.Extensions.ValueOf(mode)), idBuffer.Name, string.Empty
							, tree));
					}
				}
				ptr += ID_SZ;
			}
		}
Example #19
0
 /// <exception cref="System.Exception"></exception>
 protected internal virtual RevCommit Commit(RevTree tree, params RevCommit[] parents
                                             )
 {
     return(util.Commit(tree, parents));
 }
Example #20
0
		/// <summary>Set the common ancestor tree.</summary>
		/// <remarks>Set the common ancestor tree.</remarks>
		/// <param name="id">
		/// common base treeish; null to automatically compute the common
		/// base from the input commits during
		/// <see cref="Merge(NGit.AnyObjectId[])">Merge(NGit.AnyObjectId[])</see>
		/// .
		/// </param>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException">the object is not a treeish.
		/// 	</exception>
		/// <exception cref="NGit.Errors.MissingObjectException">the object does not exist.</exception>
		/// <exception cref="System.IO.IOException">the object could not be read.</exception>
		public virtual void SetBase(AnyObjectId id)
		{
			if (id != null)
			{
				baseTree = walk.ParseTree(id);
			}
			else
			{
				baseTree = null;
			}
		}
Example #21
0
        /// <summary>Pop the next most recent object.</summary>
        /// <remarks>Pop the next most recent object.</remarks>
        /// <returns>next most recent object; null if traversal is over.</returns>
        /// <exception cref="NGit.Errors.MissingObjectException">
        /// one or or more of the next objects are not available from the
        /// object database, but were thought to be candidates for
        /// traversal. This usually indicates a broken link.
        /// </exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException">
        /// one or or more of the objects in a tree do not match the type
        /// indicated.
        /// </exception>
        /// <exception cref="System.IO.IOException">a pack file or loose object could not be read.
        ///     </exception>
        public virtual RevObject NextObject()
        {
            pathLen = 0;
            ObjectWalk.TreeVisit tv = currVisit;
            while (tv != null)
            {
                byte[] buf = tv.buf;
                for (int ptr = tv.ptr; ptr < buf.Length;)
                {
                    int startPtr = ptr;
                    ptr = FindObjectId(buf, ptr);
                    idBuffer.FromRaw(buf, ptr);
                    ptr += ID_SZ;
                    RevObject obj = objects.Get(idBuffer);
                    if (obj != null && (obj.flags & SEEN) != 0)
                    {
                        continue;
                    }
                    int mode = ParseMode(buf, startPtr, ptr, tv);
                    int flags;
                    switch ((int)(((uint)mode) >> TYPE_SHIFT))
                    {
                    case TYPE_FILE:
                    case TYPE_SYMLINK:
                    {
                        if (obj == null)
                        {
                            obj       = new RevBlob(idBuffer);
                            obj.flags = SEEN;
                            objects.Add(obj);
                            return(obj);
                        }
                        if (!(obj is RevBlob))
                        {
                            throw new IncorrectObjectTypeException(obj, Constants.OBJ_BLOB);
                        }
                        obj.flags = flags = obj.flags | SEEN;
                        if ((flags & UNINTERESTING) == 0)
                        {
                            return(obj);
                        }
                        if (boundary)
                        {
                            return(obj);
                        }
                        continue;
                        goto case TYPE_TREE;
                    }

                    case TYPE_TREE:
                    {
                        if (obj == null)
                        {
                            obj       = new RevTree(idBuffer);
                            obj.flags = SEEN;
                            objects.Add(obj);
                            return(EnterTree(obj));
                        }
                        if (!(obj is RevTree))
                        {
                            throw new IncorrectObjectTypeException(obj, Constants.OBJ_TREE);
                        }
                        obj.flags = flags = obj.flags | SEEN;
                        if ((flags & UNINTERESTING) == 0)
                        {
                            return(EnterTree(obj));
                        }
                        if (boundary)
                        {
                            return(EnterTree(obj));
                        }
                        continue;
                        goto case TYPE_GITLINK;
                    }

                    case TYPE_GITLINK:
                    {
                        continue;
                        goto default;
                    }

                    default:
                    {
                        throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
                                                                              , string.Format("%o", Sharpen.Extensions.ValueOf(mode)), idBuffer.Name, RawParseUtils
                                                                              .Decode(buf, tv.namePtr, tv.nameEnd), tv.obj));
                    }
                    }
                }
                currVisit = tv.parent;
                ReleaseTreeVisit(tv);
                tv = currVisit;
            }
            for (; ;)
            {
                RevObject o = pendingObjects.Next();
                if (o == null)
                {
                    reader.WalkAdviceEnd();
                    return(null);
                }
                int flags = o.flags;
                if ((flags & SEEN) != 0)
                {
                    continue;
                }
                flags  |= SEEN;
                o.flags = flags;
                if ((flags & UNINTERESTING) == 0 | boundary)
                {
                    if (o is RevTree)
                    {
                        tv        = NewTreeVisit(o);
                        tv.parent = null;
                        currVisit = tv;
                    }
                    return(o);
                }
            }
        }
Example #22
0
		/// <summary>Construct an Indexdiff</summary>
		/// <param name="repository"></param>
		/// <param name="objectId">tree id. If null, an EmptyTreeIterator is used.</param>
		/// <param name="workingTreeIterator">iterator for working directory</param>
		/// <exception cref="System.IO.IOException">System.IO.IOException</exception>
		public IndexDiff(Repository repository, ObjectId objectId, WorkingTreeIterator workingTreeIterator
			)
		{
			this.repository = repository;
			if (objectId != null)
			{
				tree = new RevWalk(repository).ParseTree(objectId);
			}
			else
			{
				tree = null;
			}
			this.initialWorkingTreeIterator = workingTreeIterator;
		}
Example #23
0
		/// <summary>
		/// Add a subtree, mode is
		/// <see cref="FileMode.TREE">FileMode.TREE</see>
		/// .
		/// </summary>
		/// <param name="name">name of the entry.</param>
		/// <param name="tree">the ObjectId to store in this entry.</param>
		public virtual void Append(string name, RevTree tree)
		{
			Append(name, FileMode.TREE, tree);
		}
Example #24
0
 /// <exception cref="System.Exception"></exception>
 protected internal virtual RevObject Get(RevTree tree, string path)
 {
     return(util.Get(tree, path));
 }
Example #25
0
		/// <summary>Pop the next most recent object.</summary>
		/// <remarks>Pop the next most recent object.</remarks>
		/// <returns>next most recent object; null if traversal is over.</returns>
		/// <exception cref="NGit.Errors.MissingObjectException">
		/// one or or more of the next objects are not available from the
		/// object database, but were thought to be candidates for
		/// traversal. This usually indicates a broken link.
		/// </exception>
		/// <exception cref="NGit.Errors.IncorrectObjectTypeException">
		/// one or or more of the objects in a tree do not match the type
		/// indicated.
		/// </exception>
		/// <exception cref="System.IO.IOException">a pack file or loose object could not be read.
		/// 	</exception>
		public virtual RevObject NextObject()
		{
			if (last != null)
			{
				treeWalk = last is RevTree ? Enter(last) : treeWalk.Next();
			}
			while (!treeWalk.Eof)
			{
				FileMode mode = treeWalk.EntryFileMode;
				switch (mode.GetObjectType())
				{
					case Constants.OBJ_BLOB:
					{
						treeWalk.GetEntryObjectId(idBuffer);
						RevBlob o = LookupBlob(idBuffer);
						if ((o.flags & SEEN) != 0)
						{
							break;
						}
						o.flags |= SEEN;
						if (ShouldSkipObject(o))
						{
							break;
						}
						last = o;
						return o;
					}

					case Constants.OBJ_TREE:
					{
						treeWalk.GetEntryObjectId(idBuffer);
						RevTree o = LookupTree(idBuffer);
						if ((o.flags & SEEN) != 0)
						{
							break;
						}
						o.flags |= SEEN;
						if (ShouldSkipObject(o))
						{
							break;
						}
						last = o;
						return o;
					}

					default:
					{
						if (FileMode.GITLINK.Equals(mode))
						{
							break;
						}
						treeWalk.GetEntryObjectId(idBuffer);
						throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
							, mode, idBuffer.Name, treeWalk.EntryPathString, currentTree.Name));
					}
				}
				treeWalk = treeWalk.Next();
			}
			if (firstCommit != null)
			{
				reader.WalkAdviceBeginTrees(this, firstCommit, lastCommit);
				firstCommit = null;
				lastCommit = null;
			}
			last = null;
			for (; ; )
			{
				RevObject o = pendingObjects.Next();
				if (o == null)
				{
					reader.WalkAdviceEnd();
					return null;
				}
				if ((o.flags & SEEN) != 0)
				{
					continue;
				}
				o.flags |= SEEN;
				if (ShouldSkipObject(o))
				{
					continue;
				}
				if (o is RevTree)
				{
					currentTree = (RevTree)o;
					treeWalk = treeWalk.ResetRoot(reader, currentTree);
				}
				return o;
			}
		}
Example #26
0
 /// <exception cref="System.Exception"></exception>
 protected internal virtual RevCommit Commit(int secDelta, RevTree tree, params RevCommit
                                             [] parents)
 {
     return(util.Commit(secDelta, tree, parents));
 }
Example #27
0
        /// <summary>Pop the next most recent object.</summary>
        /// <remarks>Pop the next most recent object.</remarks>
        /// <returns>next most recent object; null if traversal is over.</returns>
        /// <exception cref="NGit.Errors.MissingObjectException">
        /// one or or more of the next objects are not available from the
        /// object database, but were thought to be candidates for
        /// traversal. This usually indicates a broken link.
        /// </exception>
        /// <exception cref="NGit.Errors.IncorrectObjectTypeException">
        /// one or or more of the objects in a tree do not match the type
        /// indicated.
        /// </exception>
        /// <exception cref="System.IO.IOException">a pack file or loose object could not be read.
        ///     </exception>
        public virtual RevObject NextObject()
        {
            if (last != null)
            {
                treeWalk = last is RevTree?Enter(last) : treeWalk.Next();
            }
            while (!treeWalk.Eof)
            {
                FileMode mode = treeWalk.EntryFileMode;
                switch (mode.GetObjectType())
                {
                case Constants.OBJ_BLOB:
                {
                    treeWalk.GetEntryObjectId(idBuffer);
                    RevBlob o = LookupBlob(idBuffer);
                    if ((o.flags & SEEN) != 0)
                    {
                        break;
                    }
                    o.flags |= SEEN;
                    if (ShouldSkipObject(o))
                    {
                        break;
                    }
                    last = o;
                    return(o);
                }

                case Constants.OBJ_TREE:
                {
                    treeWalk.GetEntryObjectId(idBuffer);
                    RevTree o = LookupTree(idBuffer);
                    if ((o.flags & SEEN) != 0)
                    {
                        break;
                    }
                    o.flags |= SEEN;
                    if (ShouldSkipObject(o))
                    {
                        break;
                    }
                    last = o;
                    return(o);
                }

                default:
                {
                    if (FileMode.GITLINK.Equals(mode))
                    {
                        break;
                    }
                    treeWalk.GetEntryObjectId(idBuffer);
                    throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().corruptObjectInvalidMode3
                                                                          , mode, idBuffer.Name, treeWalk.EntryPathString, currentTree.Name));
                }
                }
                treeWalk = treeWalk.Next();
            }
            if (firstCommit != null)
            {
                reader.WalkAdviceBeginTrees(this, firstCommit, lastCommit);
                firstCommit = null;
                lastCommit  = null;
            }
            last = null;
            for (; ;)
            {
                RevObject o = pendingObjects.Next();
                if (o == null)
                {
                    reader.WalkAdviceEnd();
                    return(null);
                }
                if ((o.flags & SEEN) != 0)
                {
                    continue;
                }
                o.flags |= SEEN;
                if (ShouldSkipObject(o))
                {
                    continue;
                }
                if (o is RevTree)
                {
                    currentTree = (RevTree)o;
                    treeWalk    = treeWalk.ResetRoot(reader, currentTree);
                }
                return(o);
            }
        }