Esempio n. 1
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;
			}
		}