Esempio n. 1
0
        /// <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));
                }
                }
            }
        }
Esempio n. 2
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();
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Executes the
        /// <code>Rm</code>
        /// command. Each instance of this class should only
        /// be used for one invocation of the command. Don't call this method twice
        /// on an instance.
        /// </summary>
        /// <returns>the DirCache after Rm</returns>
        /// <exception cref="NGit.Api.Errors.NoFilepatternException"></exception>
        public override DirCache Call()
        {
            if (filepatterns.IsEmpty())
            {
                throw new NoFilepatternException(JGitText.Get().atLeastOnePatternIsRequired);
            }
            CheckCallable();
            DirCache dc = null;

            try
            {
                dc = repo.LockDirCache();
                DirCacheBuilder builder = dc.Builder();
                TreeWalk        tw      = new TreeWalk(repo);
                tw.Reset();
                // drop the first empty tree, which we do not need here
                tw.Recursive = true;
                tw.Filter    = PathFilterGroup.CreateFromStrings(filepatterns);
                tw.AddTree(new DirCacheBuildIterator(builder));
                while (tw.Next())
                {
                    FilePath path = new FilePath(repo.WorkTree, tw.PathString);
                    FileMode mode = tw.GetFileMode(0);
                    if (mode.GetObjectType() == Constants.OBJ_BLOB)
                    {
                        // Deleting a blob is simply a matter of removing
                        // the file or symlink named by the tree entry.
                        Delete(path);
                    }
                }
                builder.Commit();
                SetCallable(false);
            }
            catch (IOException e)
            {
                throw new JGitInternalException(JGitText.Get().exceptionCaughtDuringExecutionOfRmCommand
                                                , e);
            }
            finally
            {
                if (dc != null)
                {
                    dc.Unlock();
                }
            }
            return(dc);
        }
Esempio n. 4
0
        /// <exception cref="NGit.Errors.TransportException"></exception>
        private void ProcessTree(RevObject obj)
        {
            try
            {
                treeWalk.Reset(obj);
                while (treeWalk.Next())
                {
                    FileMode mode  = treeWalk.GetFileMode(0);
                    int      sType = mode.GetObjectType();
                    switch (sType)
                    {
                    case Constants.OBJ_BLOB:
                    case Constants.OBJ_TREE:
                    {
                        treeWalk.GetObjectId(idBuffer, 0);
                        Needs(revWalk.LookupAny(idBuffer, sType));
                        continue;
                        goto default;
                    }

                    default:
                    {
                        if (FileMode.GITLINK.Equals(mode))
                        {
                            continue;
                        }
                        treeWalk.GetObjectId(idBuffer, 0);
                        throw new CorruptObjectException(MessageFormat.Format(JGitText.Get().invalidModeFor
                                                                              , mode, idBuffer.Name, treeWalk.PathString, obj.Id.Name));
                    }
                    }
                }
            }
            catch (IOException ioe)
            {
                throw new TransportException(MessageFormat.Format(JGitText.Get().cannotReadTree,
                                                                  obj.Name), ioe);
            }
            obj.Add(COMPLETE);
        }
Esempio n. 5
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);
            }
        }