コード例 #1
0
        /// <summary>
        /// Create a new pack indexer utility.
        /// </summary>
        /// <param name="db"></param>
        /// <param name="src">
        /// stream to read the pack data from. If the stream is buffered
        /// use <see cref="BUFFER_SIZE"/> as the buffer size for the stream.
        /// </param>
        /// <param name="dstBase"></param>
        public IndexPack(Repository db, Stream src, FileInfo dstBase)
        {
            _repo           = db;
            _objectDatabase = db.ObjectDatabase.newCachedDatabase();
            _stream         = src;
            _inflater       = InflaterCache.Instance.get();
            _windowCursor   = new WindowCursor();
            _buffer         = new byte[BUFFER_SIZE];
            _objectData     = new byte[BUFFER_SIZE];
            _objectDigest   = Constants.newMessageDigest();
            _tempObjectId   = new MutableObjectId();
            _packDigest     = Constants.newMessageDigest();

            if (dstBase != null)
            {
                DirectoryInfo dir = dstBase.Directory;
                string        nam = dstBase.Name;
                _dstPack = PathUtil.CombineFilePath(dir, GetPackFileName(nam));
                _dstIdx  = PathUtil.CombineFilePath(dir, GetIndexFileName(nam));
                _packOut = _dstPack.Create();
            }
            else
            {
                _dstPack = null;
                _dstIdx  = null;
            }
        }
コード例 #2
0
        /// <exception cref="System.IO.IOException"></exception>
        internal override int EstimateSize(AnyObjectId noteOn, ObjectReader or)
        {
            // If most of this fan-out is full, estimate it should still be split.
            if (LeafBucket.MAX_SIZE * 3 / 4 <= cnt)
            {
                return(1 + LeafBucket.MAX_SIZE);
            }
            // Due to the uniform distribution of ObjectIds, having less nodes full
            // indicates a good chance the total number of children below here
            // is less than the MAX_SIZE split point. Get a more accurate count.
            MutableObjectId id = new MutableObjectId();

            id.FromObjectId(noteOn);
            int sz = 0;

            for (int cell = 0; cell < 256; cell++)
            {
                NoteBucket b = table[cell];
                if (b == null)
                {
                    continue;
                }
                id.SetByte(prefixLen >> 1, cell);
                sz += b.EstimateSize(id, or);
                if (LeafBucket.MAX_SIZE < sz)
                {
                    break;
                }
            }
            return(sz);
        }
コード例 #3
0
        private static AnyObjectId Id(int first)
        {
            MutableObjectId id = new MutableObjectId();

            id.SetByte(1, first);
            return(id);
        }
コード例 #4
0
        public WalkFetchConnection(IWalkTransport t, WalkRemoteObjectDatabase w)
        {
            _idBuffer = new MutableObjectId();
            _objectDigest = Constants.newMessageDigest();

            var wt = (Transport)t;
            _local = wt.Local;
            _objCheck = wt.CheckFetchedObjects ? new ObjectChecker() : null;

            _remotes = new List<WalkRemoteObjectDatabase> { w };

            _unfetchedPacks = new LinkedList<RemotePack>();
            _packsConsidered = new List<string>();

            _noPacksYet = new LinkedList<WalkRemoteObjectDatabase>();
            _noPacksYet.AddFirst(w);

            _noAlternatesYet = new LinkedList<WalkRemoteObjectDatabase>();
            _noAlternatesYet.AddFirst(w);

            _fetchErrors = new Dictionary<ObjectId, List<Exception>>();
            _packLocks = new List<PackLock>(4);

            _revWalk = new RevWalk.RevWalk(_local);
            _treeWalk = new TreeWalk.TreeWalk(_local);

            COMPLETE = _revWalk.newFlag("COMPLETE");
            IN_WORK_QUEUE = _revWalk.newFlag("IN_WORK_QUEUE");
            LOCALLY_SEEN = _revWalk.newFlag("LOCALLY_SEEN");

            _localCommitQueue = new DateRevQueue();
            _workQueue = new LinkedList<ObjectId>();
        }
コード例 #5
0
 public _Iterator_138(FanoutBucket _enclosing, MutableObjectId id, ObjectReader reader
                      )
 {
     this._enclosing = _enclosing;
     this.id         = id;
     this.reader     = reader;
 }
コード例 #6
0
 /// <summary>
 /// Gets the <see cref="ObjectId"/> of the current entry.
 /// </summary>
 /// <param name="objectId">buffer to copy the object id into.</param>
 public virtual void getEntryObjectId(MutableObjectId objectId)
 {
     if (objectId == null)
     {
         throw new ArgumentNullException("objectId");
     }
     objectId.FromRaw(idBuffer(), idOffset());
 }
コード例 #7
0
        /// <exception cref="System.IO.IOException"></exception>
        internal override Sharpen.Iterator <Note> Iterator(AnyObjectId objId, ObjectReader
                                                           reader)
        {
            MutableObjectId id = new MutableObjectId();

            id.FromObjectId(objId);
            return(new _Iterator_138(this, id, reader));
        }
コード例 #8
0
 /// <summary>Create a blame generator for the repository and path</summary>
 /// <param name="repository">repository to access revision data from.</param>
 /// <param name="path">initial path of the file to start scanning.</param>
 public BlameGenerator(Repository repository, string path)
 {
     this.repository = repository;
     this.resultPath = PathFilter.Create(path);
     idBuf           = new MutableObjectId();
     SetFollowFileRenames(true);
     InitRevPool(false);
     remaining = -1;
 }
コード例 #9
0
ファイル: TreeWalk.cs プロジェクト: kkl713/GitSharp
        /// <summary>
        /// Create a new tree walker for a given repository.
        /// </summary>
        /// <param name="repo">
        /// The repository the walker will obtain data from.
        /// </param>
        public TreeWalk(Repository repo)
        {
            _idBuffer = new MutableObjectId();
            _cursor   = new WindowCursor();

            _db     = repo;
            _filter = TreeFilter.ALL;
            _trees  = new AbstractTreeIterator[] { new EmptyTreeIterator() };
        }
コード例 #10
0
 /// <summary>
 /// Constructs a NoteMapMerger with custom
 /// <see cref="NoteMerger">NoteMerger</see>
 /// and custom
 /// <see cref="NGit.Merge.MergeStrategy">NGit.Merge.MergeStrategy</see>
 /// .
 /// </summary>
 /// <param name="db">Git repository</param>
 /// <param name="noteMerger">note merger for merging conflicting changes on a note</param>
 /// <param name="nonNotesMergeStrategy">merge strategy for merging non-note entries</param>
 public NoteMapMerger(Repository db, NoteMerger noteMerger, MergeStrategy nonNotesMergeStrategy
                      )
 {
     this.db                    = db;
     this.reader                = db.NewObjectReader();
     this.inserter              = db.NewObjectInserter();
     this.noteMerger            = noteMerger;
     this.nonNotesMergeStrategy = nonNotesMergeStrategy;
     this.objectIdPrefix        = new MutableObjectId();
 }
コード例 #11
0
 public new CanonicalTreeParser createSubtreeIterator(Repository repo, MutableObjectId idBuffer, WindowCursor curs)
 {
     idBuffer.FromRaw(this.idBuffer(), idOffset());
     if (FileMode.Tree != EntryFileMode)
     {
         ObjectId me = idBuffer.ToObjectId();
         throw new IncorrectObjectTypeException(me, Constants.TYPE_TREE);
     }
     return(createSubtreeIterator0(repo, idBuffer, curs));
 }
コード例 #12
0
ファイル: PacketLineInTest.cs プロジェクト: ashmind/ngit
        public virtual void TestReadACK_ACKcommon1()
        {
            ObjectId        expid = ObjectId.FromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e");
            MutableObjectId actid = new MutableObjectId();

            Init("0038ACK fcfcfb1fd94829c1a1704f894fc111d14770d34e common\n");
            NUnit.Framework.Assert.AreEqual(PacketLineIn.AckNackResult.ACK_COMMON, @in.ReadACK
                                                (actid));
            NUnit.Framework.Assert.IsTrue(actid.Equals(expid));
            AssertEOF();
        }
コード例 #13
0
ファイル: PacketLineInTest.cs プロジェクト: zzia615/GitSharp
        public void testReadACK_ACKready1()
        {
            ObjectId expid = ObjectId
                             .FromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e");
            MutableObjectId actid = new MutableObjectId();

            init("0037ACK fcfcfb1fd94829c1a1704f894fc111d14770d34e ready\n");
            Assert.AreEqual(PacketLineIn.AckNackResult.ACK_READY, pckIn.readACK(actid));
            Assert.IsTrue(actid.Equals(expid));
            assertEOF();
        }
コード例 #14
0
        public virtual void TestReadACK_ACKready1()
        {
            ObjectId        expid = ObjectId.FromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e");
            MutableObjectId actid = new MutableObjectId();

            Init("0037ACK fcfcfb1fd94829c1a1704f894fc111d14770d34e ready\n");
            NUnit.Framework.Assert.AreEqual(PacketLineIn.AckNackResult.ACK_READY, @in.ReadACK
                                                (actid));
            NUnit.Framework.Assert.AreEqual(expid, actid);
            AssertEOF();
        }
コード例 #15
0
        public void testReadACK_ACKcontinue1()
        {
            ObjectId expid = ObjectId.FromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e");
            MutableObjectId actid = new MutableObjectId();
            actid.FromString(expid.Name);

            init("003aACK fcfcfb1fd94829c1a1704f894fc111d14770d34e continue\n");
            Assert.AreEqual(PacketLineIn.AckNackResult.ACK_CONTINUE, pckIn.readACK(actid));
            Assert.IsTrue(actid.Equals(expid));
            assertEOF();
        }
コード例 #16
0
ファイル: PacketLineInTest.cs プロジェクト: zzia615/GitSharp
        public void testReadACK_ACKcontinue1()
        {
            ObjectId        expid = ObjectId.FromString("fcfcfb1fd94829c1a1704f894fc111d14770d34e");
            MutableObjectId actid = new MutableObjectId();

            actid.FromString(expid.Name);

            init("003aACK fcfcfb1fd94829c1a1704f894fc111d14770d34e continue\n");
            Assert.AreEqual(PacketLineIn.AckNackResult.ACK_CONTINUE, pckIn.readACK(actid));
            Assert.IsTrue(actid.Equals(expid));
            assertEOF();
        }
コード例 #17
0
ファイル: TreeWalk.cs プロジェクト: TetradogOther/NGit
        /// <summary>Obtain the ObjectId for the current entry.</summary>
        /// <remarks>
        /// Obtain the ObjectId for the current entry.
        /// <p>
        /// Every tree supplies an object id, even if the tree does not contain the
        /// current entry. In the latter case
        /// <see cref="NGit.ObjectId.ZeroId()">NGit.ObjectId.ZeroId()</see>
        /// is supplied.
        /// <p>
        /// Applications should try to use
        /// <see cref="IdEqual(int, int)">IdEqual(int, int)</see>
        /// when possible
        /// as it avoids conversion overheads.
        /// </remarks>
        /// <param name="out">buffer to copy the object id into.</param>
        /// <param name="nth">tree to obtain the object identifier from.</param>
        /// <seealso cref="IdEqual(int, int)">IdEqual(int, int)</seealso>
        public virtual void GetObjectId(MutableObjectId @out, int nth)
        {
            AbstractTreeIterator t = trees[nth];

            if (t.matches == currentHead)
            {
                t.GetEntryObjectId(@out);
            }
            else
            {
                @out.Clear();
            }
        }
コード例 #18
0
ファイル: TreeWalk.cs プロジェクト: kkl713/GitSharp
        /**
         * Obtain the ObjectId for the current entry.
         * <para />
         * Every tree supplies an object id, even if the tree does not contain the
         * current entry. In the latter case {@link ObjectId#zeroId()} is supplied.
         * <para />
         * Applications should try to use {@link #idEqual(int, int)} when possible
         * as it avoids conversion overheads.
         *
         * @param out
         *            buffer to copy the object id into.
         * @param nth
         *            tree to obtain the object identifier from.
         * @see #idEqual(int, int)
         */
        public void getObjectId(MutableObjectId @out, int nth)
        {
            AbstractTreeIterator t = _trees[nth];

            if (t.Matches == _currentHead)
            {
                t.getEntryObjectId(@out);
            }
            else
            {
                @out.Clear();
            }
        }
コード例 #19
0
ファイル: BaseSearch.cs プロジェクト: ashmind/ngit
 internal BaseSearch(ProgressMonitor countingMonitor, ICollection <RevTree> bases,
                     ObjectIdSubclassMap <ObjectToPack> objects, IList <ObjectToPack> edges, ObjectReader
                     or)
 {
     progress         = countingMonitor;
     reader           = or;
     baseTrees        = Sharpen.Collections.ToArray(bases, new ObjectId[bases.Count]);
     objectsMap       = objects;
     edgeObjects      = edges;
     alreadyProcessed = new IntSet();
     treeCache        = new ObjectIdSubclassMap <BaseSearch.TreeWithData>();
     parser           = new CanonicalTreeParser();
     idBuf            = new MutableObjectId();
 }
コード例 #20
0
 private bool ParseObjectId(MutableObjectId id)
 {
     if (pathLen == pathPadding + Constants.OBJECT_ID_STRING_LENGTH)
     {
         try
         {
             id.FromString(path, pathPadding);
             return(true);
         }
         catch (IndexOutOfRangeException)
         {
             return(false);
         }
     }
     return(false);
 }
コード例 #21
0
        public virtual void TestEditFlat()
        {
            RevBlob   a     = tr.Blob("a");
            RevBlob   b     = tr.Blob("b");
            RevBlob   data1 = tr.Blob("data1");
            RevBlob   data2 = tr.Blob("data2");
            RevCommit r     = tr.Commit().Add(a.Name, data1).Add(b.Name, data2).Add(".gitignore",
                                                                                    string.Empty).Add("zoo-animals.txt", b).Create();

            //
            //
            //
            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            map.Set(a, data2);
            map.Set(b, null);
            map.Set(data1, b);
            map.Set(data2, null);
            NUnit.Framework.Assert.AreEqual(data2, map.Get(a));
            NUnit.Framework.Assert.AreEqual(b, map.Get(data1));
            NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
            NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2");
            MutableObjectId id = new MutableObjectId();

            for (int p = 42; p > 0; p--)
            {
                id.SetByte(1, p);
                map.Set(id, data1);
            }
            for (int p_1 = 42; p_1 > 0; p_1--)
            {
                id.SetByte(1, p_1);
                NUnit.Framework.Assert.IsTrue(map.Contains(id), "contains " + id);
            }
            RevCommit n = CommitNoteMap(map);

            map = NoteMap.Read(reader, n);
            NUnit.Framework.Assert.AreEqual(data2, map.Get(a));
            NUnit.Framework.Assert.AreEqual(b, map.Get(data1));
            NUnit.Framework.Assert.IsFalse(map.Contains(b), "no b");
            NUnit.Framework.Assert.IsFalse(map.Contains(data2), "no data2");
            NUnit.Framework.Assert.AreEqual(b, TreeWalk.ForPath(reader, "zoo-animals.txt", n.
                                                                Tree).GetObjectId(0));
        }
コード例 #22
0
ファイル: PacketLineIn.cs プロジェクト: thild/monodevelop
        /// <exception cref="System.IO.IOException"></exception>
        internal virtual PacketLineIn.AckNackResult ReadACK(MutableObjectId returnedId)
        {
            string line = ReadString();

            if (line.Length == 0)
            {
                throw new PackProtocolException(JGitText.Get().expectedACKNAKFoundEOF);
            }
            if ("NAK".Equals(line))
            {
                return(PacketLineIn.AckNackResult.NAK);
            }
            if (line.StartsWith("ACK "))
            {
                returnedId.FromString(Sharpen.Runtime.Substring(line, 4, 44));
                if (line.Length == 44)
                {
                    return(PacketLineIn.AckNackResult.ACK);
                }
                string arg = Sharpen.Runtime.Substring(line, 44);
                if (arg.Equals(" continue"))
                {
                    return(PacketLineIn.AckNackResult.ACK_CONTINUE);
                }
                else
                {
                    if (arg.Equals(" common"))
                    {
                        return(PacketLineIn.AckNackResult.ACK_COMMON);
                    }
                    else
                    {
                        if (arg.Equals(" ready"))
                        {
                            return(PacketLineIn.AckNackResult.ACK_READY);
                        }
                    }
                }
            }
            if (line.StartsWith("ERR "))
            {
                throw new PackProtocolException(Sharpen.Runtime.Substring(line, 4));
            }
            throw new PackProtocolException(MessageFormat.Format(JGitText.Get().expectedACKNAKGot
                                                                 , line));
        }
コード例 #23
0
ファイル: DiffEntry.cs プロジェクト: shoff/ngit
        // reduce the visibility of the default constructor
        /// <summary>Convert the TreeWalk into DiffEntry headers.</summary>
        /// <remarks>Convert the TreeWalk into DiffEntry headers.</remarks>
        /// <param name="walk">the TreeWalk to walk through. Must have exactly two trees.</param>
        /// <returns>headers describing the changed files.</returns>
        /// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
        public static IList <NGit.Diff.DiffEntry> Scan(TreeWalk walk)
        {
            IList <NGit.Diff.DiffEntry> r     = new AList <NGit.Diff.DiffEntry>();
            MutableObjectId             idBuf = new MutableObjectId();

            while (walk.Next())
            {
                NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
                walk.GetObjectId(idBuf, 0);
                entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
                walk.GetObjectId(idBuf, 1);
                entry.newId   = AbbreviatedObjectId.FromObjectId(idBuf);
                entry.oldMode = walk.GetFileMode(0);
                entry.newMode = walk.GetFileMode(1);
                entry.newPath = entry.oldPath = walk.PathString;
                if (entry.oldMode == FileMode.MISSING)
                {
                    entry.oldPath    = NGit.Diff.DiffEntry.DEV_NULL;
                    entry.changeType = DiffEntry.ChangeType.ADD;
                    r.AddItem(entry);
                }
                else
                {
                    if (entry.newMode == FileMode.MISSING)
                    {
                        entry.newPath    = NGit.Diff.DiffEntry.DEV_NULL;
                        entry.changeType = DiffEntry.ChangeType.DELETE;
                        r.AddItem(entry);
                    }
                    else
                    {
                        entry.changeType = DiffEntry.ChangeType.MODIFY;
                        if (RenameDetector.SameType(entry.oldMode, entry.newMode))
                        {
                            r.AddItem(entry);
                        }
                        else
                        {
                            Sharpen.Collections.AddAll(r, BreakModify(entry));
                        }
                    }
                }
            }
            return(r);
        }
コード例 #24
0
ファイル: PacketLineIn.cs プロジェクト: georgeck/GitSharp
 public AckNackResult readACK(MutableObjectId returnedId)
 {
     string line = ReadString();
     if (line.Length  == 0)
         throw new PackProtocolException("Expected ACK/NAK, found EOF");
     if ("NAK".Equals(line))
         return AckNackResult.NAK;
     if (line.StartsWith("ACK "))
     {
         returnedId.FromString(line.Slice(4, 44));
         if (line.IndexOf("continue", 44) != -1)
         {
             return AckNackResult.ACK_CONTINUE;
         }
         return AckNackResult.ACK;
     }
     throw new PackProtocolException("Expected ACK/NAK, got: " + line);
 }
コード例 #25
0
        private LeafBucket ParseLeafTree()
        {
            LeafBucket      leaf  = new LeafBucket(prefixLen);
            MutableObjectId idBuf = new MutableObjectId();

            for (; !Eof; Next(1))
            {
                if (ParseObjectId(idBuf))
                {
                    leaf.ParseOneEntry(idBuf, EntryObjectId);
                }
                else
                {
                    StoreNonNote();
                }
            }
            return(leaf);
        }
コード例 #26
0
        public virtual void TestLeafSplitsWhenFull()
        {
            RevBlob         data1 = tr.Blob("data1");
            MutableObjectId idBuf = new MutableObjectId();
            RevCommit       r     = tr.Commit().Add(data1.Name, data1).Create();

            //
            //
            tr.ParseBody(r);
            NoteMap map = NoteMap.Read(reader, r);

            for (int i = 0; i < 254; i++)
            {
                idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i);
                map.Set(idBuf, data1);
            }
            RevCommit n  = CommitNoteMap(map);
            TreeWalk  tw = new TreeWalk(reader);

            tw.Reset(n.Tree);
            while (tw.Next())
            {
                NUnit.Framework.Assert.IsFalse(tw.IsSubtree, "no fan-out subtree");
            }
            for (int i_1 = 254; i_1 < 256; i_1++)
            {
                idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 1, i_1);
                map.Set(idBuf, data1);
            }
            idBuf.SetByte(Constants.OBJECT_ID_LENGTH - 2, 1);
            map.Set(idBuf, data1);
            n = CommitNoteMap(map);
            // The 00 bucket is fully split.
            string path = Fanout(38, idBuf.Name);

            tw = TreeWalk.ForPath(reader, path, n.Tree);
            NUnit.Framework.Assert.IsNotNull(tw, "has " + path);
            // The other bucket is not.
            path = Fanout(2, data1.Name);
            tw   = TreeWalk.ForPath(reader, path, n.Tree);
            NUnit.Framework.Assert.IsNotNull(tw, "has " + path);
        }
コード例 #27
0
ファイル: PacketLineIn.cs プロジェクト: kkl713/GitSharp
        public AckNackResult readACK(MutableObjectId returnedId)
        {
            string line = ReadString();

            if (line.Length == 0)
            {
                throw new PackProtocolException("Expected ACK/NAK, found EOF");
            }
            if ("NAK".Equals(line))
            {
                return(AckNackResult.NAK);
            }
            if (line.StartsWith("ACK "))
            {
                returnedId.FromString(line.Slice(4, 44));
                if (line.IndexOf("continue", 44) != -1)
                {
                    return(AckNackResult.ACK_CONTINUE);
                }
                return(AckNackResult.ACK);
            }
            throw new PackProtocolException("Expected ACK/NAK, got: " + line);
        }
コード例 #28
0
        public AckNackResult readACK(MutableObjectId returnedId)
        {
            string line = ReadString();

            if (line.Length == 0)
            {
                throw new PackProtocolException("Expected ACK/NAK, found EOF");
            }
            if ("NAK".Equals(line))
            {
                return(AckNackResult.NAK);
            }
            if (line.StartsWith("ACK "))
            {
                returnedId.FromString(line.Slice(4, 44));

                if (line.Length == 44)
                {
                    return(AckNackResult.ACK);
                }

                string arg = line.Substring(44);
                if (arg.Equals(" continue"))
                {
                    return(AckNackResult.ACK_CONTINUE);
                }
                else if (arg.Equals(" common"))
                {
                    return(AckNackResult.ACK_COMMON);
                }
                else if (arg.Equals(" ready"))
                {
                    return(AckNackResult.ACK_READY);
                }
            }
            throw new PackProtocolException("Expected ACK/NAK, got: " + line);
        }
コード例 #29
0
        public WalkFetchConnection(IWalkTransport t, WalkRemoteObjectDatabase w)
        {
            _idBuffer     = new MutableObjectId();
            _objectDigest = Constants.newMessageDigest();

            var wt = (Transport)t;

            _local    = wt.Local;
            _objCheck = wt.CheckFetchedObjects ? new ObjectChecker() : null;

            _remotes = new List <WalkRemoteObjectDatabase> {
                w
            };

            _unfetchedPacks  = new LinkedList <RemotePack>();
            _packsConsidered = new List <string>();

            _noPacksYet = new LinkedList <WalkRemoteObjectDatabase>();
            _noPacksYet.AddFirst(w);

            _noAlternatesYet = new LinkedList <WalkRemoteObjectDatabase>();
            _noAlternatesYet.AddFirst(w);

            _fetchErrors = new Dictionary <ObjectId, List <Exception> >();
            _packLocks   = new List <PackLock>(4);

            _revWalk  = new RevWalk.RevWalk(_local);
            _treeWalk = new TreeWalk.TreeWalk(_local);

            COMPLETE      = _revWalk.newFlag("COMPLETE");
            IN_WORK_QUEUE = _revWalk.newFlag("IN_WORK_QUEUE");
            LOCALLY_SEEN  = _revWalk.newFlag("LOCALLY_SEEN");

            _localCommitQueue = new DateRevQueue();
            _workQueue        = new LinkedList <ObjectId>();
        }
コード例 #30
0
 /// <summary>
 /// Gets the <see cref="ObjectId"/> of the current entry.
 /// </summary>
 /// <param name="objectId">buffer to copy the object id into.</param>
 public virtual void getEntryObjectId(MutableObjectId objectId)
 {
     objectId.FromRaw(idBuffer(), idOffset());
 }
コード例 #31
0
 /// <exception cref="NGit.Errors.IncorrectObjectTypeException"></exception>
 /// <exception cref="System.IO.IOException"></exception>
 public override AbstractTreeIterator CreateSubtreeIterator(ObjectReader reader, MutableObjectId
                                                            idBuffer)
 {
     idBuffer.FromRaw(IdBuffer, IdOffset);
     if (!FileMode.TREE.Equals(mode))
     {
         ObjectId me = idBuffer.ToObjectId();
         throw new IncorrectObjectTypeException(me, Constants.TYPE_TREE);
     }
     return(CreateSubtreeIterator0(reader, idBuffer));
 }
コード例 #32
0
        private void Negotiate(ProgressMonitor monitor)
        {
            var ackId = new MutableObjectId();
            int resultsPending = 0;
            int havesSent = 0;
            int havesSinceLastContinue = 0;
            bool receivedContinue = false;
            bool receivedAck = false;

            NegotiateBegin();
            for (; ; )
            {
                RevCommit c = _walk.next();
                if (c == null)
                {
                    goto END_SEND_HAVES;
                }

                pckOut.WriteString("have " + c.getId().Name + "\n");
                havesSent++;
                havesSinceLastContinue++;

                if ((31 & havesSent) != 0)
                {
                    continue;
                }

                if (monitor.IsCancelled)
                    throw new CancelledException();

                pckOut.End();
                resultsPending++;

                if (havesSent == 32)
                {
                    continue;
                }

                for (; ; )
                {
                    PacketLineIn.AckNackResult anr = pckIn.readACK(ackId);

                    switch (anr)
                    {
                        case PacketLineIn.AckNackResult.NAK:
                            // More have lines are necessary to compute the
                            // pack on the remote side. Keep doing that.

                            resultsPending--;
                            goto END_READ_RESULT;

                        case PacketLineIn.AckNackResult.ACK:
                            // The remote side is happy and knows exactly what
                            // to send us. There is no further negotiation and
                            // we can break out immediately.

                            _multiAck = MultiAck.OFF;
                            resultsPending = 0;
                            receivedAck = true;
                            goto END_SEND_HAVES;

                        case PacketLineIn.AckNackResult.ACK_CONTINUE:
                        case PacketLineIn.AckNackResult.ACK_COMMON:
                        case PacketLineIn.AckNackResult.ACK_READY:
                            // The server knows this commit (ackId). We don't
                            // need to send any further along its ancestry, but
                            // we need to continue to talk about other parts of
                            // our local history.

                            MarkCommon(_walk.parseAny(ackId));
                            receivedAck = true;
                            receivedContinue = true;
                            havesSinceLastContinue = 0;
                            break;
                    }

                    if (monitor.IsCancelled)
                        throw new CancelledException();
                }

            END_READ_RESULT:
                if (receivedContinue && havesSinceLastContinue > MAX_HAVES)
                {
                    break;
                }
            }

            END_SEND_HAVES:

            if (monitor.IsCancelled)
                throw new CancelledException();
            pckOut.WriteString("done\n");
            pckOut.Flush();

            if (!receivedAck)
            {
                _multiAck = MultiAck.OFF;
                resultsPending++;
            }

            while (resultsPending > 0 || _multiAck != MultiAck.OFF)
            {
                PacketLineIn.AckNackResult anr = pckIn.readACK(ackId);
                resultsPending--;

                switch (anr)
                {
                    case PacketLineIn.AckNackResult.NAK:
                        // A NAK is a response to an end we queued earlier
                        // we eat it and look for another ACK/NAK message.
                        //
                        break;

                    case PacketLineIn.AckNackResult.ACK:
                        // A solitary ACK at this point means the remote won't
                        // speak anymore, but is going to send us a pack now.
                        //
                        goto END_READ_RESULT_2;

                    case PacketLineIn.AckNackResult.ACK_CONTINUE:
                    case PacketLineIn.AckNackResult.ACK_COMMON:
                    case PacketLineIn.AckNackResult.ACK_READY:
                        // We will expect a normal ACK to break out of the loop.
                        //
                        _multiAck = MultiAck.CONTINUE;
                        break;
                }

                if (monitor.IsCancelled)
                    throw new CancelledException();
            }

            END_READ_RESULT_2:
            ;
        }
コード例 #33
0
ファイル: IndexPack.cs プロジェクト: georgeck/GitSharp
        public IndexPack(Repository db, Stream src, FileInfo dstBase)
        {
            _repo = db;
            _stream = src;
            _crc = new Crc32();
            _inflater = InflaterCache.Instance.get();
            _windowCursor = new WindowCursor();
            _buffer = new byte[BUFFER_SIZE];
            _objectData = new byte[BUFFER_SIZE];
            _objectDigest = Constants.newMessageDigest();
            _tempObjectId = new MutableObjectId();
            _packDigest = Constants.newMessageDigest();

            if (dstBase != null)
            {
                DirectoryInfo dir = dstBase.Directory;
                string nam = dstBase.Name;
                _dstPack = new FileInfo(Path.Combine(dir.FullName, GetPackFileName(nam)));
                _dstIdx = new FileInfo(Path.Combine(dir.FullName, GetIndexFileName(nam)));
                _packOut = _dstPack.Create();
            }
            else
            {
                _dstPack = null;
                _dstIdx = null;
            }
        }
コード例 #34
0
ファイル: RevCommit.cs プロジェクト: TetradogOther/NGit
        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;
        }
コード例 #35
0
 /// <summary>
 /// Gets the <see cref="ObjectId"/> of the current entry.
 /// </summary>
 /// <param name="objectId">buffer to copy the object id into.</param>
 public virtual void getEntryObjectId(MutableObjectId objectId)
 {
     if (objectId == null)
         throw new ArgumentNullException ("objectId");
     objectId.FromRaw(idBuffer(), idOffset());
 }
コード例 #36
0
        /// <summary>
        /// Convert the TreeWalk into DiffEntry headers, depending on
        /// <code>includeTrees</code>
        /// it will add tree objects into result or not.
        /// </summary>
        /// <param name="walk">
        /// the TreeWalk to walk through. Must have exactly two trees and
        /// when
        /// <code>includeTrees</code>
        /// parameter is
        /// <code>true</code>
        /// it can't
        /// be recursive.
        /// </param>
        /// <param name="includeTrees">include tree object's.</param>
        /// <returns>headers describing the changed files.</returns>
        /// <exception cref="System.IO.IOException">the repository cannot be accessed.</exception>
        /// <exception cref="System.ArgumentException">
        /// when
        /// <code>includeTrees</code>
        /// is true and given TreeWalk is
        /// recursive. Or when given TreeWalk doesn't have exactly two
        /// trees
        /// </exception>
        public static IList <NGit.Diff.DiffEntry> Scan(TreeWalk walk, bool includeTrees)
        {
            if (walk.TreeCount != 2)
            {
                throw new ArgumentException(JGitText.Get().treeWalkMustHaveExactlyTwoTrees);
            }
            if (includeTrees && walk.Recursive)
            {
                throw new ArgumentException(JGitText.Get().cannotBeRecursiveWhenTreesAreIncluded);
            }
            IList <NGit.Diff.DiffEntry> r     = new AList <NGit.Diff.DiffEntry>();
            MutableObjectId             idBuf = new MutableObjectId();

            while (walk.Next())
            {
                NGit.Diff.DiffEntry entry = new NGit.Diff.DiffEntry();
                walk.GetObjectId(idBuf, 0);
                entry.oldId = AbbreviatedObjectId.FromObjectId(idBuf);
                walk.GetObjectId(idBuf, 1);
                entry.newId   = AbbreviatedObjectId.FromObjectId(idBuf);
                entry.oldMode = walk.GetFileMode(0);
                entry.newMode = walk.GetFileMode(1);
                entry.newPath = entry.oldPath = walk.PathString;
                if (entry.oldMode == FileMode.MISSING)
                {
                    entry.oldPath    = NGit.Diff.DiffEntry.DEV_NULL;
                    entry.changeType = DiffEntry.ChangeType.ADD;
                    r.AddItem(entry);
                }
                else
                {
                    if (entry.newMode == FileMode.MISSING)
                    {
                        entry.newPath    = NGit.Diff.DiffEntry.DEV_NULL;
                        entry.changeType = DiffEntry.ChangeType.DELETE;
                        r.AddItem(entry);
                    }
                    else
                    {
                        if (!entry.oldId.Equals(entry.newId))
                        {
                            entry.changeType = DiffEntry.ChangeType.MODIFY;
                            if (RenameDetector.SameType(entry.oldMode, entry.newMode))
                            {
                                r.AddItem(entry);
                            }
                            else
                            {
                                Sharpen.Collections.AddAll(r, BreakModify(entry));
                            }
                        }
                        else
                        {
                            if (entry.oldMode != entry.newMode)
                            {
                                entry.changeType = DiffEntry.ChangeType.MODIFY;
                                r.AddItem(entry);
                            }
                        }
                    }
                }
                if (includeTrees && walk.IsSubtree)
                {
                    walk.EnterSubtree();
                }
            }
            return(r);
        }
コード例 #37
0
        private void negotiate(ProgressMonitor monitor)
        {
            MutableObjectId ackId = new MutableObjectId();
            int resultsPending = 0;
            int havesSent = 0;
            int havesSinceLastContinue = 0;
            bool receivedContinue = false;
            bool receivedAck = false;
            bool sendHaves = true;

            negotiateBegin();
            while (sendHaves)
            {
                RevCommit c = walk.next();
                if (c == null) break;

                pckOut.WriteString("have " + c.getId().Name + "\n");
                havesSent++;
                havesSinceLastContinue++;

                if ((31 & havesSent) != 0)
                {
                    continue;
                }

                if (monitor.IsCancelled)
                    throw new CancelledException();

                pckOut.End();
                resultsPending++;

                if (havesSent == 32)
                {
                    continue;
                }

                for (;;)
                {
                    PacketLineIn.AckNackResult anr;

                    anr = pckIn.readACK(ackId);
                    if (anr == PacketLineIn.AckNackResult.NAK)
                    {
                        resultsPending--;
                        break;
                    }

                    if (anr == PacketLineIn.AckNackResult.ACK)
                    {
                        multiAck = false;
                        resultsPending = 0;
                        receivedAck = true;
                        sendHaves = false;
                        break;
                    }

                    if (anr == PacketLineIn.AckNackResult.ACK_CONTINUE)
                    {
                        markCommon(walk.parseAny(ackId));
                        receivedAck = true;
                        receivedContinue = true;
                        havesSinceLastContinue = 0;
                    }

                    if (monitor.IsCancelled)
                        throw new CancelledException();
                }

                if (receivedContinue && havesSinceLastContinue > MAX_HAVES)
                {
                    break;
                }
            }

            if (monitor.IsCancelled)
                throw new CancelledException();
            pckOut.WriteString("done\n");
            pckOut.Flush();

            if (!receivedAck)
            {
                multiAck = false;
                resultsPending++;
            }

            while (resultsPending > 0 || multiAck)
            {
                PacketLineIn.AckNackResult anr;

                anr = pckIn.readACK(ackId);
                resultsPending--;

                if (anr == PacketLineIn.AckNackResult.ACK)
                    break;

                if (anr == PacketLineIn.AckNackResult.ACK_CONTINUE)
                    multiAck = true;

                if (monitor.IsCancelled)
                    throw new CancelledException();
            }
        }
コード例 #38
0
        public AckNackResult readACK(MutableObjectId returnedId)
        {
            string line = ReadString();
            if (line.Length == 0)
                throw new PackProtocolException("Expected ACK/NAK, found EOF");
            if ("NAK".Equals(line))
                return AckNackResult.NAK;
            if (line.StartsWith("ACK "))
            {
                returnedId.FromString(line.Slice(4, 44));

                if (line.Length == 44)
                    return AckNackResult.ACK;

                string arg = line.Substring(44);
                if (arg.Equals(" continue"))
                    return AckNackResult.ACK_CONTINUE;
                else if (arg.Equals(" common"))
                    return AckNackResult.ACK_COMMON;
                else if (arg.Equals(" ready"))
                    return AckNackResult.ACK_READY;
            }
            throw new PackProtocolException("Expected ACK/NAK, got: " + line);
        }
コード例 #39
0
 public new CanonicalTreeParser createSubtreeIterator(Repository repo, MutableObjectId idBuffer, WindowCursor curs)
 {
     if (idBuffer == null)
         throw new ArgumentNullException("idBuffer");
     idBuffer.FromRaw(this.idBuffer(), idOffset());
     if (FileMode.Tree != EntryFileMode)
     {
         ObjectId me = idBuffer.ToObjectId();
         throw new IncorrectObjectTypeException(me, Constants.TYPE_TREE);
     }
     return createSubtreeIterator0(repo, idBuffer, curs);
 }
コード例 #40
0
 /**
  * Create a new iterator for the current entry's subtree.
  * <para />
  * The parent reference of the iterator must be <code>this</code>, otherwise
  * the caller would not be able to exit out of the subtree iterator
  * correctly and return to continue walking <code>this</code>.
  *
  * @param repo
  *            repository to load the tree data from.
  * @param idBuffer
  *            temporary ObjectId buffer for use by this method.
  * @param curs
  *            window cursor to use during repository access.
  * @return a new parser that walks over the current subtree.
  * @throws IncorrectObjectTypeException
  *             the current entry is not actually a tree and cannot be parsed
  *             as though it were a tree.
  * @throws IOException
  *             a loose object or pack file could not be Read.
  */
 public virtual AbstractTreeIterator createSubtreeIterator(Repository repo, MutableObjectId idBuffer, WindowCursor curs)
 {
     return(createSubtreeIterator(repo));
 }
コード例 #41
0
 /**
  * Create a new iterator for the current entry's subtree.
  * <p>
  * The parent reference of the iterator must be <code>this</code>, otherwise
  * the caller would not be able to exit out of the subtree iterator
  * correctly and return to continue walking <code>this</code>.
  *
  * @param repo
  *            repository to load the tree data from.
  * @param idBuffer
  *            temporary ObjectId buffer for use by this method.
  * @param curs
  *            window cursor to use during repository access.
  * @return a new parser that walks over the current subtree.
  * @throws IncorrectObjectTypeException
  *             the current entry is not actually a tree and cannot be parsed
  *             as though it were a tree.
  * @throws IOException
  *             a loose object or pack file could not be read.
  */
 public virtual AbstractTreeIterator createSubtreeIterator(Repository repo, MutableObjectId idBuffer, WindowCursor curs)
 {
     return createSubtreeIterator(repo);
 }
コード例 #42
0
 public new CanonicalTreeParser createSubtreeIterator(Repository repo, MutableObjectId idBuffer, WindowCursor curs)
 {
     idBuffer.FromRaw(this.idBuffer(), this.idOffset());
     if (!FileMode.Tree.Equals(mode))
     {
         ObjectId me = idBuffer.ToObjectId();
         throw new IncorrectObjectTypeException(me, Constants.TYPE_TREE);
     }
     return createSubtreeIterator0(repo, idBuffer, curs);
 }
コード例 #43
0
 /**
  * Obtain the ObjectId for the current entry.
  *
  * @param out
  *            buffer to copy the object id into.
  */
 public virtual void getEntryObjectId(MutableObjectId @out)
 {
     @out.FromRaw(idBuffer(), idOffset());
 }