Пример #1
0
        public void parseCanonical(RevWalk walk, byte[] rawTag)
        {
            MutableInteger pos = new MutableInteger();
            int oType;

            pos.value = 53; // "@object $sha1\ntype "
            oType = Constants.decodeTypeString(this, rawTag, (byte)'\n', pos);
            walk.idBuffer.FromString(rawTag, 7);
            @object = walk.lookupAny(walk.idBuffer, oType);

            int p = pos.value += 4; // "tag "
            int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1;
            name = RawParseUtils.decode(Constants.CHARSET, rawTag, p, nameEnd);
            buffer = rawTag;
            flags |= PARSED;
        }
Пример #2
0
        private void AddObject(RevObject obj)
        {
            if ((obj.Flags & InPending) != 0) return;

            obj.Flags |= InPending;
            _pendingObjects.add(obj);
        }
Пример #3
0
        public void testWritePack3()
        {
            _writer.ReuseDeltas = false;
            var forcedOrder = new[]
                              	{
                              		ObjectId.FromString("82c6b885ff600be425b4ea96dee75dca255b69e7"),
                              		ObjectId.FromString("c59759f143fb1fe21c197981df75a7ee00290799"),
                              		ObjectId.FromString("aabf2ffaec9b497f0950352b3e582d73035c2035"),
                              		ObjectId.FromString("902d5476fa249b7abc9d84c611577a81381f0327"),
                              		ObjectId.FromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"),
                              		ObjectId.FromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3")
                              	};
            var parser = new GitSharp.RevWalk.RevWalk(db);
            var forcedOrderRevs = new RevObject[forcedOrder.Length];

            for (int i = 0; i < forcedOrder.Length; i++)
            {
                forcedOrderRevs[i] = parser.parseAny(forcedOrder[i]);
            }

            CreateVerifyOpenPack(forcedOrderRevs.AsEnumerable());

            Assert.AreEqual(forcedOrder.Length, _writer.getObjectsNumber());
            VerifyObjectsOrder(forcedOrder);
            Assert.AreEqual("ed3f96b8327c7c66b0f8f70056129f0769323d86", _writer.computeName().Name);
        }
Пример #4
0
 private void writeAdvertisedTag(StringBuilder m, char[] idtmp, RevObject tag, string name)
 {
     RevObject o = tag;
     while (o is RevTag)
     {
         try
         {
             walk.parse(((RevTag) o).getObject());
         }
         catch (IOException)
         {
             return;
         }
         o = ((RevTag) o).getObject();
         o.add(ADVERTISED);
     }
     advertise(m, idtmp, ((RevTag) tag).getObject(), name + "^{}");
     writeAdvertisedRef(m);
 }
Пример #5
0
        private void ProcessTree(RevObject obj)
        {
            try
            {
                _treeWalk.reset(obj);
                while (_treeWalk.next())
                {
                    FileMode mode = _treeWalk.getFileMode(0);
                    int sType = mode.Bits;

                    switch (sType)
                    {
                        case Constants.OBJ_BLOB:
                        case Constants.OBJ_TREE:
                            _treeWalk.getObjectId(_idBuffer, 0);
                            Needs(_revWalk.lookupAny(_idBuffer, sType));
                            continue;

                        default:
                            if (FileMode.GitLink.Equals(sType))
                                continue;
                            _treeWalk.getObjectId(_idBuffer, 0);
                            throw new CorruptObjectException("Invalid mode " + mode + " for " + _idBuffer.Name + " " +
                                                             _treeWalk.getPathString() + " in " + obj.getId().Name + ".");
                    }
                }
            }
            catch (IOException ioe)
            {
                throw new TransportException("Cannot Read tree " + obj.Name, ioe);
            }
            obj.add(COMPLETE);
        }
Пример #6
0
 private void ProcessCommit(RevObject obj)
 {
     var commit = (RevCommit)obj;
     MarkLocalCommitsComplete(commit.CommitTime);
     Needs(commit.Tree);
     foreach (RevCommit p in commit.Parents)
     {
         Needs(p);
     }
     obj.add(COMPLETE);
 }
Пример #7
0
        private void Needs(RevObject obj)
        {
            if (obj.has(COMPLETE)) return;

            if (!obj.has(IN_WORK_QUEUE))
            {
                obj.add(IN_WORK_QUEUE);
                _workQueue.AddLast(obj);
            }
        }
Пример #8
0
        private void MarkLocalObjComplete(RevObject obj)
        {
            while (obj.Type == Constants.OBJ_TAG)
            {
                obj.add(COMPLETE);
                obj.DisposeBody();
                obj = ((RevTag)obj).getObject();
                _revWalk.parseHeaders(obj);
            }

            switch (obj.Type)
            {
                case Constants.OBJ_BLOB:
                    obj.add(COMPLETE);
                    break;

                case Constants.OBJ_COMMIT:
                    PushLocalCommit((RevCommit)obj);
                    break;

                case Constants.OBJ_TREE:
                    MarkTreeComplete(obj);
                    break;
            }
        }
Пример #9
0
 private void addObject(RevObject o)
 {
     if ((o.flags & IN_PENDING) == 0)
     {
         o.flags |= IN_PENDING;
         pendingObjects.add(o);
     }
 }
Пример #10
0
        /**
         * Mark an object to not produce in the output.
         * <p>
         * Uninteresting objects denote not just themselves but also their entire
         * reachable chain, back until the merge base of an uninteresting commit and
         * an otherwise interesting commit.
         * <p>
         * Callers are encouraged to use {@link RevWalk#parseAny(AnyObjectId)}
         * instead of {@link RevWalk#lookupAny(AnyObjectId, int)}, as this method
         * requires the object to be parsed before it can be added as a root for the
         * traversal.
         * <p>
         * The method will automatically parse an unparsed object, but error
         * handling may be more difficult for the application to explain why a
         * RevObject is not actually valid. The object pool of this walker would
         * also be 'poisoned' by the invalid RevObject.
         * <p>
         * This method will automatically call {@link RevWalk#markStart(RevCommit)}
         * if passed RevCommit instance, or a RevTag that directly (or indirectly)
         * references a RevCommit.
         *
         * @param o
         *            the object to start traversing from. The object passed must be
         * @throws MissingObjectException
         *             the object supplied is not available from the object
         *             database. This usually indicates the supplied object is
         *             invalid, but the reference was constructed during an earlier
         *             invocation to {@link RevWalk#lookupAny(AnyObjectId, int)}.
         * @throws IncorrectObjectTypeException
         *             the object was not parsed yet and it was discovered during
         *             parsing that it is not actually the type of the instance
         *             passed in. This usually indicates the caller used the wrong
         *             type in a {@link RevWalk#lookupAny(AnyObjectId, int)} call.
         * @
         *             a pack file or loose object could not be read.
         */
        public void markUninteresting(RevObject o)
        {
            while (o is RevTag)
            {
                o.flags |= UNINTERESTING;
                if (hasRevSort(RevSort.BOUNDARY))
                    addObject(o);
                o = ((RevTag)o).getObject();
                parse(o);
            }

            if (o is RevCommit)
                base.markUninteresting((RevCommit)o);
            else if (o is RevTree)
                markTreeUninteresting((RevTree)o);
            else
                o.flags |= UNINTERESTING;

            if (o.getType() != Constants.OBJ_COMMIT && hasRevSort(RevSort.BOUNDARY))
            {
                addObject(o);
            }
        }
Пример #11
0
        /**
         * Mark an object or commit to start graph traversal from.
         * <p>
         * Callers are encouraged to use {@link RevWalk#parseAny(AnyObjectId)}
         * instead of {@link RevWalk#lookupAny(AnyObjectId, int)}, as this method
         * requires the object to be parsed before it can be added as a root for the
         * traversal.
         * <p>
         * The method will automatically parse an unparsed object, but error
         * handling may be more difficult for the application to explain why a
         * RevObject is not actually valid. The object pool of this walker would
         * also be 'poisoned' by the invalid RevObject.
         * <p>
         * This method will automatically call {@link RevWalk#markStart(RevCommit)}
         * if passed RevCommit instance, or a RevTag that directly (or indirectly)
         * references a RevCommit.
         *
         * @param o
         *            the object to start traversing from. The object passed must be
         *            from this same revision walker.
         * @throws MissingObjectException
         *             the object supplied is not available from the object
         *             database. This usually indicates the supplied object is
         *             invalid, but the reference was constructed during an earlier
         *             invocation to {@link RevWalk#lookupAny(AnyObjectId, int)}.
         * @throws IncorrectObjectTypeException
         *             the object was not parsed yet and it was discovered during
         *             parsing that it is not actually the type of the instance
         *             passed in. This usually indicates the caller used the wrong
         *             type in a {@link RevWalk#lookupAny(AnyObjectId, int)} call.
         * @
         *             a pack file or loose object could not be read.
         */
        public void markStart(RevObject o)
        {
            while (o is RevTag)
            {
                addObject(o);
                o = ((RevTag)o).getObject();
                parse(o);
            }

            if (o is RevCommit)
                base.markStart((RevCommit)o);
            else
                addObject(o);
        }
Пример #12
0
        private void Want(RevObject o)
        {
            if (o.has(WANT)) return;

            o.add(WANT);
            _wantAll.Add(o);

            if (o is RevCommit)
            {
                _wantCommits.Add((RevCommit)o);
            }
            else if (o is RevTag)
            {
                do
                {
                    o = ((RevTag)o).getObject();
                } while (o is RevTag);

                if (o is RevCommit)
                {
                    Want(o);
                }
            }
        }
Пример #13
0
 private void AddCommonBase(RevObject o)
 {
     if (o.has(COMMON)) return;
     o.add(COMMON);
     _commonBase.Add(o);
 }
Пример #14
0
        public void parseCanonical(RevWalk walk, byte[] rawTag)
        {
            var pos = new MutableInteger { value = 53 };

            int oType = Constants.decodeTypeString(this, rawTag, (byte)'\n', pos);
            walk.IdBuffer.FromString(rawTag, 7);
            _object = walk.lookupAny(walk.IdBuffer, oType);

            int p = pos.value += 4; // "tag "
            int nameEnd = RawParseUtils.nextLF(rawTag, p) - 1;
            _name = RawParseUtils.decode(Constants.CHARSET, rawTag, p, nameEnd);

            if (walk.isRetainBody())
                _buffer = rawTag;
            Flags |= PARSED;
        }
Пример #15
0
        private void MarkTreeUninteresting(RevObject tree)
        {
            if ((tree.Flags & UNINTERESTING) != 0) return;
            tree.Flags |= UNINTERESTING;

            _treeWalk = _treeWalk.resetRoot(Repository, tree, WindowCursor);
            while (!_treeWalk.eof())
            {
                FileMode mode = _treeWalk.EntryFileMode;
                var sType = (int)mode.ObjectType;

                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(Repository, t, WindowCursor);
                            continue;
                        }
                        break;

                    default:
                        if (FileMode.GitLink == FileMode.FromBits(mode.Bits)) break;
                        _treeWalk.getEntryObjectId(IdBuffer);

                        throw new CorruptObjectException("Invalid mode " + mode
                                + " for " + IdBuffer + " "
                                + _treeWalk.EntryPathString + " in " + tree + ".");
                }

                _treeWalk = _treeWalk.next();
            }
        }
Пример #16
0
 private bool ShouldSkipObject(RevObject o)
 {
     return (o.Flags & UNINTERESTING) != 0 && !hasRevSort(RevSort.BOUNDARY);
 }
Пример #17
0
 private void advertiseAny(RevObject obj, string refName)
 {
     obj.add(ADVERTISED);
     advertiseId(obj, refName);
 }
Пример #18
0
        private void MarkTreeComplete(RevObject tree)
        {
            if (tree.has(COMPLETE)) return;

            tree.add(COMPLETE);
            _treeWalk.reset(tree);
            while (_treeWalk.next())
            {
                FileMode mode = _treeWalk.getFileMode(0);
                int sType = mode.Bits;

                switch (sType)
                {
                    case Constants.OBJ_BLOB:
                        _treeWalk.getObjectId(_idBuffer, 0);
                        _revWalk.lookupAny(_idBuffer, sType).add(COMPLETE);
                        continue;

                    case Constants.OBJ_TREE:
                        {
                            _treeWalk.getObjectId(_idBuffer, 0);
                            RevObject o = _revWalk.lookupAny(_idBuffer, sType);
                            if (!o.has(COMPLETE))
                            {
                                o.add(COMPLETE);
                                _treeWalk.enterSubtree();
                            }
                            continue;
                        }

                    default:
                        if (FileMode.GitLink.Equals(sType))
                            continue;
                        _treeWalk.getObjectId(_idBuffer, 0);
                        throw new CorruptObjectException("Invalid mode " + mode + " for " + _idBuffer.Name + " " +
                                                         _treeWalk.getPathString() + " in " + tree.Name);
                }
            }
        }
Пример #19
0
 private void advertiseAnyOnce(RevObject obj, string refName)
 {
     if (!obj.has(ADVERTISED))
     {
         advertiseAny(obj, refName);
     }
 }
Пример #20
0
 private void ProcessBlob(RevObject obj)
 {
     if (!_local.HasObject(obj))
     {
         throw new TransportException("Cannot Read blob " + obj.Name, new MissingObjectException(obj, Constants.TYPE_BLOB));
     }
     obj.add(COMPLETE);
 }
Пример #21
0
        public bool Equals(RevObject other)
        {
            if (ReferenceEquals(null, other))
            {
                return false;
            }

            if (ReferenceEquals(this, other))
            {
                return true;
            }

            return base.Equals(other) && other.Flags == Flags;
        }
Пример #22
0
 private void ProcessTag(RevObject obj)
 {
     var tag = (RevTag)obj;
     Needs(tag.getObject());
     obj.add(COMPLETE);
 }
 private void markCommon(RevObject obj)
 {
     obj.add(COMMON);
     if (obj is RevCommit)
     {
         ((RevCommit) obj).carry(COMMON);
     }
 }
Пример #24
0
 private void advertise(StringBuilder m, char[] idtmp, RevObject o, string name)
 {
     o.add(ADVERTISED);
     m.Length = 0;
     o.getId().CopyTo(idtmp, m);
     m.Append(' ');
     m.Append(name);
 }
Пример #25
0
        /// <summary>
        /// Mark an object or commit to start graph traversal from. 
        /// <para />
        /// Callers are encouraged to use <see cref="RevWalk.parseAny(AnyObjectId)"/>
        /// instead of <see cref="RevWalk.lookupAny(AnyObjectId, int)"/>, as this method
        /// requires the object to be parsed before it can be added as a root for the
        /// traversal.
        /// <para />
        /// The method will automatically parse an unparsed object, but error
        /// handling may be more difficult for the application to explain why a
        /// RevObject is not actually valid. The object pool of this walker would
        /// also be 'poisoned' by the invalid <see cref="RevObject"/>.
        /// <para />
        /// This method will automatically call <see cref="RevWalk.markStart(RevCommit)"/>
        /// if passed RevCommit instance, or a <see cref="RevTag"/> that directly (or indirectly)
        /// references a <see cref="RevCommit"/>.
        /// </summary>
        /// <param name="o">
        /// The object to start traversing from. The object passed must be
        /// from this same revision walker.
        /// </param>
        /// <exception cref="MissingObjectException">
        /// The object supplied is not available from the object
        /// database. This usually indicates the supplied object is
        /// invalid, but the reference was constructed during an earlier
        /// invocation to <see cref="RevWalk.lookupAny(AnyObjectId, int)"/>.
        /// </exception>
        /// <exception cref="IncorrectObjectTypeException">
        /// The object was not parsed yet and it was discovered during
        /// parsing that it is not actually the type of the instance
        /// passed in. This usually indicates the caller used the wrong
        /// type in a <see cref="RevWalk.lookupAny(AnyObjectId, int)"/> call.
        /// </exception>
        /// <exception cref="Exception">
        /// A pack file or loose object could not be Read.
        /// </exception>
        public void markStart(RevObject o)
        {
            while (o is RevTag)
            {
                AddObject(o);
                o = ((RevTag)o).getObject();
                parseHeaders(o);
            }

            if (o is RevCommit)
            {
                base.markStart((RevCommit)o);
            }
            else
            {
                AddObject(o);
            }
        }
Пример #26
0
        private void want(RevObject o)
        {
            if (!o.has(WANT))
            {
                o.add(WANT);
                wantAll.Add(o);

                if (o is RevCommit)
                    wantCommits.Add((RevCommit) o);
                else if (o is RevTag)
                {
                    do
                    {
                        o = ((RevTag) o).getObject();
                    } while (o is RevTag);
                    if (o is RevCommit)
                        want(o);
                }
            }
        }
Пример #27
0
        /// <summary>
        /// Mark an object to not produce in the output.
        /// <para />
        /// Uninteresting objects denote not just themselves but also their entire
        /// reachable chain, back until the merge base of an uninteresting commit and
        /// an otherwise interesting commit.
        /// <para />
        /// Callers are encouraged to use <see cref="RevWalk.parseAny(AnyObjectId)"/>
        /// instead of <see cref="RevWalk.lookupAny(AnyObjectId, int)"/>, as this method
        /// requires the object to be parsed before it can be added as a root for the
        /// traversal.
        /// <para />
        /// The method will automatically parse an unparsed object, but error
        /// handling may be more difficult for the application to explain why a
        /// RevObject is not actually valid. The object pool of this walker would
        /// also be 'poisoned' by the invalid <see cref="RevObject"/>.
        /// <para />
        /// This method will automatically call <see cref="RevWalk.markStart(RevCommit)"/>
        /// if passed RevCommit instance, or a <see cref="RevTag"/> that directly (or indirectly)
        /// references a <see cref="RevCommit"/>.
        /// </summary>
        /// <param name="o">
        /// The object to start traversing from. The object passed must be
        /// from this same revision walker.
        /// </param>
        /// <exception cref="MissingObjectException">
        /// The object supplied is not available from the object
        /// database. This usually indicates the supplied object is
        /// invalid, but the reference was constructed during an earlier
        /// invocation to <see cref="RevWalk.lookupAny(AnyObjectId, int)"/>.
        /// </exception>
        /// <exception cref="IncorrectObjectTypeException">
        /// The object was not parsed yet and it was discovered during
        /// parsing that it is not actually the type of the instance
        /// passed in. This usually indicates the caller used the wrong
        /// type in a <see cref="RevWalk.lookupAny(AnyObjectId, int)"/> call.
        /// </exception>
        /// <exception cref="Exception">
        /// A pack file or loose object could not be Read.
        /// </exception>
        public void markUninteresting(RevObject o)
        {
            while (o is RevTag)
            {
                o.Flags |= UNINTERESTING;
                if (hasRevSort(RevSort.BOUNDARY))
                {
                    AddObject(o);
                }
                o = ((RevTag)o).getObject();
                parseHeaders(o);
            }

            if (o is RevCommit)
            {
                base.markUninteresting((RevCommit)o);
            }
            else if (o is RevTree)
            {
                MarkTreeUninteresting(o);
            }
            else
            {
                o.Flags |= UNINTERESTING;
            }

            if (o.Type != Constants.OBJ_COMMIT && hasRevSort(RevSort.BOUNDARY))
            {
                AddObject(o);
            }
        }