コード例 #1
0
        public override string ToString()
        {
            byte[] raw            = ToByteArray();
            CanonicalTreeParser p = new CanonicalTreeParser();

            p.Reset(raw);
            StringBuilder r = new StringBuilder();

            r.Append("Tree={");
            if (!p.Eof)
            {
                r.Append('\n');
                try
                {
                    new ObjectChecker().CheckTree(raw);
                }
                catch (CorruptObjectException error)
                {
                    r.Append("*** ERROR: ").Append(error.Message).Append("\n");
                    r.Append('\n');
                }
            }
            while (!p.Eof)
            {
                FileMode mode = p.EntryFileMode;
                r.Append(mode);
                r.Append(' ');
                r.Append(Constants.TypeString(mode.GetObjectType()));
                r.Append(' ');
                r.Append(p.EntryObjectId.Name);
                r.Append(' ');
                r.Append(p.EntryPathString);
                r.Append('\n');
                p.Next();
            }
            r.Append("}");
            return(r.ToString());
        }
コード例 #2
0
ファイル: ObjectWalk.cs プロジェクト: shoff/ngit
        /// <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);
            }
        }