コード例 #1
0
ファイル: DirCacheBuilder.cs プロジェクト: gilran/GitSharp
 private void beforeAdd(DirCacheEntry newEntry)
 {
     if (FileMode.Tree.Equals(newEntry.getRawMode()))
         throw bad(newEntry, "Adding subtree not allowed");
     if (sorted && entryCnt > 0)
     {
         DirCacheEntry lastEntry = entries[entryCnt - 1];
         int cr = DirCache.cmp(lastEntry, newEntry);
         if (cr > 0)
         {
             // The new entry sorts before the old entry; we are
             // no longer sorted correctly. We'll need to redo
             // the sorting before we can close out the build.
             //
             sorted = false;
         }
         else if (cr == 0)
         {
             // Same file path; we can only insert this if the
             // stages won't be violated.
             //
             int peStage = lastEntry.getStage();
             int dceStage = newEntry.getStage();
             if (peStage == dceStage)
                 throw bad(newEntry, "Duplicate stages not allowed");
             if (peStage == 0 || dceStage == 0)
                 throw bad(newEntry, "Mixed stages not allowed");
             if (peStage > dceStage)
                 sorted = false;
         }
     }
 }
コード例 #2
0
        public void testBuildOneFile_FinishWriteCommit()
        {
            string path = "a-File-path";
            var mode = GitSharp.FileMode.RegularFile;
            long lastModified = 1218123387057L;
            int Length = 1342;
            DirCacheEntry entOrig;

            DirCache dc = DirCache.Lock(db);
            DirCacheBuilder b = dc.builder();
            Assert.IsNotNull(b);

            entOrig = new DirCacheEntry(path);
            entOrig.setFileMode(mode);
            entOrig.setLastModified(lastModified);
            entOrig.setLength(Length);

            Assert.AreNotSame(path, entOrig.getPathString());
            Assert.AreEqual(path, entOrig.getPathString());
            Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId());
            Assert.AreEqual(mode.Bits, entOrig.getRawMode());
            Assert.AreEqual(0, entOrig.getStage());
            Assert.AreEqual(lastModified, entOrig.getLastModified());
            Assert.AreEqual(Length, entOrig.getLength());
            Assert.IsFalse(entOrig.isAssumeValid());
            b.add(entOrig);

            b.finish();
            Assert.AreEqual(1, dc.getEntryCount());
            Assert.AreSame(entOrig, dc.getEntry(0));

            dc.write();
            Assert.IsTrue(dc.commit());

            dc = DirCache.read(db);
            Assert.AreEqual(1, dc.getEntryCount());

            DirCacheEntry entRead = dc.getEntry(0);
            Assert.AreNotSame(entOrig, entRead);
            Assert.AreEqual(path, entRead.getPathString());
            Assert.AreEqual(ObjectId.ZeroId, entOrig.getObjectId());
            Assert.AreEqual(mode.Bits, entOrig.getRawMode());
            Assert.AreEqual(0, entOrig.getStage());
            Assert.AreEqual(lastModified, entOrig.getLastModified());
            Assert.AreEqual(Length, entOrig.getLength());
            Assert.IsFalse(entOrig.isAssumeValid());
        }
コード例 #3
0
 public static bool Equals(CGitIndexRecord cgir, DirCacheEntry dirCacheEntry)
 {
     return cgir.Mode == dirCacheEntry.getRawMode() &&
            cgir.Id == dirCacheEntry.getObjectId() &&
            cgir.Stage == dirCacheEntry.getStage() &&
            cgir.Path == dirCacheEntry.getPathString();
 }
コード例 #4
0
        private void ParseEntry()
        {
            _currentEntry = Cache.getEntry(_pointer);
            byte[] cep = _currentEntry.Path;

            if (_nextSubtreePos != Tree.getChildCount())
            {
                DirCacheTree s = Tree.getChild(_nextSubtreePos);
                if (s.contains(cep, PathOffset, cep.Length))
                {
                    // The current position is the first file of this subtree.
                    // Use the subtree instead as the current position.
                    //
                    _currentSubtree = s;
                    _nextSubtreePos++;

                    if (s.isValid())
                    {
                        s.getObjectId().copyRawTo(SubtreeId, 0);
                    }
                    else
                    {
                        SubtreeId.Fill((byte)0);
                    }

                    Mode = FileMode.Tree.Bits;

                    Path = cep;
                    PathLen = PathOffset + s.nameLength();
                    return;
                }
            }

            // The current position is a file/symlink/gitlink so we
            // do not have a subtree located here.
            //
            Mode = _currentEntry.getRawMode();
            Path = cep;
            PathLen = cep.Length;
            _currentSubtree = null;
        }
コード例 #5
0
        private static void AssertAreEqual(CGitIndexRecord c, DirCacheEntry j)
        {
            Assert.IsNotNull(c);
            Assert.IsNotNull(j);

            Assert.AreEqual(c.Path, j.getPathString());
            Assert.AreEqual(c.Id, j.getObjectId());
            Assert.AreEqual(c.Mode, j.getRawMode());
            Assert.AreEqual(c.Stage, j.getStage());
        }